找回密码
 加入
搜索
查看: 5662|回复: 8

注册表 .REG转.AU3文件 Beta 1.01

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

同意,貌似楼主经常放出这种“残疾”脚本:有的#include用全角字符,有的代码不完整……
比如:http://www.autoitx.com/forum.php ... &extra=page%3D1
但是楼主收集脚本的广度和乐于分享的精神还是值得学习的!
发表于 2008-5-10 23:46:13 | 显示全部楼层
是的。楼主非常之不负责。。。我是非常的BS他。。。
发表于 2009-5-27 16:02:53 | 显示全部楼层
都说不对,那我路过了
发表于 2009-5-28 20:02:34 | 显示全部楼层
还行吧还行吧还行吧还行吧
发表于 2012-1-1 01:19:18 | 显示全部楼层
好啊好啊好啊好啊好啊好啊好啊好啊
发表于 2012-1-19 20:55:10 | 显示全部楼层
应该顶一下的,辛苦了!
发表于 2018-11-13 15:46:58 | 显示全部楼层
学习学习,谢谢分享
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-22 22:01 , Processed in 0.075206 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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