@@ -364,6 +364,15 @@ formatHotkeyText(hotkey) {
364
364
return hotkey
365
365
}
366
366
367
+ assertProfileExists (profileName ) {
368
+ Loop Reg REG_KEY_PATH " \Profiles" , " K" {
369
+ if A_LoopRegName = profileName
370
+ return true
371
+ }
372
+ MsgBox " The profile '" profileName " ' does not exist or has been deleted." , " Error" , " Iconx 8192"
373
+ return false
374
+ }
375
+
367
376
General_ClickIntervalModeChanged (* ) {
368
377
local isRange := ! AutoclickerGui[" General_ClickIntervalMode_Radio" ].Value
369
378
AutoclickerGui[" General_ClickIntervalRange_Text" ].Visible := isRange
@@ -826,71 +835,63 @@ Message: {}
826
835
}
827
836
828
837
ProfileLoad (profileName, * ) {
829
- local currentConfig := {}
830
-
831
838
add_log " Loading profile '" profileName " '"
832
839
833
- Loop Reg REG_KEY_PATH " \Profiles" , " K" {
834
- if A_LoopRegName = profileName {
835
- Loop Reg A_LoopRegKey " \" A_LoopRegName
836
- currentConfig.%A_LoopRegName % := RegRead ()
837
-
838
- add_log " Configuration imported"
840
+ if ! assertProfileExists(profileName) {
841
+ setupProfiles
842
+ return
843
+ }
839
844
840
- local err
841
- try {
842
- local name, value
843
- for name, value in currentConfig.OwnProps() {
844
- if name = " Hotkeys" {
845
- add_log " Update Hotkeys"
846
- Hotkeys_ClearAllHotkeys
847
- Loop Parse value, " `n" {
848
- if ! A_LoopField
849
- continue
850
- local hotkeyDataMatch
851
- RegExMatch A_LoopField , " ^(?P<Hotkey>.+?)%(?P<Scope>\d)%(?P<Action>\d)$" , & hotkeyDataMatch
852
- configured_hotkeys.Push {
853
- Hotkey : hotkeyDataMatch[" Hotkey" ],
854
- HotkeyText: formatHotkeyText(hotkeyDataMatch[" Hotkey" ]),
855
- Scope: hotkeyDataMatch[" Scope" ],
856
- Action: hotkeyDataMatch[" Action" ]
857
- }
858
- }
859
- Hotkeys_updateHotkeyBindings
860
- } else {
861
- add_log " Update: " name " (value=" value " )"
862
- local ctrl := AutoclickerGui[name]
863
- if ctrl .Type = " Radio" {
864
- local radioInfo := RadioGroups.%name%
865
- radioInfo.Controls[value].Value := true
866
- if radioInfo.Callback
867
- radioInfo.Callback.Call radioInfo.Controls[value]
868
- } else {
869
- ctrl .Value := value
870
- if ctrl .Type = " Checkbox" {
871
- local checkableInfo := Checkables.%name%
872
- if checkableInfo.HasProp(" Callback" )
873
- checkableInfo.Callback.Call ctrl
874
- }
875
- }
845
+ local err
846
+ try {
847
+ Loop Reg REG_KEY_PATH " \Profiles\" profileName {
848
+ local value := RegRead ()
849
+ if A_LoopRegName = " Hotkeys" {
850
+ add_log " Update Hotkeys"
851
+ Hotkeys_ClearAllHotkeys
852
+ Loop Parse value, " `n" {
853
+ if ! A_LoopField
854
+ continue
855
+ local hotkeyDataMatch
856
+ RegExMatch A_LoopField , " ^(?P<Hotkey>.+?)%(?P<Scope>\d)%(?P<Action>\d)$" , & hotkeyDataMatch
857
+ configured_hotkeys.Push {
858
+ Hotkey : hotkeyDataMatch[" Hotkey" ],
859
+ HotkeyText: formatHotkeyText(hotkeyDataMatch[" Hotkey" ]),
860
+ Scope: hotkeyDataMatch[" Scope" ],
861
+ Action: hotkeyDataMatch[" Action" ]
876
862
}
877
863
}
878
- add_log " Configuration GUI updated from profile"
879
- } catch as err {
880
- add_log " Load Profile error: " err.Message
881
- MsgBox Format ("
882
- (
864
+ Hotkeys_updateHotkeyBindings
865
+ } else {
866
+ add_log " Update: " A_LoopRegName " (value=" value " )"
867
+ local ctrl := AutoclickerGui[A_LoopRegName ]
868
+ if ctrl .Type = " Radio" {
869
+ local radioInfo := RadioGroups.%A_LoopRegName %
870
+ radioInfo.Controls[value].Value := true
871
+ if radioInfo.Callback
872
+ radioInfo.Callback.Call radioInfo.Controls[value]
873
+ } else {
874
+ ctrl .Value := value
875
+ if ctrl .Type = " Checkbox" {
876
+ local checkableInfo := Checkables.%A_LoopRegName %
877
+ if checkableInfo.HasProp(" Callback" )
878
+ checkableInfo.Callback.Call ctrl
879
+ }
880
+ }
881
+ }
882
+ }
883
+
884
+ add_log " Completed profile load"
885
+ } catch as err {
886
+ add_log " Load Profile error: " err.Message
887
+ MsgBox Format ("
888
+ (
883
889
An error occurred whilst loading the profile '{}'.
884
890
This is likely due to corrupt data.
885
891
886
892
Message: {}
887
893
)" , profileName, err.Message), " Load Profile" , " Iconx 8192 "
888
- }
889
- return
890
- }
891
894
}
892
- MsgBox " The profile '" profileName " ' does not exist or has been deleted." , " Error" , " Iconx 8192"
893
- setupProfiles
894
895
}
895
896
896
897
LogsOpen (* ) {
@@ -1168,6 +1169,22 @@ for optionInfo in PersistentOptions {
1168
1169
OptionsMenu.Add
1169
1170
OptionsMenu.Add SZ_TABLE.Menu_Options_ResetToDefault, ResetOptionsToDefault
1170
1171
1172
+ if A_Args.Length > 0 && A_Args[1 ] = " /profile" {
1173
+ add_log " Detected /profile switch"
1174
+
1175
+ if A_Args.Length < 2 {
1176
+ MsgBox " A profile name must be specified." , " Error" , " Iconx 262144"
1177
+ ExitApp
1178
+ }
1179
+
1180
+ if ! assertProfileExists(A_Args[2 ])
1181
+ ExitApp
1182
+
1183
+ ProfileLoad(A_Args[2 ])
1184
+ Start()
1185
+ Close()
1186
+ }
1187
+
1171
1188
AutoclickerGui.Show " x0"
1172
1189
add_log " Showed main GUI"
1173
1190
0 commit comments