Advertisement
Guest User

SoA Mod Tool Beta 0.3

a guest
Mar 19th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 32.17 KB | None | 0 0
  1. #RequireAdmin
  2. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  3. #AutoIt3Wrapper_Icon=ModTool2.ico
  4. #AutoIt3Wrapper_Outfile=Siege of Avalon ModTool.exe
  5. #AutoIt3Wrapper_UseUpx=n
  6. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  7.  
  8. 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!")
  9.  
  10. $sProgVer = 'Beta 0.3'
  11.  
  12. #include <REOrdner.au3>
  13. #include <Crypt.au3>
  14. #include <File.au3>
  15. #include <GUIConstantsEx.au3>
  16. #include <ComboConstants.au3>
  17.  
  18.  
  19.  
  20. ;Opt("TrayIconDebug",1)
  21.  
  22. $sIniPath = @ScriptDir & "\SoAMods.ini"
  23.  
  24. Global $iInstallMethod
  25.  
  26. If IniRead($sIniPath,"General","InstallMethod",'error') = 'error' Then
  27.     IniWrite($sIniPath,"General","InstallMethod",1)
  28.     $iInstallMethod = 1
  29. Else
  30.     $iInstallMethod = IniRead($sIniPath,"General","InstallMethod",'error') ; 1=Slow 0=Fast(Scheisse)
  31. EndIf
  32.  
  33. $MainForm = GUICreate("SoA Mod Tool " & $sProgVer, 707, 512, 300, 155)
  34. $MainMenuFile = GUICtrlCreateMenu("&Datei")
  35. $MainMenuInfo = GUICtrlCreateMenuItem("Info", $MainMenuFile)
  36. $MainMenuDev = GUICtrlCreateMenuItem("Entwickleroptionen", $MainMenuFile)
  37. $MainMenuReset = GUICtrlCreateMenuItem("Alles zurücksetzen", $MainMenuFile)
  38. $MainMenuExit = GUICtrlCreateMenuItem("Beenden", $MainMenuFile)
  39. $MainModList = GUICtrlCreateList("", 0, 0, 409, 409)
  40. $MainImportModButton = GUICtrlCreateButton("Mod importieren", 0, 408, 409, 25)
  41. $MainModActivateButton = GUICtrlCreateButton("Mod aktivieren", 416, 407, 289, 25)
  42. $MainLabel1 = GUICtrlCreateLabel("Aktiviert:", 536, 0, 54, 20)
  43. GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
  44. $MainInterActiveLabelActivated = GUICtrlCreateLabel("Siege of Avalon", 488, 16, 136, 28)
  45. GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
  46. $MainDownloadModButton = GUICtrlCreateButton("Mods herunterladen", 416, 368, 289, 33)
  47. $MainLabel3 = GUICtrlCreateLabel("Von Fliwatt für", 264, 472, 71, 17)
  48. $MainClickableLableSoamigos = GUICtrlCreateLabel("soamigos.de", 336, 472, 63, 17)
  49. GUICtrlSetColor(-1, 0x0000FF)
  50. $MainProgress = GUICtrlCreateProgress(0, 448, 705, 17)
  51. $MainRunButton = GUICtrlCreateButton("Spiel starten", 416, 48, 289, 33)
  52. Global $MainInteractiveStatusLabel = GUICtrlCreateLabel("Bereit", 0, 434, 9999, 13)
  53. GUICtrlSetColor(-1, 0x008000)
  54. GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)
  55. GUISetState(@SW_SHOW)
  56.  
  57. $7ZipPath = @TempDir & "\7za.exe"
  58. FileInstall("7za.exe",$7ZipPath)
  59.  
  60.  
  61. If IniRead($sIniPath,"General","SoAPath",'error') = 'error' or IniRead($sIniPath,"General","SoAPath",'error') = "" Then
  62.     FileGetLongName(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DigitalTome\Siege of Avalon","InstallPath"))
  63.     If @error Then
  64.         MsgBox(64,"SoA Mod Tool","Bitte wählen sie ihren SoA Pfad aus")
  65.         IniWrite($sIniPath,"General","SoAPath",FileSelectFolder("Bitte wählen sie ihren SoA Pfad aus",""))
  66.     Else
  67.         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
  68.             IniWrite($sIniPath,"General","SoAPath",FileGetLongName(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\DigitalTome\Siege of Avalon","InstallPath")))
  69.         Else
  70.             MsgBox(64,"SoA Mod Tool","Bitte wählen sie ihren SoA Pfad aus")
  71.             While 1
  72.                 $sFileSelectFolder = FileSelectFolder("Bitte wählen sie ihren SoA Pfad aus","")
  73.                 If $sFileSelectFolder <> '' Then
  74.                     IniWrite($sIniPath,"General","SoAPath",$sFileSelectFolder)
  75.                     ExitLoop
  76.                 Else
  77.                     MsgBox(16,"SoA Mod Tool","Ungültiger Pfad!")
  78.                 EndIf
  79.             Wend
  80.         EndIf
  81.     EndIf
  82. EndIf
  83. Global $sSoaPath = IniRead($sIniPath,"General","SoAPath",'error')
  84.  
  85. If IniRead($sIniPath,"General","ModsPath",'error') = 'error' Then IniWrite($sIniPath,"General","ModsPath",@ScriptDir & "\Mods")
  86. Global $sModsPath = IniRead($sIniPath,"General","ModsPath",'error')
  87.  
  88. $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
  89. $aModNamesRead = IniReadSection($sIniPath,"ModNames")
  90. If IsArray($aInstalledModPackagesRead) Then
  91.     For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
  92.         GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
  93.     Next
  94. EndIf
  95.  
  96.  
  97. #region Virtual Storage Check
  98. Global $bVirtualStore
  99. Global $sVirtualStoragePath
  100. If IniRead($sIniPath,"General","VirtualStore",'error') = 'error' Then
  101.     $sVirtualStoragePath = EnvGet("LOCALAPPDATA") & "\VirtualStore\Program Files (x86)\Digital Tome\Siege Of Avalon"
  102.     If FileExists($sVirtualStoragePath) Then
  103.         ;MsgBox(0,"","EXISTS!" & @CRLF & $sVirtualStoragePath)
  104.         IniWrite($sIniPath,"General","VirtualStore",$sVirtualStoragePath)
  105.         $bVirtualStore = 1
  106.     Else
  107.         $bVirtualStore = 0
  108.     EndIf
  109. ElseIf IniRead($sIniPath,"General","VirtualStore",'error') = '0' Then
  110.     $bVirtualStore = 0
  111. Else
  112.     $bVirtualStore = 1
  113.     $sVirtualStoragePath = IniRead($sIniPath,"General","VirtualStore",'error')
  114. EndIf
  115. #EndRegion Virtual Storage Check
  116.  
  117. GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
  118. If GUICtrlRead($MainInterActiveLabelActivated) = "False" Then
  119.     IniWrite($sIniPath,"General","ActivatedMod","soa")
  120.     IniWrite($sIniPath,"ModNames","soa","Siege of Avalon")
  121.     IniWrite($sIniPath,"InstalledModPackages","soa",1)
  122.     $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
  123.     $aModNamesRead = IniReadSection($sIniPath,"ModNames")
  124.     If IsArray($aInstalledModPackagesRead) Then
  125.     For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
  126.         GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
  127.     Next
  128.     EndIf
  129.     GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
  130. EndIf
  131.  
  132. $SoaModTemp = @TempDir & "\SoAModTemp"
  133. DirCreate($SoaModTemp)
  134. While 1
  135.     If GUICtrlRead($MainInteractiveStatusLabel) <> "Bereit" Then
  136.         GUICtrlSetData($MainInteractiveStatusLabel,"Bereit")
  137.         GUICtrlSetColor($MainInteractiveStatusLabel, 0x008000)
  138.     EndIf
  139.     Switch GUIGetMsg()
  140.         Case $GUI_EVENT_CLOSE,$MainMenuExit
  141.             Exit
  142.         Case $MainClickableLableSoamigos
  143.             ShellExecute("http://soamigos.de")
  144.         Case $MainDownloadModButton
  145.             ShellExecute("http://poamigos.yooco.de/p.modpakete.html")
  146.         Case $MainImportModButton
  147.             $sModZipDir = FileOpenDialog("Bitte wählen Sie die .zip Datei aus","","SoA Mod (*.zip)")
  148.             If @error Then ContinueLoop
  149.             GUICtrlSetData($MainInteractiveStatusLabel,"Mod wird eingelesen...")
  150.             GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
  151.             RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $SoaModTemp & '" *.soamod -y')
  152.             If Not FileExists($SoaModTemp & "\info.soamod") Then
  153.                 MsgBox(16,"SoA Mod Tool","Fehler im Mod Package: info.soamod fehlt!")
  154.                 DirRemove($SoaModTemp,1)
  155.                 ContinueLoop
  156.             EndIf
  157.             Local $aSoAModInfo
  158.             _FileReadToArray($SoaModTemp & "\info.soamod",$aSoAModInfo)
  159.             DirRemove($SoaModTemp,1)
  160.             $aSoAModInfo = _ArraySplit($aSoAModInfo,"=",1)
  161.             If _GetValueFromArray($aSoAModInfo,"AddMod") <> False Then
  162.                 If IniRead($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),0) = 1 Then
  163.                     MsgBox(16,"SoA Mod Tool","Fehler: Dieses Paket wurde bereits installiert")
  164.                     ContinueLoop
  165.                 EndIf
  166.                 ToolTip(_GetValueFromArray($aSoAModInfo,"DisplayName") & " wird installiert...",0,0)
  167.                 DirCreate($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod"))
  168.                 GUICtrlSetData($MainInteractiveStatusLabel,"Dateien werden extrahiert...")
  169.                 GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
  170.                 RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & '" -y')
  171.                 ConsoleWrite('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & '" -y' & @CRLF)
  172.                 FileDelete($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"AddMod") & "\info.soamod")
  173.                 IniWrite($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),1)
  174.                 IniWrite($sIniPath,"InstalledModPackages",_GetValueFromArray($aSoAModInfo,"AddMod"),1)
  175.                 IniWrite($sIniPath,"ModNames",_GetValueFromArray($aSoAModInfo,"AddMod"),_GetValueFromArray($aSoAModInfo,"DisplayName"))
  176.                 GUICtrlSetData($MainModList,"|")
  177.                 $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
  178.                 $aModNamesRead = IniReadSection($sIniPath,"ModNames")
  179.                 For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
  180.                     GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
  181.                 Next
  182.                 ToolTip("",0,0)
  183.             Else
  184.                 If IniRead($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),0) = 1 Then
  185.                     MsgBox(16,"SoA Mod Tool","Fehler: Dieses Paket wurde bereits installiert")
  186.                     ContinueLoop
  187.                 EndIf
  188.                 $aRequiredMods = StringSplit(_GetValueFromArray($aSoAModInfo,"Required"),'|')
  189.                 For $iCounter = 1 To $aRequiredMods[0]
  190.                     If IniRead($sIniPath,"InstalledMods",$aRequiredMods[$iCounter],0) = 0 Then
  191.                         MsgBox(16,"SoA Mod Tool",_GetValueFromArray($aSoAModInfo,"MissingDialog"))
  192.                         ContinueCase
  193.                     EndIf
  194.                 Next
  195.                 ToolTip(_GetValueFromArray($aSoAModInfo,"DisplayName") & " wird installiert...",0,0)
  196.                 If IniRead($sIniPath,"General","ActivatedMod",'soa') = _GetValueFromArray($aSoAModInfo,"UpdateMod") Then
  197.                     GUICtrlSetData($MainInteractiveStatusLabel,"Aktueller Mod wird deaktiviert...")
  198.                     GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
  199.                     If $iInstallMethod = 0 Then
  200.                         FastActivate("soa",1)
  201.                     Else
  202.                         SlowActivate("soa",1)
  203.                     EndIf
  204.                 EndIf
  205.                 GUICtrlSetData($MainInteractiveStatusLabel,"Dateien werden extrahiert...")
  206.                 GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
  207.                 RunWait('"' & $7ZipPath & '" x "' & $sModZipDir & '" -o"' & $sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"UpdateMod") & '" -y')
  208.                 FileDelete($sModsPath & "\" & _GetValueFromArray($aSoAModInfo,"UpdateMod") & "\info.soamod")
  209.                 IniWrite($sIniPath,"ModNames",_GetValueFromArray($aSoAModInfo,"UpdateMod"),_GetValueFromArray($aSoAModInfo,"DisplayName"))
  210.                 IniWrite($sIniPath,"InstalledMods",_GetValueFromArray($aSoAModInfo,"ModName"),1)
  211.                 GUICtrlSetData($MainModList,"|")
  212.                 $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
  213.                 $aModNamesRead = IniReadSection($sIniPath,"ModNames")
  214.                 For $iCounter = 1 To $aInstalledModPackagesRead[0][0]
  215.                     GUICtrlSetData($MainModList,_GetValueFromArray($aModNamesRead,$aInstalledModPackagesRead[$iCounter][0]) & "|")
  216.                 Next
  217.                 GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
  218.                 ToolTip("",0,0)
  219.             EndIf
  220.             MsgBox(0,"SoA Mod Tool",_GetValueFromArray($aSoAModInfo,"DisplayName") & " wurde erfolgreich installiert!")
  221.         Case $MainModActivateButton
  222.             $aInstalledModPackagesRead = IniReadSection($sIniPath,"InstalledModPackages")
  223.             $aModNamesRead = IniReadSection($sIniPath,"ModNames")
  224.             Switch $iInstallMethod
  225.                 Case 0
  226.                     For $iCounter = 1 To $aModNamesRead[0][0]
  227.                         If $aModNamesRead[$iCounter][1] = GUICtrlRead($MainModList) Then FastActivate($aModNamesRead[$iCounter][0])
  228.                     Next
  229.                 Case 1
  230.                     For $iCounter = 1 To $aModNamesRead[0][0]
  231.                         If $aModNamesRead[$iCounter][1] = GUICtrlRead($MainModList) Then SlowActivate($aModNamesRead[$iCounter][0])
  232.                     Next
  233.             EndSwitch
  234.             $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
  235.             If $sCurrentlyActivated = "soa" and IniRead($sSoaPath & "\siege.ini","MapNames","forestcave",'error') = 'error' Then ;SoAmigos Patch Checker
  236.                 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")
  237.             EndIf
  238.         Case $MainMenuInfo
  239.             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")
  240.         Case $MainMenuDev
  241.             DevOptions()
  242.         Case $MainMenuReset
  243.             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
  244.             If IniRead($sIniPath,"General","ActivatedMod",'soa') <> "soa" Then
  245.                 If $iInstallMethod = 0 Then
  246.                         FastActivate("soa",1)
  247.                     Else
  248.                         SlowActivate("soa",1)
  249.                 EndIf
  250.             EndIf
  251.             FileDelete($sIniPath)
  252.             DirRemove($sModsPath,1)
  253.             MsgBox(64,"SoA Mod Tool","Reset erfolgreich, Programm wird nun beendet!")
  254.             Exit
  255.         Case $MainRunButton
  256.             If MsgBox(36,"SoA Mod Tool","Programm nach Öffnen des Spiels beenden?") = 6 Then
  257.                 _RunWithReducedPrivileges($sSoaPath & "\DTMain1.exe",'',$sSoaPath)
  258.                 Exit
  259.             Else
  260.                 _RunWithReducedPrivileges($sSoaPath & "\DTMain1.exe",'',$sSoaPath)
  261.             EndIf
  262.     EndSwitch
  263. WEnd
  264.  
  265. Func _ArraySplit($avArray,$sCharacter,$iBeginOn=0)
  266.     Local $aSplittedArray[UBound($avArray) - $iBeginOn][2]
  267.     For $iArraySplitCounter = 0 To UBound($avArray) -$iBeginOn - 1
  268.         $aSplitted = StringSplit($avArray[$iArraySplitCounter + $iBeginOn],$sCharacter)
  269.         $aSplittedArray[$iArraySplitCounter][0] = $aSplitted[1]
  270.         $aSplittedArray[$iArraySplitCounter][1] = $aSplitted[2]
  271.     Next
  272.     Return $aSplittedArray
  273. EndFunc
  274.  
  275. Func _GetValueFromArray($avArray,$sValueToGet)
  276.     For $iGetValueFromArrayCounter = 0 To UBound($avArray) -1
  277.         If $avArray[$iGetValueFromArrayCounter][0] = $sValueToGet Then Return $avArray[$iGetValueFromArrayCounter][1]
  278.     Next
  279.     Return False
  280. EndFunc
  281.  
  282. #region fast
  283. Func FastActivate($sModToActivate,$bSilent = 0)
  284.     MsgBox(0,"","FAST Modus, nicht empfohlen!")
  285.     $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
  286.     If $sCurrentlyActivated = $sModToActivate Then
  287.         MsgBox(16,"SoA Mod Tool","Dieser Mod ist bereits aktiviert!")
  288.         Return
  289.     EndIf
  290.     If Not FileExists($sModsPath & "\" & $sCurrentlyActivated) Then DirCreate($sModsPath & "\" & $sCurrentlyActivated)
  291.     If $bVirtualStore = 1 Then
  292.         DirRemove($sVirtualStoragePath & "\cache" ,1)
  293.         DirRemove($sVirtualStoragePath & "\Maps" ,1)
  294.         FileDelete($sVirtualStoragePath & "\siege.ini")
  295.         FileDelete($sVirtualStoragePath & "\siege.log")
  296.         FileDelete($sVirtualStoragePath & "\DTLoader.dat")
  297.         DirMove($sVirtualStoragePath & "\games",$sModsPath & "\" & $sCurrentlyActivated)
  298.     Else
  299.         DirMove($sSoaPath & "\games",$sModsPath & "\" & $sCurrentlyActivated)
  300.     EndIf
  301.     _DirCopyBackupFast($sModsPath & "\" & $sModToActivate & "\",$sSoaPath& "\",$sModsPath & "\" & $sCurrentlyActivated & "\")
  302.     If $bVirtualStore = 1 Then DirMove($sSoaPath & "\games",$sVirtualStoragePath)
  303.     IniWrite($sIniPath,"General","ActivatedMod",$sModToActivate)
  304.     GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
  305.     DirRemove($sModsPath & "\" & $sModToActivate,1)
  306.     GUICtrlSetData($MainProgress,0)
  307.     If $bSilent = 0 Then MsgBox(0,"",_GetValueFromArray($aModNamesRead,$sModToActivate)& " wurde erfolgreich aktiviert!")
  308.     Return
  309. EndFunc
  310. #EndRegion fast
  311. Func SlowActivate($sModToActivate,$bSilent = 0)
  312.     $sCurrentlyActivated = IniRead($sIniPath,"General","ActivatedMod",'soa')
  313.     If $sCurrentlyActivated = $sModToActivate Then
  314.         MsgBox(16,"SoA Mod Tool","Dieser Mod ist bereits aktiviert!")
  315.         Return
  316.     EndIf
  317.     If Not FileExists($sModsPath & "\" & $sCurrentlyActivated) Then DirCreate($sModsPath & "\" & $sCurrentlyActivated)
  318.     If $bVirtualStore = 1 Then
  319.         DirRemove($sVirtualStoragePath & "\cache" ,1)
  320.         DirRemove($sVirtualStoragePath & "\Maps" ,1)
  321.         FileDelete($sVirtualStoragePath & "\siege.ini")
  322.         FileDelete($sVirtualStoragePath & "\siege.log")
  323.         FileDelete($sVirtualStoragePath & "\DTLoader.dat")
  324.         DirMove($sVirtualStoragePath & "\games",$sModsPath & "\" & $sCurrentlyActivated & "\games")
  325.     Else
  326.         DirMove($sSoaPath & "\games",$sModsPath & "\" & $sCurrentlyActivated & "\games")
  327.     EndIf
  328.     _DirCopyBackup($sModsPath & "\" & $sModToActivate & "\",$sSoaPath& "\",$sModsPath & "\" & $sCurrentlyActivated & "\")
  329.     If $bVirtualStore = 1 Then DirMove($sSoaPath & "\games",$sVirtualStoragePath & "\games")
  330.     IniWrite($sIniPath,"General","ActivatedMod",$sModToActivate)
  331.     GUICtrlSetData($MainInterActiveLabelActivated,_GetValueFromArray($aModNamesRead,IniRead($sIniPath,"General","ActivatedMod",'soa')))
  332.     DirRemove($sModsPath & "\" & $sModToActivate,1)
  333.     GUICtrlSetData($MainProgress,0)
  334.     If $bSilent = 0 Then MsgBox(0,"",_GetValueFromArray($aModNamesRead,$sModToActivate)& " wurde erfolgreich aktiviert!")
  335.     Return
  336. EndFunc
  337.  
  338. Func _DirCopyBackup($sSource, $sTarget, $sBackupFolder)
  339.     _Crypt_Startup()
  340.     GUICtrlSetColor($MainInteractiveStatusLabel,0xFF0000)
  341.     Local $iCounterDirCopyBackup = 1
  342.     Local $iCounterDirCopyBackup2 = 1
  343.     Local $fFound = 0
  344.     Local $aSourceRecursive = _ordner_rekursiv($sSource)
  345.     Local $aTargetRecursive = _ordner_rekursiv($sTarget)
  346.     Local $aSourceAssigned [UBound($aSourceRecursive)]
  347.     Local $aTargetAssigned [UBound($aTargetRecursive)]
  348.     For $iCounterDirCopyBackup = 1 To Ubound ($aSourceRecursive) - 1
  349.         $aSourceAssigned [$iCounterDirCopyBackup] = $aSourceRecursive[$iCounterDirCopyBackup][0] & $aSourceRecursive[$iCounterDirCopyBackup] [1]
  350.     Next
  351.     For $iCounterDirCopyBackup = 1 To UBound ($aTargetRecursive) - 1
  352.         $aTargetAssigned [$iCounterDirCopyBackup] = $aTargetRecursive[$iCounterDirCopyBackup] [0] & $aTargetRecursive[$iCounterDirCopyBackup] [1]
  353.     Next
  354.     For $iCounterDirCopyBackup = 1 To Ubound ($aSourceAssigned) - 1
  355.         GUICtrlSetData($MainProgress,_converttopercent($iCounterDirCopyBackup,UBound($aSourceAssigned) -1))
  356.         For $iCounterDirCopyBackup2 = 1 To Ubound ($aTargetAssigned) - 1
  357.             If StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)) = StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)) Then
  358.                 If _Crypt_HashFile($aSourceAssigned [$iCounterDirCopyBackup],$CALG_MD5) <> _Crypt_HashFile($aTargetAssigned[$iCounterDirCopyBackup2],$CALG_MD5) Then
  359.                     GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aTargetAssigned[$iCounterDirCopyBackup2])
  360.                     FileCopy($aTargetAssigned[$iCounterDirCopyBackup2],$sBackupFolder & StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)),9)
  361.                     GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aSourceAssigned[$iCounterDirCopyBackup])
  362.                     FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$aTargetAssigned[$iCounterDirCopyBackup2],1)
  363.                     $fFound = 1
  364.                     ExitLoop
  365.                 Else
  366.                     $fFound = 1
  367.                     ExitLoop
  368.                 EndIf
  369.             EndIf
  370.         Next
  371.         If $fFound = 0 Then
  372.             FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$sTarget & StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)),9)
  373.             GUICtrlSetData($MainInteractiveStatusLabel,"Kopiert:"& $aSourceAssigned[$iCounterDirCopyBackup])
  374.         Else
  375.             $fFound = 0
  376.         Endif
  377.     Next
  378.     _Crypt_Shutdown()
  379.     Return $aSourceAssigned
  380. EndFunc   ;==>_DirCopyBackup
  381.  
  382.  
  383.  
  384. Func _DirCopyBackupFast($sSource, $sTarget, $sBackupFolder)
  385.     Local $iCounterDirCopyBackup = 1
  386.     Local $iCounterDirCopyBackup2 = 1
  387.     Local $fFound = 0
  388.     Local $aSourceRecursive = _ordner_rekursiv($sSource)
  389.     Local $aTargetRecursive = _ordner_rekursiv($sTarget)
  390.     Local $aSourceAssigned [UBound($aSourceRecursive)]
  391.     Local $aTargetAssigned [UBound($aTargetRecursive)]
  392.     For $iCounterDirCopyBackup = 1 To Ubound ($aSourceRecursive) - 1
  393.         $aSourceAssigned [$iCounterDirCopyBackup] = $aSourceRecursive[$iCounterDirCopyBackup][0] & $aSourceRecursive[$iCounterDirCopyBackup] [1]
  394.     Next
  395.     For $iCounterDirCopyBackup = 1 To UBound ($aTargetRecursive) - 1
  396.         $aTargetAssigned [$iCounterDirCopyBackup] = $aTargetRecursive[$iCounterDirCopyBackup] [0] & $aTargetRecursive[$iCounterDirCopyBackup] [1]
  397.     Next
  398.     For $iCounterDirCopyBackup = 1 To Ubound ($aSourceAssigned) - 1
  399.         GUICtrlSetData($MainProgress,_converttopercent($iCounterDirCopyBackup,UBound($aSourceAssigned) -1))
  400.         For $iCounterDirCopyBackup2 = 1 To Ubound ($aTargetAssigned) - 1
  401.             If StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)) = StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)) Then
  402.                 FileCopy($aTargetAssigned[$iCounterDirCopyBackup2],$sBackupFolder & StringTrimLeft($aTargetAssigned[$iCounterDirCopyBackup2],StringLen($sTarget)),9)
  403.                 FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$aTargetAssigned[$iCounterDirCopyBackup2],1)
  404.                 $fFound = 1
  405.                 ExitLoop
  406.             EndIf
  407.         Next
  408.         If $fFound = 0 Then
  409.             FileCopy($aSourceAssigned[$iCounterDirCopyBackup],$sTarget & StringTrimLeft($aSourceAssigned[$iCounterDirCopyBackup],StringLen($sSource)),9)
  410.         Else
  411.             $fFound = 0
  412.         Endif
  413.     Next
  414.     Return $aSourceAssigned
  415. EndFunc   ;==>_DirCopyBackup
  416.  
  417. Func DevOptions()
  418.     $DevMainForm = GUICreate("SoA Mod Tool Entwickleroptionen", 602, 219, 229, 133)
  419.     $DevLabel1 = GUICtrlCreateLabel("Installationsmethode:", 0, 0, 156, 24)
  420.     GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  421.     $DevInstallMethodCombo = GUICtrlCreateCombo("", 160, 0, 441, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
  422.     $DevLabel2 = GUICtrlCreateLabel("", 0, 24, 4, 4)
  423.     $DevLabel3 = GUICtrlCreateLabel("SoA Pfad:", 0, 24, 76, 24)
  424.     GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  425.     $DevSoAPathInput = GUICtrlCreateInput("", 80, 24, 521, 21)
  426.     $DevLabel4 = GUICtrlCreateLabel("Mods Pfad:", 0, 48, 84, 24)
  427.     GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  428.     $DevModsPathInput = GUICtrlCreateInput("", 88, 48, 513, 21)
  429.     $DevLabel5 = GUICtrlCreateLabel("Virtual Store:", 0, 72, 96, 24)
  430.     GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  431.     $DevVirtualStoreInput = GUICtrlCreateInput("", 96, 72, 505, 21)
  432.     $DevLabel6 = GUICtrlCreateLabel("Aktivierter Mod:", 0, 96, 113, 24)
  433.     GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  434.     $DevActivatedModInput = GUICtrlCreateInput("", 112, 96, 489, 21)
  435.     $DevOpenIniButton = GUICtrlCreateButton("SoAMods.ini öffnen", 0, 120, 601, 33)
  436.     $DevAbortButton = GUICtrlCreateButton("Einstellungen verwerfen", 0, 152, 601, 33)
  437.     $DevConfirmButton = GUICtrlCreateButton("Einstellungen übernehmen", 0, 184, 601, 33)
  438.     GUISetState(@SW_SHOW)
  439.     If $iInstallMethod = 0 Then
  440.         GUICtrlSetData($DevInstallMethodCombo,"|Schnell|Langsam","Schnell")
  441.     Else
  442.         GUICtrlSetData($DevInstallMethodCombo,"|Schnell|Langsam","Langsam")
  443.     EndIf
  444.     GUICtrlSetData($DevSoAPathInput,IniRead($sIniPath,"General","SoAPath",'error'))
  445.     GUICtrlSetData($DevModsPathInput,IniRead($sIniPath,"General","ModsPath",'error'))
  446.     GUICtrlSetData($DevVirtualStoreInput,IniRead($sIniPath,"General","VirtualStore",'error'))
  447.     GUICtrlSetData($DevActivatedModInput,IniRead($sIniPath,"General","ActivatedMod",'error'))
  448.     While 1
  449.         Switch GUIGetMsg()
  450.             Case $GUI_EVENT_CLOSE,$DevAbortButton
  451.                 GUIDelete($DevMainForm)
  452.                 Return
  453.             Case $DevOpenIniButton
  454.                 ShellExecute($sIniPath)
  455.             Case $DevConfirmButton
  456.                 If GUICtrlRead($DevInstallMethodCombo) = "Schnell" and $iInstallMethod = 1 Then
  457.                     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
  458.                 EndIf
  459.                 If GUICtrlRead($DevInstallMethodCombo) = "Schnell" Then
  460.                     IniWrite($sIniPath,"General","InstallMethod",0)
  461.                     $iInstallMethod = 0
  462.                 Else
  463.                     IniWrite($sIniPath,"General","InstallMethod",1)
  464.                     $iInstallMethod = 1
  465.                 EndIf
  466.                 IniWrite($sIniPath,"General","SoAPath",GUICtrlRead($DevSoAPathInput))
  467.                 $sSoaPath = GUICtrlRead($DevSoAPathInput)
  468.                 IniWrite($sIniPath,"General","ModsPath",GUICtrlRead($DevModsPathInput))
  469.                 $sModsPath = GUICtrlRead($DevModsPathInput)
  470.                 IniWrite($sIniPath,"General","VirtualStore",GUICtrlRead($DevVirtualStoreInput))
  471.                 $sVirtualStoragePath = GUICtrlRead($DevVirtualStoreInput)
  472.                 If $sVirtualStoragePath <> '' Then $bVirtualStore = 1
  473.                 IniWrite($sIniPath,"General","ActivatedMod",GUICtrlRead($DevActivatedModInput))
  474.                 $sCurrentlyActivated = GUICtrlRead($DevActivatedModInput)
  475.                 GUIDelete($DevMainForm)
  476.                 Return
  477.         EndSwitch
  478.     WEnd
  479.     Return
  480. EndFunc
  481.  
  482. ; ===============================================================================================================================
  483. ; <_RunWithReducedPrivileges.au3>
  484. ;
  485. ; Function to run a program with reduced privileges.
  486. ;   Useful when running in a higher privilege mode, but need to start a program with reduced privileges.
  487. ;   - A common problem this fixes is drag-and-drop not working, and misc functions (sendmessage, etc) not working.
  488. ;
  489. ; Functions:
  490. ;   _RunWithReducedPrivileges()     ; runs a process with reduced privileges if currently running in a higher privilege mode
  491. ;
  492. ; INTERNAL Functions:
  493. ;   _RWRPCleanup()      ; Helper function for the above
  494. ;
  495. ; Reference:
  496. ;   See 'Creating a process with Medium Integration Level from the process with High Integration Level in Vista'
  497. ;       @ http://www.codeproject.com/KB/vista-security/createprocessexplorerleve.aspx
  498. ;     See Elmue's comment 'Here the cleaned and bugfixed code'
  499. ;   Also see: 'High elevation can be bad for your application: How to start a non-elevated process at the end of the installation'
  500. ;       @ http://www.codeproject.com/KB/vista-security/RunNonElevated.aspx
  501. ;     (Elmue has the same code here too in his response to FaxedHead's comment ('Another alternative to this method'))
  502. ;   Another alternative using COM methods:
  503. ;     'Getting the shell to run an application for you - Part 2:How | BrandonLive'
  504. ;       @ http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/
  505. ;
  506. ; Author: Ascend4nt, based on code by Elmue's fixed version of Alexey Gavrilov's code
  507. ; ===============================================================================================================================
  508.  
  509. ; ===================================================================================================================
  510. ; Func _RunWithReducedPrivileges($sPath,$sCmd='',$sFolder='',$iShowFlag=@SW_SHOWNORMAL,$bWait=False)
  511. ;
  512. ; Function to run a program with reduced privileges.
  513. ;   Useful when running in a higher privilege mode, but need to start a program with reduced privileges.
  514. ;   - A common problem this fixes is drag-and-drop not working, and misc functions (sendmessage, etc) not working.
  515. ;
  516. ; $sPath = Path to executable
  517. ; $sCmd = Command-line (optional)
  518. ; $sFolder = Folder to start in (optional)
  519. ; $iShowFlag = how the program should appear on startup. Default is @SW_SHOWNORMAL.
  520. ;   All the regular @SW_SHOW* macros should work here
  521. ; $bWait = If True, waits for the process to finish before returning with an exit code
  522. ;   If False, it returns without waiting for the process to finish, with the process ID #
  523. ;
  524. ; Returns:
  525. ;   Success: If $bWait=True, the exit code of the Process. If $bWait=False, then the Process ID # of the process
  526. ;   Failure: 0, with @error set:
  527. ;       @error = 2 = DLLCall error. @extended contains the DLLCall error code (see AutoIt Help)
  528. ;       @error = 3 = API returned failure. Call 'GetLastError' API function to get more info.
  529. ;
  530. ; Author: Ascend4nt, based on code by Elmue's fixed version of Alexey Gavrilov's code
  531. ; ===================================================================================================================
  532.  
  533. Func _RunWithReducedPrivileges($sPath, $sCmd = '', $sFolder = '', $iShowFlag = @SW_SHOWNORMAL, $bWait = False)
  534.     Local $aRet, $iErr, $iRet = 1, $hProcess, $hToken, $hDupToken, $stStartupInfo, $stProcInfo
  535.     Local $sCmdType = "wstr", $sFolderType = "wstr"
  536.  
  537. ;~  Run normally if not in an elevated state, or if pre-Vista O/S
  538.     If Not IsAdmin() Or StringRegExp(@OSVersion, "_(XP|200(0|3))") Then ; XP, XPe, 2000, or 2003?
  539.         If $bWait Then Return RunWait($sPath & ' ' & $sCmd, $sFolder)
  540.         Return Run($sPath & ' ' & $sCmd, $sFolder)
  541.     EndIf
  542.  
  543. ;~  Check Parameters and adjust DLLCall types accordingly
  544.     If Not IsString($sCmd) Or $sCmd = '' Then
  545.         $sCmdType = "ptr"
  546.         $sCmd = 0
  547.     EndIf
  548.     If Not IsString($sFolder) Or $sFolder = '' Then
  549.         $sFolderType = "ptr"
  550.         $sFolder = 0
  551.     EndIf
  552.     #cs
  553.         ; STARTUPINFOW struct: cb,lpReserved,lpDesktop,lpTitle,dwX,dwY,dwXSize,dwYSize,dwXCountChars,dwYCountChars,dwFillAttribute,
  554.         ;   dwFlags,wShowWindow,cbReserved2,lpReserved2,hStdInput,hStdOutput,hStdError
  555.         ;   NOTE: This is for process creation info. Also, not sure if the Std I/O can be redirected..?
  556.     #ce
  557.     $stStartupInfo = DllStructCreate("dword;ptr[3];dword[7];dword;word;word;ptr;handle[3]")
  558.     DllStructSetData($stStartupInfo, 1, DllStructGetSize($stStartupInfo))
  559.     DllStructSetData($stStartupInfo, 4, 1) ; STARTF_USESHOWWINDOW
  560.     DllStructSetData($stStartupInfo, 5, $iShowFlag)
  561.  
  562.     ; PROCESS_INFORMATION struct: hProcess, hThread, dwProcessId, dwThreadId
  563.     ;   This is for *receiving* info
  564.     $stProcInfo = DllStructCreate("handle;handle;dword;dword")
  565.  
  566. ;~  Open a handle to the Process
  567.     ; Explorer runs under a lower privilege, so it is the basis for our security info.
  568.     ;   Open the process with PROCESS_QUERY_INFORMATION (0x0400) access
  569.     $aRet = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", 0x0400, "bool", False, "dword", ProcessExists("explorer.exe"))
  570.     If @error Then Return SetError(2, @error, 0)
  571.     If Not $aRet[0] Then Return SetError(3, 0, 0)
  572.     $hProcess = $aRet[0]
  573.  
  574. ;~  Open a handle to the Process's token (for duplication)
  575.     ; TOKEN_DUPLICATE = 0x0002
  576.     $aRet = DllCall("advapi32.dll", "bool", "OpenProcessToken", "handle", $hProcess, "dword", 2, "handle*", 0)
  577.     If @error Then Return SetError(_RWRPCleanup($hProcess, 0, 0, 2, @error), @extended, 0)
  578.     If $aRet[0] = 0 Then Return SetError(_RWRPCleanup($hProcess, 0, 0, 3), @extended, 0)
  579.     $hToken = $aRet[3]
  580.  
  581. ;~  Duplicate the token handle
  582.     ; TOKEN_ALL_ACCESS = 0xF01FF, SecurityImpersonation = 2, TokenPrimary = 1,
  583.     $aRet = DllCall("advapi32.dll", "bool", "DuplicateTokenEx", "handle", $hToken, "dword", 0xF01FF, "ptr", 0, "int", 2, "int", 1, "handle*", 0)
  584.     If @error Then Return SetError(_RWRPCleanup($hProcess, $hToken, 0, 2, @error), @extended, 0)
  585.     If Not $aRet[0] Then Return SetError(_RWRPCleanup($hProcess, $hToken, 0, 3), @extended, 0)
  586.     $hDupToken = $aRet[6]
  587.  
  588. ;~  Create the process using 'CreateProcessWithTokenW' (Vista+ O/S function)
  589.     $aRet = DllCall("advapi32.dll", "bool", "CreateProcessWithTokenW", "handle", $hDupToken, "dword", 0, "wstr", $sPath, $sCmdType, $sCmd, _
  590.             "dword", 0, "ptr", 0, $sFolderType, $sFolder, "ptr", DllStructGetPtr($stStartupInfo), "ptr", DllStructGetPtr($stProcInfo))
  591.     $iErr = @error
  592.     _RWRPCleanup($hProcess, $hToken, $hDupToken, 2, @error)
  593.     If $iErr Then Return SetError(2, $iErr, 0)
  594.     If Not $aRet[0] Then Return SetError(3, 0, 0)
  595.  
  596. ;~  MsgBox(0,"Info","Process info data: Process handle:"&DllStructGetData($stProcInfo,1)&", Thread handle:"&DllStructGetData($stProcInfo,2)& _
  597. ;~      ", Process ID:"&DllStructGetData($stProcInfo,3)&", Thread ID:"&DllStructGetData($stProcInfo,4)&@CRLF)
  598.  
  599.     $iRet = DllStructGetData($stProcInfo, 3) ; Process ID
  600.  
  601. ;~  If called in 'RunWait' style, wait for the process to close
  602.     If $bWait Then
  603.         ProcessWaitClose($iRet)
  604.         $iRet = @extended ; Exit code
  605.     EndIf
  606.  
  607. ;~  Close Thread and then Process handles (order here is important):
  608.     _RWRPCleanup(0, DllStructGetData($stProcInfo, 2), DllStructGetData($stProcInfo, 1), 0)
  609.  
  610.     Return $iRet
  611. EndFunc   ;==>_RunWithReducedPrivileges
  612.  
  613. ; ===================================================================================================================
  614. ; Func _RWRPCleanup($hProcess,$hToken,$hDupToken,$iErr=0,$iExt=0)
  615. ;
  616. ; INTERNAL: Helper function for _RunWithReducedPrivileges()
  617. ;
  618. ; Author: Ascend4nt
  619. ; ===================================================================================================================
  620.  
  621. Func _RWRPCleanup($hProcess, $hToken, $hDupToken, $iErr = 0, $iExt = 0)
  622.     Local $aHandles[3] = [$hToken, $hDupToken, $hProcess] ; order is important
  623.     For $i = 0 To 2
  624.         If $aHandles[$i] <> 0 Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aHandles[$i])
  625.     Next
  626.     Return SetExtended($iExt, $iErr)
  627. EndFunc   ;==>_RWRPCleanup
  628.  
  629. Func _converttopercent($iCount, $iOf)
  630.     Return Round(($iCount / $iOf) * 100)
  631. EndFunc   ;==>_converttopercent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement