-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainConfig.ahk
253 lines (205 loc) · 7.68 KB
/
mainConfig.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
; Optional file of private variables.
#Include *i %A_LineFile%/../../../config/local/privateVariables.ahk
; Constants for machines.
global MACHINE_EpicLaptop := "EPIC_LAPTOP"
global MACHINE_HomeAsus := "HOME_ASUS"
global MACHINE_HomeDesktop := "HOME_DESKTOP"
; Constants for what the menu key should do.
global MENUKEYACTION_MiddleClick := "MIDDLE_CLICK"
global MENUKEYACTION_WindowsKey := "WINDOWS_KEY"
global MAIN_CENTRAL_SCRIPT := "MAIN_CENTRAL_SCRIPT"
; Config class which holds the various options and settings that go into this set of scripts' slightly different behavior in different situations.
class MainConfig {
static multiDelim := "|"
static defaultSettings := {"VIM_CLOSE_KEY":"F9"}
static settings := []
static windows := []
static folders := [] ; abbrev => path
static programs := []
static games := []
init(settingsFile, windowsFile, foldersFile, programsFile, gamesFile) {
this.settings := this.loadSettings(settingsFile)
this.windows := this.loadWindows(windowsFile)
this.folders := this.loadFolders(foldersFile)
this.programs := this.loadPrograms(programsFile)
this.games := this.loadGames(gamesFile)
; DEBUG.popup("MainConfig", "End of init", "Settings", this.settings, "Window settings", this.windows, "Program info", this.programs)
}
loadSettings(filePath) {
settingsAry := []
settingsAry["MACHINE"] := this.loadSettingFromFile(filePath, "MACHINE") ; Which machine this is, from MACHINE_* constants
settingsAry["MENU_KEY_ACTION"] := this.loadSettingFromFile(filePath, "MENU_KEY_ACTION") ; What to do with the menu key, from MENU_KEY_ACTION_* constants
settingsAry["VIM_CLOSE_KEY"] := this.loadSettingFromFile(filePath, "VIM_CLOSE_KEY") ; Which keys should close tabs via vimBindings (generally F-keys).
; DEBUG.popup("Settings", settingsAry)
return settingsAry
}
loadSettingFromFile(filePath, configName) {
IniRead, value, %filePath%, Main, %configName%
; DEBUG.popup("Filepath", filePath, "Config name", configName, "Value", value)
; Multi-entry value, put into an array.
if(stringContains(value, this.multiDelim))
return StrSplit(value, this.multiDelim)
; Single value, use it as-is.
else if(value)
return value
; Empty value, use default.
return this.defaultSettings[configName]
}
loadWindows(filePath) {
tl := new TableList(filePath)
return tl.getFilteredTable("MACHINE", MainConfig.getMachine())
}
loadFolders(filePath) {
global epicPersonalFolder
; Tags that can be used in folders.tl
systemTags := []
systemTags["AHK_ROOT"] := reduceFilepath(A_LineFile, 3) ; 2 levels out, plus one to get out of file itself.
systemTags["USER_ROOT"] := reduceFilepath(A_Desktop, 1)
systemTags["EPIC_PERSONAL"] := epicPersonal
systemTags["EPIC_NFS_3DAY_UNIX"] := epicNFS3DayUnix
systemTags["EPIC_NFS_3DAY"] := epicNFS3Day
systemTags["EPIC_NFS_ASK"] := epicNFSAsk
systemTags["EPIC_NET_HOME"] := epicNetHome
systemTags["EPIC_SOURCE_S1"] := epicSourceCurrentS1
systemTags["EPIC_SOURCE_S2"] := epicSourceCurrentS2
systemTags["EPIC_USERNAME"] := epicUsername
tl := new TableList(filePath)
folderTable := tl.getFilteredTableUnique("NAME", "MACHINE", MainConfig.getMachine())
; Build abbrev-indexed array of entries.
folderPaths := []
For i,folder in folderTable {
abbrevAry := forceArray(folder["ABBREV"])
For j,abbrev in abbrevAry { ; Handle having multiple abbrevs defined (with | syntax)
if(!abbrev) ; Ignore folders with no shortcuts, mostly headers and Selector settings.
Continue
folderPaths[abbrev] := replaceTags(folder["PATH"], systemTags)
}
}
return folderPaths
}
loadPrograms(filePath) {
tl := new TableList(filePath)
uniquePrograms := tl.getFilteredTableUnique("NAME", "MACHINE", this.getMachine())
; DEBUG.popup("MainConfig", "loadPrograms", "Unique table", uniquePrograms)
; Index it by name and machine.
programsAry := []
For i,pAry in uniquePrograms {
name := pAry["NAME"] ; Identifying name of this entry (which this.programs will be indexed by)
if(!IsObject(programsAry[name])) ; Initialize the array.
programsAry[name] := []
programsAry[name] := pAry
}
; DEBUG.popup("MainConfig", "loadPrograms", "Finished programs", programsAry)
return programsAry
}
loadGames(filePath) {
tl := new TableList(filePath)
return tl.getTable()
}
; Note that this will return an array of values if that's what's in settings.
getSetting(settingName = "") {
if(settingName)
return this.settings[settingName]
else
return this.settings
}
setSetting(settingName, value, saveToFile = false) {
this.settings[settingName] := value
if(saveToFile) {
; If it's an array, turn it into a delimited string to write it to the file.
if(isObject(value)) {
For i,v in value {
if(i > 1)
valToWrite .= this.multiDelim
valToWrite .= v
}
} else {
valToWrite := value
}
IniWrite, %valToWrite%, %configFolder%\settings.tl, Main, %settingName%
}
}
getWindow(name = "", exe = "", ahkClass = "", title = "", controlClass = "") {
retWindow := ""
if(!name && !exe && !ahkClass && !title && !controlClass)
return ""
For i,w in this.windows {
; DEBUG.popup("EXE", exe, "Class", ahkClass, "Title", title, "Control", controlClass, "Against settings", w)
if(name && w["NAME"] && (name != w["NAME"]) )
Continue
if(exe && w["EXE"] && (exe != w["EXE"]) )
Continue
if(ahkClass && w["CLASS"] && (ahkClass != w["CLASS"]) )
Continue
if(title && w["TITLE"] && (title != w["TITLE"]) )
Continue
if(controlClass && w["CONTROL_CLASS"] && (controlClass != w["CONTROL_CLASS"]) )
Continue
retWindow := w.clone()
Break
}
; DEBUG.popup("MainConfig","getWindow", "Found window",retWindow)
return retWindow
}
getFolder(abbrev) {
if(!abbrev)
return ""
return this.folders[abbrev]
}
replacePathTags(inputPath) {
return replaceTags(inputPath, this.folders)
}
; Subscripts available (only set if set in file):
; NAME - Program name
; CLASS - ahk_class (or sometimes title prefaced with "{NAME} ")
; PATH - Full path to the executable, including the executable.
; ARGS - Arguments to run with.
; EXE - Executable name (+.exe)
; MACHINE - Machine this was specific to, "" if default.
getProgram(name, subscript = "") {
if(subscript) { ; Get the specific subscript.
return this.programs[name][subscript]
} else { ; Just return the whole array.
return this.programs[name]
}
}
; === Comparison functions for easy "check if this hotkey should trigger X" type needs ===
; Checks for the given value (regardless of whether the desired setting is an array or not).
settingIsValue(configName, value) {
; DEBUG.popup("Name", configName, "Check value", value, "Name value", this.settings[configName], "All settings", this.settings)
; If the setting has multiple values, loop over them and return true if it's in there.
if(IsObject(this.settings[configName])) {
For i,s in this.settings[configName] {
if(s = value)
return true
}
} else {
if(this.settings[configName] = value)
return true
}
return false
}
windowIsGame(titleString := "A") {
WinGet, ahkExe, ProcessName, %titleString%
if(!ahkExe)
return false
For i,game in this.games {
if(ahkExe = game["EXE"])
return true
}
return false
}
; === Shortcut functions for oft-used settings ===
getMachine() {
return this.getSetting("MACHINE")
}
isMachine(machineName) {
return this.settingIsValue("MACHINE", machineName)
}
getMachineTableListFilter() {
filter := []
filter["COLUMN"] := "MACHINE"
filter["VALUE"] := this.getMachine()
return filter
}
}