-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoRun.au3
1995 lines (1907 loc) · 87.8 KB
/
AutoRun.au3
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
;#RequireAdmin
#AutoIt3Wrapper_Run_After=del "%scriptfile%_x32.exe"
#AutoIt3Wrapper_Run_After=ren "%out%" "%scriptfile%_x32.exe"
#AutoIt3Wrapper_Run_After=del "%scriptfile%_stripped.au3"
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/PreExpand /StripOnly /RM ;/RenameMinimum
#AutoIt3Wrapper_Compile_both=y
#AutoIt3Wrapper_Res_Description=AutoRun LWMenu
#cs
[FileVersion]
#ce
#AutoIt3Wrapper_Res_Fileversion=1.6.4
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (C) https://lior.weissbrod.com
#pragma compile(AutoItExecuteAllowed, True)
#cs
Copyright (C) https://lior.weissbrod.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Additional restrictions under GNU GPL version 3 section 7:
In accordance with item 7b), it is required to preserve the reasonable legal notices/author attributions in the material and in the Appropriate Legal Notices displayed by works containing it (including in the footer).
In accordance with item 7c), misrepresentation of the origin of the material must be marked in reasonable ways as different from the original version.
#ce
;#include <Date.au3>
;#Include <Crypt.au3>
#include <AssoArrays.au3>
#include <GUIScrollbars_Ex.au3>
#include <ColorConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3> ; for path detection
#include <WinAPIFiles.au3> ; for symlinks
#include <WinAPIProc.au3> ; for symlinks
#include <WinAPIGdi.au3> ; to get GUI colors
;Opt('ExpandEnvStrings', 1)
Opt("GUIOnEventMode", 1)
$programname = "AutoRun LWMenu"
$version =StringRegExpReplace(@Compiled ? StringRegExpReplace(FileGetVersion(@ScriptFullPath), "\.0+$", "") : IniRead(@ScriptFullPath, "FileVersion", "#AutoIt3Wrapper_Res_Fileversion", "0.0.0"), "(\d+\.\d+\.\d+)\.(\d+)", "$1 beta $2")
$thedate = @YEAR
$pass = "*****"
$product_id = "702430" ;"284748"
$keygen_url = "https:/no-longer-used.com/keygen?action={action}&productId={product_id}&key={key}&uniqueMachineId={unique_id}"
$keygen_return = "[\s\S]+<{tag}>(.+)</{tag}>[\s\S]+"
$validate = "validate"
$register = "register"
$unregister = "unregister"
$s_Config = "autorun.inf"
$taskbartitle = "[CLASS:Shell_TrayWnd]" ; for when needing to blink the taskbar when done
$taskbartext = "" ; for when needing to blink the taskbar when done
$taskbarbuttons = "[CLASS:MSTaskListWClass]" ; for when needing to blink the taskbar when done
$shareware = False ; True requires to uncomment <Date.au3> and <Crypt.au3> statements
$fakecmd = ""
; If @Compiled Then
if $cmdline[0] > 0 then
$thecmdline = $cmdline
ElseIf $fakecmd <> "" Then
$thecmdline = StringRegExp($fakecmd, '[^,\s"]+|("[^"]*"\h*)', 3)
$thecmdline = StringSplit(StringReplace(_ArrayToString($thecmdline), """", ""), "|")
Else
Local $thecmdline[1] = [0]
EndIf
If $shareware Then
$keygen_url = StringReplace($keygen_url, "{product_id}", $product_id)
$keyfile = @ScriptDir & "\" & StringLeft(@ScriptName, StringLen(@ScriptName) - StringLen(".au3")) & ".key"
EndIf
$width = StringLen("word1 word2 word3 word4 word5") * 20
;$height=
$left_align = (@DesktopWidth - $width) / 2
$top = 30
If @DesktopWidth / @DesktopHeight < 1.37 Then
$left = @DesktopWidth / 3
Else
$left = @DesktopWidth / 4
EndIf
If Not $shareware Then
$trial = False
ElseIf Not FileExists($keyfile) Then
$trial = True
Else
$trial = False
If StringInStr(FileGetAttrib($keyfile), "R") Then
FileSetAttrib($keyfile, "-R")
EndIf
$keytime = FileGetTime($keyfile)
;$datediff=_DateDiff("D", $keytime[0] & "/" & $keytime[1] & "/" & $keytime[2] & " " & $keytime[3] & ":" & $keytime[4] & ":" & _
;$keytime[5], _NowCalc()) ;requires <Date.au3>
;if FileGetTime($keyfile, default, 1)<FileGetTime(@ScriptFullPath, default, 1) or $datediff>90 Then; requires <Date.au3>
;validate($datediff)
;endif
EndIf
Global $Form1, $nav, $needs_dark_mode = false, $focusbutton_needed = true, $clickbutton_needed = true
load()
While 1
Sleep(100)
WEnd
Func load($check_cmd = True, $skiptobutton = False)
x_del('')
local $cmd_used = StringSplit("simulate singlerun singleclick admin blinktaskbarwhendone netaccess skiptobutton focusbutton clickbutton maxbuttons kiosk debugger", " ", $STR_ENTIRESPLIT), $cmd_matches[0], $cmd_found
If $thecmdline[0] > 0 Then ;and FileExists($thecmdline[1]) and FileGetAttrib($thecmdline[1])="D" then
if $check_cmd then
if _ArraySearch($thecmdline, "^[-/](help|h|\?)$", 1, default, default, 3) > - 1 then
Call("commandlinesyntax", true) ; Using Call to avoid a clash with a later parameter-less event call for same function
Form1Close()
elseif _ArraySearch($thecmdline, "^[-/]envlist$", 1, default, default, 3) > - 1 then
if is_app_dark_theme() And not $needs_dark_mode then
$needs_dark_mode = true
EndIf
Call("listEnvironmentVariables", true) ; Using Call to avoid a clash with a later parameter-less event call for same function
Form1Close()
Else
local $i
EndIf
local $the_path = -1, $cmd_passed_temp = $thecmdline[$thecmdline[0]], $cmd_passed[0] = [], $sim_mode = _ArraySearch($thecmdline, "^[-/]simulate(=\d+|)$", 1, default, default, 3)>-1
$cmd_passed_temp = _ArraySearch($thecmdline, "^[^/-].*", 1, default, default, 3)
if $cmd_passed_temp > -1 then
For $i = $cmd_passed_temp To $thecmdline[0]
_ArrayAdd($cmd_passed, (FileExists($thecmdline[$i]) and StringInStr($thecmdline[$i], chr(32))) ? (chr(34) & $thecmdline[$i] & chr(34)) : $thecmdline[$i])
Next
$cmd_passed = _ArrayToString($cmd_passed, chr(32))
if not x('CUSTOM MENU.cmd_passed') Then ; The only way it exists is if it's a program default
x('CUSTOM MENU.cmd_passed', $cmd_passed)
if x('CUSTOM MENU.simulate') or $sim_mode Then
msgbox($MB_ICONINFORMATION, "Simulation mode", "Will add" & @crlf & $cmd_passed & @crlf & "to all command line parameters")
EndIf
EndIf
$the_path = @ScriptDir
EndIf
local $the_path_temp = _ArraySearch($thecmdline, "^[-/]ini=", 1, default, default, 3)
if $the_path_temp > - 1 then
$the_path = StringSplit($thecmdline[$the_path_temp], "=", 2)[1]
EndIf
if $the_path <> -1 then
$the_path = EnvGet_Full($the_path)
if @WorkingDir = $the_path then
If x('CUSTOM MENU.simulate') or $sim_mode Then
msgbox($MB_ICONINFORMATION, "Simulation mode", "Did not change paths since" & @crlf & $the_path & @crlf & "is already the working folder")
EndIf
else
local $original_path = @WorkingDir
if FileChangeDir($the_path) = 0 Then
msgbox($MB_ICONWARNING, "Failed to change paths", "Could not change" & @crlf & $original_path & @crlf & "to " & @crlf & $the_path)
ElseIf x('CUSTOM MENU.simulate') or $sim_mode Then
msgbox($MB_ICONINFORMATION, "Simulation mode", "Succesfully changed" & @crlf & $original_path & @crlf & "to " & @crlf & $the_path)
EndIf
EndIf
EndIf
EndIf
For $i = 1 To $cmd_used[0]
$cmd_found = _ArraySearch($thecmdline, "^[-/]" & $cmd_used[$i] & "(=\d+|)$", 1, default, default, 3)
if $cmd_found>-1 Then
_ArrayAdd($cmd_matches, StringMid($thecmdline[$cmd_found], 2) & ((StringInStr($thecmdline[$cmd_found], "=", default, default, 2)>0) ? "" : "=1"))
endif
Next
EndIf
global $s_Config_final = StringSplit(@ScriptName, "."), $s_Config_Name = _ArrayToString($s_Config_final, ".", 1, $s_Config_final[0]-1)
$s_Config_final = $s_Config_Name & ".ini"
if not FileExists($s_Config_final) then
$s_Config_final = $s_Config
FileInstall("Autorun.inf", $s_Config)
EndIf
IniRenameSection_alt($s_Config_final, "CUSTOM CD MENU", "CUSTOM MENU")
_ReadAssocFromIni_alt(@WorkingDir & "\" & $s_Config_final, False, '', '~')
For $i = 0 To ubound($cmd_matches)-1
$cmd_found = StringSplit($cmd_matches[$i], "=", 2)
if not x('CUSTOM MENU.' & $cmd_found[0]) or x('CUSTOM MENU.' & $cmd_found[0])<>$cmd_found[1] Then
x('CUSTOM MENU.' & $cmd_found[0], $cmd_found[1])
endif
Next
; Set defaults
x_default('CUSTOM MENU.fontface', 'helvetica')
x_default('CUSTOM MENU.fontsize', '10')
;x_default('CUSTOM MENU.buttoncolor', '#fefee0')
x_default('CUSTOM MENU.buttonwidth', ($width - $left) / 3 + $left)
x_default('CUSTOM MENU.buttonheight', '50')
x_default('CUSTOM MENU.titletext', $programname)
colorcode("CUSTOM MENU.textcolor")
colorcode("CUSTOM MENU.buttoncolor")
colorcode("CUSTOM MENU.menucolor")
x_extra()
If $trial Then
x('CUSTOM MENU.titletext', x('CUSTOM MENU.titletext') & @crlf & '(trial mode)')
EndIf
If x('CUSTOM MENU.simulate') Then
msgbox($MB_ICONINFORMATION, "Simulation mode", "Succesfully loaded " & $s_Config_final)
x('CUSTOM MENU.titletext', x('CUSTOM MENU.titletext') & @crlf & '(simulation mode)')
EndIf
If x('CUSTOM MENU.admin') Then
x('CUSTOM MENU.titletext', x('CUSTOM MENU.titletext') & @crlf & '(admin mode)')
EndIf
if StringInStr(x('CUSTOM MENU.titletext'), @crlf) Then
$top += ubound(StringRegExp(x('CUSTOM MENU.titletext'), @crlf, 3))*$top
EndIf
AdlibRegister("afterExec")
If x('CUSTOM MENU.kiosk') Or x('CUSTOM MENU.hidetrayicon') > 0 Then
Opt("TrayIconHide", 1)
EndIf
If $skiptobutton > 0 or x('CUSTOM MENU.skiptobutton') > 0 Then
if displaybuttons(False, Number(($skiptobutton > 0) ? $skiptobutton : x('CUSTOM MENU.skiptobutton'))) then
return
endif
EndIf
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate(StringReplace(x('CUSTOM MENU.titletext'), @crlf, chr(32)), $width, 0, $left_align, @DesktopHeight, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX))
$nav = GUICtrlCreateMenu("&Navigation")
$help = GUICtrlCreateMenu("&Help")
$upper_enabled = False
If FileExists(StringRegExpReplace(@WorkingDir, "(^.*)\\(.*)", "\1") & "\" & $s_Config) Then
$upper = GUICtrlCreateMenuItem("&Up" & @TAB & "Backspace", $nav)
GUICtrlSetOnEvent(-1, "upper")
$upper_enabled = True
EndIf
$reload = GUICtrlCreateMenuItem("&Reload" & @TAB & "F5", $nav)
GUICtrlSetOnEvent(-1, "reload")
If $upper_enabled Then
Local $AccelKeys2[2][2] = [["{Backspace}", $upper], ["{F5}", $reload]]
Else
Local $AccelKeys2[1][2] = [["{F5}", $reload]]
EndIf
GUISetAccelerators($AccelKeys2)
GUICtrlCreateMenuItem("&Scan", $nav)
GUICtrlSetOnEvent(-1, "scanfiles")
If $trial Then
GUICtrlCreateMenuItem("&Register", $help)
GUICtrlSetOnEvent(-1, "register")
ElseIf $shareware Then
GUICtrlCreateMenuItem("&Unregister", $help)
GUICtrlSetOnEvent(-1, "unregister")
;GUICtrlCreateMenuItem("&Validate", $help)
;GUICtrlSetOnEvent(-1, "validate")
EndIf
GUICtrlCreateMenuItem("&Command line syntax", $help)
GUICtrlSetOnEvent(-1, "commandlinesyntax")
GUICtrlCreateMenuItem("&Environmental variables", $help)
GUICtrlSetOnEvent(-1, "listEnvironmentVariables")
GUICtrlCreateMenuItem("&Generate shortcuts", $help)
GUICtrlSetOnEvent(-1, "genShortcuts")
GUICtrlCreateMenuItem("&About", $help)
GUICtrlSetOnEvent(-1, "about")
If x('CUSTOM MENU.textcolor') <> "" Then
GUICtrlSetDefColor(x('CUSTOM MENU.textcolor'))
EndIf
If x('CUSTOM MENU.buttoncolor') <> "" Then
GUICtrlSetDefBkColor(x('CUSTOM MENU.buttoncolor'))
EndIf
If x('CUSTOM MENU.menucolor') <> "" Then
GUISetBkColor(x('CUSTOM MENU.menucolor'))
EndIf
local $theme = "system"
if x('CUSTOM MENU.theme') And _ArraySearch(StringSplit('dark|light', '|', 2), x('CUSTOM MENU.theme'))>-1 then
$theme = x('CUSTOM MENU.theme')
endif
if $theme == 'dark' Or ($theme = 'system' And is_app_dark_theme()) then
if not $needs_dark_mode then
$needs_dark_mode = true
EndIf
set_dark_theme($Form1, True)
endif
$Label1 = GUICtrlCreateLabel(x('CUSTOM MENU.titletext'), ($width - $left) / 3, -1, x('CUSTOM MENU.buttonwidth'), $top, BitOR($GUI_SS_DEFAULT_LABEL, $SS_CENTER))
GUICtrlSetFont(-1, x('CUSTOM MENU.fontsize') * 2, 1000, 0, x('CUSTOM MENU.fontface'))
If x('CUSTOM MENU.kiosk') Then
GUISetStyle(BitAND(GUIGetStyle()[0], BitNOT($WS_CAPTION)))
else
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
EndIf
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
displaybuttons()
GUISetState(@SW_SHOW)
If $clickbutton_needed then
$clickbutton_needed = false
if x('CUSTOM MENU.clickbutton') > 0 and x('ctrlIds.BUTTON' & x('CUSTOM MENU.clickbutton')) and x('BUTTON' & x('CUSTOM MENU.clickbutton') & '.relativepathandfilename') Then
ControlClick($Form1, "", x('ctrlIds.BUTTON' & x('CUSTOM MENU.clickbutton')))
EndIf
EndIf
#EndRegion ### END Koda GUI section ###
EndFunc ;==>load
Func _GUIGetColor($hWnd, $background = true)
Local $hDC = _WinAPI_GetDC($hWnd), $iColor
if $background then
$iColor = _WinAPI_GetBkColor($hDC)
else
$iColor = _WinAPI_GetTextColor($hDC)
EndIf
_WinAPI_ReleaseDC($hWnd, $hDC)
Return $iColor
EndFunc
func is_app_dark_theme()
return(regread('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize', 'AppsUseLightTheme') == 0) ? True : False
endfunc
func set_dark_theme($hwnd, $dark_theme = True)
; before this build set to 19, otherwise set to 20, no thanks Windaube to document anything ??
$DWMWA_USE_IMMERSIVE_DARK_MODE = (@osbuild <= 18985) ? 19 : 20
$dark_theme = ($dark_theme == True) ? 1 : 0
dllcall( _
'dwmapi.dll', _
'long', 'DwmSetWindowAttribute', _
'hwnd', $hwnd, _
'dword', $DWMWA_USE_IMMERSIVE_DARK_MODE, _
'dword*', $dark_theme, _
'dword', 4 _
)
if $dark_theme then
GUICtrlSetDefColor(BitXOR(_GUIGetColor($hwnd, false), 0xFFFFFF))
GUICtrlSetDefBkColor(BitXOR(0xE1E1E1, 0xFFFFFF))
GUISetBkColor(BitXOR(_GUIGetColor($hwnd), 0xFFFFFF))
endif
endfunc
func EnvGet_Full($string)
local $dummy = chr(1)
$string = StringReplace($string, "'", $dummy)
$string = Execute("'" & StringRegExpReplace($string, "%([\w\(\)]+)%", "' & EnvGet('$1') & '" ) & "'")
$string = StringReplace($string, $dummy, "'")
return $string
EndFunc
func mklink($link, $target, $is_folder)
If Number(_WinAPI_GetVersion()) < 6.0 Then
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Require Windows Vista or later.')
return false
EndIf
; Enable "SeCreateSymbolicLinkPrivilege" privilege to create a symbolic links
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
Local $aAdjust
_WinAPI_AdjustTokenPrivileges($hToken, $SE_CREATE_SYMBOLIC_LINK_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)
If @error Or @extended Then
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'You do not have the required privileges.')
return false
EndIf
; Create symbolic link to the directory where this file is located with prefix "@" on your Desktop
if not FileExists($target) and (($is_folder and not DirCreate($target)) or (not $is_folder and FileOpen($target, $FO_APPEND + $FO_CREATEPATH) = -1)) then
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', "Couldn't create " & $target)
return false
EndIf
If Not _WinAPI_CreateSymbolicLink($link, $target, $is_folder) Then
_WinAPI_ShowLastError()
FileDelete($target)
return false
EndIf
; Restore "SeCreateSymbolicLinkPrivilege" privilege by default
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)
return true
EndFunc
Func readxml($url, $type, $datediff = 0)
$content = BinaryToString(InetRead($url))
x('activate.status', StringRegExpReplace($content, StringReplace($keygen_return, "{tag}", "status"), "$1"))
$replace = StringRegExpReplace($content, StringReplace($keygen_return, "{tag}", "days_till_expiration"), "$1")
If @extended > 0 Then
x('activate.days', $replace)
EndIf
$replace = StringRegExpReplace($content, StringReplace($keygen_return, "{tag}", "use_count"), "$1")
If @extended > 0 Then
x('activate.use', $replace)
EndIf
Switch x('activate.status')
Case "SUCCESS"
x('activate.message', 'Successfully ' & $type & '!')
If $type = "validated" Then
x('activate.message', x('activate.message') & _
@CRLF & '(This is an occasional anti-crack check.' & _
@CRLF & 'Sorry for the inconvenience.)')
EndIf
Case "ERROR_INVALIDKEY"
x('activate.message', 'Invalid key')
Case "ERROR_INVALIDPRODUCT"
x('activate.message', 'Invalid product')
Case "ERROR_EXPIREDKEY"
x('activate.message', 'Expired key')
Case "ERROR_INVALIDMACHINE"
x('activate.message', 'Invalid machine')
Case "ERROR_ALREADYREG"
x('activate.message', 'This machine is already registered')
Case "ERROR_MAXCOUNT"
x('activate.message', 'Already registered on multiple machines')
Case Else
x('activate.status', 'Else')
x('activate.message', 'Problem accessing the server in order to get ' & $type & '.' & _
@CRLF & @CRLF & _
'Consider upgrading the software, if a new version exist.' & _
@CRLF & @CRLF & _
'This could also mean either the server or your Internet connection are down.' & _
@CRLF & 'Please accept our apologies and try again later.')
If $datediff > 95 Then
x('activate.message', x('activate.message') & _
@CRLF & @CRLF & _
'In the mean time, we will have to enter you in TRIAL mode.' & _
@CRLF & @CRLF & _
'If this is an unfortunate mistake, please click register' & _
@CRLF & 'when possible, and use your license key again.')
EndIf
EndSwitch
If x('activate.days') <> "" Then
$plusorminus = StringLeft(x('activate.days'), StringLen("+"))
x('activate.days', StringMid(x('activate.days'), StringLen("+") + 1))
If $plusorminus = "+" Then
$message = "Reminder: your general registration will expire at " & @CRLF & x('activate.days')
Else
$message = "Your registration expired at " & @CRLF & x('activate.days')
EndIf
x('activate.message', x('activate.message') & _
@CRLF & @CRLF & $message)
EndIf
If x('activate.use') <> "" Then
$message = "This key has been in use " & x('activate.use') & " time"
If x('activate.use') > 1 Then $message &= "s"
x('activate.message', x('activate.message') & _
@CRLF & @CRLF & $message)
EndIf
EndFunc ;==>readxml
Func upper()
FileChangeDir(StringRegExpReplace(@WorkingDir, "(^.*)\\(.*)", "\1"))
reload()
EndFunc ;==>upper
Func scanfiles()
GUICtrlSetData(@GUI_CtrlId, "[Scan completed]")
GUICtrlSetState(@GUI_CtrlId, $GUI_DISABLE)
$search = FileFindFirstFile("*")
If $search = -1 Then Return
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($file), "D") And FileExists($file & "\" & $s_Config) Then
GUICtrlCreateMenuItem($file, $nav)
GUICtrlSetOnEvent(-1, "subber")
EndIf
WEnd
FileClose($search)
Send("!N")
EndFunc ;==>scanfiles
Func subber()
FileChangeDir(GUICtrlRead(@GUI_CtrlId, 1))
reload()
EndFunc ;==>subber
Func reload()
GUIDelete()
load(false)
EndFunc ;==>reload
Func unique_id()
Return DriveGetSerial("")
EndFunc ;==>unique_id
Func keyfile()
$thekeyfile = FileOpen($keyfile)
$thekey = FileReadLine($thekeyfile)
;$thekey=_Crypt_DecryptData($thekey, $pass, $CALG_RC4) ;requires <Crypt.au3>
FileClose($thekeyfile)
Return $thekey
EndFunc ;==>keyfile
Func validate($datediff)
$keygen_validate = $keygen_url
$keygen_validate = StringReplace($keygen_validate, "{action}", $validate)
$keygen_validate = StringReplace($keygen_validate, "{key}", keyfile())
$keygen_validate = StringReplace($keygen_validate, "{unique_id}", unique_id())
readxml($keygen_validate, "validated", $datediff)
If x('activate.status') = "SUCCESS" Then
FileSetTime($keyfile, "")
ElseIf x('activate.status') <> "Else" Or $datediff > 95 Then
FileDelete($keyfile)
EndIf
MsgBox(0, $programname, x('activate.message'))
If (x('activate.status') = "SUCCESS" And $trial) Or (x('activate.status') <> "SUCCESS" And Not $trial) Then
selfrestart()
EndIf
EndFunc ;==>validate
Func register()
$keygen_register = $keygen_url
$input = InputBox("Key code", "What is your key code?", Default, Default, Default, Default, Default, Default, Default, $Form1)
If $input <> "" Then
$keygen_register = StringReplace($keygen_register, "{action}", $register)
$keygen_register = StringReplace($keygen_register, "{key}", $input)
$keygen_register = StringReplace($keygen_register, "{unique_id}", unique_id())
;readxml($keygen_register, "registered")
x('activate.status', "SUCCESS")
If x('activate.status') = "SUCCESS" Then
$file = FileOpen($keyfile, 2)
;filewrite($file, _Crypt_EncryptData($input, $pass, $CALG_RC4)) ;requires <Crypt.au3>
FileClose($file)
EndIf
MsgBox(0, $programname, x('activate.message'))
If x('activate.status') = "SUCCESS" Then selfrestart()
EndIf
EndFunc ;==>register
Func unregister()
$keygen_unregister = $keygen_url
$keygen_unregister = StringReplace($keygen_unregister, "{action}", $unregister)
$keygen_unregister = StringReplace($keygen_unregister, "{key}", keyfile())
$keygen_unregister = StringReplace($keygen_unregister, "{unique_id}", unique_id())
readxml($keygen_unregister, "unregistered")
If x('activate.status') = "SUCCESS" Then
FileDelete($keyfile)
EndIf
MsgBox(0, $programname, x('activate.message'))
If x('activate.status') = "SUCCESS" Then selfrestart()
EndFunc ;==>unregister
Func about()
Opt("GUIOnEventMode", Default)
GUICreate("About " & $programname, -1, 450, -1, -1, -1, $WS_EX_MDICHILD, $Form1)
if $needs_dark_mode then set_dark_theme(GUICtrlGetHandle(-1), True)
$localleft = 10
$localtop = 10
$message = $programname & " - Version " & $version & @CRLF & _
@CRLF & _
$programname & " is a portable program that lets you control menus" & _
@CRLF & "via " & $s_Config & " files." & _
@CRLF & @CRLF & _
"It also serves as a portable enforcer/simulator for semi-portable programs" & _
@CRLF & "that don't need installation but do otherwise leave leftovers forever."
If $shareware Then
$message &= @CRLF & @CRLF & "This is the "
If Not $trial Then
$message &= "full version. Thank you for supporting future development!"
Else
$message &= "shareware version. Please support future development registering."
EndIf
EndIf
GUICtrlCreateLabel($message, $localleft, $localtop)
$message = Chr(169) & $thedate & " LWC"
GUICtrlCreateLabel($message, $localleft, ControlGetPos(GUICtrlGetHandle(-1), "", 0)[3] + 18)
Local $aLabel = GUICtrlCreateLabel("https://lior.weissbrod.com", ControlGetPos(GUICtrlGetHandle(-1), "", 0)[2] + 10, _
ControlGetPos(GUICtrlGetHandle(-1), "", 0)[1] + ControlGetPos(GUICtrlGetHandle(-1), "", 0)[3] - $localtop - 12)
GUICtrlSetFont(-1, -1, -1, 4)
GUICtrlSetColor(-1, eval("COLOR_" & ($needs_dark_mode ? "DeepSkyBlue" : "Blue")))
GUICtrlSetCursor(-1, 0)
$message = " This program is free software: you can redistribute it and/or modify" & _
@CRLF & " it under the terms of the GNU General Public License as published by" & _
@CRLF & " the Free Software Foundation, either version 3 of the License, or" & _
@CRLF & " (at your option) any later version." & _
@CRLF & _
@CRLF & " This program is distributed in the hope that it will be useful," & _
@CRLF & " but WITHOUT ANY WARRANTY; without even the implied warranty of" & _
@CRLF & " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" & _
@CRLF & " GNU General Public License for more details." & _
@CRLF & _
@CRLF & " You should have received a copy of the GNU General Public License" & _
@CRLF & " along with this program. If not, see <https://www.gnu.org/licenses/>." & _
@CRLF & @CRLF & _
"Additional restrictions under GNU GPL version 3 section 7:" & _
@CRLF & @CRLF & _
"* In accordance with item 7b), it is required to preserve the reasonable legal notices/author attributions in the material and in the Appropriate Legal Notices displayed by works containing it (including in the footer)." & _
@CRLF & @CRLF & _
"* In accordance with item 7c), misrepresentation of the origin of the material must be marked in reasonable ways as different from the original version."
#cs
$message = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:" & _
@crlf & @crlf & _
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." & _
@crlf & @crlf & _
"THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
#ce
GUICtrlCreateLabel($message, $localleft, ControlGetPos(GUICtrlGetHandle(-1), "", 0)[1] + ControlGetPos(GUICtrlGetHandle(-1), "", 0)[3], 380, 280)
$okay = GUICtrlCreateButton("OK", $localleft + 140, $localtop + 410, 100)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $okay
Form2Close()
ExitLoop
Case $aLabel
clicker(GUICtrlRead($msg))
EndSwitch
WEnd
EndFunc ;==>about
Func commandlinesyntax($nogui = false)
local $title = "Command line syntax", $msg = "[/simulate] [/singlerun] [/singleclick] [/admin] [/blinktaskbarwhendone] [/netaccess=0 | /netaccess=1] [/skiptobutton=X] [/focusbutton=X] [/clickbutton=X] [/kiosk] [/ini=[drive:]path] [/debugger] [extra]" & @crlf & _
"[/envlist]" & @crlf & _
"[/?]" & @crlf & @crlf & _
chr(32) & "/simulate" & @TAB & "Run in simulation mode" & @crlf & _
chr(32) & "/singlerun" & @TAB & "Warn from launching already running apps" & @crlf & _
chr(32) & "/singleclick" & @TAB & "Prevent clicking already clicked buttons" & @crlf & _
chr(32) & "/admin" & @TAB & "Launch programs as an administrator" & @crlf & _
chr(32) & "/blinktaskbarwhendone" & @TAB & "Blink taskbar after apps close" & @crlf & _
chr(32) & "/netaccess=X" & @TAB & "Block/allow apps in Windows Firewall" & @crlf & _
chr(32) & "/skiptobutton=X" & @TAB & "Skip the menu for button X (e.g. 5)" & @crlf & _
chr(32) & "/focusbutton=X" & @TAB & "Focus on button X (e.g. 5) instead of 1" & @crlf & _
chr(32) & "/clickbutton=X" & @TAB & "Open the menu and click button X (e.g. 5)" & @crlf & _
chr(32) & "/maxbuttons=X" & @TAB & "Show only the first X (e.g. 5) buttons" & @crlf & _
chr(32) & "/kiosk" & @TAB & "Open the menu in unmovable kiosk mode" & @crlf & _
chr(32) & "/ini=[drive:]path" & @TAB & "A folder that contains " & $s_Config & @crlf & _
chr(32) & "/debugger" & @TAB & "Reserved for internal debugging" & @crlf & _
chr(32) & "extra" & @TAB & "Pass this extra to the launched programs" & @crlf & _
@crlf & _
chr(32) & "/envlist" & @TAB & "Displays a list of environment variables" & @crlf & _
chr(32) & "/?" & @TAB & "Displays this help"
if IsDeclared("nogui")<>0 then
msgbox($MB_ICONINFORMATION, $title, $msg)
else
msgbox($MB_ICONINFORMATION, $title, $msg, default, $Form1)
EndIf
EndFunc
Func selfrestart($admin = false, $key = "", $close = true, $debug = false)
local $thecmdlineTemp = ""
if $thecmdline[0] > 0 then
$thecmdlineTemp = $thecmdline
EndIf
if ($key = "") then
Form2Close()
else
local $keyNum = StringReplace($key, "BUTTON", "")
local $pos, $extra = "/skiptobutton=" & $keyNum
if $thecmdline[0] > 0 then
$pos = _ArraySearch($thecmdlineTemp, "[-/]skiptobutton=\d+$", 1, default, default, 3)
if $pos = -1 Then
_ArrayInsert($thecmdlineTemp, 1, $extra)
else
if StringSplit($thecmdlineTemp[$pos], "=", 2)[1] <> $keyNum then
$thecmdlineTemp[$pos] = $extra
EndIf
EndIf
$thecmdlineTemp = _ArrayToString(addCMDQuotes($thecmdlineTemp), " ", 1)
Else
$thecmdlineTemp = $extra
EndIf
EndIf
if $debug then ConsoleWrite("Launching " & ($admin ? "(as admin) " : "") & @AutoItExe & " " & (@compiled ? "" : (chr(34) & @ScriptFullPath & chr(34) & " ")) & $thecmdlineTemp & @CRLF)
if $admin then
ShellExecute(@AutoItExe, (@compiled ? "" : (chr(34) & @ScriptFullPath & chr(34) & " ")) & $thecmdlineTemp, Default, "runas")
else
ShellExecute(@AutoItExe, (@compiled ? "" : (chr(34) & @ScriptFullPath & chr(34) & " ")) & $thecmdlineTemp)
EndIf
if $close then
if $debug then ConsoleWrite("Asked to close everything" & @CRLF)
Form1Close()
ElseIf not x('CUSTOM MENU.kiosk') And x($key & '.closemenuonclick') == 1 Then
if $debug then ConsoleWrite("Launched button with menu + asked to close menu + not kiosk => close menu" & @CRLF)
GUIDelete()
endif
EndFunc ;==>selfrestart
Func clicker($item)
ShellExecute($item)
EndFunc ;==>clicker
Func Form2Close()
GUIDelete()
if Opt("GUIOnEventMode") <> 1 then
Opt("GUIOnEventMode", 1)
EndIf
EndFunc ;==>Form2Close
Func Form1Close()
Exit
EndFunc ;==>Form1Close
Func Form1Maximize()
EndFunc ;==>Form1Maximize
Func Form1Minimize()
EndFunc ;==>Form1Minimize
Func Form1Restore()
EndFunc ;==>Form1Restore
Func IniReadSectionNames_alt($hIniLocation)
local $aSections = IniReadSectionNames($hIniLocation)
if not @error then
return $aSections
EndIf
local $filecontent = FileRead($hIniLocation)
if @error Then
SetError(@error)
else
local $aSections = StringRegExp($filecontent, '^|(?m)^\s*\[([^\]]+)', 3)
$aSections[0] = UBound($aSections) - 1
return $aSections
EndIf
EndFunc
; The original function doesn't just rename but also moves sections
Func IniRenameSection_alt($hIniLocation, $aSectionOld, $aSectionNew)
Local $fullPathText = @CRLF & @WorkingDir & "\" & $hIniLocation & @CRLF, $sFileContent = FileRead($hIniLocation)
If @error Then
SetError(@error)
else
Local $regex = "(?m)^(\[)" & $aSectionOld & "(\])(?=\s*(;.*)?$)", $value = StringRegExp($sFileContent, $regex, 1)
If IsArray($value) Then
local $rand = dummywait(true, true)
local $msgReturn = MsgBox($MB_ICONQUESTION + $MB_YESNO, "Upgrade required", "In order to proceed, do you agree to automatically upgrade your" & $fullPathText & "config file from the obsolete section" & @CRLF & _
"[" & $aSectionOld & "] into [" & $aSectionNew & "]?")
dummywait(true, true, $rand)
if $msgReturn <> $IDYES then
Form1Close()
else
Local $file = fileopen($hIniLocation, 2)
if $file == -1 then
msgbox($MB_ICONERROR + $MB_SYSTEMMODAL, "Couldn't open file", "Please check if " & $fullPathText & " is write protected")
Form1Close()
else
if not FileWrite($file, StringRegExpReplace($sFileContent, $regex, "$1" & $aSectionNew & "$2")) then
msgbox($MB_ICONERROR + $MB_SYSTEMMODAL, "Couldn't update file", "Please check if " & $fullPathText & " is write protected")
Form1Close()
Else
msgbox($MB_ICONINFORMATION, "File succesfully updated", "Update done in " & $fullPathText)
EndIf
EndIf
EndIf
EndIf
EndIf
EndFunc
Func IniReadSection_alt($hIniLocation, $aSection)
local $aKV = IniReadSection($hIniLocation, $aSection)
if not @error then
return $aKV
else
IniReadSectionNames($hIniLocation) ; In case reading a specific section failed, try reading them all
if not @error Then
SetError(1) ; Fake an error if reading them all worked, proving reading a specific section isn't the problem
else
local $filecontent = FileRead($hIniLocation)
if @error Then
SetError(@error)
else
local $value = StringRegExp($filecontent, "\Q" & $aSection & ']\E\s+([^\[]+)', 1)
If Not IsArray($value) Then
SetError(1) ; Fake an error if a section couldn't be found
else
If StringInStr($value[0], @CRLF, 1, 1) Then
$value = StringSplit(StringStripCR($value[0]), @LF)
ElseIf StringInStr($value[0], @LF, 1, 1) Then
$value = StringSplit($value[0], @LF)
Else
$value = StringSplit($value[0], @CR)
EndIf
Local $aKV[1][2]
For $xCount = 1 To $value[0]
If $value[$xCount] = "" Or StringLeft($value[$xCount], 1) = ";" Then ContinueLoop
ReDim $aKV[UBound($aKV) + 1][UBound($aKV, 2)]
$value_temp = StringSplit($value[$xCount], "=", 3)
$aKV[UBound($aKV) - 1][0] = $value_temp[0]
$aKV[UBound($aKV) - 1][1] = _ArrayToString($value_temp, "=", 1)
$aKV[0][0] += 1
Next
If $aKV[0][0] = "" Then SetError(1) ; Fake an error if a section is empty
return $aKV
EndIf
EndIf
EndIf
EndIf
EndFunc
;read AssocArray from IniFile Section
;returns number of items read - sets @error on failure
Func _ReadAssocFromIni_alt($myIni = 'config.ini', $multi = True, $mySection = '', $sSep = "|")
If Not StringInStr($myIni,".") Then $myIni &= ".ini"
if $multi then
Local $sIni = StringLeft($myIni,StringInStr($myIni,".")-1)
EndIf
If $mySection == '' Then
$aSection = IniReadSectionNames_alt($myIni); All sections
If @error Then Return SetError(@error, 0, 0)
Else
Dim $aSection[2] = [1,$mySection]; specific Section
EndIf
For $i = 1 To UBound($aSection)-1
Local $sectionArray = IniReadSection_alt($myIni, $aSection[$i])
If @error Then ContinueLoop
For $x = 1 To $sectionArray[0][0]
local $valTemp = ($multi ? $sIni&"." : "")&$aSection[$i]&"."&$sectionArray[$x][0]
If x($valTemp) or IsArray(x($valTemp)) Then
$sectionArray[$x][1] = (x($valTemp) ? x($valTemp) : _ArrayToString(x($valTemp), $sSep)) & $sSep & $sectionArray[$x][1]
EndIf
$sectionArray[$x][1] = StringStripWS(StringSplit($sectionArray[$x][1], ";")[1], 3) ; Support for mid-sentence comments
$sectionArray[$x][1] = BinaryToString($sectionArray[$x][1], $SB_UTF8)
If StringInStr($sectionArray[$x][1], $sSep) then
$posS = _MakePosArray($sectionArray[$x][1], $sSep)
Else
$posS = $sectionArray[$x][1]
EndIf
x($valTemp, $posS)
Next
next
Return $sectionArray[0][0]
EndFunc ;==>_ReadAssocFromIni
Func x_default($key, $default)
if not x($key) Then
x($key, $default)
EndIf
EndFunc
Func x_extra()
specialbutton("CUSTOM MENU.button_browse")
specialbutton("CUSTOM MENU.button_edit")
specialbutton("CUSTOM MENU.button_close")
If x('CUSTOM MENU.button_browse') = "" Or x('CUSTOM MENU.button_browse') <> "hidden" Then
x('button_browse.buttontext', 'Browse Folder')
x('button_browse.relativepathandfilename', 'explorer')
x('button_browse.optionalcommandlineparams', '.')
x('button_browse.programpath', '.')
if not x('CUSTOM MENU.closemenuonclick') then
x('button_browse.closemenuonclick', '1')
EndIf
If x('CUSTOM MENU.button_browse') Then
x('button_browse.show', x('CUSTOM MENU.button_browse'))
EndIf
EndIf
If x('CUSTOM MENU.button_edit') = "" Or x('CUSTOM MENU.button_edit') <> "hidden" Then
x('button_edit.buttontext', 'Edit ' & $s_Config_final)
x('button_edit.relativepathandfilename', $s_Config_final)
if not x('CUSTOM MENU.closemenuonclick') then
x('button_edit.closemenuonclick', '1')
EndIf
If x('CUSTOM MENU.button_edit') Then
x('button_edit.show', x('CUSTOM MENU.button_edit'))
EndIf
EndIf
If not x('CUSTOM MENU.kiosk') And x('CUSTOM MENU.button_close') = "" Or x('CUSTOM MENU.button_close') <> "hidden" Then
x('button_close.buttontext', 'Close menu')
If x('CUSTOM MENU.button_close') = "blocked" Then
x('button_close.show', x('CUSTOM MENU.button_close'))
EndIf
EndIf
Local $key = "CUSTOM MENU", $simulate = x($key & '.simulate'), $set_arr
If IsArray(x($key & '.setenv')) Then
For $i = 0 To UBound(x($key & '.setenv'))-1
if StringInStr(x($key & '.setenv')[$i], "|") > 0 Then
$set_arr = StringSplit(StringReplace(x($key & '.setenv')[$i], " | ", "|"), "|")
if $set_arr[0]>2 then
$set_arr[2] = absolute_or_relative(@WorkingDir, $set_arr[2])
EndIf
if $simulate then
msgbox($MB_ICONINFORMATION, "Simulation mode", "Would have set " & $set_arr[1] & " as " & $set_arr[2])
else
EnvSet($set_arr[1], $set_arr[2])
EndIf
EndIf
Next
EndIf
EndFunc ;==>x_extra
Func displaybuttons($all = True, $skiptobutton = False) ; False is for actual button clicks
local $trueSkip = false
; IsDeclared() is needed to check if GUICtrlSetOnEvent was used, in which case parameters including optional ones aren't used
If IsDeclared("skiptobutton")<>0 and $skiptobutton > 0 then
local $has_command = x('BUTTON' & $skiptobutton & '.relativepathandfilename')
if not $has_command and not $all Then
Return
EndIf
if $Form1 == "" then
$trueSkip = true ; not just buttonafter
EndIf
EndIf
If IsDeclared("all")<>0 And $all Then
$defpush = True
$space = 55
$pad = 10
$localtop = $top + $pad
EndIf
local $btnCount = 0
For $key In x('')
If StringLeft($key, StringLen('button')) = "button" Then ; is it a button?
If $key <> 'button_close' then
IfStringThenArray($key & ".setenv")
IfStringThenArray($key & ".symlink")
IfStringThenArray($key & ".service")
local $optionalcommandlineparams = (not x($key & '.optionalcommandlineparams')) ? "" : x($key & '.optionalcommandlineparams')
if x('CUSTOM MENU.cmd_passed') then
$optionalcommandlineparams = ($optionalcommandlineparams = "") ? x('CUSTOM MENU.cmd_passed') : ($optionalcommandlineparams & " " & x('CUSTOM MENU.cmd_passed'))
EndIf
EndIf
If IsDeclared("all")<>0 And $all Then
if x($key & '.hidefrommenu') > 0 then
ContinueLoop
EndIf
$btnCount += 1
; if a regular button is beyond the allowed max buttons
if x('CUSTOM MENU.maxbuttons') and Number(StringReplace($key, "button", "", 1))>0 and $btnCount>Number(x('CUSTOM MENU.maxbuttons')) then
ContinueLoop
EndIf
useDefault($key, "closemenuonclick")
useDefault($key, "show")
useDefault($key, "hidefrommenu")
$buttonstyle = -1
If x($key & '.buttontext') = "" Or ($key <> 'button_close' And x($key & '.relativepathandfilename') = "") Then
$buttonstyle = $WS_DISABLED
ElseIf x($key & '.show') <> "" And x($key & '.show') = "blocked" Then
$buttonstyle = $WS_DISABLED
x($key & '.buttontext', x($key & '.buttontext') & " <blocked>")
ElseIf $key <> 'button_close' And ( _
StringRegExp(x($key & '.relativepathandfilename'), "^\S+:\S+$") = 0 And _ ; if not URLs (protocol:...)
StringInStr(x($key & '.relativepathandfilename'), ".") > 0 And _ ; if not OS paths (no ".")
Not FileExists(FileGetLongName(EnvGet_Full(x($key & '.relativepathandfilename')), 1)) And _;Then
Not FileExists(FileGetLongName(EnvGet_Full(x($key & '.programpath') & "\" & x($key & '.relativepathandfilename')), 1))) _
or (x($key & ".set_variable") or x($key & ".symlink_link") or x($key & ".services")) Then ; Obsolete variants
$buttonstyle = $WS_DISABLED
local $blocked_msg[0]
Select
case x($key & ".set_variable") or x($key & ".symlink_link") or x($key & ".services")
if x($key & ".set_variable") then _ArrayAdd($blocked_msg, "Use setenv instead of set_variable")
if x($key & ".symlink_link") then _ArrayAdd($blocked_msg, "Use symlink instead of symlink_link")
if x($key & ".services") then _ArrayAdd($blocked_msg, "Use service instead of services")
$blocked_msg = _ArrayToString($blocked_msg, @CRLF)
case Else
$blocked_msg = "File not found"
EndSelect
x($key & '.buttontext', x($key & '.buttontext') & " <" & $blocked_msg & ">")
EndIf
if not x($key & '.buttontext') then
x($key & '.buttontext', $key)
EndIf
if x($key & '.simulate') then
x($key & '.buttontext', x($key & '.buttontext') & " (Simulation mode)")
EndIf
if x($key & '.admin') then
x($key & '.buttontext', x($key & '.buttontext') & " (Admin mode)")
EndIf
If $defpush And $buttonstyle = -1 Then
$buttonstyle = $BS_DEFPUSHBUTTON
$defpush = False
EndIf
x('ctrlIds.' & $key, GUICtrlCreateButton(x($key & '.buttontext'), -1, $localtop, x('CUSTOM MENU.buttonwidth'), x('CUSTOM MENU.buttonheight'), $buttonstyle))
if StringLeft($key, StringLen("button_")) <> "button_" then
x('BTNIds.' & $key, StringMid($key, StringLen("BUTTON")+1))
EndIf
if $focusbutton_needed and x('CUSTOM MENU.focusbutton') and x('CUSTOM MENU.focusbutton')<>"" and $key = "BUTTON" & x('CUSTOM MENU.focusbutton') then
$focusbutton_needed = false
GUICtrlSetState(-1, $GUI_FOCUS)
EndIf
GUICtrlSetFont(-1, x('CUSTOM MENU.fontsize'), 1000, 0, x('CUSTOM MENU.fontface'))
GUICtrlSetOnEvent(-1, "displaybuttons")
$localtop += $space
ElseIf (IsDeclared("skiptobutton")<>0 And $key == ("BUTTON" & $skiptobutton)) Or (IsDeclared("skiptobutton")==0 and $Form1 <> "" And GUICtrlRead(@GUI_CtrlId)<>"" and x($key & '.buttontext') = GUICtrlRead(@GUI_CtrlId)) Then
local $ctrlId = ""
if not (IsDeclared("skiptobutton")<>0 And $key == ("BUTTON" & $skiptobutton)) Then
$ctrlId = @GUI_CtrlId
EndIf
if IsDeclared("skiptobutton")<>0 and (x($key & ".set_variable") or x($key & ".symlink_link") or x($key & ".services")) Then ; Obsolete variants
local $blocked_msg[0] = [0]
if x($key & ".set_variable") then _ArrayAdd($blocked_msg, "Use setenv instead of set_variable")
if x($key & ".symlink_link") then _ArrayAdd($blocked_msg, "Use symlink instead of symlink_link")
if x($key & ".services") then _ArrayAdd($blocked_msg, "Use service insead of services")
$blocked_msg = _ArrayToString($blocked_msg, @CRLF)
msgbox($MB_ICONWARNING, "Needs migration", $blocked_msg)