找回密码
 加入
搜索
查看: 9333|回复: 7

[AU3基础] 求助,处理 unicode 格式文件

[复制链接]
发表于 2014-8-10 09:23:14 | 显示全部楼层 |阅读模式
本帖最后由 yuanyannian 于 2014-8-10 09:26 编辑

我是 AU3 外行初学,想处理 .INF 文件(一般都是 unicode 格式,个别是 ANSI 格式),请各位专家指点、修改如下代码,谢谢!
Dim $Msg, $rFile, $iPath, $tPath, $sLoca
$Msg = "Example:  HojoHE.exe -Sdefault -ID:\aaa -TE:\aaa\bbb -L00000409"
If $CmdLine[0]=4 Then
    If StringLeft($CmdLine[1],2)="-S" And StringLeft($CmdLine[2],2)="-I" And StringLeft($CmdLine[3],2)="-T" And StringLeft($CmdLine[4],2)="-L" Then
        $rFile = StringMid($CmdLine[1],3)
        $iPath = StringMid($CmdLine[2],3)
        $tPath = StringMid($CmdLine[3],3)
        $sLoca = StringMid($CmdLine[4],3)
    Else
        MsgBox(0,"Error", "Input Error"& @CRLF & @CRLF & $msg)
    EndIf
ElseIf $CmdLine[0]=3 Then
    If StringLeft($CmdLine[1],2)="-S" And StringLeft($CmdLine[2],2)="-I" And StringLeft($CmdLine[3],2)="-T" Then
        $rFile = StringMid($CmdLine[1],3)
        $iPath = StringMid($CmdLine[2],3)
        $tPath = StringMid($CmdLine[3],3)
    Else
        MsgBox(0,"Error", "Input Error"& @CRLF & @CRLF & $msg)
    EndIf
ElseIf $CmdLine[0]=1 Then
    If ($CmdLine[1])="?" Then
        MsgBox(0,"Exp", $Msg)
    Else
        MsgBox(0,"Error", "Input Error" & @CRLF & @CRLF & "Example:  HojoHE.exe ?")
    EndIf
Else
    MsgBox(0,"Error", "Input Error" & @CRLF & @CRLF & $Msg)
EndIf

; 以下这段太罗嗦了,用vbs 可以数组解决,AU3 我就不会了。
If FileExists($tPath) = 0 Then DirCreate($tPath)
Dim $ss, $File
Select
    Case $rFile = "default"
        If FileExists($iPath & "\HIVEDEF.INF") Then FileCopy($iPath & "\HIVEDEF.INF", $tPath, 1)
        $File = $tPath & "\HIVEDEF.INF"
        FileProcess()
    Case $rFile = "software"
        If FileExists($iPath & "\HIVESFT.INF") Then
            FileCopy($iPath & "\HIVESFT.INF", $tPath, 1)
            $File = $tPath & "\HIVESFT.INF"
            FileProcess()
        EndIf
        If FileExists($iPath & "\HIVECLS.INF") Then
            FileCopy($iPath & "\HIVECLS.INF", $tPath, 1)
            $File = $tPath & "\HIVECLS.INF"
            FileProcess()
        EndIf
        If FileExists($iPath & "\HIVESXS.INF") Then
            FileCopy($iPath & "\HIVESXS.INF", $tPath, 1)
            $File = $tPath & "\HIVESXS.INF"
            FileProcess()
        EndIf
        If FileExists($iPath & "\HIVSFT32.INF") Then
            FileCopy($iPath & "\HIVSFT32.INF", $tPath, 1)
            $File = $tPath & "\HIVSFT32.INF"
            FileProcess()
        EndIf
        If FileExists($iPath & "\HIVCLS32.INF") Then
            FileCopy($iPath & "\HIVCLS32.INF", $tPath, 1)
            $File = $tPath & "\HIVCLS32.INF"
            FileProcess()
        EndIf
        If FileExists($iPath & "\DMREG.INF") Then
            FileCopy($iPath & "\DMREG.INF", $tPath, 1)
            $File = $tPath & "\DMREG.INF"
            FileProcess()
        EndIf
    Case $rFile = "setupreg.hiv"
        If FileExists($iPath & "\HIVESYS.INF") Then FileCopy($iPath & "\HIVESYS.INF", $tPath, 1)
        $File = $tPath & "\HIVESYS.INF"
        FileProcess()
    Case Else
        MsgBox(0, "Error", "The parameter isn't supported!" & @CRLF & @CRLF & "Must be 'default', or 'software', or 'setupreg.hiv'.")
EndSelect

Func FileProcess()
    MsgBox(0,"Error", $File)
;此处,如何判断相应文件,如果是ANSI格式,转换为 unicode 格式?
;此处,如何查找并替换相应文本中的字符串,如果存在就替换,不存在就忽略,并添加行?
;需要替换的内容:
;HKCU," 替换为 HKLM,"WB-default\     (HKCU, 后面可能有空格,如果存在就替换,否则忽略,下同)
;HKLM,"SYSTEM\ 为 HKLM,"WB-setup\
;HKLM,"SOFTWARE\ 为 HKLM,"WB-software\
;HKCR," 为 HKLM,"WB-software\Classes\
;HKCR,. 为 HKLM,WB-software\Classes\.
;添加 [DefaultInstall] 和其下面的 AddReg = AddReg 和 AddReg = AddReg.Upgarde 行
EndFunc
 楼主| 发表于 2014-8-10 20:49:17 | 显示全部楼层
不知是我提的问题太幼稚,或是什么,很着急,却怎么不见热心的帮助?
 楼主| 发表于 2014-8-11 19:18:17 | 显示全部楼层
怎么没有协助,AU3论坛?
发表于 2014-8-11 20:55:35 | 显示全部楼层
本帖最后由 user3000 于 2014-8-11 21:09 编辑

回复 3# yuanyannian

判断文件编码格式: FileGetEncoding
转换ANSI ---> unicode:  StringToBinary   BinaryToString

用数组,简化的代码:
    Case $rFile = "software"
                Local $aSoft[6] = ['HIVESFT.INF', 'HIVECLS.INF', 'HIVESXS.INF', 'HIVSFT32.INF', 'HIVCLS32.INF', 'DMREG.INF']
                For $i = 0 To UBound($aSoft) -1
                     Local $sFile = $iPath & '\' & $aSoft[$i]
             If FileExists($sFile) Then
                FileCopy($sFile, $tPath, 1)
                $File = $tPath & '\' & $aSoft[$i]
                FileProcess()
            EndIf
                Next
 楼主| 发表于 2014-8-12 21:24:24 | 显示全部楼层
回复 4# user3000
感谢了。
另外,我想重点解决:文件处理后如何保持原有文件编码格式不变?比如处理前是 unicode ,处理过程及处理后仍然是 unicode 格式。现在这段代码,处理后会统一变成 ANSI 编码格式。

请求帮助!
 楼主| 发表于 2014-8-15 07:19:25 | 显示全部楼层
为何总是没有高手帮助?
发表于 2014-9-10 23:32:42 | 显示全部楼层
前来学习。。。。。。。。。。。。。。。。。。。
发表于 2014-9-11 13:48:06 | 显示全部楼层
碰到和你一样的问题,试下看看能解决不~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-7-5 12:58 , Processed in 0.085305 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表