-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportableapps-autoinstaller.ahk
143 lines (112 loc) · 4.64 KB
/
portableapps-autoinstaller.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#Requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force
; Author: Davide DG
; Source: https://github.com/davidedg/PortableApps-Updates-Automator
; Version: 1.0
PA_exefullpath := FileSelect(1+2, A_ScriptDir, "Pick Portable Apps Installer", "PA Installer (*.paf.exe)")
if PA_exefullpath = ""
ExitApp
; PA_exefullpath := "W:\cp\GoogleChromePortable_120.0.6099.225_online.paf.exe"
SplitPath PA_exefullpath, &PA_exename, &PA_dir ; e.g.: F:\Downloads\GoogleChromePortable_120.0.6099.225_online.paf.exe -> GoogleChromePortable_120.0.6099.225_online.paf.exe
PA_name := StrSplit(PA_exename,"_",1)[1] ; GoogleChromePortable_120.0.6099.225_online.paf.exe -> [1]: GoogleChromePortable
TargetDirs_cfgfname := PA_name ".targets"
TargetDirs_cfgpath := PA_dir "\" TargetDirs_cfgfname
if not FileExist(TargetDirs_cfgpath) {
MsgBox TargetDirs_cfgpath "`r`n`r`ndoes not exists. Creating a default one.`r`nPlease modify it and then re-rerun this script", "Cfg File does not exist"
FileAppend
(
"; this is the default path`r`n"
".\" PA_name "`r`n"
"`r`n"
"; uncomment and modify to add more targets`r`n"
"; .\" PA_name "-2" "`r`n"
"; .\" PA_name "-3" "`r`n"
"; " A_MyDocuments "\" PA_name "-4`r`n"
), TargetDirs_cfgpath
ExitApp
}
TargetDirs := Array()
Loop read, TargetDirs_cfgpath {
if InStr(A_LoopReadLine, "\") ; lines must contain a path separator ('\') to be considered valid
AND NOT A_LoopReadLine ~= "^[\s\t]*;" ; allows commenting with a starting semicolon
TargetDirs.push GetFullPathName(A_LoopReadLine)
}
switch PA_name {
case "GoogleChromePortable": Installer__GoogleChromePortable
default: Installer__NA
}
MsgBox "All Targets completed",,"T5"
ExitApp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Installer__GoogleChromePortable() {
Loop TargetDirs.Length {
T := TargetDirs[A_Index]
failed := false
Run PA_exefullpath ,PA_dir,,&PA_pid
WinWaitActive "ahk_pid " PA_pid,,5
Sleep 250
WinActivate
Send "English" ; Set the Installer Language to English (this is required to then catch the "&Finish" button at the end)
Sleep 250
Send "{Enter}" ; confirm the language
WinWaitNotActive "ahk_pid " PA_pid,,2
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Sleep 250
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Send "{Enter}" ; Send Enter to Start Install
Sleep 250
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Send "{Enter}" ; Send Enter to acknowledge the License
Sleep 250
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Send T ; Send the Target path to the already selected edit input box
Sleep 250
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Send "{Enter}" ; Enter to confirm install
; now we wait up to 30 seconds for the installation to finish
MAX_INSTALL_TIMEWAIT := 30000 ; DEBUG 30000
_starttime := A_TickCount
_elapsed := 0
waiting_finish_button := true
while (waiting_finish_button and (_elapsed < MAX_INSTALL_TIMEWAIT)) {
try {
waiting_finish_button := ControlGetEnabled("Button2",, "&Finish") = false
} catch TargetError {
sleep 250
_elapsed := A_TickCount - _starttime
}
}
if _elapsed >= MAX_INSTALL_TIMEWAIT {
MsgBox("Installation did not complete in time:`r`n" T, "ERROR","OK Iconx")
ExitApp
}
Sleep 1000
WinWaitActive "ahk_pid " PA_pid,,5
WinActivate
Send "{Enter}" ; Enter to click the default (Finish) button
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Installer__NA() {
MsgBox "Installer for " PA_name " not yet implemented"
ExitApp
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetFullPathName(path) {
cc := DllCall("GetFullPathNameW", "str", path, "uint", 0, "ptr", 0, "ptr", 0, "uint")
buf := Buffer(cc*2)
DllCall("GetFullPathNameW", "str", path, "uint", cc, "ptr", buf, "ptr", 0, "uint")
return StrGet(buf)
}