找回密码
 加入
搜索
楼主: 131738

[原创] 更新 AutoIt v3.3.14.5 (2) 中文安装包

 火...   [复制链接]
发表于 2011-5-27 20:15:53 | 显示全部楼层
好的。谢谢
 楼主| 发表于 2011-5-27 16:00:35 | 显示全部楼层
本帖最后由 131738 于 2011-5-27 16:07 编辑
回复  131738


    很久没弄这个了,都忘了… 就前辈反映的241行的问题,我做了简单测试_FileSearchTo ...
afan 发表于 2011-5-27 13:28


不做任何修改,功能完全正常,我现在是要添加功能:

将函数解释的的英文描述与对应的中文写入二维数组,然后在脚本中 For 读入到窗口对应的输入框

(代替手工操作),这一步能正常操作到数组读完,而且脚本读取输入框的数据也正常,但到这个脚本的:
RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & $sFilter & '" /a:-d /b /s > ' & $sOUT, '', 0);写记录文件
不能生成相应的 $afilelist 文件清单数组,使得后面的搜索替换失败,$$$_____temp_filelist.txt 文件为空。

这一句大概是 DOS 命令吧,后面一句是正则,都是我不懂的。。。。。。。。。。。。

只是想能够一键汉化全部函数解释部分,然后慢慢向二维数组添加其它数据,至到加入全部需汉化的

数据,免了手工操作的麻烦,如此法能实现,则可每类函数做一个,实现每类函数都能一键汉化,

然后再检测到未汉化的就可断定是变动部分了,在然后修改这个二维数组。。。。

说了这许多,不知我意思表达明白了没有,我的语文水平实在不怎么样的。。。谢谢!!!
发表于 2011-5-27 15:42:32 | 显示全部楼层
谢谢分享哈
发表于 2011-5-27 13:28:58 | 显示全部楼层
本帖最后由 afan 于 2011-5-27 13:32 编辑

回复 1243# 131738


    很久没弄这个了,都忘了… 就前辈反映的241行的问题,我做了简单测试_FileSearchToArray(),没发现任何问题,$$$_____temp_filelist.txt 文件完全正确的记录了文件路径。
是不是win7的原因,我这是xpsp3?
#include <Array.au3>

$aFileList = _FileSearchToArray('html文件夹', '*.htm')
_ArrayDisplay($aFileList)

Func _FileSearchToArray($sPath, $sFilter = '*.*') ;遍历搜索*.htm文件(包括子目录)到数组
        If StringRight($sPath, 1) <> '\' Then $sPath &= '\' ;路径变量加 "" 结尾
        If Not StringInStr(FileGetAttrib($sPath), 'D') Then Return SetError(1, 0, 0) ;无此目录,则返回错误
        If StringReplace($sFilter, ' ', '') = '' Then $sFilter = '*';文件类型变量为空,则变量='*'
        Local $sOUT = @ScriptDir & '\$$$_____temp_filelist.txt' 
        FileClose(FileOpen($sOUT, 2));清空记录文本
        RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & $sFilter & '" /a:-d /b /s > ' & $sOUT, '', 0);写记录文件
        Local $FR = FileRead($sOUT);读记录文件
        ;FileDelete($sOUT);删除记录文件
        Local $afilelist = StringRegExp('1' & @CRLF & $FR, '\V+', 3);返回全局匹配的数组
        If @error Or UBound($afilelist) = 1 Then Return SetError(2, 0, 0) ;该目录无文件
        $afilelist[0] = UBound($afilelist) - 1        
        Return $afilelist
EndFunc   ;==>_FileSearchToArray
 楼主| 发表于 2011-5-27 11:10:28 | 显示全部楼层
本帖最后由 131738 于 2011-5-27 11:49 编辑
搜索、替换、改格式 近500个文件不到4秒,效率是不用说的,呵呵~
afan 发表于 2010-12-1 03:47


看到你在线,焦头烂额,又向你求教了,还是汉化问题,帮忙看看这段代码,

在原来基础上,想增加英-汉对应的数组操,二维数组已建好,调试到 241 行后没有反应了,

