-
Notifications
You must be signed in to change notification settings - Fork 19
/
Launch_AutoGUI.ahk
170 lines (154 loc) · 5.29 KB
/
Launch_AutoGUI.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#Requires Autohotkey v2.0
#SingleInstance Force
Persistent
cwd := A_ScriptDir "\required"
#Include "*i %A_ScriptDir%\required\convert\ConvertFuncs.ahk"
#Include "*i %A_ScriptDir%\required\convert\converterMod.ahk"
#Include "*i %A_ScriptDir%\required\Include\splash.ahk"
#Include "*i %A_ScriptDir%\required\convert\_vars.ahk"
#Include "*i %A_ScriptDir%\required\convert\github.ahk"
; --- Readme ---
; Alguimist's Easy AutoGUI for AHK-v2 is a GUI designer for creating AHK-v2 scripts with a focus on ease of use.
; It is built on AHKv1 but handles real-time conversion to AHKv2, making it user-friendly for both beginners and advanced users.
; This script acts as a launcher for Easy AutoGUI, handling the conversion process.
; Credits:
; - Easy AutoGUI was created by -Alguimist-, creator of the Adventure IDE: https://sourceforge.net/projects/autogui/.
; - The AHKv2 converter by contributors like https://github.com/mmikeww and https://github.com/dmtr99.
; - The Autohotkey.com forum user "Boiler" provided the MessageBox Creator within the tools menu.
; These individuals' hard work laid the foundation for this project. I played a small part in bringing Easy AutoGUI to AHKv2 by weaving these two solutions together.
; ------------------------------
Main()
; Main function
Main() {
global PID
missingFilesPrompt() ; Prompt user if required files are missing
, showSplashScreen() ; Display a splash screen
, setDesignMode() ; Set the design mode
, cleanFiles(FileList) ; Clean temporary files
, Run(launch_autogui_cmd, , , &PID) ; Run the AutoGUI command
, Sleep(1000)
EAhwnd := findEasyAutoGUI(PID) ; Find and wait for Easy AutoGUI to launch
while ProcessExist(PID) {
CheckConversionStatus()
}
ExitApp()
}
ExitApp()
CheckConversionStatus() {
while ProcessExist(PID) {
if FileExist(logsPath) {
status := tryRead(logsPath)
inscript := status != "" ? tryRead(ahkv1CodePath) : ""
if (inscript != "") {
writer("", logsPath) ; Clear log file
try {
ConvertandCompile(inscript, ahkv2CodePath)
}
catch as e {
errorLogHandler(e.Message)
sleep(5)
continue
}
}
} else {
Sleep(10)
continue
}
}
ExitApp()
}
; Convert script from AHK v1 to v2
ConvertandCompile(inscript, ahkv2CodePath) {
script := Convert(inscript)
, final_code := modifyAhkv2ConverterOutput(ahkv1CodePath, script)
, writer(final_code, ahkv2CodePath)
, writer("1", returnStatusPath)
}
; Prompt user about missing files
missingFilesPrompt() {
msg := { text: "", title: "Missing Files", show: false }
if not DirExist(cwd) {
msg.show := true
msg.text := 'The `'/required/`' directory included with this app is missing. Would you like to download the required files?`nOtherwise, this app will exit.'
}
else if not FileExist(cwd "\AutoHotKey Exe\AutoHotkeyV1.exe") {
msg.text := 'The `'\required\AutoHotKey Exe\AutoHotkeyV1.exe`' file included with this app is missing. `n`nIf you downloaded from the Github code page, you`'ll need the release to run this application.`nOr edit the _vars.ahk file with your ahkv1 64bit exe. `n`nWould you like to download the required files?`nOtherwise, this app will exit.'
msg.show := true
}
else
{
return
}
if msg.show = True
{
userResponse := MsgBox(msg.text, msg.title, '52')
if (userResponse = "Yes") {
Run("https://github.com/samfisherirl/Easy-Auto-GUI-for-AHK-v2/releases")
}
ExitApp()
}
}
; Clean temporary files
cleanFiles(FileList)
{
for f in FileList {
writer("", f)
}
}
; Find Easy AutoGUI process
findEasyAutoGUI(PID) {
Loop 10 {
if ProcessExist(PID) {
break
}
else {
Sleep(1000)
}
}
try
{
return WinGetID("ahk_pid " PID)
}
}
; Try reading a file
tryRead(path) {
try {
F := FileOpen(path, "r", "utf-8")
out := F.Read()
F.Close()
return out
}
catch as e {
errorLogHandler(e.Message)
Sleep(2)
return ""
}
}
; Write to a file
writer(str_to_write := "", path := "") {
F := FileOpen(path, "w", "utf-8")
F.Write(str_to_write)
F.Close()
}
; Set design mode options
setDesignMode() {
IniWrite "1", settings, "Options", "DesignMode"
IniWrite "1", settings, "Options", "SnapToGrid"
IniWrite "1", settings, "Editor", "DarkTheme"
IniWrite "0", settings, "Sessions", "AutoLoadLast"
IniWrite "0", settings, "Sessions", "SaveOnExit"
IniWrite "0", settings, "Editor", "WordWrap"
}
; Check for the latest version
versionCheck() {
if not FileExist(versionPath) {
try {
Github.latest("samfisherirl", "Easy-Auto-GUI-for-AHK-v2")
}
}
}
; Handle errors and write to the error log
errorLogHandler(errorMsg) {
logMsg := "error occurred at: " FormatTime() " => " errorMsg "`n`n`n"
writer(logMsg, errorLog)
}