-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbt_console_select.ahk
1702 lines (1361 loc) · 44.9 KB
/
sbt_console_select.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
#NoEnv
#Warn
#SingleInstance force
#InstallKeybdHook
; https://github.com/zhamlin/AHKhttp
#include, Lib\AHKhttp.ahk
; http://www.autohotkey.com/forum/viewtopic.php?p=355775
#include, Lib\AHKsock.ahk
license := "
(
/*
--------------------------------------------------------------------------------*
*
* sbt_console_select.ahk
*
* use UTF-8 BOM codec
*
* Version -> appVersion
*
* Copyright (c) 2020 jvr.de. All rights reserved.
*
*
--------------------------------------------------------------------------------*
*/
/*
--------------------------------------------------------------------------------*
*
* MIT License
*
*
* Copyright (c) 2020 jvr.de. All rights reserved.
* 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, sub-license, 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:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANT-ABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* UTHORS 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.
*
--------------------------------------------------------------------------------*
*/
)"
/*
--------------------------------------------------------------------------------*
* Main view element is the ListView LV1.
* Upon a click guiMainListViewClick() is called.
--------------------------------------------------------------------------------*
*/
;SetWinDelay, -1
DetectHiddenWindows, On
DetectHiddenText, On
SendMode Input
FileEncoding, UTF-8-RAW
SetWorkingDir, %A_ScriptDir%
; SetKeyDelay, 10, 10
CoordMode, Mouse, Screen
;----------------------------- global variables -----------------------------
global variables
appName := "Sbt_console_select"
appnameLower := "sbt_console_select"
appVersion := "0.236"
app := appName . " " . appVersion
extension := ".exe"
bit := (A_PtrSize=8 ? "64" : "32")
if (!A_IsUnicode)
bit := "A" . bit
bitName := (bit="64" ? "" : bit)
wrkDir := A_ScriptDir . "\"
replFilePart1 := wrkDir . "replPart1.hs"
replFilePart2 := wrkDir . "replPart2.hs"
lastPid := 0
editTextFileFilename := ""
editTextFileContent := ""
usingWSL := false
msgDefault := "Hold key down while clicking: [CTRL] -> open filemanager"
posXsave := 0
posYsave := 0
nomenu := false
lastOpenedTitle := ""
fontDefault := "Segoe UI"
font := fontDefault
fontsizeDefault := 9
fontsize := fontsizeDefault
listWidthDefault := 700
cmdFile := "sbt_console_select.txt"
configFile := "sbt_console_select.ini"
shortcutsFile := "sbt_console_select_shortcuts.txt"
filemanagerPathDefault := "%SystemRoot%\explorer.exe"
filemanagerpath := filemanagerPathDefault
importFileName := ""
wslStart := ""
menuhotkeyDefault := "!t"
menuhotkey := menuhotkeyDefault
replLoadHotkeyDefault := "!e"
replLoadHotkey := replLoadHotkeyDefault
replSelectLoadHotkeyDefault := "^e"
replSelectLoadHotkey := replSelectLoadHotkeyDefault
replSelectLoadPart2HotkeyDefault := "+!e"
replSelectLoadPart2Hotkey := replSelectLoadPart2HotkeyDefault
replResetHotkeyDefault := "^r"
replResetHotkey := replResetHotkeyDefault
exitHotkeyDefault := "+!t"
exitHotkey := exitHotkeyDefault
scsRestPortDefault := 65505
scsRestPort := scsRestPortDefault
localVersionFileDefault := "version.txt"
serverURLDefault := "https://github.com/jvr-ks/"
serverURLExtensionDefault := "/raw/main/"
;------------------------------- Gui parameter -------------------------------
clientWidthDefault := 800
clientHeightDefault := 600
windowPosXDefault := 0
windowPosYDefault := 0
windowPosX := windowPosXDefault
windowPosY := windowPosYDefault
clientWidth := clientWidthDefault
clientHeight := clientHeightDefault
;---------------------------------- objects ----------------------------------
entryNameArr := {}
entryIndexArr := []
directoriesArr := []
startcmdArr := []
shortcutsArr := {}
replcommandsArr := []
;---------------------------------- Params ----------------------------------
hideOnStartup := false
autoselect := false
autoselectName := ""
restapi := true
;------------------------------ Default values ------------------------------
localVersionFile := localVersionFileDefault
serverURL := serverURLDefault
serverURLExtension := serverURLExtensionDefault
updateServer := serverURL . appnameLower . serverURLExtension
replcommandsDefault := ":reset,--load imports--,--load the code part 1--,--load the code part 2--"
replcommands := replcommandsDefault
wsltitlecmd := "echo -ne '\033]0;§§THE TITLE§§\a'"
MouseGetPos, posXsave, posYsave
allArgs := ""
Loop % A_Args.Length()
{
if(eq(A_Args[A_index],"remove"))
ExitApp
if(eq(SubStr(A_Args[A_index],-3,4),".ini"))
configFile := A_Args[A_index]
if(eq(SubStr(A_Args[A_index],-3,4),".txt"))
cmdFile := A_Args[A_index]
if(eq(A_Args[A_index],"restapioff")){
restapioff := 1
}
if(eq(A_Args[A_index],"hidewindow")){
hideOnStartup := 1
}
if(eq(A_Args[A_index],"showwindow")){
hideOnStartup := 0
}
FoundPos := RegExMatch(A_Args[A_index],"\([\s\w]+?\)", found)
If (FoundPos > 0){
autoSelectName := found
autoselect := true
showMessageRed(app . " selected entry: " . autoSelectName, 5000)
; old instance must be closed, takes time ...
sleep,3000
}
allArgs .= A_Args[A_index] . " "
}
additionalCommand := ""
replcommand1 := ""
replcommand2 := ""
replcommand3 := ""
replcommand4 := ""
replcommand5 := ""
replcommand6 := ""
replcommand7 := ""
replcommand8 := ""
replcommand9 := ""
replcommand10 := ""
restapioff := 0
; start global
if (FileExist(appnameLower . ".ini")){
readConfig()
readGuiData()
} else {
saveConfig()
}
readCmd()
readShortcuts()
; serverHttp
if (!restapioff){
; Servermode
paths := {}
paths["/scs"] := Func("scsRest")
serverHttp := new HttpServer()
if (!serverHttp)
msgbox, Could not start HttpServer!
serverHttp.LoadMimes(A_ScriptDir . "/mime.types")
serverHttp.SetPaths(paths)
if (scsRestPort != "" && scsRestPort > 1000){
serverHttp.Serve(0 + scsRestPort)
} else {
serverHttp.Serve(65505)
}
} else {
showMessageRed(app . " Rest API disabled", 3000)
}
if (hideOnStartup){
msg1 := app . " started`n`nCommand-file: " . cmdFile . "`nConfig-file: " . configFile . "`nMenu-hotkey is: " . hotkeyToText(menuhotkey)
showHint(msg1, 6000, 1)
}
mainWindow()
OnMessage(0x03,"WM_MOVE")
return
;---------------------------------- WM_MOVE ----------------------------------
WM_MOVE(wParam, lParam){
global hMain, windowPosX, windowPosY
WinGetPos, windowPosX, windowPosY,,, ahk_id %hMain%
return
}
;---------------------------------- scsRest ----------------------------------
scsRest(ByRef req, ByRef res) {
global autoSelectName, app, entryNameArr
; request example -> curl http://localhost:65505/scs?open=(testareaQuick)
; request example -> curl http://localhost:65505/scs?close=(testareaQuick)
autoSelectName := req.queries["open"]
closeName := req.queries["close"]
if (autoSelectName != ""){
sel := entryNameArr[autoselectName]
if(sel > 0){
res.SetBodyText("Starting / opening: " . autoSelectName)
showMessageGreen(app . " selected entry (" . sel . "): " . autoSelectName, 4000)
res.status := 200
runInDir(sel)
} else {
res.SetBodyText("Selected entry: " . autoSelectName . " not found!")
showHint(app . " selected entry: " . autoSelectName . " not found!", 4000)
res.status := 200
}
}
if (closeName != ""){
res.SetBodyText("Closing: " . closeName)
res.status := 200
toClose := StrReplace(closeName,"(","")
toClose := StrReplace(toClose,")","")
if WinExist(toClose){
Winclose
} else {
msgbox, Window to close (%toClose%) not found!
}
}
return
}
;-------------------------------- mainWindow --------------------------------
mainWindow() {
global hMain, windowPosX, windowPosY, clientWidth, clientHeight
global hideOnStartup
global font, fontsize, wrkDir
global cmdFile, configFile, shortcutsFile, entryNameArr
global entryIndexArr, directoriesArr, startcmdArr, app
global appName, posXsave, posYsave, appVersion, menuhotkey, exitHotkey
global LV1, listWidthDefault, msgDefault, autoselectName, restapioff
global scsRestPort, autoselect
global messagetextRed, messagetextGreen
Menu, Tray, UseErrorLevel ; This affects all menus, not just the tray.
Menu, MainMenu, DeleteAll
Menu, MainMenuEdit, DeleteAll
Menu, MainMenuEdit,Add,Edit Command-file: "%cmdFile%", editTextFileCmdFile
Menu, MainMenuEdit,Add,Edit Command-file: "%cmdFile%" with system default editor,editCommandFileExternal
Menu, MainMenuEdit,Add,
Menu, MainMenuEdit,Add,Edit Shortcuts-file: "%shortcutsFile%", editTextFileShortcutsFile
Menu, MainMenuEdit,Add,Edit Shortcuts-file: "%shortcutsFile%" with system default editor,editShortcutsFileExternal
Menu, MainMenuEdit,Add,
Menu, MainMenuEdit,Add,Edit Config-file: "%configFile%", editTextFileConfigFile
Menu, MainMenuEdit,Add,Edit Config-file: "%configFile%" with system default editor,editConfigFileExternal
Menu, MainMenuEdit,Add,
Menu, MainMenuUpdate, Add,Check if new version is available, checkUpdate
Menu, MainMenuUpdate, Add,Start updater, startUpdate
Menu, MainMenu, NoDefault
Menu, MainMenu, Add,Edit,:MainMenuEdit
Menu, MainMenu, Add,Update,:MainMenuUpdate
Menu, MainMenu, Add,Github,openGithubPage
Menu, MainMenu, Add,Kill %appname%,exit
if (restapioff)
Gui,guiMain:New,+OwnDialogs +LastFound MaximizeBox HwndhMain +Resize, %app% (RestAPI: offline)
Else
Gui,guiMain:New,+OwnDialogs +LastFound MaximizeBox HwndhMain +Resize, %app% (RestAPI-port: %scsRestPort%)
Gui, guiMain:Font, s%fontsize%, %font%
xStart := 2
yStart := 2
xStartLV1 := xStart
yStartLV1 := yStart + 20
Gui, guiMain:Add, Text, VmessagetextRed w400 r1 cRed x%xStart% y%yStart%
Gui, guiMain:Add, Text, VmessagetextGreen w400 r1 cGreen x%xStart% y%yStart%
linesInList := directoriesArr.length()
Gui, guiMain:Add, ListView, x%xStartLV1% y%yStartLV1% r%linesInList% w%listWidthDefault% GguiMainListViewClick vLV1 Grid AltSubmit -Multi NoSortHdr -LV0x10, |Name|Directory|Command
Loop % directoriesArr.length()
{
LV_Add("",A_index,entryIndexArr[A_index],directoriesArr[A_index], startcmdArr[A_index])
}
LV_ModifyCol(1,"Auto Integer")
LV_ModifyCol(2,"Auto")
LV_ModifyCol(3,"Auto")
LV_ModifyCol(4,"Auto")
LV_ModifyCol(5,"Auto")
LV_ModifyCol(6,"Auto")
LV_ModifyCol(7,"Auto")
Gui, guiMain:Add, StatusBar, hwndMainStatusBarHwnd -Theme +BackgroundSilver 0x800
showMessage("", msgDefault)
Gui, guiMain:Menu, MainMenu
if (!hideOnStartup){
setTimer,checkFocus,3000
Gui, guiMain:Show, x%windowPosX% y%windowPosY% w%clientWidth% h%clientHeight%
} else {
Gui, guiMain:Show, x%windowPosX% y%windowPosY% w%clientWidth% h%clientHeight%
hideWindow()
}
if (autoselectName != ""){
n := entryNameArr[autoselectName]
if(n > 0){
hideWindow()
runInDir(n)
} else {
msgbox, Entry not found: %autoselectName%
}
}
return
}
;------------------------------ guiMainGuiSize ------------------------------
guiMainGuiSize(){
global clientWidthDefault, clientHeightDefault, clientWidth, clientHeight
if (A_EventInfo != 1) {
; not minimized
clientWidth := A_GuiWidth
clientHeight := A_GuiHeight
borderX := 10
borderY := 50 ; reserve some space for statusbar and scrollbar
GuiControl, Move, LV1, % "W" . (clientWidth - borderX) . " H" . (clientHeight - borderY)
}
return
}
;-------------------------------- iniReadSave --------------------------------
iniReadSave(name, section, defaultValue){
global configFile
r := ""
IniRead, r, %configFile%, %section%, %name%, %defaultValue%
if (r == "" || r == "ERROR")
r := defaultValue
if (r == "#empty!")
r := ""
return r
}
;----------------------------------- readIni ------------------------------
readConfig(){
global msgDefault, configFile, menuhotkeyDefault, menuhotkey
global replLoadHotkeyDefault, replLoadHotkey, replSelectLoadHotkeyDefault, replSelectLoadHotkey
global replSelectLoadPart2HotkeyDefault, replSelectLoadPart2Hotkey, replResetHotkeyDefault, replResetHotkey
global exitHotkeyDefault, exitHotkey
global filemanagerpath, filemanagerpathDefault
global fontDefault, font, fontsizeDefault, fontsize
global listWidthDefault, replcommands, replcommandsDefault, replcommandsArr
global additionalCommand, wslStart
global scsRestPortDefault, scsRestPort, restapioff
global wsltitlecmd, lastOpenedTitle
; read Hotkey definition
font := iniReadSave("font", "config", fontDefault)
menuhotkey := iniReadSave("menuhotkey", "config", menuhotkeyDefault)
Hotkey, %menuhotkey%, showWindowRefreshed
replLoadHotkey := iniReadSave("replLoadHotkey", "hotkeys", replLoadHotkeyDefault)
Hotkey, %replLoadHotkey%, replLoad
replSelectLoadHotkey := iniReadSave("replSelectLoadHotkey", "hotkeys", replSelectLoadHotkeyDefault)
Hotkey, %replSelectLoadHotkey%, replSelectLoad
replSelectLoadPart2Hotkey := iniReadSave("replSelectLoadPart2Hotkey", "hotkeys", replSelectLoadPart2HotkeyDefault)
Hotkey, %replSelectLoadPart2Hotkey%, replSelectLoadExec
replResetHotkey := iniReadSave("replResetHotkey", "hotkeys", replResetHotkeyDefault)
Hotkey, %replResetHotkey%, replReset
exitHotkey := iniReadSave("exitHotkey", "hotkeys", exitHotkey)
Hotkey, %exitHotkey%, sendExit
filemanagerpath := iniReadSave("filemanagerpath", "external", filemanagerpathDefault)
font := iniReadSave("font", "config", fontDefault)
fontsize := iniReadSave("fontsize", "config", fontsizeDefault)
additionalCommand := iniReadSave("additionalCommand", "config", "")
wslStart := iniReadSave("wslStart", "config", "C:\Windows\System32\wsl.exe")
scsRestPort := iniReadSave("scsRestPort", "config", scsRestPortDefault)
restapioff := iniReadSave("restapioff", "config", 0)
replcommandsArr := StrSplit(iniReadSave("replcommands", "config", replcommandsDefault),",")
wsltitlecmd := iniReadSave("wsltitlecmd", "config", "echo -ne '\033]0;§§THE TITLE§§\a'")
lastOpenedTitle := iniReadSave("lastOpenedTitle", "config", "")
return
}
;-------------------------------- saveConfig --------------------------------
saveConfig(){
global configFile
global menuhotkey, replLoadHotkey, replSelectLoadHotkey, replSelectLoadPart2Hotkey
global replResetHotkey, exitHotkey, filemanagerpath
global font, fontsize, additionalCommand, wslStart, scsRestPort, restapioff
global replcommands, replcommandsArr
; config section:
IniWrite, "%menuhotkey%", %configFile%, config, menuhotkey
IniWrite, "%replLoadHotkey%", %configFile%, config, replLoadHotkey
IniWrite, "%replSelectLoadHotkey%", %configFile%, config, replSelectLoadHotkey
IniWrite, "%replSelectLoadPart2Hotkey%", %configFile%, config, replSelectLoadPart2Hotkey
IniWrite, "%replResetHotkey%", %configFile%, config, replResetHotkey
IniWrite, "%exitHotkey%", %configFile%, config, exitHotkey
IniWrite, "%filemanagerpath%", %configFile%, config, filemanagerpath
IniWrite, "%font%", %configFile%, config, font
IniWrite, "%fontsize%", %configFile%, config, fontsize
IniWrite, "%additionalCommand%", %configFile%, config, additionalCommand
IniWrite, "%wslStart%", %configFile%, config, wslStart
IniWrite, "%scsRestPort%", %configFile%, config, scsRestPort
IniWrite, "%restapioff%", %configFile%, config, restapioff
IniWrite, "%replcommands%", %configFile%, config, replcommands
return
}
;-------------------------------- readConfig --------------------------------
readGuiData(){
global configFile, windowPosX, windowPosY, clientWidth, clientHeight
global windowPosXDefault, windowPosYDefault, clientWidthDefault, clientHeightDefault
windowPosX := iniReadSave("windowPosX","gui", windowPosXDefault)
windowPosY := iniReadSave("windowPosY","gui", windowPosYDefault)
clientWidth := iniReadSave("clientWidth","gui", clientWidthDefault)
clientHeight := iniReadSave("clientHeight","gui", clientHeightDefault)
windowPosX := max(windowPosX,-100)
windowPosY := max(windowPosY,-100)
return
}
;-------------------------------- saveGuiData --------------------------------
saveGuiData(){
global hMain, configFile, windowPosX, windowPosY, clientWidth, clientHeight, windowPosXSave
IniWrite, %windowPosX%, %configFile%, gui, windowPosX
IniWrite, %windowPosY%, %configFile%, gui, windowPosY
IniWrite, %clientWidth%, %configFile%, gui, clientWidth
IniWrite, %clientHeight%, %configFile%, gui, clientHeight
return
}
;----------------------------- showMessageGreen -----------------------------
showMessageGreen(s, t := 0){
global messagetextRed, messagetextGreen
GuiControl,guiMain:, messagetextGreen,%s%
if (t > 0){
tvalue := -1 * t
SetTimer,showMessageRemove,%tvalue%
}
return
}
;------------------------------ showMessageRed ------------------------------
showMessageRed(s, t := 0){
global messagetextRed, messagetextGreen
GuiControl,guiMain:, messagetextRed,%s%
if (t > 0){
tvalue := -1 * t
SetTimer,showMessageRemove,%tvalue%
}
return
}
;----------------------------- showMessageRemove -----------------------------
showMessageRemove(){
global messagetextRed, messagetextGreen
GuiControl,guiMain:, messagetextRed,
GuiControl,guiMain:, messagetextGreen,
return
}
;----------------------------- checkUpdate -----------------------------
checkUpdate(){
global appname, appnameLower, localVersionFile, updateServer
localVersion := getLocalVersion(localVersionFile)
remoteVersion := getVersionFromGithubServer(updateServer . localVersionFile)
if (remoteVersion != "unknown!" && remoteVersion != "error!"){
if (remoteVersion > localVersion){
checkUpdateMsg1 := "New version available: (" . localVersion . " -> " . remoteVersion . ")`, please use the Updater (updater.exe) to update " . appname . "!"
showMessageRed(checkUpdateMsg1, 5000)
} else {
checkUpdateMsg2 := "No new version available (" . localVersion . " -> " . remoteVersion . ")"
showMessageGreen(checkUpdateMsg2, 5000)
}
} else {
checkUpdateMsg := "Update-check failed: (" . localVersion . " -> " . remoteVersion . ")"
showMessageRed(checkUpdateMsg, 5000)
}
return
}
;------------------------------ getLocalVersion ------------------------------
getLocalVersion(file){
versionLocal := 0.000
if (FileExist(file) != ""){
file := FileOpen(file,"r")
versionLocal := file.Read()
file.Close()
}
return versionLocal
}
;------------------------ getVersionFromGithubServer ------------------------
getVersionFromGithubServer(url){
ret := "unknown!"
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Try
{
whr.Open("GET", url)
whr.Send()
status := whr.Status
if (status == 200){
ret := whr.ResponseText
} else {
msgArr := {}
msgArr.push("Error while reading actual app version!")
msgArr.push("Connection to:")
msgArr.push(url)
msgArr.push("failed!")
msgArr.push("URL -> clipboard")
msgArr.push("Closing Updater due to an error!")
errorExit(msgArr, url)
}
}
catch e
{
ret := "error!"
}
return ret
}
;--------------------------- GetProcessMemoryUsage ---------------------------
GetProcessMemoryUsage() {
PID := DllCall("GetCurrentProcessId")
size := 440
VarSetCapacity(pmcex,size,0)
ret := ""
hProcess := DllCall( "OpenProcess", UInt,0x400|0x0010,Int,0,Ptr,PID, Ptr )
if (hProcess)
{
if (DllCall("psapi.dll\GetProcessMemoryInfo", Ptr, hProcess, Ptr, &pmcex, UInt,size))
ret := Round(NumGet(pmcex, (A_PtrSize=8 ? "16" : "12"), "UInt") / 1024**2, 2)
DllCall("CloseHandle", Ptr, hProcess)
}
return % ret
}
;------------------------------ resetStatusBar ------------------------------
resetStatusBar(){
global msgDefault
showMessage("", msgDefault)
return
}
;-------------------------------- showMessage --------------------------------
showMessage(hk1 := "", hk2 := "", part1 := 200, part2 := 500){
global menuHotkey, exitHotkey
SB_SetParts(part1,part2)
if (hk1 != ""){
SB_SetText(" " . hk1 , 1, 0)
} else {
SB_SetText(" " . "Hotkey: " . hotkeyToText(menuHotkey) , 1, 0)
}
if (hk2 != ""){
SB_SetText(" " . hk2 , 2, 0)
} else {
SB_SetText(" " . "Exit-hotkey: " . hotkeyToText(exitHotkey) , 2, 0)
}
memory := "[" . GetProcessMemoryUsage() . " MB] "
SB_SetText("`t`t" . memory , 3, 0)
return
}
;-------------------------------- startUpdate --------------------------------
startUpdate(){
global appname, bitName, extension
updaterExeVersion := "updater" . bitName . extension
if(FileExist(updaterExeVersion)){
msgbox,Starting "Updater" now, please restart "%appname%" afterwards!
run, %updaterExeVersion% runMode
exit()
} else {
msgbox, Updater not found!
}
showWindow()
return
}
;-------------------------------- checkFocus --------------------------------
checkFocus(){
global hMain
if (hMain != WinActive("A")){
hideWindow()
}
return
}
;--------------------------------- replLoad ---------------------------------
replLoad(){
replLoadAction(true)
return
}
;------------------------------ replSelectLoad ------------------------------
replSelectLoad(){
replLoadAction(false)
return
}
;--------------------------------- isComment ---------------------------------
isComment(s){
ret := RegExMatch(s, "(?<!\w)\/\/")
return ret
}
;------------------------------ replLoadAction ------------------------------
replLoadAction(selectAll := false){
global replcommandsArr, lastOpenedTitle, replFilePart1, replFilePart2
global usingWSL, wslStart, importFileName
global replSelectLastDirUsed, lastPid
clipSaved := ClipboardAll
resetStatusBar()
toSend := ""
isWin := WinActive("A")
if (selectAll){
Send {Ctrl down}a{Ctrl up}
}
Send {Ctrl down}c{Ctrl up}
sleep,1000
if (clipboard != ""){
code := clipboard
if (code != ""){
isLoad := RegExMatch(code,"iO)\/\*\* code part 2 section((.|`n|`r)+?)\*\/",m)
if (isLoad > 0){
s := m.Value(1)
FileDelete, %replFilePart2%
FileAppend, %s%, %replFilePart2%
showHint("Loaded code part 2: " . s, 15000)
FileAppend ,`n, %replFilePart2%
}
FileDelete, %replFilePart1%
FileAppend, %code%, %replFilePart1%
FileAppend,`n, %replFilePart1%
if (winExist(lastOpenedTitle)){
winActivate,%lastOpenedTitle%
;--------------------------- replcommands overload ---------------------------
replcommandsFile := replSelectLastDirUsed . "\replcommands.txt"
if (replSelectLastDirUsed != ""){
if (FileExist(replcommandsFile)){
FileRead, replComm, %replcommandsFile%
if (replComm != ""){
replcommandsArr := {}
replcommandsArr := StrSplit(replComm,",")
}
}
}
;---------------------------- command parse loop ----------------------------
l := replcommandsArr.length()
Loop, %l%
{
toSend := replcommandsArr[A_Index]
specialCommand := false
comment := isComment(toSend)
isLoad := RegExMatch(toSend, "i)--load the code part 1--")
if (isLoad && !comment){
if (FileExist(replFilePart1)){
if (!usingWSL){
; not reliable sending multible underscores!
; sendTextViaControl(":load " . replFilePart1, lastPid)
sendTextClipBoard(":load " . replFilePart1, lastPid)
sleep,200
} else {
sendLinuxClipBoard(":load " . cvtToLinux(replFilePart1), lastPid)
sleep,200
}
} else {
msgbox,48,ERROR, File %replFilePart1% not found!
}
specialCommand := true
}
isLoadExec := RegExMatch(toSend, "i)--load the code part 2--")
if (isLoadExec && !comment){
if (FileExist(replFilePart2)){
FileGetSize, fSize, %replFilePart2%
if (0 + fSize > 6){
if (!usingWSL){
; not reliable sending multible underscores!
; sendTextViaControl(":load " . replFilePart2, lastPid)
sendTextClipBoard(":load " . replFilePart2, lastPid)
sleep,200
} else {
sendLinuxClipBoard(":load " . cvtToLinux(replFilePart2), lastPid)
sleep,200
}
}
}
specialCommand := true
}
isLoadExec := RegExMatch(toSend, "i)--load imports--")
if (isLoadExec){
useImportFile := RegExMatch(code,"iO)\/\*\* useImports=([\w\.]*)",m)
if (useImportFile > 0){
importFileName := m.Value(1)
if (importFileName != ""){
if (!usingWSL){
sendTextViaControl(":load " . importFileName, lastPid)
sleep,200
} else {
sendLinuxClipBoard(":load " . cvtToLinux(importFileName), lastPid)
sleep,200
}
}
}
specialCommand := true
}
;---------------------------- other REPL-commands ----------------------------
if (!specialCommand && !comment){
SendInput,{text}%toSend%
SendInput,{Enter}
}
}
showHint("Press [CTRL]-key to return to the previously open window!", 0)
endlessloop:
loop
{
KeyWait,Ctrl,D
sleep,900
if (getkeystate("Ctrl","P") == 0)
break endlessloop
}
showHintDestroy()
if !ErrorLevel
{
winActivate,ahk_id %isWin%
}
} else {
if (lastOpenedTitle == ""){
msgbox,48,ERROR, Console-Window to open, title is empty!
} else {
msgbox,48,ERROR, Console-Window %lastOpenedTitle% not found!
}
}
} else {
msgbox, No code to run in REPL selected!
}
} else {
msgbox, Clipboard is empty or contains wrong data-type!
}
clipBoard := clipSaved
return
}
;-------------------------------- cvtToLinux --------------------------------
cvtToLinux(d){
pathLinux := RegExReplace(d,"\\","/")
pathLinux := RegExReplace(pathLinux,"i)c:","/mnt/c")
pathLinux := RegExReplace(pathLinux,"i)d:","/mnt/d")
pathLinux := RegExReplace(pathLinux,"i)e:","/mnt/e")
pathLinux := RegExReplace(pathLinux,"i)~","$HOME")
return pathLinux
}
;---------------------------- replSelectLoadExec ----------------------------
replSelectLoadExec(){
; save part 2-code to file "replPart2.tmp" or delete it, if clipBoard is empty
global replFilePart2
clipSaved := clipBoardAll
Send {Ctrl down}c{Ctrl up}
sleep,1000
clp := Trim(clipBoard)
clipBoard :=
if (clp != ""){
if (FileExist(replFilePart2))
FileDelete, %replFilePart2%
FileAppend , %clp%, %replFilePart2%
FileAppend ,`n, %replFilePart2%
showHint("Saved as code part 2: `n" . clp, 5000)
} else {
if (FileExist(replFilePart2)){
FileDelete, %replFilePart2%
showHint("Code part 2 removed!", 5000)
}
}
clipBoard := clipSaved
return
}
;----------------------------- SetTextAndResize -----------------------------
SetTextAndResize(controlHwnd, newText) {
dc := DllCall("GetDC", "Ptr", controlHwnd)
; 0x31 = WM_GETFONT
SendMessage 0x31,,,, ahk_id %controlHwnd%
hFont := ErrorLevel
oldFont := 0
if (hFont != "FAIL")
oldFont := DllCall("SelectObject", "Ptr", dc, "Ptr", hFont)
VarSetCapacity(rect, 16, 0)
; 0x440 = DT_CALCRECT | DT_EXPANDTABS
h := DllCall("DrawText", "Ptr", dc, "Ptr", &newText, "Int", -1, "Ptr", &rect, "UInt", 0x440)
; width = rect.right - rect.left
w := NumGet(rect, 8, "Int") - NumGet(rect, 0, "Int")
if oldFont
DllCall("SelectObject", "Ptr", dc, "Ptr", oldFont)
DllCall("ReleaseDC", "Ptr", controlHwnd, "Ptr", dc)
GuiControl,, %controlHwnd%, %newText%
GuiControl Move, %controlHwnd%, % "w" w
return w
}
;------------------------------ replReset ------------------------------
replReset(){
global lastOpenedTitle, replFilePart1, replFilePart2