生成的 $$$_____temp_filelist.txt 文件为空!想另外做个与 _FileSearchToArray 函数生成的这个文件又无从下手!

“编码转换”按钮功能正常,问题在“替换字符”按钮上。打扰了。。。谢谢!!!
#AutoIt3Wrapper_Icon=E:\Icon_1.ico
#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region 英-汉数据数组
Global $Chinese[11][2]
$Chinese[0][0]="Below is a complete list of the functions available in AutoIt"
$Chinese[0][1]="下面是 AutoIt 函数的完整列表"
$Chinese[1][0]="Calculates the absolute value of a number"
$Chinese[1][1]="计算数的绝对值"
$Chinese[2][0]="Calculates the arcCosine of a number"
$Chinese[2][1]="计算数的反余弦值"
$Chinese[3][0]="Registers an Adlib function"
$Chinese[3][1]="注册 Adlib 函数"
$Chinese[4][0]="Unregisters an adlib function"
$Chinese[4][1]="注销 Adlib 函数"
$Chinese[5][0]="Returns the ASCII code of a character"
$Chinese[5][1]="返回字符的 ASCII 码"
$Chinese[6][0]="Returns the unicode code of a character"
$Chinese[6][1]="返回字符的 Unicode 代码"
$Chinese[7][0]="Calculates the arcsine of a number"
$Chinese[7][1]="计算数的反正弦值"
$Chinese[8][0]="Assigns a variable by name with the data"
$Chinese[8][1]="给变量赋值"
$Chinese[9][0]="Calculates the arctangent of a number"
$Chinese[9][1]="计算数的反正切值"
$Chinese[10][0]="Changes the operation of various AutoIt functions/parameters"
$Chinese[10][1]="调整 Autoit 函数或参数的操作方式"
#EndRegion 英-汉数据数组
;_ArrayDisplay($Chinese,'Debug~~~')
# ==============================================================================

Global $BakDir = 'E:\htm备份\html\'
Global $LogFile = @ScriptDir & '\替换记录.txt'
Global $filesl[1] ;拖入的文件数组
Global $File_Path, $File_Array
Global $A = "Calculates the absolute value of a number"
Global $B = "计算数的绝对值"
If FileExists(@ScriptDir & '\替换.ini') = 0 Then
        _FileCreate(@ScriptDir & '\替换.ini')
        IniWrite(@ScriptDir & '\替换.ini', "配置", "路径", "")
        ;IniWrite(@ScriptDir & '\替换.ini', "配置", "换码", "0")
Else
        $Path = IniRead(@ScriptDir & '\替换.ini', "配置", "路径", "0")
        ;$State = IniRead(@ScriptDir & '\替换.ini', "配置", "换码", "0")
EndIf

$Form1_1 = GUICreate("Form1", 633, 105, 2, 2, BitOR($WS_POPUP, $WS_BORDER), _
                BitOR($WS_EX_DLGMODALFRAME, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES)) ;$WS_EX_ACCEPTFILES支持拖放
$Button1 = GUICtrlCreateButton("文 本 替 换", 520, 80, 105, 20)
$Button2 = GUICtrlCreateButton("编 码 替 换", 345, 80, 105, 20)
$Button3 = GUICtrlCreateButton("退       出", 170, 80, 105, 20)

$Label1 = GUICtrlCreateLabel("搜索字符", 5, 30, 52, 17)
$Label2 = GUICtrlCreateLabel("替换字符", 5, 57, 52, 17)
$Label3 = GUICtrlCreateLabel("文件地址", 5, 7, 52, 17)
$Label4 = GUICtrlCreateLabel("当前完成", 5, 85, 65, 17)

