AU3-BC2辅助更新源码
#NoTrayIconDim $UpdateNow, $Refb, $RunError, $CodeTest
$SN = StringSplit(@ScriptName, ".")
$Section = $SN[1]
$IniFile = @ScriptDir&Chr(92)&$Section&".ini"
If $CmdLine[0] <> 0 Then
$Section = $CmdLine[1]
Else
$Section = InputBox("提示", "请输入游戏名称", "", "", 1, 1, -1, -1)
If @error Or $Section = '' Then Exit
EndIf
$g_szVersion = $Section
If WinExists('《'&$g_szVersion&'》') Then
MsgBox(4160, '提示', '《'&$g_szVersion&'》更新已存在!', 3)
Exit
EndIf
AutoItWinSetTitle('《'&$g_szVersion&'》')
$CodeTest = "OK"
$Images = IniRead($IniFile, $Section, "同步目录", "")
If $Images = "" Then
While Not FileExists($Images) OR $Images = ""
$Images = FileSelectFolder('请指定或输入《'&$Section&'》的同步目录所在位置。例如:\\Server\Share\'&$Section, "", 4)
If @error Then Exit 0
If FileExists($Images) AND $Images <> "" Then IniWrite($IniFile, $Section, "同步目录", '"'&$Images&'"')
WEnd
EndIf
$OldInfo = IniRead($IniFile, $Section, "同步信息", "")
$RunPath = IniRead($IniFile, $Section, "游戏目录", "")
$RunName = IniRead($IniFile, $Section, "执行文件", "")
If $RunPath <> "" AND FileExists($RunPath) Then SplashTextOn('《'&$g_szVersion&'》', '等待更新《'&$g_szVersion&'》......', -1, 24, 0, 0, 1, '', 18, 0)
$size = DirGetSize($Images, 1)
$time = FileGetTime($Images, 0, 1)
If $size = -1 OR $time = 1 Then
$NewInfo = ''
ElseIf $size[0] = 0 Then
$NewInfo = ''
Else
$NewInfo = StringReplace(($size[1]+$size[2]+$size[0])/($time*($size[1]+$size[2])), "e-", "");这里会导至某些游戏验证慢。
EndIf
IniWrite($IniFile, $Section, "同步信息", '"'&$OldInfo&'"')
If $RunPath <> "" AND Not FileExists($RunPath) Then DirCreate($RunPath)
If $RunPath = "" OR $RunName = "" OR Not FileExists($RunPath) Then
While Not FileExists($RunPath) OR $RunPath = "" OR $RunName = ""
$FullName = FileOpenDialog('请指定《'&$Section&'》执行文件所在位置,如无文件夹请按取消然后创建。', "", "执行文件(*.exe;*.com;*.bat)", 1+4)
If @error Then
$RunPath = FileSelectFolder('请指定或输入《'&$Section&'》文件夹所在位置,或新建文件夹。', "", 1+2+4)
If @error Then Exit
$FullName = FileOpenDialog('请指定《'&$Section&'》执行文件名,或按取消手动输入。', $Images, "执行文件(*.exe;*.com;*.bat)", 1+4)
If @error Then
$RunName = InputBox("提示", "请手动输入游戏执行文件名", "", "", 1, 1, -1, -1)
If @error Then Exit
$FN = StringSplit($RunName, ".")
If $FN[0] = 1 Then $RunName = $FN[1]&'.exe'
Else
$FN = StringSplit($FullName, "\")
$RunName = $FN[$FN[0]]
EndIf
Else
$FN = StringSplit($FullName, "\")
$RunName = $FN[$FN[0]]
$RunPath = StringReplace($FullName, "\"&$FN[$FN[0]], "")
EndIf
WEnd
IniWrite($IniFile, $Section, "游戏目录", '"'&$RunPath&'"')
IniWrite($IniFile, $Section, "执行文件", '"'&$RunName&'"')
$ShortcutName = FileSaveDialog('请指定创建游戏快捷方式位置。', @DesktopDir, "快捷方式(*.lnk)", 1+2+4+8, $Section)
If Not @error Then FileCreateShortcut( _
@ScriptFullPath, _
$ShortcutName, "", '"'&$Section&'"', "Make By Amu", $RunPath&Chr(92)&$RunName, "", "0")
$UpdateNow = MsgBox(36,"提示!","是否立即运行更新?")
If $UpdateNow = 7 Then Exit 0
EndIf
If Not FileExists($RunPath&Chr(92)&$RunName) AND $RunPath <> "" AND $RunName <> "" Then $Refb = 1
If ( FileExists($Images) AND $NewInfo <> $OldInfo ) OR ( Not FileExists($RunPath&Chr(92)&$RunName) AND $RunPath <> "" AND $RunName <> "" ) Then
;安装BC2软件
$BC2Name = _InstallBC2()
$FormPos = Int((@DesktopWidth-401)/2)&','&Int((@DesktopHeight-351)/2)&','&Int((@DesktopWidth-401)/2)+112&','&Int((@DesktopHeight-351)/2)+27&',1,0,96'
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmFileMove", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmFileCompare", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmFileCopy", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmFolderCreate", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmReadonly", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmOverwriteSysFile", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmMoveOverExisting", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfirmContentCompare", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "SyncInteractive", "REG_DWORD", "1")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ConfigMode", "REG_DWORD", "4")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "SyncRight", "REG_SZ", "0022224100")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "ShowOnStartup", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\Settings", "Recycle", "REG_DWORD", "0")
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\FolderViewer", "FormPos", "REG_SZ", $FormPos)
RegWrite("HKCU\Software\Scooter Software\Beyond Compare\FolderViewer\Menu", "SyncRight", "REG_DWORD", "16834642")
$Pid = -1
If FileExists($BC2Name) AND $CodeTest = "OK" Then $Pid = Run($BC2Name&' /expandall "'&$Images&'" "'&$RunPath&'"', @TempDir )
$Title = '正在更新《'&$g_szVersion&'》'
AutoItSetOption("WinTitleMatchMode", 4)
While ProcessExists($Pid) AND Not WinExists('同步预览', '')
WinActivate("classname=TApplication", '' )
Send('+^!r')
Sleep(100)
WEnd
SplashOff()
While ProcessExists($Pid) AND WinExists('同步预览', '')
If ControlCommand('同步预览', '', 'TButton3', "IsVisible", "") = 1 Then
If ControlCommand('同步预览', '', 'TButton3', "IsEnabled", "") = 1 Then ControlClick('同步预览', '', 'TButton3')
Sleep(100)
If WinExists('同步到', '') Then
WinSetTitle('同步到', '', $Title)
$TitlePos = WinGetPos($Title, '')
WinMove($Title, '', $TitlePos[0], $TitlePos[1], 399, 131 )
ControlMove($Title, '', 'TBCCheckBox1', -13, 80, 400, 17)
ControlSetText($Title, '', 'TBCCheckBox1', '注意!更新过程中请不要强行退出,否则不能正常进入游戏。')
ControlHide($Title, '取消', 'TButton2')
WinSetState("classname=TDirectoryViewerForm", '', @SW_HIDE )
WinSetTitle("classname=TApplication", "", $g_szVersion)
ExitLoop
EndIf
Else
Sleep(100)
ControlClick('同步预览', '取消', 'TButton2')
ExitLoop
EndIf
WEnd
While ProcessExists($Pid) AND WinExists($Title, '')
If WinExists($Title, '无法') AND ControlCommand($Title, '', 'TButton2', "IsVisible", "") = 0 Then
ControlShow($Title, '', 'TButton2')
ControlSetText($Title, '', 'TBCCheckBox1', '更新过程中出现错误,可能无法正常运行游戏;请与网管联系。')
EndIf
If WinGetState("classname=TDirectoryViewerForm", '') = 2 Then WinSetState("classname=TDirectoryViewerForm", '', @SW_HIDE )
If ControlCommand($Title, "", "TBCCheckBox1", "IsChecked", "") = 1 Then _
ControlCommand($Title, "", "TBCCheckBox1", "UnCheck", "")
If WinExists($Title, '请求') AND $RunError <> 1 Then
WinSetTitle( $Title, '请求', '已取消更新《'&$g_szVersion&'》' )
$RunError = 1
EndIf
Sleep(500)
WEnd
ProcessClose($Pid)
SplashOff()
If $CodeTest = "OK" Then IniWrite($IniFile, $Section, "同步信息", '"'&$NewInfo&'"')
If $Refb = 1 Then
$RefbFile = @TempDir&Chr(92)&Chr(Random(Asc("A"), Asc("Z"), 1))&'.tmp'
IniWrite($RefbFile, "version", "signature", "$chicago$" )
IniWrite($RefbFile, "version", "SetupClass", "BASE" )
RunWait('rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 '&$RefbFile, @SystemDir, @SW_HIDE)
If FileExists($RefbFile) Then FileDelete($RefbFile)
EndIf
;清除临时文件
FileRecycleEmpty()
RegDelete("HKCU\Software\Scooter Software")
If FileExists($BC2Name) Then
FileDelete($BC2Name)
FileDelete(@TempDir&'\bc2.key')
EndIf
EndIf
If $RunError = 1 Then Exit 1
;导入注册表
$RN = StringSplit($RunName, ".")
$RegFile = 'Path.dll'
If FileExists($RunPath&Chr(92)&$RegFile) Then RunWait('Regedit.exe -s "'&$RunPath&Chr(92)&$RegFile&'"', @SystemDir)
$RegFile = $RN[1]&'.reg'
If FileExists($RunPath&Chr(92)&$RegFile) Then RunWait('Regedit.exe -s "'&$RunPath&Chr(92)&$RegFile&'"', @SystemDir)
;不运行游戏
If StringLower($CmdLine[$CmdLine[0]]) = '-n' OR StringLower($CmdLine[$CmdLine[0]]) = '-norun' OR $UpdateNow = 6 Then
MsgBox(0, $g_szVersion, '《'&$g_szVersion&'》更新已完成', 1)
Exit
EndIf
;运行游戏
If FileExists($RunPath&Chr(92)&$RunName) AND $RunPath <> "" AND $RunName <> "" Then Run($RunPath&Chr(92)&$RunName, $RunPath)
;自定义函数
Func _InstallBC2()
$b = Chr(92)&Chr(Random(Asc("a"), Asc("z"), 1))
For $i = 1 to Random(2, 7, 1)
$b = $b&Chr(Random(Asc("a"), Asc("z"), 1))
Next
$b = @TempDir&$b&'.exe'
FileInstall ("c:\bc2.exe", $b, 1)
FileInstall ("c:\bc2.key", @TempDir&'\bc2.key', 1)
return $b
EndFunc 这个我找了好久,终出现了。谢谢!楼主!
页:
[1]