installAu3.au3 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #NoTrayIcon
  2. #AutoIt3Wrapper_Change2CUI=y
  3. Global $sAutoitDir = RegRead('HKLM\SOFTWARE\AutoIt v3\Autoit', 'InstallDir')
  4. If Not FileExists($sAutoitDir) Or @error Then
  5. MsgBox(64, "Au3-CLI", "Could not find autoit installDir, exiting.")
  6. Exit
  7. EndIf
  8. If Not @Compiled Then
  9. EnvUpdate()
  10. Global $sPathRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
  11. Global $sCompilerPath = $sAutoitDir & "\Aut2Exe\Aut2exe.exe"
  12. Global $sDesiredDir = @AppDataDir & "\au3"
  13. Global $sDesiredFullPath = $sDesiredDir & "\au3.exe"
  14. Global $aEnvs = StringSplit(RegRead($sPathRegKey, "PATH"), ";")
  15. Global $has_env = 0
  16. Global $has_exe = FileExists($sDesiredDir & "\au3.exe")
  17. For $i = 1 To $aEnvs[0]
  18. If $sDesiredDir == $aEnvs[$i] Then $has_env = 1
  19. Next
  20. If ($has_env + $has_exe) == 2 Then
  21. MsgBox(64, "Au3-CLI", "Au3-CLI is setup properly.")
  22. Exit
  23. EndIf
  24. ; Add au3 to PATH env var
  25. If $has_env == 0 Then
  26. RegWrite($sPathRegKey, "PATH", "REG_EXPAND_SZ", RegRead($sPathRegKey, "PATH") & ";" & $sDesiredDir)
  27. EnvUpdate()
  28. EndIf
  29. ; Compile
  30. If $has_exe == 0 Then
  31. If Not FileExists($sDesiredDir) Then DirCreate($sDesiredDir)
  32. RunWait(StringFormat('"%s" /in "%s" /out "%s" /console', $sCompilerPath, @ScriptFullPath, $sDesiredFullPath))
  33. EndIf
  34. MsgBox(64, "Au3-CLI", "Setup complete")
  35. Exit
  36. EndIf
  37. ;Utility buffer
  38. ConsoleWrite(@LF)
  39. If $CmdLine[0] < 1 Then
  40. ConsoleWrite("Usage " & @LF & @LF & "au3 <file> <param1 param2 param3...>" & @LF & "au3 run <Script name>" & @LF)
  41. Exit
  42. EndIf
  43. ; Check if any scripts should be ran
  44. If $CmdLine[1] == "run" Then
  45. If $CmdLine[0] < 2 Then
  46. ConsoleWrite("Usage: 'au3 run <name>'" & @LF)
  47. Exit
  48. EndIf
  49. runScript($CmdLine[2])
  50. Exit
  51. EndIf
  52. Global $AutoitExe = $sAutoitDir & "\AutoIt3.exe"
  53. Global $sFile = StringRight($CmdLine[1], 3) <> "au3" ? $CmdLine[1] & ".au3" : $CmdLine[1]
  54. Global $sParams = StringReplace($CmdLineRaw, $CmdLine[1], "")
  55. Global $iPid = Run($AutoitExe & ' "' & $sFile & '" ' & $sParams, "", Default, 0x6)
  56. Global $sLine
  57. While 1
  58. $sLine = StdoutRead($iPid)
  59. If @error Or Not ProcessExists($iPid) Then Exit
  60. If $sLine <> '' Then ConsoleWrite($sLine)
  61. WEnd
  62. While 1
  63. $sLine = StderrRead($iPid)
  64. If @error Then Exit
  65. ConsoleWrite($sLine)
  66. Exit
  67. WEnd
  68. Func runScript($scriptname)
  69. Local $aScripts = IniReadSection("au3.ini", "scripts")
  70. If @error Then
  71. ConsoleWrite("No scripts defined." & @LF)
  72. Exit
  73. EndIf
  74. For $i = 0 To $aScripts[0][0]
  75. If $aScripts[$i][0] == $scriptname Then
  76. ConsoleWrite(StringFormat("Running script '%s'", $scriptname) & @LF)
  77. Local $aScriptConent = StringSplit($aScripts[$i][1], "|")
  78. For $j = 1 To $aScriptConent[0]
  79. RunWait($aScriptConent[$j])
  80. Next
  81. Exit
  82. EndIf
  83. Next
  84. ConsoleWrite(StringFormat("Script '%s' does not exist", $scriptname) & @LF)
  85. Exit
  86. EndFunc ;==>runScript