$Input3 = GUICtrlCreateInput($Path, 62, 5, 560, 17);输入文件路径
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$Input1 = GUICtrlCreateInput("", 62, 28, 560, 20)
$Input2 = GUICtrlCreateInput("", 62, 56, 560, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
$Input4 = GUICtrlCreateInput("", 62, 82, 80, 17)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $GUI_EVENT_DROPPED ;拖入文件 MsgBox(0,0,$GUI_EVENT_DROPPED)=-13
                        Local $mouse = GUIGetCursorInfo($Form1_1);获取相对于 GUI 窗口的鼠标光标位置,返回包含光标信息的 5 元素数组
                        ;发送命令到指定控件,$mouse[4]=光标下控件ID,'GetSelected'=返回编辑框选定的文本
                        Local $_str = ControlCommand($Form1_1, '', $mouse[4], 'GetSelected', '');返回拖放文件的完整路径+文件名
                        GUICtrlSetData($Input3, $_str);完整路径+文件名写入地址框
                Case $Button1 ;文本替换
                        _Abcdef();_Replacement(GUICtrlRead($Input3));读取路径作为传递的参数
                Case $Button2 ;编码替换
                        _format(GUICtrlRead($Input3));读取路径作为传递的参数
                Case $Button3 ;退出
                        Global $Path01 = GUICtrlRead($Input3)
                        ;Global $State0 = GUICtrlGetState($Button2)
                        ;If $State0 = 144 Then $State = 1;禁用=144 ,启用= 80 设置 0=启用  1=禁用
                        If $Path01 = '' Then $State = 0
                        IniWrite(@ScriptDir & '\替换.ini', "配置", "路径", $Path01)
                        ;IniWrite(@ScriptDir & '\替换.ini', "配置", "换码", $State)
                        Exit
        EndSwitch
WEnd

Func _format($WorkDir) ;编码替换
        If $WorkDir = "" Or $WorkDir = "输入文件路径,或直接拖入文件" Then Return MsgBox(0, 0, "无路径!", 1)
        Local $szDrive, $szDir, $szFName, $szExt
        #Region 处理 目录文件 开始
        Local $File_Path2 = _PathSplit($WorkDir, $szDrive, $szDir, $szFName, $szExt);完整路径拆分
        Local $File = $File_Path2[1] & $File_Path2[2] & 'AutoIt3 TOC.hhc'
        Local $str = String(FileRead($File));返回表达式的字符串结果
        $str = StringRegExpReplace($str, '(?<=\w)%20(?=\w)', ' ')
        If Not @error And @extended > 0 Then
                FileMove($File, $File & '.bak');移动文件为备份文件
                FileWrite($File, $str)
        EndIf
        #EndRegion 处理 目录文件 开始
        Local $ts = TimerInit() ;返回一个时间戳(开始计算耗时)
        Local $File_Array = _FileSearchToArray($WorkDir, '*.htm') ;遍历搜索*.htm文件(包括子目录)到数组 $File_Array[$i]=完整路径+文件名 $i 从 1 开始循环
        If @error Then Return MsgBox(4096, '错误', '未搜索到文件 ')
        Local $FR, $thStr, $FLog1 = '', $FLog2 = '', $x1 = 0, $x2 = 0

        For $i = 1 To $File_Array[0]
                $FR = String(FileRead($File_Array[$i]))

                Local $ChangeBj1 = 0, $ChangeBj2 = 0 ;修改标记                
                $FR = StringRegExpReplace($FR, '(?i)(?<=h1>)Function Reference(?=</h1>)', '函 数 参 考')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)Parameters(?=</b>)', '参 数')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)Return Value(?=</b>)', '返 回 值')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)Remarks(?=</b>)', '备 注')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)Related(?=</b>)', '相 关 函 数')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)Example(?=</b>)', '函 数 示 例')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=valign="top">)Success(?=:</td>)', '成 功')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=valign="top">)Failure(?=:</td>)', '失 败')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=h1>)Keyword Reference(?=</h1>)', '关 键 字 参 考')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)See Also(?=</b>)', '参 考 资 料')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1
                $FR = StringRegExpReplace($FR, '(?i)(?<=b>)\[optional\](?=</b>)', '可选参数');b>[optional]</b>
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;b>[optional]</b>
                $FR = StringRegExpReplace($FR, '(?i)(?<=">)Old(?=</th>)', '旧 名')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;        >Old</th>
                $FR = StringRegExpReplace($FR, '(?i)(?<=">)New(?=</th>)', '新 名')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;>New</th>
                $FR = StringRegExpReplace($FR, '(?i)(?<=">)Comments(?=</th>)', '注 解')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;>Comments</th>        
                
                $FR = StringRegExpReplace($FR, '(?<=\s)Success:', '成 功:')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;>Comments</th>
                
                $FR = StringRegExpReplace($FR, '(?<=br>\h)Failure(?=:)', '失 败:');??????????????
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;br>Failure: 
                
                $FR = StringRegExpReplace($FR, '(?i)(?<=>)Returns 0.(?=</)', '返回 0.')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1;>Returns 0.</
                
                $FR = StringRegExpReplace($FR, '(?<=b>)User Defined Function(?=</b>)', '用 户 定 义 函 数')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;b>User Defined Function</b>
                
                $FR = StringRegExpReplace($FR, '(?<=b>)Description(?=</b>)', '描 述')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;b>Description</b>
                
                $FR = StringRegExpReplace($FR, '(?<=\s)user defined functions Reference(?=</h1>)', '用户定义函数参考')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;user defined functions Reference</h1>
                
                $FR = StringRegExpReplace($FR, '(?<=p>)user defined functions Reference(?=\s)', '要使用它们,你需要添加语句:');????????????
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;<p>When using them you need to add a
                
                $FR = StringRegExpReplace($FR, '(?<=p>)user defined functions Reference(?=. )', '下面是定义在 AutoIt 中的用户定义函数完整列表');???????????
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;<p>Below is a complete list of the user defined functions available in AutoIt
                
                $FR = StringRegExpReplace($FR, '(?<=\s)Click on a user defined function name for a detailed description.(?=</p>)', '点击用户定义函数的名称查阅详细描述.')
                If Not @error And @extended > 0 Then $ChangeBj1 = 1 ;Click on a user defined function name for a detailed description.</p>
                
                If $ChangeBj1 Then ;有汉化字符
                        $FLog1 &= $File_Array[$i] & @CRLF ;做输出记录
                        $x1 += 1
                EndIf
                ;--------以上先替换这些基本汉化内容
                $thStr = StringRegExpReplace($FR, '(?<=charset=)iso-8859-1(?=")|(?<=charset=)Windows-1252(?=")', 'GB2312', 1)
                If Not @error And @extended > 0 Then ;有修改编码字符
                        $ChangeBj2 = 1
                        $FLog2 &= $File_Array[$i] & @CRLF ;做输出记录
                        $x2 += 1
                EndIf
                ;--------以上替换编码格式字符内容

                If $ChangeBj1 Or $ChangeBj2 Then ;有修改记录
                        FileMove($File_Array[$i], $BakDir & StringRegExpReplace($File_Array[$i], '.+?\\html\\', ''), 9) ;备份文件及目录结构
                        FileWrite($File_Array[$i], $thStr) ;创建ANSI格式文件
                        GUICtrlSetData($Input4, $x1 & ' - ' & $x2);实时显示修改数
                EndIf
        Next
        Local $te = Round(TimerDiff($ts))
        FileDelete($LogFile)
        Local $textOut = '耗时 ' & $te & ' 毫秒' & @CRLF & @CRLF
        If $FLog1 <> '' Then $textOut &= '汉化基本字符文件 ' & $x1 & ' 个,以下为记录:' & @CRLF & $FLog1 & @CRLF & @CRLF
        If $FLog2 <> '' Then $textOut &= '修改为GB2312 编码 ANSI格式的文件 ' & $x2 & ' 个,以下为记录:' & @CRLF & $FLog2 & @CRLF
        FileWrite($LogFile, $textOut)
        ShellExecute($LogFile)
        ;GUICtrlSetState($Button2, $GUI_DISABLE);禁用 编码转换 按钮
