-
Notifications
You must be signed in to change notification settings - Fork 3
/
GUI.ahk
537 lines (406 loc) · 13.8 KB
/
GUI.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
;;
;; GUI for AdminHelper.ahk
;; Author: Danil Valov <[email protected]>
;;
#NoEnv
#SingleInstance Force
#Include scripts\ConfigReader.ahk
DetectHiddenWindows, On
class AdminHelperGui
{
windowTitle := "Íàñòðîéêè - AdminHelper.ahk"
windowWidth := 900
windowHeight := 700
LabelWidth := 500
plugins := {}
__hasValueInArray(Array, Value)
{
for Key, Val in Array {
if (Val = Value) {
Return Key
}
}
Return 0
}
__stringJoin(Array, Delimiter = ";")
{
Result =
Loop
If Not Array[A_Index] Or Not Result .= (Result ? Delimiter : "") Array[A_Index]
Return Result
}
trayMenuGeneration()
{
Menu, Tray, NoStandard
Menu, Tray, Add, AdminHelper, SettingsGuiOpen
Menu, Tray, Disable, AdminHelper
Menu, Tray, Add
Menu, Tray, Add, Ïåðåçàïóñòèòü, ScriptReload
Menu, Tray, Add, Íàñòðîéêè, SettingsGuiOpen
Menu, Tray, Default, Íàñòðîéêè
Menu, Tray, Add
Menu, Tray, Add, Âûéòè, AppExit
Return
}
guiGeneration()
{
Gui, Settings:New
Gui, Settings:Default
Gui, Settings:+LastFound
this.pluginsViewGeneration()
this.userBindsGeneration()
Gui, Settings:Tab
Gui, Settings:Add, Button, x10 gGuiSave, Ñîõðàíèòü
Gui, Settings:Add, Button, x+5 gSettingsGuiClose, Îòìåíèòü
Gui, Settings:Show, , % this.windowTitle
Return WinExist()
}
modulesListRead()
{
Loop, Files, modules\*.*, D
{
If (FileExist("modules\" A_LoopFileName "\Meta.ini")) {
this.modules[A_LoopFileName] := {}
this.modules[A_LoopFileName]["About"] := ConfigReader.readIniSection("modules\" A_LoopFileName "\Meta.ini", "About")
this.modules[A_LoopFileName]["Config"] := ConfigReader.readIniSection("modules\" A_LoopFileName "\Meta.ini", "Config")
this.modules[A_LoopFileName]["Options"] := ConfigReader.readIniSection("modules\" A_LoopFileName "\Meta.ini", "Options")
}
}
Return
}
pluginsListRead()
{
Global Config
Loop, Files, plugins\*.*, D
{
If (FileExist("plugins\" A_LoopFileName "\Meta.ini")) {
this.plugins[A_LoopFileName] := {}
this.plugins[A_LoopFileName]["About"] := ConfigReader.readIniSection("plugins\" A_LoopFileName "\Meta.ini", "About")
this.plugins[A_LoopFileName]["Config"] := ConfigReader.readIniSection("plugins\" A_LoopFileName "\Meta.ini", "Config")
this.plugins[A_LoopFileName]["Options"] := ConfigReader.readIniSection("plugins\" A_LoopFileName "\Meta.ini", "Options")
this.plugins[A_LoopFileName]["Enabled"] := !!this.__hasValueInArray(Config["EnabledPlugins"], A_LoopFileName)
}
}
Return
}
pluginsViewGeneration()
{
this.modulesListRead()
this.pluginsListRead()
TabString := "Ïëàãèíû|Áèíäåð"
TabString := this.tabListGenerator(TabString)
TabWidth := this.windowWidth - 20
TabHeight := this.windowHeight - 40
this.LabelWidth := TabWidth - 35
Gui, Settings:Add, Tab2, w%TabWidth% h%TabHeight%, %TabString%
this.modulesTabsGeneration()
this.pluginsListGeneration()
this.pluginsTabsGeneration()
Return
}
modulesTabsGeneration()
{
Global Config
LabelWidth := this.LabelWidth
For ModuleName, ModuleVariableObject in Config["modules"] {
ModuleDescription := this.modules[ModuleName]["About"]["Description"]
Gui, Settings:Tab, %ModuleName%, , Exact
Gui, Settings:Font, Bold
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %ModuleName%
Gui, Settings:Font
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+10, %ModuleDescription%
For VariableName, VariableValue in ModuleVariableObject {
VariableDescription := StrSplit(this.modules[ModuleName]["Options"][VariableName], "|")[2]
this.inputGeneration("Module" ModuleName VariableName, VariableValue, VariableDescription, LabelWidth)
}
}
Return
}
pluginsListGeneration()
{
Global
Local LabelWidth := this.LabelWidth
Gui, Settings:Tab, 1
this.inputGeneration("AdminLVL", Config["AdminLVL"], "Óðîâåíü Àäìèíèñòðàòîðà")
Local PluginName, PluginData
For PluginName, PluginData in this.plugins {
if (PluginData["Config"]["AdminLVL"] <= Config["AdminLVL"]) {
Local PluginStatus := PluginData["Enabled"]
Local PluginDescription := PluginData["About"]["Description"]
Gui, Settings:Add, Checkbox, +Wrap w%LabelWidth% y+15 vGuiPlugin%PluginName%Status checked%PluginStatus%, %PluginName% - %PluginDescription%
}
}
Return
}
pluginsTabsGeneration()
{
Global Config
LabelWidth := this.LabelWidth
For PluginName, PluginVariableObject in Config["plugins"] {
if (this.plugins[PluginName]["Enabled"]) {
PluginDescription := this.plugins[PluginName]["About"]["Description"]
Gui, Settings:Tab, %PluginName%, , Exact
Gui, Settings:Font, Bold
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %PluginName%
Gui, Settings:Font
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+10, %PluginDescription%
For VariableName, VariableValue in PluginVariableObject {
VariableDescription := StrSplit(this.plugins[PluginName]["Options"][VariableName], "|")[2]
this.inputGeneration("Plugin" PluginName VariableName, VariableValue, VariableDescription)
}
}
}
Return
}
inputGeneration(VariableName, VariableValue, VariableDescription)
{
Global
Local LabelWidth := this.LabelWidth
if (VariableName = "AdminLVL") {
VariableValue += 1
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %VariableDescription%:
Gui, Settings:Add, DropDownList, w40 vGui%VariableName%Input Choose%VariableValue%, 0|1|2|3|4|5|6
} else if (SubStr(VariableName, -2) = "Key") {
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %VariableDescription%:
Gui, Settings:Add, Hotkey, w150 vGui%VariableName%Input y+5, %VariableValue%
} else if (SubStr(VariableName, -6) = "Boolean") {
if (SubStr(VariableDescription, 1, 4) = "1 - ") {
VariableDescription := SubStr(VariableDescription, 5)
}
Gui, Settings:Add, Checkbox, +Wrap w%LabelWidth% y+15 vGui%VariableName%Input checked%VariableValue%, %VariableDescription%
} else if (SubStr(VariableName, -3) = "File") {
Local TextAreaWidth := this.windowWidth - 45
Local TextAreaRowsCount := (this.windowHeight - 170) / 14
Local FileContents
FileRead, FileContents, %VariableValue%
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %VariableDescription%:
Gui, Settings:Add, Edit, r%TextAreaRowsCount% w%TextAreaWidth% vGui%VariableName%Input, %FileContents%
} else {
Gui, Settings:Add, Text, +Wrap w%LabelWidth% y+15, %VariableDescription%:
if (StrLen(VariableValue) >= 10 || StrLen(VariableValue) = 0) {
Gui, Settings:Add, Edit, w%LabelWidth% vGui%VariableName%Input y+5, %VariableValue%
} else {
Gui, Settings:Add, Edit, w150 vGui%VariableName%Input y+5, %VariableValue%
}
}
Return
}
tabListGenerator(TabString)
{
Global Config
For ModuleName, ModuleVariable in Config["modules"] {
TabString := TabString "|" ModuleName
}
For PluginName, PluginVariables in Config["plugins"] {
if (this.plugins[PluginName]["Enabled"]) {
TabString := TabString "|" PluginName
}
}
Return TabString
}
userBindsGeneration()
{
Global
Gui, Settings:Tab, 2
Local UserBindsWidth := this.windowWidth - 45
Local UserBindsRowsCount := (this.windowHeight - 60) / 14
Local FileContents
FileRead, FileContents, UserBinds.ahk
Gui, Settings:Add, Edit, r%UserBindsRowsCount% w%UserBindsWidth% vGuiUserBindsInput, %FileContents%
Gui, Settings:Tab
Return
}
changeKeyboardLayoutToDefault()
{
RegRead, DefaultKeyboardLayout , HKEY_CURRENT_USER, Keyboard Layout\Preload, 1
DefaultKeyboardLayout := DllCall("LoadKeyboardLayout", "Str", DefaultKeyboardLayout , "Int", 1)
PostMessage, 0x50, 0, %DefaultKeyboardLayout%, , ahk_id %A_ScriptHWND%
SendMessage, 0x50,, %DefaultKeyboardLayout%, , ahk_id %A_ScriptHWND%
Return
}
dataUpdate()
{
Global Config
this.changeKeyboardLayoutToDefault()
For ModuleName, ModuleVariableObject in Config["modules"] {
For ModuleVariableName, ModuleVariableData in ModuleVariableObject {
ModuleVariableInputName = GuiModule%ModuleName%%ModuleVariableName%Input
GuiControlGet, %ModuleVariableInputName%, Settings:
ModuleVariableInputValue := %ModuleVariableInputName%
if (SubStr(ModuleVariableName, -3) <> "File") {
Config["modules"][ModuleName][ModuleVariableName] := ModuleVariableInputValue
} else {
this.textAreaSave(ModuleVariableData, ModuleVariableInputValue)
}
}
}
For PluginName, PluginVariableObject in this.plugins {
GuiControlGet, GuiPlugin%PluginName%Status, Settings:
this.plugins[PluginName]["Status"] := GuiPlugin%PluginName%Status
}
For PluginName, PluginVariableObject in Config["plugins"] {
For PluginVariableName, PluginVariableData in PluginVariableObject {
PluginVariableInputName = GuiPlugin%PluginName%%PluginVariableName%Input
GuiControlGet, %PluginVariableInputName%, Settings:
PluginVariableInputValue := %PluginVariableInputName%
if (SubStr(PluginVariableName, -3) <> "File") {
Config["plugins"][PluginName][PluginVariableName] := PluginVariableInputValue
} else {
this.textAreaSave(PluginVariableData, PluginVariableInputValue)
}
}
}
GuiControlGet, GuiAdminLVLInput, Settings:
Config["AdminLVL"] := GuiAdminLVLInput
this.pluginsStatusesSave()
this.configSave()
this.userBindsSave()
Return
}
pluginsStatusesSave()
{
Global Config
EnabledPlugins := []
For PluginName, PluginData in this.plugins {
If (PluginData["Status"] && PluginData["Config"]["AdminLVL"] <= Config["AdminLVL"]) {
EnabledPlugins.Insert(PluginName)
}
}
Config["EnabledPlugins"] := EnabledPlugins
Return
}
saveOption(OptionName, OptionValue, OptionType, OptionPath)
{
if (OptionType = "Array") {
OptionType := "REG_MULTI_SZ"
} else if (OptionType = "Number") {
OptionType := "REG_DWORD"
} else {
OptionType := "REG_SZ"
}
if (!OptionPath) {
OptionPath := ""
} else {
OptionPath := "\" OptionPath
}
RegWrite, % OptionType, % "HKEY_CURRENT_USER\Software\AdminHelper" OptionPath, % OptionName, % OptionValue
Return
}
configSave()
{
Global Config
this.saveOption("AdminLVL", Config["AdminLVL"], "Number", "")
this.saveOption("EnabledPlugins", this.__stringJoin(Config["EnabledPlugins"], "`n"), "Array", "")
For ModuleName, ModuleVariablesData in Config["modules"] {
For ModuleVariableName, ModuleVariableValue in ModuleVariablesData {
this.saveOption(ModuleVariableName, ModuleVariableValue, "String", "modules\" ModuleName)
}
}
Loop, % Config["EnabledPlugins"].MaxIndex()
{
PluginName := Config["EnabledPlugins"][A_Index]
PluginVariablesData := Config["plugins"][PluginName]
For PluginVariableName, PluginVariableValue in PluginVariablesData {
this.saveOption(PluginVariableName, PluginVariableValue, "String", "plugins\" PluginName)
}
}
Return
}
textAreaSave(File, Value)
{
FileDelete, .cache\%File%.tmp
FileAppend, % Value, .cache\%File%.tmp
FileCopy, .cache\%File%.tmp, %File%, 1
FileDelete, .cache\%File%.tmp
Return
}
userBindsSave()
{
FileDelete, .cache\UserBinds.ahk.tmp
GuiControlGet, GuiUserBindsInput, Settings:
FileAppend, %GuiUserBindsInput%, .cache\UserBinds.ahk.tmp
FileCopy, .cache\UserBinds.ahk.tmp, UserBinds.ahk, 1
FileDelete, .cache\UserBinds.ahk.tmp
Return
}
guiClose()
{
Gui, Settings:Destroy
Return
}
open()
{
IfWinExist, % this.windowTitle
{
WinActivate
} else {
this.guiGeneration()
}
Return
}
done()
{
Gui, Settings:Submit, NoHide
this.dataUpdate()
FullPath := A_ScriptFullPath
If (SubStr(FullPath, -(StrLen(".cache\AdminHelper.ahk") - 1)) = ".cache\AdminHelper.ahk") {
FullPath := "AdminHelper.ahk"
}
If (FileExist(".cache\AdminHelper.ahk")) {
FileDelete, .cache\AdminHelper.ahk
}
Run "%A_AhkPath%" /r "%FullPath%" /saved
ExitApp
Return
}
}
AdminHelperGui := new AdminHelperGui()
CurrentAttribute = %1%
if (CurrentAttribute = "/saved") {
if (A_ScriptName = "AdminHelper.ahk") {
AdminHelperGui.trayMenuGeneration()
}
AdminHelperGui.open()
MsgBox, Ââåä¸ííûå äàííûå ñîõðàíåíû óñïåøíî.`nÍîâûå ïàðàìåòðû óæå ïðèìåíåíû.
} else if (A_ScriptName <> "AdminHelper.ahk") {
AdminHelperGui.open()
} else {
AdminHelperGui.trayMenuGeneration()
if (!Config["FirstLaunch"]) {
AdminHelperGui.saveOption("FirstLaunch", "1", "Number", "")
AdminHelperGui.open()
MsgBox, Âàñ ïðèâåòñòâóåò AdminHelper.ahk`n- óäîáíàÿ óòèëèòà äëÿ Àäìèíèñòðèðîâàíèÿ SAMP-RP ñåðâåðîâ.`n`nÏðèøëî âðåìÿ ïðîèçâåñòè íà÷àëüíóþ íàñòðîéêó ñêðèïòà.`nÝòî íóæíî ñäåëàòü âñåãî ëèøü îäèí ðàç, à äàëüøå âñå íàñòðîéêè`náóäóò ñîõðàíÿòüñÿ íà êîìïüþòåðå àâòîìàòè÷åñêè.`n`nÄëÿ ìèíèìàëüíîé íàñòðîéêè âàì íóæíî óêàçàòü âàø ËÂË Àäìèíèñòðàòîðà.`nÇäåñü òàêæå âû ìîæåòå âêëþ÷àòü/îòêëþ÷àòü ïëàãèíû, ìåíÿòü èõ íàñòðîéêè.`n`n×òîáû çàéòè â ìåíþ íàñòðîåê â áóäóùåì, ïðîñòî êëèêíèòå 2 ðàçà`nïî çåë¸íîé èêîíêå AdminHelper'à ñïðàâà ñíèçó â òðåå (ðÿäîì ñ ÷àñàìè).
}
}
Return
SettingsGuiOpen:
{
AdminHelperGui.open()
Return
}
GuiSave:
{
AdminHelperGui.done()
Return
}
ButtonCancel:
SettingsGuiClose:
{
if (A_ScriptName <> "AdminHelper.ahk") {
ExitApp
} else {
AdminHelperGui.guiClose()
}
Return
}
ScriptReload:
{
Run "%A_AhkPath%" AdminHelper.ahk
ExitApp
Return
}
AppExit:
{
ExitApp
Return
}