-
Notifications
You must be signed in to change notification settings - Fork 0
/
program_launcher.ahk
2996 lines (2459 loc) · 101 KB
/
program_launcher.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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;-------------------------------------;
; ;
; PUBLIC DOMAIN ;
; ;
; This file is released ;
; under the cc0 license. ;
; ;
;-------------------------------------;
; ;
; Written by: ;
; Gamepad-Coder ;
; ;
;-------------------------------------;
;-----------------------------------------------------------------------;
; program_launcher.ahk ;
;-----------------------------------------------------------------------;
; ;
; version 2 ;
; ;
;-----------------------------------------------------------------------;
; ;
; ==================== ;
; About the program: ;
; ==================== ;
; ;
; ---------------- ;
; What it does: ;
; ---------------- ;
; ;
; program_launcher.ahk is a small utility ;
; to reduce the number of steps to ;
; ;
; (1) open programs or ;
; (2) navigate to folders ;
; (by opening the folder ;
; in a new Windows Explorer window). ;
; ;
; You can register a word or phrase as a [Command] ;
; which program_launcher.ahk will associate with an [Action]. ;
; ;
; Program Launcher's main hotkey will open a small popup. ;
; Type a Command into the popup, then press enter ;
; and your Action will run! ;
; ;
; -------------------------------------- ;
; See the function Default_Save_File() ;
; at the bottom of this file to read: ;
; -------------------------------------- ;
; ;
; () an overview, ;
; () user guide, ;
; () and syntax for the sections of the settings file ;
; ;
; Note: ;
; ;
; This script does provide a graphic user interface ;
; to change settings, so the syntax guide is mainly for ;
; debugging and users who want to understand the script better. ;
; ;
;-----------------------------------------------------------------------;
;================================================;
; ;
; begin autorun section ;
; ;
;================================================;
;---------;`
; ? ;
;---------------------------------------------------------;``
; For more information about the "auto-execute section" ;
; at the beginning of an AutoHotkey script, see: ;
; https://www.autohotkey.com/docs/Scripts.htm#auto ;
;---------------------------------------------------------;```
#SingleInstance Force
SetWinDelay, -1
SetControlDelay, -1
;
; more info:
;
; https://www.autohotkey.com/docs/commands/SetControlDelay.htm
; https://www.autohotkey.com/boards/viewtopic.php?t=9660
;
; https://www.autohotkey.com/docs/commands/SetWinDelay.htm
;
; https://www.autohotkey.com/docs/commands/_SingleInstance.htm
;---------------------------------------------------------------------------
_AHK_DIR := "C:\[autohotkey]\"
;-----------------------------------------------------------------`
; variables
;-----------------------------------------------------------------``
;
;
; [_savefile_path]
;
; Default name of the settings file from which
; program_launcher.ahk loads settings and saved commands.
;
; This filename can be changed here.
;
;
; [_savefile__default_content]
;
; Holds the default text to insert into
; the %_savefile_path%.ini file.
;
;
; [_hotkey_for_commandline_popup]
;
; Assigned by .ini settings, by default <^#Space>
; If unlisted in .ini
; then automatically assigned to default.
;
; Program is useless without at least this,
; so it can't be omitted.
;
; Edge cases with buggy AHK scripts can result in blocking
; keyboard or mouse input. But for normal use this hotkey
; will always allow the user to exit the application:
; - by opening the command prompt
; - then typing the Command associated with Quit.
;
;
; [_hotkey_for_quit]
;
; Assigned via .ini, by default <^#Q>.
; If unlisted in .ini
; then there will be no hotkey assigned
; to quit program_launcher.ahk
;
; If unlisted, program can be quit:
; (1) by right clicking the Notification Tray icon
; for program_launcher.ahk, then selecting quit,
;
; or
;
; (2) by opening the commandline popup
; then entering the command assigned to the Quit aciton.
;-----------------------------------------------------------------```
_o_Gui_ProgramLauncher_UserInputCommand_Popup := ""
_o_Gui_Config_Main := ""
_o_Gui_Config_Popup := ""
_o_Gui_Config_IconPicker := ""
_COMMANDS := {}
_ACTIONS := {}
_ICON_INDEX := 138
_savefile_path := "program_launcher_settings.ini"
_savefile__default_content := ""
_hotkey_for_commandline_popup := ""
_hotkey_for_settings := ""
_hotkey_for_reload := ""
_hotkey_for_quit := ""
FILE_HELPER.Load_Settings()
Menu, Tray, Icon, Shell32.dll, %_ICON_INDEX%
return
;================================;
; </> end of autorun section ;
;================================;
;-----------------------------------------------------------------------------------------------
;================================================;
; ;
; Hotkeys ;
; ;
;================================================;
;=======================================================;
; (KEY) AutoHotkey hotkey syntax : ;
;=======================================================;
; ;
; + shift ;
; ^ ctrl ;
; # win ;
; ! alt ;
; ;
; For more information see: ;
; https://www.autohotkey.com/docs/commands/Hotkey.htm ;
; https://www.autohotkey.com/docs/KeyList.htm ;
;=======================================================;
;---------------------------------------------;
; These hotkeys are dynamically assigned ;
; from the settings file when the app starts. ;
;---------------------------------------------;
;
; ^#Space::
; ProgramLauncherPopupCommand
; return
;
; ^#!q::
; ProgramLauncherQuit
; return
; TODO
;
; Ran out of time,
; going to add this to the settings file in the next version.
;
^#!r::
Reload
return
;==================================;
; </> end of Hotkey definitions ;
;==================================;
;-----------------------------------------------------------------------------------------------
;================================================;
; ;
; Labels ;
; ;
;================================================;
;======================
; Quit
;======================
ProgramLauncherQuit:
ExitApp
return
;===================================================
; SETTINGS
;
;-> Open the window to configure Program Launcher.
;===================================================
OpenConfigurationWindow:
_o_Gui_Config_Main := new GuiConfigMain
return
;======================================================
; Reload Settings Window
;
; -> Reloads the configuration window
; in order to display a new icon in the title bar.
;======================================================
ReloadConfigurationWindow:
{
;--------------------------------------------------------------------`
; When the user selects a new Icon,
; the Configuration Gui should reflect this change.
;--------------------------------------------------------------------``
;
; Progression:
;
; 1. The user changes the program's icon using
; the "Settings" tab of the Configuration Gui
; 2. The Configuration Gui's class stores the user's choice
; in the global _ICON_INDEX variable.
; 3. The Config Gui calls this label.
; 4. This label deletes both the Configuration Window's
; global object instance & the Config Window Gui.
; 5. This label re-creates the Config Window's object & Gui.
; 6. The Config Window is told to change to the "Settings" tab.
; 7. The Config Window now has a new icon and the user is still
; oriented and on the same tab.
;
; Aesthetically, this implementation is a bit choppy in presentation,
; but it's a simple way to accomplish changing the icon
; without telling the user
;
; "This will be reflected the next time you run this application."
;
; Alternatively:
;
; It seems like a title bar icon can be changed at runtime
; without destroying the gui by using .dll calls,
; but I haven't personally researched this.
;
; Further reading:
;
; https://www.autohotkey.com/boards/viewtopic.php?t=72727
;
;--------------------------------------------------------------------```
_o_Gui_Config_Main := ""
_o_Gui_Config_Main := new GuiConfigMain
_o_Gui_Config_Main.Fn_Change_to_Settings_Tab()
return
}
;======================
; Command Line Popup
;======================
ProgramLauncherPopupCommand:
{
;---------------------------------------------------------`
; This label creates the "Command Line" popup
; where the user can type a Command to trigger an Action.
;---------------------------------------------------------``
;
; If the Command exists and is not disabled,
; then the Action associated with the Command is run,
; and the popup is closed.
;
; If the Command is disabled, or text is typed
; which does not match any Command,
; then the popup silently closes.
;---------------------------------------------------------```
box_title := "Program Launcher!"
box_prompt := "`nEnter your command... : ) "
box_option_noHide := ""
box_width := 300
box_height := 150
Inputbox, userEnteredString
, %box_title%
, %box_prompt%
, %box_option_noHide%
, %box_width%
, %box_height%
; , X
; , Y
; , Font
; , Timeout
; , Default string for editable field
;-----------------------------------------------------------------------
; https://www.autohotkey.com/docs/commands/InputBox.htm#Error_Handling
;
; If the user hits cancel or escape,
; then don't process the entered text.
;
;
if( 0 != ErrorLevel ){
return
}
if( _COMMANDS.HasKey( userEnteredString ) ){
cmd := _COMMANDS[ userEnteredString ]
;------------------------------------------
; If a Command is disabled, it will still
; exist in the app at runtime, but
; calls to run it will be ignored here:
;
if( false == cmd["enabled"] ){
return
}
else{
run_action_id := cmd["action_id"]
gosub RunActionID
}
}
return
}
;======================
; Run Action
;======================
RunActionID:
{
;----------------------------------------------------------------------`
; This is the only place in the code
; where Actions are actually run.
;----------------------------------------------------------------------``
;
; This label is separate from the "ProgramLauncherPopupCommand" label
; to allow the user to run Actions from both of these windows:
;
; (1) from the Command input popup
; (2) from the Actions tab of the Configuration Gui.
;
;----------------------------------------------------------------------```
;---------------------------------------------------------------`
; Currently, the only two Actions which call internal functions
;---------------------------------------------------------------``
; for Program Launcher are Quit & Settings.
;
; The Quit Action :
; - closes any opened popups
; - unassigns any hotkeys registered by the app
; - and terminates the application.
;
; The Settings Action will open
; a window for the user to interactively :
; - add, edit, and remove Actions & Commands
; - enable or disable Commands
; - change settings, including which icon to
; display (this icon appears in the title bar
; and in the Notification Area of the Windows Taskbar).
; ```
if( run_action_id == "QUIT" ){
ExitApp
}
else
if( cmd.action_id == "SETTINGS" ){
gosub OpenConfigurationWindow
}
;-------------------------------------------------------`
; For all other Actions
;-------------------------------------------------------``
;
; Either:
; - a specific folder is opened or
; - a specific app is run
; optionally with added arguments / parameters
;
; For example, if your Chrome web browser
; has multiple profiles, you can tell it to load
; for a specific user by using the argument:
;
; --profile-directory="Profile 2"
; ```
else
if( _ACTIONS.HasKey( run_action_id ) ){
act := _ACTIONS[ run_action_id ]
act_path := act["path"]
act_type := act["type"]
act_arg := act["arg"]
if( "folder" == act_type ){
run explorer.exe "%act_path%"
}
else
if( "app" == act_type ){
run "%act_path%" %act_arg%
}
}
return
}
;===============================;
; </> end of Label section ;
;===============================;
;-----------------------------------------------------------------------------------------------
;===========================================================;
; ;
; ;
; Class - Savefile Parser & Writer functions ;
; ;
; ;
;===========================================================;
;====================================================================`
; About the FILE_HELPER class
;====================================================================``
;
; FILE_HELPER contains all the functionality to
;
; (1) Read the settings file.
; (2) Create a settings file if it doesn't exist.
; (3) Update the settings file when the user changes
; settings in the CONFIG graphic user interface window.
;
; When the app is initialized, FILE_HELPER is called
; to read the savefile.
;
; When the user alters a setting in the CONFIG window,
; FILE_HELPER is called with the new setting name and value
; updates the savefile, then tells the GUI window to proceed.
;
; The GUI knows about the COMMANDS and ACTIONS arrays,
; but it knows nothing of the savefile nor functions to
; alter the savefile. By organizing the app like this,
; functionality is modular and isolated, and each class
; has a specific scope it acts within, instead of having
; one giant class of spaghetti code which handles
; all types of functionality. This is cleaner and easier
; to both maintain and extend.
;
;
; REGULAR EXPRESSIONS:
;
; FILE_HELPER uses Regular Expressions extensively.
;
; I have tried to add annotations and breakdowns,
; but if you're unfamiliar with Regular Expressions
; (or if you're unfamiliar with programming in general)
; this section might seem a bit arcane without further study.
;
; If you are unfamiliar with Regular Expressions,
; here are some resources to help you get started:
;
; () regex101.com is a phenomenal tool for
; learning, writing, and debugging Regular Expressions.
;
; () AutoHotkey's RegEx Quick Reference
; is a great resource for starting.
;
; And the AHK documentation for RegExReplace and RegExMatch
; should help you understand this section better.
;
; https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
; https://www.autohotkey.com/docs/commands/RegExMatch.htm
; https://www.autohotkey.com/docs/commands/RegExReplace.htm
;
; () Finally, if you're planning on using Regular Expressions
; in AutoHotkey long-term, or for complicated use cases:
;
; AHK Forum user "jeeswg" has created an EPIC tutorial post
; detailing how to use Regular Expressions in AutoHotkey
; in great and exhaustive detail:
;
; https://www.autohotkey.com/boards/viewtopic.php?t=28031
;
; Shoutout to jeeswg and thanks for all your excellent posts.
;
;
; NOTE:
;
; This class is not meant to be instantiated as an object.
; It could have been a collection of isolated functions
; at the toplevel of this script, but for long scripts this
; quickly becomes noisy.
;
; I grouped these functions together in a class to improve
; readability, organization, and to enable NotePad++'s
; code-block folding to quickly expand or contract
; thematically related sections of code.
;
;====================================================================```
class FILE_HELPER {
static init__ar_duplicate_actions_found := []
static init__ar_duplicate_commands_found := []
Load_Settings() {
FILE_HELPER.Initialize_Load_Savefile()
FILE_HELPER.Init_Validate_and_Prompt_User_if_Errors()
}
;======================================================================;`
; About Initialize_Load_Savefile() ;
;======================================================================;``
; ;
; ---------- ;
; First ;
; ---------- ;
; ;
; When the script begins, ;
; the Auto-Execute section at the very beginning of this file ;
; initializes some global variables, then immediately calls ;
; FILE_HELPER.Load_Settings(), which then calls this function. ;
; ;
; Before Program Launcher can be useful, it needs to be initialized. ;
; Here, FILE_HELPER reads the settings file into memory. ;
; ;
; --------------------------------------- ;
; Missing settings file? No problem. ;
; --------------------------------------- ;
; ;
; Initialize_Load_Savefile() will create a default savefile ;
; if the settings file does not exist. ;
; ;
; For pre-existing and newly added savefiles, ;
; the process from that point is identical. ;
; ;
; ----------------------------- ;
; What is initialized here? ;
; ----------------------------- ;
; ;
; The settings file will be read into the program's memory: ;
; ;
; (1) settings will be assigned ;
; (such as the icon to display in the notification area), ;
; ;
; (2) hotkeys will be assigned, ;
; ;
; (3) Commands will be registered with their Action to call ;
; ;
; (4) Actions will be registered with their function to run. ;
; ;
; ----------------------------------------------------- ;
; Comments a.k.a Ignored lines in the settings file ;
; ----------------------------------------------------- ;
; ;
; This parsing function will ignore ;
; any line beginning with a ';' in the settings file: ;
; ;
; (a) This allows the user to comment out sections of ;
; the settings file which they wish to keep, ;
; but don't want to keep active. ;
; ;
; (b) This comment/ignore-a-line feature ;
; allows me to embed a tutorial into the settings file itself. ;
; ;
; --------------------------------- ;
; So how does the parsing work? ;
; --------------------------------- ;
; ;
; Initialize_Load_Savefile() will look for ;
; three sections in the savefile: ;
; "Settings[", "Commands[" and "Actions[". ;
; ;
; The ([) open square bracket must be ;
; on the same line as the section title (Section[). ;
; ;
; Then there will be some lines following the start of a section ;
; which correspond to settings for that section. ;
; ;
; Then each section ends with a line which contains nothing ;
; but a "]" close square bracket. ;
; ;
; For example, the default Settings section ;
; in the settings file looks like this: ;
; ;
; SETTINGS[ ;
; icon: 95 ;
; hotkey_for_commandline_popup: ctrl win space ;
; hotkey_for_quit: ctrl win alt q ;
; ] ;
; ;
; ;
; Initialize_Load_Savefile() will keep track of which section ;
; it is currently parsing within, ;
; ;
; and for each line it reads within a section, ;
; it will call one of these and pass the current line as a parameter: ;
; ;
; Init_Parse_Savefile_SettingsLine( current_line ) ;
; Init_Parse_Savefile_CommandLine( current_line ) ;
; Init_Parse_Savefile_ActionLine( current_line ) ;
; ;
; ;
;======================================================================;```
Initialize_Load_Savefile() {
global
/*
===============================================
Steps:
===============================================
(1) See if Savefile exists.
(2) Read Savefile into program memory
(2.1) Ignore commented lines (any line beginning with a semicolon ';')
(2.2) Look for one of these sections:
'settings['
'commands['
'actions['
(2.3) Parse each line as section
til matching line beginning with ']'
(and containing no other non-whitespace characters)
is found :
(2.4) Repeat til all 3 items in (2.2) are searched for
(3) Defaults & Error Correction
(3.1) if not (1),
Generate default savefile
Load default settings
(3.2) if missing
settings:'_hotkey_for_commandline_popup',
Use default hotkey <Ctrl+Win+Space>
if unable to get hotkey from
settings:'_hotkey_for_commandline_popup',
Exit Application and inform user how to debug.
(This behaviour is intended to prevent
pushing hotkey and overriding other AutoHotkey scripts.)
(3.3) if missing settings:'icon'
Use default icon
(3.4) if missing command for quit or settings,
if no conflict with other user commands:
Add Command:'Quit':Quit
Add Command:'Settings':Settings
if user command conflicts with Quit or Settings
notify as soon as init done.
Done.
*/
;-------------------------------------------
; Create Savefile if it doesn't exist.
;-------------------------------------------
if( ! FileExist(_savefile_path) ){
;---------------------------------------------------------------
; Either 1st run, or user renamed, deleted, or moved savefile.
; Steps to take:
;
; (1) init _savefile__default_content
; (2) create default save file
;---------------------------------------------------------------
Default_Save_File() ; located at the bottom of this file.
FileAppend, %_savefile__default_content%, %_savefile_path%
}
;------------------------------------
; Parse savefile into memory
;------------------------------------
if( FileExist(_savefile_path) ){
; data := ""
; FileRead, data, %_savefile_path%
str := ""
;-----------------------------------------------------------------------
; Parser's counter values:
; 0 when (section"[") not encountered
; 1 when (section"[") encountered and section lines being parsed
; 2 when ("]") has been encountered and finished processing section
;-----------------------------------------------------------------------
counter_settings := 0
counter_commands := 0
counter_actions := 0
;-------------------------------------------------------------
; For more information about Regular Expressions, see:
;
; AHK Doc Pages:
; https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
; https://www.autohotkey.com/docs/commands/RegExReplace.htm
; https://www.autohotkey.com/docs/commands/RegExMatch.htm
;
; Online RegEx Tester + Guide:
; https://regex101.com/
;
; jeeswg's RegEx Tutorial:
; https://www.autohotkey.com/boards/viewtopic.php?t=28031
;
;-------------------------------------------------------------
match_lines_beginning_with_semi := "^[ \t]*[;].*"
match_entirely_whitespace_lines := "^[ \t]*$"
match_settings := "i)^[ \t]*SETTINGS[ \t]*\[[ \t]*$"
match_commands := "i)^[ \t]*COMMANDS[ \t]*\[[ \t]*$"
match_actions := "i)^[ \t]*ACTIONS[ \t]*\[[ \t]*$"
match_close_set_group := "i)^[ \t]*\][ \t]*$"
str_for_usr_output := ""
FILE_HELPER.init__ar_duplicate_commands_found := []
FILE_HELPER.init__ar_duplicate_actions_found := []
;---------------------------------------------
; Read _program_launcher_settings.ini,
; one line at a time.
;
Loop, Read, %_savefile_path%
{
is_comment := RegExMatch(A_LoopReadLine, match_lines_beginning_with_semi)
is_empty := RegExMatch(A_LoopReadLine, match_entirely_whitespace_lines)
is_empty := (A_LoopReadLine=="" or is_empty)
;--------------------------------------------------
; (;) comment encountered
; or empty line (with entirely whitespace characters) encountered
;
; (;) at beginning of line or
; any number of whitespace (anynum spaces and/or anynum tabs) then (;)
;
if( is_comment or is_empty ){
continue
}
;----------------------------------------------------
; (settings[) encountered
;
; (settings), case insensitive
; followed by ([), spaces before, between, or after are ignored
;
else if( RegExMatch(A_LoopReadLine, match_settings) ){
if( counter_settings == 0
and counter_actions != 1
and counter_commands != 1 )
{
; Found "Settings[" && not in the middle of "Commands[" nor "Actions["
counter_settings := 1
continue
}
else{
; either
; section actions[ is open but not closed
; section commands[ is open but not closed
; duplicate line settings[ encountered
; when section settings[ is either already open or finished
}
}
;----------------------------------------------------
; (commands[) encountered
;
; (commands), case insensitive
; followed by ([), spaces before, between, or after are ignored
;
else if( RegExMatch(A_LoopReadLine, match_commands) ){
if( counter_commands == 0
and counter_settings != 1
and counter_actions != 1 )
{
; Found "Commands[" && not in the middle of "Settings[" nor "Actions["
counter_commands := 1
continue
}
else{
; either
; section settings[ is open but not closed
; section actions[ is open but not closed
; duplicate line commands[ encountered
; when section commands[ is either already open or finished
}
}
;----------------------------------------------------
; (actions[) encountered
;
; (actions), case insensitive
; followed by ([), spaces before, between, or after are ignored
;
else if( RegExMatch(A_LoopReadLine, match_actions) ){
if( counter_actions == 0
and counter_commands != 1
and counter_settings != 1 )
{
; Found "Actions[" && not in the middle of "Commands[" nor "Settings["
counter_actions := 1
continue
}
else{
; either
; section commands[ is open but not closed
; section settings[ is open but not closed
; duplicate line actions[ encountered
; when section actions[ is either already open or finished
}
}
;----------------------------------
; (]) encountered while inside either
;
; (settings[),
; (commands[), or
; (actions[)
;
else if( RegExMatch(A_LoopReadLine, match_close_set_group) ){
; ? set counter to 2 if just closed that section,
; : otherwise leave unaltered
counter_settings := (counter_settings==1) ? 2 : counter_settings
counter_commands := (counter_commands==1) ? 2 : counter_commands
counter_actions := (counter_actions ==1) ? 2 : counter_actions
}
;----------------------------------
; (anything else) encountered while inside either
;
; (settings[),
; (commands[), or
; (actions[)
;
else{
if( counter_settings == 1 ){
FILE_HELPER.Init_Parse_Savefile_SettingsLine( A_LoopReadLine )
}
else
if( counter_commands == 1 ){
FILE_HELPER.Init_Parse_Savefile_CommandLine( A_LoopReadLine )
}
else
if( counter_actions == 1 ){
FILE_HELPER.Init_Parse_Savefile_ActionLine( A_LoopReadLine )
}
}
}
}
return
}
;=================================;
; ;
; HELPER FUNCTIONS FOR ;
; ;
; Initialize_Load_Savefile() ;
; ;
;=================================;
Init_Parse_Savefile_SettingsLine( full_line_text ) {
global _ICON_INDEX
match_set_icon := "i)^[ \t]*icon[ \t]*:[ \t]*(\d+)[ \t]*$"
match_set_hot_pop := "i)^[ \t]*hotkey_for_commandline_popup[ \t]*:[ \t]*((\w+[ \t]*)+)$"
match_set_hot_quit := "i)^[ \t]*hotkey_for_quit[ \t]*:[ \t]*((\w+[ \t]*)+)$"
; extract text, ignoring leading spaces before first non-whitepace character
line := RegExReplace(full_line_text, "(^[ \t]*)(.*)", "$2")
int_icon := RegExReplace(line, match_set_icon, "$1", found_icon)
str_hot_pop := RegExReplace(line, match_set_hot_pop, "$1", found_pop )
str_hot_quit := RegExReplace(line, match_set_hot_quit, "$1", found_quit)
if( found_icon ){
_ICON_INDEX := int_icon
}
else if( found_pop
or found_quit )
{
which_hotkey := (found_pop) ? "commandline_popup" : "quit"
ssv_key_list := (found_pop) ? str_hot_pop : str_hot_quit
; ssv similar to csv, space separated values
FILE_HELPER.Init_Parse_Settings_Hotkey(which_hotkey, ssv_key_list, line)
}
return
}
Init_Parse_Savefile_CommandLine( full_line_text ) {
global _ACTIONS
global _COMMANDS
;-----------------------------
; Command syntax in savefile:
;
; Command: decimal