EndFunc   ;==>_format

Func _Abcdef()
        For $k = 0 To UBound($Chinese)
                If $Chinese[$k][0] = "" Then Return MsgBox(0, 0, "替换完毕", 1)
                GUICtrlSetData($Input1,$Chinese[$k][0]);读入搜索字串到 $Input1
                Sleep(550)
                GUICtrlSetData($Input2,$Chinese[$k][1]);读入替换字串到 $Input2
                Sleep(550)                
                _Replacement(GUICtrlRead($Input3));读取路径作为传递的参数
        Next        
EndFunc        

Func _Replacement($WorkDir) ;文本替换        
        If $WorkDir = "" Or $WorkDir = "输入文件路径,或直接拖入文件" Then Return MsgBox(0, 0, "无路径!", 1)
        GUICtrlSetData($Input4, "");清空修改数
        Local $Count = 0
        Local $Original = GUICtrlRead($Input1)
        Local $replace = GUICtrlRead($Input2)
        ;遍历搜索*.htm文件(包括子目录)到数组 $File_Array[$i]=完整路径+文件名 $i 从 1 开始循环:
        Local $File_Array = _FileSearchToArray($WorkDir, '*.htm')
        For $i = 1 To UBound($File_Array);[0]+1
                
                $retval = _ReplaceStringInFile($File_Array[$i], $Original, $replace, 0, 1);替换文本文件的字符串
                If Not @error Then
                        $Count += $retval
                        GUICtrlSetData($Input4, $Count);实时显示修改数
                EndIf
        Next
        MsgBox(0, 0, "完成。已替换 " & $Count & " 处。", 1)
        GUICtrlSetData($Input1, "")
        GUICtrlSetData($Input2, "")
