<p>;;;;;;;;;;;程序写的比较急,比较臃肿,很多地方不完善,大家如果发现有什么BUG可以说出来,我尽量改进。</p><p>;;;;;;;;;;;因为.reg文件比较复杂,程序里面有很多处理字符串的地方,写的又乱,估计大家不容易看懂,见谅.</p><p>;;;;;;;;;;;昨天睡觉突然想到.reg文件的格式和.ini文件比较像,可以用处理INI的几个函数来处理,应该比现在这种方式更简单,不过当时程序已经写好一大半,不太好改了,只能像现在这样.</p><p>;;;;下面是更改楼下所说的错误后的源代码</p><p>#i nclude<GUIConstants.au3><br />#i nclude<file.au3><br />#NoTrayIcon<br />;;改进了处理多行的HEX字段时只能读取第一行的BUG<br />;;改进了处理路径时的BUG<br />;;改进了对目标文件名判断上的一个小BUG<br />GUICreate(".REG转.AU3 Beta 1.02", 425, 145)<br />GUICtrlCreateGroup("", 10, 4, 348, 115) </p><p>$Input1 = GUICtrlCreateInput("", 20, 36, 260, 21, )<br />$Input2 = GUICtrlCreateInput("", 20, 84, 260, 21, -1)</p><p>GUICtrlCreateLabel("待转换.REG文件路径:", 20, 18,-1,17)<br />GUICtrlCreateLabel("转换为.AU3文件路径:", 20, 66,-1,17)<br />GUICtrlCreateLabel("程序制作:路人 技术支持:" , 10, 125,-1,17)<br />$help = GUICtrlCreateLabel("<a href="http://autoit.8800.org/" target="_blank">http://autoit.8800.org</a>" , 200, 125,-1,17)<br />guictrlsetfont($help,-1,-1,4)<br />GUICtrlSetColor($help,0x0000FF)<br />GUICtrlSetCursor($help,0)<br />$Runstatus = GUICtrlCreateLabel("" , 364, 36, 66, 21,0x0201)<br />$Button1 = GUICtrlCreateButton("浏览", 290, 36, 53, 21)<br />$Button2 = GUICtrlCreateButton("浏览", 290, 84, 53, 21)<br />$Button3 = GUICtrlCreateButton("生成", 364, 84, 53, 21)</p><p>GUISetState(@SW_SHOW)<br />While 1<br /> $msg = GuiGetMsg()<br /> Select<br /> Case $msg = $GUI_EVENT_CLOSE <br /> $exit = MsgBox (8192+36,"询问","你确定退出本程序?")<br /> IF $EXIT = 7 THEN <br /> ContinueLoop<br /> ELSE<br /> EXIT<br /> ENDIF<br /> Case $msg = $Button1<br /> $SFile = FileOpenDialog ( "请选择文件", -1, "Windows注册表文件(*.REG)",1 )<br /> IF $SFile Then <br /> GUICtrlSetData($input1,$SFile)<br /> EndIf<br /> Case $msg = $Button2<br /> $DFile = FileOpenDialog ( "请选择文件", -1, "Autoit V3脚本文件(*.AU3)",2 )<br /> IF $DFile Then<br /> GUICtrlSetData($input2,$DFile)<br /> EndIf<br /> Case $msg = $Button3<br /> $SFile = GUICtrlRead($input1)<br /> $DFile = GUICtrlRead($input2)<br /> $checkdfilepath = checkdfilepath($SFile, $DFile)<br /> IF $checkdfilepath = -1 Then<br /> msgbox(8192+16,"错误","源文件并不存在.")<br /> ElseIf $checkdfilepath = -2 Then<br /> msgbox(8192+16,"错误","目标文件名填写不正确!")<br /> ElseIf FileExists($checkdfilepath) Then<br /> $msgbox = MsgBox(8192+256+32+4,"确认覆盖","目标文件已存在,是否覆盖?")<br /> If $msgbox = 7 Then <br /> ContinueLoop<br /> EndIf<br /> MAKE($SFile,$checkdfilepath)<br /> Else<br /> MAKE($SFile,$checkdfilepath)<br /> EndIf<br /> Case $msg = $help<br /> run(@ProgramFilesDir & "\Internet Explorer\IEXPLORE.EXE <a href="http://autoit.8800.org/" target="_blank">http://autoit.8800.org</a>")<br /> EndSelect<br />Wend</p><p>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func checkdfilepath( $SFile, $DFile)<br />If not FileExists($SFile) then<br /> return -1 <br />ElseIf StringLen(StringStripWS($DFile,3)) = 0 Then<br /> $DFile = StringReplace($SFile,stringlen($SFile) - 2 ,"AU3")<br /> GUICtrlSetData($input2,$DFile)<br /> Return $DFile<br />Else<br /> Dim $szDrive, $szDir, $szFName, $szExt<br /> _PathSplit($DFile, $szDrive, $szDir, $szFName, $szExt)<br /> If FileExists($szDrive & $szDir) AND StringStripWS($szFName,3) <> "" AND $szExt = ".AU3" Then<br /> Return $DFile<br /> Else<br /> Return -2<br /> EndIf<br />EndIf<br />EndFunc</p><p>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br />Func make($sfilepath,$dfilepath)<br />dim $value>$tFile = fileopen($sfilepath,0)<br />$lines = filereadline($tFile,1)<br />If stringleft($lines,36) <> "Windows Registry Editor Version 5.00" AND stringleft($lines,8) <> "REGEDIT4" Then<br /> msgbox(8192+16,"错误","源文件的编码格式不为ANSI或它不是一个有效的注册表脚本文件.")<br /> Return<br />EndIf<br />$x = 1<br />while 1 ;;;;;;;;;;;;;;;;;;;;;;;<br /> $x = $x + 1<br /> $lines = filereadline($tFile,$x)<br /> if @error = 1 or @error = -1 then<br /> ExitLoop<br /> EndIf<br /> $lines = StringStripWS($lines,3)<br /> $left1 = stringleft($lines,1)<br /> $left2 = StringMid($lines,2,1)<br /> $reghead = -1<br /> If $left1 = "[" then<br /> if $left2 = "-" Then<br /> $reghead = 2<br /> $key> Else<br /> $key> EndIf<br /> ElseIf $left1 = chr(34) or $left1 = "@" Then<br /> If $key> $reghead = 0<br /> EndIf<br /> $dhArray = StringSplit($lines,"=")<br /> If $dhArray[0] = 2 Then<br /> If stringleft($dhArray[2],1) <> '"' Then<br /> $typeArray = stringsplit($dhArray[2],":")<br /> Else<br /> dim $typeArray[2]<br /> $typeArray[0] = 1<br /> $typeArray[1] = $dhArray[2]<br /> EndIf<br /> ElseIf $dhArray[0] > 2 Then<br /> msgbox(8192,"出错了!","一个错误出现在第" & $x & "行,程序会尝试去解析它,但生成的脚本可能会与源文件有出入。",3)<br /> for $m = 3 to $dhArray[0]<br /> $dhArray[2] = $dhArray[2]& "=" & $dhArray[$m]<br /> Next<br /> If stringleft($dhArray[2],1) <> '"' Then<br /> $typeArray = stringsplit($dhArray[2],":")<br /> Else<br /> dim $typeArray[2]<br /> $typeArray[0] = 1<br /> $typeArray[1] = $dhArray[2]<br /> EndIf<br /> Else<br /> ContinueLoop<br /> EndIf<br /> $value> If $value> $value> EndIf<br /> If $typeArray[0] = 1 Then<br /> If $typeArray[1] = "-" Then<br /> $reghead = 1<br /> Else<br /> $type = '"REG_SZ"'<br /> $value = StringReplace($typeArray[1],"<a href="http://autoit.8800.org/'file:////","/'">\\","\</a>")<br /> EndIf<br /> ElseIf $typeArray[0] = 2 Then<br /> if $typeArray[1] = "dword" Then<br /> $type = '"REG_DWORD"'<br /> $value = chr(39) & dec($typeArray[2]) & chr(39)<br /> Else<br /> If $typeArray[1] = "hex" Then<br /> $type = '"REG_BINARY"'<br /> ElseIf $typeArray[1] = "hex(7)" Then<br /> $type = '"REG_MULTI_SZ"'<br /> ElseIf $typeArray[1] = "hex(2)" Then<br /> $type = '"REG_EXPAND_SZ"'<br /> EndIf<br /> $right1 = StringRight($typeArray[2],1)<br /> $value = $typeArray[2]<br /> while $right1 = "\"<br /> $x = $x + 1<br /> $lines = filereadline($tFile,$x)<br /> if @error = 1 or @error = -1 then<br /> ExitLoop<br /> EndIf<br /> $lines = StringStripWS($lines,3)<br /> $left2 = stringleft($lines,2) <br /> If StringIsXDigit($left2) Then<br /> $value = $value & $lines<br /> EndIf<br /> $right1 = StringRight($lines,1)<br /> WEnd<br /> $value = StringReplace($value, "\", "")<br /> If $type = '"REG_BINARY"' Then<br /> $value = StringReplace($value, ",", "")<br /> ElseIf $type = '"REG_MULTI_SZ"' or $type = '"REG_EXPAND_SZ"' Then<br /> $splitvalue = stringsplit($value,",")<br /> $hexvalue = ""<br /> for $n = 1 to $splitvalue[0] step 2<br /> $chr = chr(dec($splitvalue[$n]))<br /> if $chr <> "" Then<br /> $hexvalue = $hexvalue & $chr<br /> EndIf<br /> Next<br /> $value = $hexvalue<br /> EndIf<br /> $value = chr(39) & $value & chr(39)<br /> EndIf<br /> EndIf<br /> Else<br /> ContinueLoop<br /> EndIf<br /> If $reghead = 0 Then<br /> $wlines = $wlines & "RegWrite (" & chr(39) & $key> ElseIf $reghead = 1 Then<br /> $wlines = $wlines & "RegDelete (" & chr(39) & $key> Elseif $reghead = 2 Then<br /> $wlines = $wlines & "RegDelete (" & chr(39) & $key> EndIf<br />GUICtrlSetData($Runstatus,"处理行" & $x)<br />WEnd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</p><p>FileClose($tFile)<br />$DFilehd = FileOpen($dfilepath,2)<br />$filewrite= FileWrite($DFilehd,$wlines)<br />FileClose($DFilehd)</p><p>If $filewrite Then<br /> GUICtrlSetData($Runstatus,"完成")<br />Else<br /> GUICtrlSetData($Runstatus,"写入失败")<br />EndIf<br />Return<br />EndFunc</p> |