Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireAdmin
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Icon=ModTool2.ico
- #AutoIt3Wrapper_Outfile=Siege of Avalon ModTool.exe
- #AutoIt3Wrapper_UseUpx=n
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- If Not @Compiled Then MsgBox(64,"SoA Mod Tool","Das Programm wird nicht kompiliert ausgeführt, für volle Funktionsweise ist es nötig das Programm zu kompilieren!")
- $sProgVer = 'Beta 0.3'
- #include <REOrdner.au3>
- #include <Crypt.au3>
- #include <File.au3>
- #include <GUIConstantsEx.au3>
- #include <ComboConstants.au3>
- ;Opt("TrayIconDebug",1)
- $sIniPath = @ScriptDir & "\SoAMods.ini"
- Global $iInstallMethod
- If IniRead($sIniPath,"General","InstallMethod",'error') = 'error' Then
- IniWrite($sIniPath,"General","InstallMethod",1)
- $iInstallMethod = 1
- Else
- $iInstallMethod = IniRead($sIniPath,"General","InstallMethod",'error') ; 1=Slow 0=Fast(Scheisse)
- EndIf
- $MainForm = GUICreate("SoA Mod Tool " & $sProgVer, 707, 512, 300, 155)
- $MainMenuFile = GUICtrlCreateMenu("&Datei")
- $MainMenuInfo = GUICtrlCreateMenuItem("Info", $MainMenuFile)
- $MainMenuDev = GUICtrlCreateMenuItem("Entwickleroptionen", $MainMenuFile)
- $MainMenuReset = GUICtrlCreateMenuItem("Alles zurücksetzen", $MainMenuFile)
- $MainMenuExit = GUICtrlCreateMenuItem("Beenden", $MainMenuFile)
- $MainModList = GUICtrlCreateList("", 0, 0, 409, 409)
- $MainImportModButton = GUICtrlCreateButton("Mod importieren", 0, 408, 409, 25)
- $MainModActivateButton = GUICtrlCreateButton("Mod aktivieren", 416, 407, 289, 25)
- $MainLabel1 = GUICtrlCreateLabel("Aktiviert:", 536, 0, 54, 20)
- GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
- $MainInterActiveLabelActivated = GUICtrlCreateLabel("Siege of Avalon", 488, 16, 136, 28)
- GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
- $MainDownloadModButton = GUICtrlCreateButton("Mods herunterladen", 416, 368, 289, 33)
- $MainLabel3 = GUICtrlCreateLabel("Von Fliwatt für", 264, 472, 71, 17)
- $MainClickableLableSoamigos = GUICtrlCreateLabel("soamigos.de", 336, 472, 63, 17)
- GUICtrlSetColor(-1, 0x0000FF)
- $MainProgress = GUICtrlCreateProgress(0, 448, 705, 17)
- $MainRunButton = GUICtrlCreateButton("Spiel starten", 416, 48, 289, 33)
- Global $MainInteractiveStatusLabel = GUICtrlCreateLabel("Bereit", 0, 434, 9999, 13)
- GUICtrlSetColor(-1, 0x008000)
- GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
- GUISetState(@SW_SHOW)
- $7ZipPath = @TempDir & "\7za.exe"
- FileInstall("7za.exe",$7ZipPath)
- If IniRead($sIniPath,"General","SoAPath",'error') = 'error' or IniRead($sIniPath,"General","SoAPath",'error') = "" Then
- FileGetLongName(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DigitalTome\Siege of Avalon","InstallPath"))
- If @error Then
- MsgBox(64,"SoA Mod Tool","Bitte wählen sie ihren SoA Pfad aus")
- IniWrite($sIniPath,"General","SoAPath",FileSelectFolder("Bitte wählen sie ihren SoA Pfad aus",""))
- Else
- If MsgBox(4,"SoA Mod Tool","Ist dieser Siege of Avalon Pfad korrekt?" & @CRLF & FileGetLongName(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DigitalTome\Siege of Avalon","InstallPath"))) = 6 Then ;Ja
- IniWrite($sIniPath,"General","SoAPath",FileGetLongName(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DigitalTome\Siege of Avalon","InstallPath")))
- Else
- MsgBox(64,"SoA Mod Tool","Bitte wählen sie ihren SoA Pfad aus")
- While 1
- $sFileSelectFolder = FileSelectFolder("Bitte wählen sie ihren SoA Pfad aus","")
- If $sFileSelectFolder <> '' Then
- IniWrite($sIniPath,"General","SoAPath",$sFileSelectFolder)
- ExitLoop
- Else
- MsgBox(16,"SoA Mod Tool","Ungültiger Pfad!")
- EndIf
- Wend
- EndIf
- EndIf
- EndIf
- Global $sSoaPath = IniRead($sIniPath,"General","SoAPath",'error')
- If IniRead($sIniPath,"General","ModsPath",'error') = 'error' Then IniWrite($sIniPath,"General","ModsPath",@ScriptDir & "\Mods")
- Global $sModsPath = IniRead($sIniPath,"General","ModsPath",'error')
- $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
- $aModNamesRead = IniReadSection($sIniPath,"ModNames")
- If IsArray($aInstalledModPackagesRead) Then
- For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
- GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
- Next
- EndIf
- #region Virtual Storage Check
- Global $bVirtualStore
- Global $sVirtualStoragePath
- If IniRead($sIniPath,"General","VirtualStore",'error') = 'error' Then
- $sVirtualStoragePath = EnvGet("LOCALAPPDATA") & "\VirtualStore\Program Files (x86)\Digital Tome\Siege Of Avalon"
- If FileExists($sVirtualStoragePath) Then
- ;MsgBox(0,"","EXISTS!" & @CRLF & $sVirtualStoragePath)
- IniWrite($sIniPath,"General","VirtualStore",$sVirtualStoragePath)
- $bVirtualStore = 1
- Else
- $bVirtualStore = 0
- EndIf
- ElseIf IniRead($sIniPath,"General","VirtualStore",'error') = '0' Then
- $bVirtualStore = 0
- Else
- $bVirtualStore = 1
- $sVirtualStoragePath = IniRead($sIniPath,"General","VirtualStore",'error')
- EndIf
- #EndRegion Virtual Storage Check
- GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
- If GUICtrlRead($MainInterActiveLabelActivated) = "False" Then
- IniWrite($sIniPath,"General","ActivatedMod","soa")
- IniWrite($sIniPath,"ModNames","soa","Siege of Avalon")
- IniWrite($sIniPath,"InstalledModPackages","soa",1)
- $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
- $aModNamesRead = IniReadSection($sIniPath,"ModNames")
- If IsArray($aInstalledModPackagesRead) Then
- For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
- GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
- Next
- EndIf
- GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
- EndIf
- $SoaModTemp = @TempDir & "\SoAModTemp"
- DirCreate($SoaModTemp)
- While 1
- If GUICtrlRead($MainInteractiveStatusLabel) <> "Bereit" Then
- GUICtrlSetData($MainInteractiveStatusLabel,"Bereit")
- GUICtrlSetColor($MainInteractiveStatusLabel, 0x008000)
- EndIf
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE,$MainMenuExit
- Exit
- Case $MainClickableLableSoamigos
- ShellExecute("http://soamigos.de")
- Case $MainDownloadModButton
- ShellExecute("http://poamigos.yooco.de/p.modpakete.html")
- Case $MainImportModButton
- $sModZipDir = FileOpenDialog("Bitte wählen Sie die .zip Datei aus","","SoA Mod (*.zip)")
- If @error Then ContinueLoop
- GUICtrlSetData($MainInteractiveStatusLabel,"Mod wird eingelesen...")
- GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
- RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $SoaModTemp & '" *.soamod -y')
- If Not FileExists($SoaModTemp & "\info.soamod") Then
- MsgBox(16,"SoA Mod Tool","Fehler im Mod Package: info.soamod fehlt!")
- DirRemove($SoaModTemp,1)
- ContinueLoop
- EndIf
- Local $aSoAModInfo
- _FileReadToArray($SoaModTemp & "\info.soamod",$aSoAModInfo)
- DirRemove($SoaModTemp,1)
- $aSoAModInfo = _ArraySplit($aSoAModInfo,"=",1)
- If _GetValueFromArray($aSoAModInfo,"AddMod") <> False Then
- If IniRead($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),0) = 1 Then
- MsgBox(16,"SoA Mod Tool","Fehler: Dieses Paket wurde bereits installiert")
- ContinueLoop
- EndIf
- ToolTip(_GetValueFromArray($aSoAModInfo,"DisplayName") & " wird installiert...",0,0)
- DirCreate($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod"))
- GUICtrlSetData($MainInteractiveStatusLabel,"Dateien werden extrahiert...")
- GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
- RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & '" -y')
- ConsoleWrite('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & '" -y' & @CRLF)
- FileDelete($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & "\info.soamod")
- IniWrite($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),1)
- IniWrite($sIniPath,"InstalledModPackages",_GetValueFromArray($aSoAModInfo,"AddMod"),1)
- IniWrite($sIniPath,"ModNames",_GetValueFromArray($aSoAModInfo,"AddMod"),_GetValueFromArray($aSoAModInfo,"DisplayName"))
- GUICtrlSetData($MainModList,"|")
- $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
- $aModNamesRead = IniReadSection($sIniPath,"ModNames")
- For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
- GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
- Next
- ToolTip("",0,0)
- Else
- If IniRead($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),0) = 1 Then
- MsgBox(16,"SoA Mod Tool","Fehler: Dieses Paket wurde bereits installiert")
- ContinueLoop
- EndIf
- $aRequiredMods = StringSplit(_GetValueFromArray($aSoAModInfo,"Required"),'|')
- For $iCounter = 1 To $aRequiredMods[0]
- If IniRead($sIniPath,"InstalledMods",$aRequiredMods[$iCounter],0) = 0 Then
- MsgBox(16,"SoA Mod Tool",_GetValueFromArray($aSoAModInfo,"MissingDialog"))
- ContinueCase
- EndIf
- Next
- ToolTip(_GetValueFromArray($aSoAModInfo,"DisplayName") & " wird installiert...",0,0)
- If IniRead($sIniPath,"General","ActivatedMod",'soa') = _GetValueFromArray($aSoAModInfo,"UpdateMod") Then
- GUICtrlSetData($MainInteractiveStatusLabel,"Aktueller Mod wird deaktiviert...")
- GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
- If $iInstallMethod = 0 Then
- FastActivate("soa",1)
- Else
- SlowActivate("soa",1)
- EndIf
- EndIf
- GUICtrlSetData($MainInteractiveStatusLabel,"Dateien werden extrahiert...")
- GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
- RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"UpdateMod") & '" -y')
- FileDelete($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"UpdateMod") & "\info.soamod")
- IniWrite($sIniPath,"ModNames",_GetValueFromArray($aSoAModInfo,"UpdateMod"),_GetValueFromArray($aSoAModInfo,"DisplayName"))
- IniWrite($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),1)
- GUICtrlSetData($MainModList,"|")
- $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
- $aModNamesRead = IniReadSection($sIniPath,"ModNames")
- For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
- GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
- Next
- GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
- ToolTip("",0,0)
- EndIf
- MsgBox(0,"SoA Mod Tool",_GetValueFromArray($aSoAModInfo,"DisplayName") & " wurde erfolgreich installiert!")
- Case $MainModActivateButton
- $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
- $aModNamesRead = IniReadSection($sIniPath,"ModNames")
- Switch $iInstallMethod
- Case 0
- For $iCounter = 1 To $aModNamesRead[0][0]
- If $aModNamesRead[$iCounter][1] = GUICtrlRead($MainModList) Then FastActivate($aModNamesRead[$iCounter][0])
- Next
- Case 1
- For $iCounter = 1 To $aModNamesRead[0][0]
- If $aModNamesRead[$iCounter][1] = GUICtrlRead($MainModList) Then SlowActivate($aModNamesRead[$iCounter][0])
- Next
- EndSwitch
- $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
- If $sCurrentlyActivated = "soa" and IniRead($sSoaPath & "\siege.ini","MapNames","forestcave",'error') = 'error' Then ;SoAmigos Patch Checker
- If MsgBox(68,"SoA Mod Tool","Der SoAmigos Patch 0.7 wurde nicht gefunden," & @CRLF & "es wird drigend empfohlen diesen Patch zu installieren!" & @CRLF & "Wollen sie die Website zum Download öffnen?(Registrierung erforderlich)" & @CRLF & @CRLF & "Bitte den Patch nur installieren, wenn Siege of Avalon aktiviert ist!") = 6 Then ShellExecute("http://soamigos.de/wbb/thread.php?threadid=2748")
- EndIf
- Case $MainMenuInfo
- MsgBox(64,"SoA Mod Tool","Siege of Avalon Modtool:" & @CRLF & "© 2014 Fliwatt" & @CRLF & "Siege of Avalon © 2000 Digital Tome" & @CRLF & "Vielen Dank für das Benutzen dieses Tools" & @CRLF &"Fliwatt")
- Case $MainMenuDev
- DevOptions()
- Case $MainMenuReset
- If MsgBox(52,"SoA Mod Tool","Wollen sie wirklich das Siege of Avalon Modtool zurücksetzen und alle installierten Mods löschen?") = 7 Then ContinueLoop
- If IniRead($sIniPath,"General","ActivatedMod",'soa') <> "soa" Then
- If $iInstallMethod = 0 Then
- FastActivate("soa",1)
- Else
- SlowActivate("soa",1)
- EndIf
- EndIf
- FileDelete($sIniPath)
- DirRemove($sModsPath,1)
- MsgBox(64,"SoA Mod Tool","Reset erfolgreich, Programm wird nun beendet!")
- Exit
- Case $MainRunButton
- If MsgBox(36,"SoA Mod Tool","Programm nach Öffnen des Spiels beenden?") = 6 Then
- _RunWithReducedPrivileges($sSoaPath & "\DTMain1.exe",'',$sSoaPath)
- Exit
- Else
- _RunWithReducedPrivileges($sSoaPath & "\DTMain1.exe",'',$sSoaPath)
- EndIf
- EndSwitch
- WEnd
- Func _ArraySplit($avArray,$sCharacter,$iBeginOn=0)
- Local $aSplittedArray[UBound($avArray) - $iBeginOn][2]
- For $iArraySplitCounter = 0 To UBound($avArray) -$iBeginOn - 1
- $aSplitted = StringSplit($avArray[$iArraySplitCounter + $iBeginOn],$sCharacter)
- $aSplittedArray[$iArraySplitCounter][0] = $aSplitted[1]
- $aSplittedArray[$iArraySplitCounter][1] = $aSplitted[2]
- Next
- Return $aSplittedArray
- EndFunc
- Func _GetValueFromArray($avArray,$sValueToGet)
- For $iGetValueFromArrayCounter = 0 To UBound($avArray) -1
- If $avArray[$iGetValueFromArrayCounter][0] = $sValueToGet Then Return $avArray[$iGetValueFromArrayCounter][1]
- Next
- Return False
- EndFunc
- #region fast
- Func FastActivate($sModToActivate,$bSilent = 0)
- MsgBox(0,"","FAST Modus, nicht empfohlen!")
- $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
- If $sCurrentlyActivated = $sModToActivate Then
- MsgBox(16,"SoA Mod Tool","Dieser Mod ist bereits aktiviert!")
- Return
- EndIf
- If Not FileExists($sModsPath & "\" & $sCurrentlyActivated) Then DirCreate($sModsPath & "\" & $sCurrentlyActivated)
- If $bVirtualStore = 1 Then
- DirRemove($sVirtualStoragePath & "\cache" ,1)
- DirRemove($sVirtualStoragePath & "\Maps" ,1)
- FileDelete($sVirtualStoragePath & "\siege.ini")
- FileDelete($sVirtualStoragePath & "\siege.log")
- FileDelete($sVirtualStoragePath & "\DTLoader.dat")
- DirMove($sVirtualStoragePath & "\games",$sModsPath & "\" & $sCurrentlyActivated)
- Else
- DirMove($sSoaPath & "\games",$sModsPath & "\" & $sCurrentlyActivated)
- EndIf
- _DirCopyBackupFast($sModsPath & "\" & $sModToActivate & "\",$sSoaPath& "\",$sModsPath & "\" & $sCurrentlyActivated & "\")
- If $bVirtualStore = 1 Then DirMove($sSoaPath & "\games",$sVirtualStoragePath)
- IniWrite($sIniPath,"General","ActivatedMod",$sModToActivate)
- GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
- DirRemove($sModsPath & "\" & $sModToActivate,1)
- GUICtrlSetData($MainProgress,0)
- If $bSilent = 0 Then MsgBox(0,"",_GetValueFromArray($aModNamesRead,$sModToActivate)& " wurde erfolgreich aktiviert!")
- Return
- EndFunc
- #EndRegion fast
- Func SlowActivate($sModToActivate,$bSilent = 0)
- $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
- If $sCurrentlyActivated = $sModToActivate Then
- MsgBox(16,"SoA Mod Tool","Dieser Mod ist bereits aktiviert!")
- Return
- EndIf
- If Not FileExists($sModsPath & "\" & $sCurrentlyActivated) Then DirCreate($sModsPath & "\" & $sCurrentlyActivated)
- If $bVirtualStore = 1 Then
- DirRemove($sVirtualStoragePath & "\cache" ,1)
- DirRemove($sVirtualStoragePath & "\Maps" ,1)
- FileDelete($sVirtualStoragePath & "\siege.ini")
- FileDelete($sVirtualStoragePath & "\siege.log")
- FileDelete($sVirtualStoragePath & "\DTLoader.dat")
- DirMove($sVirtualStoragePath & "\games",$sModsPath & "\" & $sCurrentlyActivated & "\games")
- Else
- DirMove($sSoaPath & "\games",$sModsPath & "\" & $sCurrentlyActivated & "\games")
- EndIf
- _DirCopyBackup($sModsPath & "\" & $sModToActivate & "\",$sSoaPath& "\",$sModsPath & "\" & $sCurrentlyActivated & "\")
- If $bVirtualStore = 1 Then DirMove($sSoaPath & "\games",$sVirtualStoragePath & "\games")
- IniWrite($sIniPath,"General","ActivatedMod",$sModToActivate)
- GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
- DirRemove($sModsPath & "\" & $sModToActivate,1)
- GUICtrlSetData($MainProgress,0)
- If $bSilent = 0 Then MsgBox(0,"",_GetValueFromArray($aModNamesRead,$sModToActivate)& " wurde erfolgreich aktiviert!")
- Return
- EndFunc
- Func _DirCopyBackup($sSource, $sTarget, $sBackupFolder)
- _Crypt_Startup()
- GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
- Local $iCounterDirCopyBackup = 1
- Local $iCounterDirCopyBackup2 = 1
- Local $fFound = 0
- Local $aSourceRecursive = _ordner_rekursiv($sSource)
- Local $aTargetRecursive = _ordner_rekursiv($sTarget)
- Local $aSourceAssigned [UBound($aSourceRecursive)]
- Local $aTargetAssigned [UBound($aTargetRecursive)]
- For $iCounterDirCopyBackup = 1 To Ubound ($aSourceRecursive) - 1
- $aSourceAssigned [$iCounterDirCopyBackup] = $aSourceRecursive[$iCounterDirCopyBackup][0] & $aSourceRecursive[$iCounterDirCopyBackup] [1]
- Next
- For $iCounterDirCopyBackup = 1 To UBound ($aTargetRecursive) - 1
- $aTargetAssigned [$iCounterDirCopyBackup] = $aTargetRecursive[$iCounterDirCopyBackup] [0] & $aTargetRecursive[$iCounterDirCopyBackup] [1]
- Next
- For $iCounterDirCopyBackup = 1 To Ubound ($aSourceAssigned) - 1
- GUICtrlSetData($MainProgress,_converttopercent($iCounterDirCopyBackup,UBound($aSourceAssigned) -1))
- For $iCounterDirCopyBackup2 = 1 To Ubound ($aTargetAssigned) - 1
- If StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)) = StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)) Then
- If _Crypt_HashFile($aSourceAssigned [$iCounterDirCopyBackup],$CALG_MD5) <> _Crypt_HashFile($aTargetAssigned[$iCounterDirCopyBackup2],$CALG_MD5) Then
- GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aTargetAssigned[$iCounterDirCopyBackup2])
- FileCopy($aTargetAssigned[$iCounterDirCopyBackup2],$sBackupFolder & StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)),9)
- GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aSourceAssigned[$iCounterDirCopyBackup])
- FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$aTargetAssigned[$iCounterDirCopyBackup2],1)
- $fFound = 1
- ExitLoop
- Else
- $fFound = 1
- ExitLoop
- EndIf
- EndIf
- Next
- If $fFound = 0 Then
- FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$sTarget & StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)),9)
- GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aSourceAssigned[$iCounterDirCopyBackup])
- Else
- $fFound = 0
- Endif
- Next
- _Crypt_Shutdown()
- Return $aSourceAssigned
- EndFunc ;==>_DirCopyBackup
- Func _DirCopyBackupFast($sSource, $sTarget, $sBackupFolder)
- Local $iCounterDirCopyBackup = 1
- Local $iCounterDirCopyBackup2 = 1
- Local $fFound = 0
- Local $aSourceRecursive = _ordner_rekursiv($sSource)
- Local $aTargetRecursive = _ordner_rekursiv($sTarget)
- Local $aSourceAssigned [UBound($aSourceRecursive)]
- Local $aTargetAssigned [UBound($aTargetRecursive)]
- For $iCounterDirCopyBackup = 1 To Ubound ($aSourceRecursive) - 1
- $aSourceAssigned [$iCounterDirCopyBackup] = $aSourceRecursive[$iCounterDirCopyBackup][0] & $aSourceRecursive[$iCounterDirCopyBackup] [1]
- Next
- For $iCounterDirCopyBackup = 1 To UBound ($aTargetRecursive) - 1
- $aTargetAssigned [$iCounterDirCopyBackup] = $aTargetRecursive[$iCounterDirCopyBackup] [0] & $aTargetRecursive[$iCounterDirCopyBackup] [1]
- Next
- For $iCounterDirCopyBackup = 1 To Ubound ($aSourceAssigned) - 1
- GUICtrlSetData($MainProgress,_converttopercent($iCounterDirCopyBackup,UBound($aSourceAssigned) -1))
- For $iCounterDirCopyBackup2 = 1 To Ubound ($aTargetAssigned) - 1
- If StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)) = StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)) Then
- FileCopy($aTargetAssigned[$iCounterDirCopyBackup2],$sBackupFolder & StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)),9)
- FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$aTargetAssigned[$iCounterDirCopyBackup2],1)
- $fFound = 1
- ExitLoop
- EndIf
- Next
- If $fFound = 0 Then
- FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$sTarget & StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)),9)
- Else
- $fFound = 0
- Endif
- Next
- Return $aSourceAssigned
- EndFunc ;==>_DirCopyBackup
- Func DevOptions()
- $DevMainForm = GUICreate("SoA Mod Tool Entwickleroptionen", 602, 219, 229, 133)
- $DevLabel1 = GUICtrlCreateLabel("Installationsmethode:", 0, 0, 156, 24)
- GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
- $DevInstallMethodCombo = GUICtrlCreateCombo("", 160, 0, 441, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
- $DevLabel2 = GUICtrlCreateLabel("", 0, 24, 4, 4)
- $DevLabel3 = GUICtrlCreateLabel("SoA Pfad:", 0, 24, 76, 24)
- GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
- $DevSoAPathInput = GUICtrlCreateInput("", 80, 24, 521, 21)
- $DevLabel4 = GUICtrlCreateLabel("Mods Pfad:", 0, 48, 84, 24)
- GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
- $DevModsPathInput = GUICtrlCreateInput("", 88, 48, 513, 21)
- $DevLabel5 = GUICtrlCreateLabel("Virtual Store:", 0, 72, 96, 24)
- GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
- $DevVirtualStoreInput = GUICtrlCreateInput("", 96, 72, 505, 21)
- $DevLabel6 = GUICtrlCreateLabel("Aktivierter Mod:", 0, 96, 113, 24)
- GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
- $DevActivatedModInput = GUICtrlCreateInput("", 112, 96, 489, 21)
- $DevOpenIniButton = GUICtrlCreateButton("SoAMods.ini öffnen", 0, 120, 601, 33)
- $DevAbortButton = GUICtrlCreateButton("Einstellungen verwerfen", 0, 152, 601, 33)
- $DevConfirmButton = GUICtrlCreateButton("Einstellungen übernehmen", 0, 184, 601, 33)
- GUISetState(@SW_SHOW)
- If $iInstallMethod = 0 Then
- GUICtrlSetData($DevInstallMethodCombo,"|Schnell|Langsam","Schnell")
- Else
- GUICtrlSetData($DevInstallMethodCombo,"|Schnell|Langsam","Langsam")
- EndIf
- GUICtrlSetData($DevSoAPathInput,IniRead($sIniPath,"General","SoAPath",'error'))
- GUICtrlSetData($DevModsPathInput,IniRead($sIniPath,"General","ModsPath",'error'))
- GUICtrlSetData($DevVirtualStoreInput,IniRead($sIniPath,"General","VirtualStore",'error'))
- GUICtrlSetData($DevActivatedModInput,IniRead($sIniPath,"General","ActivatedMod",'error'))
- While 1
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE,$DevAbortButton
- GUIDelete($DevMainForm)
- Return
- Case $DevOpenIniButton
- ShellExecute($sIniPath)
- Case $DevConfirmButton
- If GUICtrlRead($DevInstallMethodCombo) = "Schnell" and $iInstallMethod = 1 Then
- IF MsgBox(68,"SoA Mod Tool","Achtung, ich habe die Erfahrung gemacht, dass häufig die langsame Methode besser und auf manchen Rechnern sogar schneller läuft." & @CRLF & "Ich empfehle die langsame Aktivierung!" & @CRLF & "Trotzdem fortfahren?") = 7 Then ContinueLoop
- EndIf
- If GUICtrlRead($DevInstallMethodCombo) = "Schnell" Then
- IniWrite($sIniPath,"General","InstallMethod",0)
- $iInstallMethod = 0
- Else
- IniWrite($sIniPath,"General","InstallMethod",1)
- $iInstallMethod = 1
- EndIf
- IniWrite($sIniPath,"General","SoAPath",GUICtrlRead($DevSoAPathInput))
- $sSoaPath = GUICtrlRead($DevSoAPathInput)
- IniWrite($sIniPath,"General","ModsPath",GUICtrlRead($DevModsPathInput))
- $sModsPath = GUICtrlRead($DevModsPathInput)
- IniWrite($sIniPath,"General","VirtualStore",GUICtrlRead($DevVirtualStoreInput))
- $sVirtualStoragePath = GUICtrlRead($DevVirtualStoreInput)
- If $sVirtualStoragePath <> '' Then $bVirtualStore = 1
- IniWrite($sIniPath,"General","ActivatedMod",GUICtrlRead($DevActivatedModInput))
- $sCurrentlyActivated = GUICtrlRead($DevActivatedModInput)
- GUIDelete($DevMainForm)
- Return
- EndSwitch
- WEnd
- Return
- EndFunc
- ; ===============================================================================================================================
- ; <_RunWithReducedPrivileges.au3>
- ;
- ; Function to run a program with reduced privileges.
- ; Useful when running in a higher privilege mode, but need to start a program with reduced privileges.
- ; - A common problem this fixes is drag-and-drop not working, and misc functions (sendmessage, etc) not working.
- ;
- ; Functions:
- ; _RunWithReducedPrivileges() ; runs a process with reduced privileges if currently running in a higher privilege mode
- ;
- ; INTERNAL Functions:
- ; _RWRPCleanup() ; Helper function for the above
- ;
- ; Reference:
- ; See 'Creating a process with Medium Integration Level from the process with High Integration Level in Vista'
- ; @ http://www.codeproject.com/KB/vista-security/createprocessexplorerleve.aspx
- ; See Elmue's comment 'Here the cleaned and bugfixed code'
- ; Also see: 'High elevation can be bad for your application: How to start a non-elevated process at the end of the installation'
- ; @ http://www.codeproject.com/KB/vista-security/RunNonElevated.aspx
- ; (Elmue has the same code here too in his response to FaxedHead's comment ('Another alternative to this method'))
- ; Another alternative using COM methods:
- ; 'Getting the shell to run an application for you - Part 2:How | BrandonLive'
- ; @ http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/
- ;
- ; Author: Ascend4nt, based on code by Elmue's fixed version of Alexey Gavrilov's code
- ; ===============================================================================================================================
- ; ===================================================================================================================
- ; Func _RunWithReducedPrivileges($sPath,$sCmd='',$sFolder='',$iShowFlag=@SW_SHOWNORMAL,$bWait=False)
- ;
- ; Function to run a program with reduced privileges.
- ; Useful when running in a higher privilege mode, but need to start a program with reduced privileges.
- ; - A common problem this fixes is drag-and-drop not working, and misc functions (sendmessage, etc) not working.
- ;
- ; $sPath = Path to executable
- ; $sCmd = Command-line (optional)
- ; $sFolder = Folder to start in (optional)
- ; $iShowFlag = how the program should appear on startup. Default is @SW_SHOWNORMAL.
- ; All the regular @SW_SHOW* macros should work here
- ; $bWait = If True, waits for the process to finish before returning with an exit code
- ; If False, it returns without waiting for the process to finish, with the process ID #
- ;
- ; Returns:
- ; Success: If $bWait=True, the exit code of the Process. If $bWait=False, then the Process ID # of the process
- ; Failure: 0, with @error set:
- ; @error = 2 = DLLCall error. @extended contains the DLLCall error code (see AutoIt Help)
- ; @error = 3 = API returned failure. Call 'GetLastError' API function to get more info.
- ;
- ; Author: Ascend4nt, based on code by Elmue's fixed version of Alexey Gavrilov's code
- ; ===================================================================================================================
- Func _RunWithReducedPrivileges($sPath, $sCmd = '', $sFolder = '', $iShowFlag = @SW_SHOWNORMAL, $bWait = False)
- Local $aRet, $iErr, $iRet = 1, $hProcess, $hToken, $hDupToken, $stStartupInfo, $stProcInfo
- Local $sCmdType = "wstr", $sFolderType = "wstr"
- ;~ Run normally if not in an elevated state, or if pre-Vista O/S
- If Not IsAdmin() Or StringRegExp(@OSVersion, "_(XP|200(0|3))") Then ; XP, XPe, 2000, or 2003?
- If $bWait Then Return RunWait($sPath & ' ' & $sCmd, $sFolder)
- Return Run($sPath & ' ' & $sCmd, $sFolder)
- EndIf
- ;~ Check Parameters and adjust DLLCall types accordingly
- If Not IsString($sCmd) Or $sCmd = '' Then
- $sCmdType = "ptr"
- $sCmd = 0
- EndIf
- If Not IsString($sFolder) Or $sFolder = '' Then
- $sFolderType = "ptr"
- $sFolder = 0
- EndIf
- #cs
- ; STARTUPINFOW struct: cb,lpReserved,lpDesktop,lpTitle,dwX,dwY,dwXSize,dwYSize,dwXCountChars,dwYCountChars,dwFillAttribute,
- ; dwFlags,wShowWindow,cbReserved2,lpReserved2,hStdInput,hStdOutput,hStdError
- ; NOTE: This is for process creation info. Also, not sure if the Std I/O can be redirected..?
- #ce
- $stStartupInfo = DllStructCreate("dword;ptr[3];dword[7];dword;word;word;ptr;handle[3]")
- DllStructSetData($stStartupInfo, 1, DllStructGetSize($stStartupInfo))
- DllStructSetData($stStartupInfo, 4, 1) ; STARTF_USESHOWWINDOW
- DllStructSetData($stStartupInfo, 5, $iShowFlag)
- ; PROCESS_INFORMATION struct: hProcess, hThread, dwProcessId, dwThreadId
- ; This is for *receiving* info
- $stProcInfo = DllStructCreate("handle;handle;dword;dword")
- ;~ Open a handle to the Process
- ; Explorer runs under a lower privilege, so it is the basis for our security info.
- ; Open the process with PROCESS_QUERY_INFORMATION (0x0400) access
- $aRet = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", 0x0400, "bool", False, "dword", ProcessExists("explorer.exe"))
- If @error Then Return SetError(2, @error, 0)
- If Not $aRet[0] Then Return SetError(3, 0, 0)
- $hProcess = $aRet[0]
- ;~ Open a handle to the Process's token (for duplication)
- ; TOKEN_DUPLICATE = 0x0002
- $aRet = DllCall("advapi32.dll", "bool", "OpenProcessToken", "handle", $hProcess, "dword", 2, "handle*", 0)
- If @error Then Return SetError(_RWRPCleanup($hProcess, 0, 0, 2, @error), @extended, 0)
- If $aRet[0] = 0 Then Return SetError(_RWRPCleanup($hProcess, 0, 0, 3), @extended, 0)
- $hToken = $aRet[3]
- ;~ Duplicate the token handle
- ; TOKEN_ALL_ACCESS = 0xF01FF, SecurityImpersonation = 2, TokenPrimary = 1,
- $aRet = DllCall("advapi32.dll", "bool", "DuplicateTokenEx", "handle", $hToken, "dword", 0xF01FF, "ptr", 0, "int", 2, "int", 1, "handle*", 0)
- If @error Then Return SetError(_RWRPCleanup($hProcess, $hToken, 0, 2, @error), @extended, 0)
- If Not $aRet[0] Then Return SetError(_RWRPCleanup($hProcess, $hToken, 0, 3), @extended, 0)
- $hDupToken = $aRet[6]
- ;~ Create the process using 'CreateProcessWithTokenW' (Vista+ O/S function)
- $aRet = DllCall("advapi32.dll", "bool", "CreateProcessWithTokenW", "handle", $hDupToken, "dword", 0, "wstr", $sPath, $sCmdType, $sCmd, _
- "dword", 0, "ptr", 0, $sFolderType, $sFolder, "ptr", DllStructGetPtr($stStartupInfo), "ptr", DllStructGetPtr($stProcInfo))
- $iErr = @error
- _RWRPCleanup($hProcess, $hToken, $hDupToken, 2, @error)
- If $iErr Then Return SetError(2, $iErr, 0)
- If Not $aRet[0] Then Return SetError(3, 0, 0)
- ;~ MsgBox(0,"Info","Process info data: Process handle:"&DllStructGetData($stProcInfo,1)&", Thread handle:"&DllStructGetData($stProcInfo,2)& _
- ;~ ", Process ID:"&DllStructGetData($stProcInfo,3)&", Thread ID:"&DllStructGetData($stProcInfo,4)&@CRLF)
- $iRet = DllStructGetData($stProcInfo, 3) ; Process ID
- ;~ If called in 'RunWait' style, wait for the process to close
- If $bWait Then
- ProcessWaitClose($iRet)
- $iRet = @extended ; Exit code
- EndIf
- ;~ Close Thread and then Process handles (order here is important):
- _RWRPCleanup(0, DllStructGetData($stProcInfo, 2), DllStructGetData($stProcInfo, 1), 0)
- Return $iRet
- EndFunc ;==>_RunWithReducedPrivileges
- ; ===================================================================================================================
- ; Func _RWRPCleanup($hProcess,$hToken,$hDupToken,$iErr=0,$iExt=0)
- ;
- ; INTERNAL: Helper function for _RunWithReducedPrivileges()
- ;
- ; Author: Ascend4nt
- ; ===================================================================================================================
- Func _RWRPCleanup($hProcess, $hToken, $hDupToken, $iErr = 0, $iExt = 0)
- Local $aHandles[3] = [$hToken, $hDupToken, $hProcess] ; order is important
- For $i = 0 To 2
- If $aHandles[$i] <> 0 Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aHandles[$i])
- Next
- Return SetExtended($iExt, $iErr)
- EndFunc ;==>_RWRPCleanup
- Func _converttopercent($iCount, $iOf)
- Return Round(($iCount / $iOf) * 100)
- EndFunc ;==>_converttopercent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement