Guest User

"Portable Application Launcher" source code

a guest
Mar 30th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.65 KB | None | 0 0
  1. ;Portable Application Launcher Beta
  2. ;Copyright 2011 Konstantinos Asimakis
  3. ;http://inshame.blogspot.com
  4. ;You may use the binary in any way you want.
  5. ;You may redistribute this code and the binary version UNMODIFIED ONLY but
  6. ;if you make modifications you can either send them to me to incorporate them
  7. ;to the original version or, at your option, you may use this code and binaries under the GNU/GPL v3 terms.
  8. ;NOTE: (2017-03-30)
  9. ;Code harvested from archive at https://bittit.info/publicDro/PAL.zip
  10.  
  11. #NoTrayIcon
  12. #include <File.au3>
  13. Opt("ExpandEnvStrings", 1)
  14.  
  15. FileChangeDir(@ScriptFullPath)
  16.  
  17. Dim $types[11]
  18. $types[0] = "REG_NONE"
  19. $types[1] = "REG_SZ"
  20. $types[2] = "REG_EXPAND_SZ"
  21. $types[3] = "REG_BINARY"
  22. $types[4] = "REG_DWORD"
  23. $types[5] = "REG_DWORD_BIG_ENDIAN"
  24. $types[6] = "REG_LINK"
  25. $types[7] = "REG_MULTI_SZ"
  26. $types[8] = "REG_RESOURCE_LIST"
  27. $types[9] = "REG_FULL_RESOURCE_DESCRIPTOR"
  28. $types[10] = "REG_RESOURCE_REQUIREMENTS_LIST"
  29.  
  30. Func hex2str($from)
  31.     Local $to = ""
  32.     For $i = 1 To BinaryLen($from) Step 2
  33.         Local $number = Dec(BinaryToString(BinaryMid($from, $i, 2)))
  34.         If Not @error Then $to &= Chr($number)
  35.     Next
  36.     Return $to
  37. EndFunc   ;==>hex2str
  38.  
  39. Func str2hex($from)
  40.     Local $to = ""
  41.     For $i = 1 To BinaryLen($from)
  42.         $to &= Hex(BinaryMid($from, $i, 1))
  43.     Next
  44.     Return $to
  45. EndFunc   ;==>str2hex
  46.  
  47. ;while True
  48. ;   msgbox(0,"",hex2str(inputbox("","")))
  49. ;   ClipPut(str2hex(inputbox("in","")))
  50. ;WEnd
  51.  
  52. Func RegKeyLoad($regfile)
  53.     $h = FileOpen($regfile, 0)
  54.     Do
  55.         $keyname = FileReadLine($h)
  56.         $valuename = FileReadLine($h)
  57.         $type = FileReadLine($h)
  58.         If $type == 3 Then
  59.             $value = hex2str(FileReadLine($h))
  60.         Else
  61.             $value = FileReadLine($h)
  62.         EndIf
  63.         RegWrite($keyname, $valuename, $types[$type], $value)
  64.         ;Switch @error
  65.         ;case 1
  66.         ;   msgbox(48,"Error","Unable to open requested key. " & $regfile)
  67.         ;case 2
  68.         ;   msgbox(48,"Error","Unable to open requested main key. " & $regfile)
  69.         ;case 3
  70.         ;   msgbox(48,"Error","Unable to remote connect to the registry. " & $regfile)
  71.         ;case -1
  72.         ;   msgbox(48,"Error","Unable to open requested value. " & $regfile)
  73.         ;case -2
  74.         ;   msgbox(48,"Error","Value type not supported. " & $regfile)
  75.         ;EndSwitch
  76.     Until @error <> 0
  77.     FileClose($h)
  78. EndFunc   ;==>RegKeyLoad
  79.  
  80. Func RegKeySave($key, $regfile)
  81.     $h = FileOpen($regfile, 1)
  82.     $instance = 1
  83.     Do
  84.         $value = RegEnumVal($key, $instance)
  85.         $type = @extended
  86.         If @error <> 0 Then ExitLoop
  87.         FileWriteLine($h, $key)
  88.         FileWriteLine($h, $value)
  89.         FileWriteLine($h, $type)
  90.         If $type == 3 Then
  91.             FileWriteLine($h, str2hex(RegRead($key, $value)))
  92.         Else
  93.             FileWriteLine($h, RegRead($key, $value))
  94.         EndIf
  95.         $instance += 1
  96.     Until False
  97.     $instance = 1
  98.     Do
  99.         $newkey = RegEnumKey($key, $instance)
  100.         If @error <> 0 Then ExitLoop
  101.         ConsoleWrite("New subkey: " & $key & "\" & $newkey & @CRLF)
  102.         RegKeySave($key & "\" & $newkey, $regfile)
  103.         $instance += 1
  104.     Until False
  105.     FileClose($h)
  106. EndFunc   ;==>RegKeySave
  107.  
  108. Func restore()
  109.     ConsoleWrite("EXIT" & @CRLF)
  110.     If ProcessExists($pid) Then
  111.         ProgressOn("PAL", "Waiting for portable program to exit...")
  112.         ProcessWaitClose($pid, 30)
  113.         ProcessClose($pid)
  114.         ProgressOff()
  115.     EndIf
  116.     ProgressOn("PAL", "Saving portable application data...")
  117.     DirRemove(@ScriptDir & "\PortableData", 1)
  118.     DirCopy($filespath, @ScriptDir & "\PortableData", 0)
  119.     FileDelete("PortableRegistry.dat")
  120.     RegKeySave($regpath, "PortableRegistry.dat")
  121.     DirRemove($filespath, 1)
  122.     DirCopy(@ScriptDir & "\LocalData", $filespath, 0)
  123.     DirRemove(@ScriptDir & "\LocalData", 1)
  124.     RegDelete($regpath)
  125.     RegKeyLoad("LocalRegistry.dat")
  126.     FileDelete("LocalRegistry.dat")
  127.     ProgressOff()
  128. EndFunc   ;==>restore
  129.  
  130. OnAutoItExitRegister("restore")
  131.  
  132. $cmdl = ""
  133. For $i = 1 To $cmdline[0]
  134.     $cmdl &= " " & $cmdline[$cmdline[0]]
  135. Next
  136. $exe = IniRead("PAL.ini", "PALOptions", "Executable", "") & $cmdl
  137. If $exe == "" Then
  138.     MsgBox(16, "PAL", "You have not setup the main executable in the INI file.")
  139.     Exit 2
  140. EndIf
  141. $regpath = IniRead("PAL.ini", "PALOptions", "RegistryPath", "")
  142. $filespath = IniRead("PAL.ini", "PALOptions", "FilesPath", "")
  143.  
  144. Dim $drive, $dir, $filename, $ext
  145. _PathSplit($exe, $drive, $dir, $filename, $ext)
  146.  
  147. ProgressOn("PAL", "Loading portable application data...")
  148. If Not FileExists("LocalRegistry.dat") And Not FileExists("LocalData") Then
  149.     ConsoleWrite("OK" & @CRLF)
  150.     DirCopy($filespath, @ScriptDir & "\LocalData", 0)
  151.     RegKeySave($regpath, "LocalRegistry.dat")
  152.     DirRemove($filespath, 1)
  153.     RegDelete($regpath)
  154.     DirCopy(@ScriptDir & "\PortableData", $filespath, 1)
  155.     RegKeyLoad("PortableRegistry.dat")
  156.     RegKeyLoad("PortableRegistryConsts.dat")
  157. EndIf
  158. ProgressOff()
  159.  
  160. ConsoleWrite(@WorkingDir & " " & $dir & @CRLF)
  161. $pid = RunWait($exe)
  162. Exit 0
Add Comment
Please, Sign In to add comment