EndFunc   ;==>_Replacement

Func _FileSearchToArray($sPath, $sFilter = '*.*') ;遍历搜索*.htm文件(包括子目录)到数组
        If StringRight($sPath, 1) <> '\' Then $sPath &= '\' ;路径变量加 "" 结尾
        If Not StringInStr(FileGetAttrib($sPath), 'D') Then Return SetError(1, 0, 0) ;无此目录,则返回错误
        If StringReplace($sFilter, ' ', '') = '' Then $sFilter = '*';文件类型变量为空,则变量='*'
        Local $sOUT = @ScriptDir & '\$$$_____temp_filelist.txt' 
        FileClose(FileOpen($sOUT, 2));清空记录文本
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPath & $sFilter = ' & $sPath & $sFilter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console        
        RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & $sFilter & '" /a:-d /b /s > ' & $sOUT, '', 0);写记录文件
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPath & $sFilter = ' & $sPath & $sFilter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
        Local $FR = FileRead($sOUT);读记录文件
        ;FileDelete($sOUT);删除记录文件
        Local $afilelist = StringRegExp('1' & @CRLF & $FR, '\V+', 3);返回全局匹配的数组
        If @error Or UBound($afilelist) = 1 Then Return SetError(2, 0, 0) ;该目录无文件
        $afilelist[0] = UBound($afilelist) - 1        
        Return $afilelist
        
EndFunc   ;==>_FileSearchToArray
发表于 2011-5-26 22:12:41 | 显示全部楼层
赶紧的回复啊
发表于 2011-5-26 21:10:38 | 显示全部楼层
强帖,支持
发表于 2011-5-26 15:04:25 | 显示全部楼层
收藏一下。
发表于 2011-5-24 14:44:31 | 显示全部楼层
谢谢楼主分享~~
发表于 2011-5-24 11:10:01 | 显示全部楼层
先顶后下是规矩
发表于 2011-5-23 20:10:29 | 显示全部楼层
谢谢分享,需要这玩意学习一下
发表于 2011-5-23 13:58:08 | 显示全部楼层
收藏一下
以后可能会用到
发表于 2011-5-23 10:15:48 | 显示全部楼层
终于等到更新了,先下载试试
发表于 2011-5-23 07:44:15 | 显示全部楼层
谢谢楼主!!!
发表于 2011-5-23 00:07:18 | 显示全部楼层
谢分享,对初学者来说资料很重要。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 06:20 , Processed in 0.091566 second(s), 16 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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