-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Functions.ahk
1683 lines (1237 loc) · 42.3 KB
/
Functions.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Modular Simulator Controller System - Global Functions ;;;
;;; ;;;
;;; Author: Oliver Juwig (TheBigO) ;;;
;;; License: (2021) Creative Commons - BY-NC-SA ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;-------------------------------------------------------------------------;;;
;;; Global Include Section ;;;
;;;-------------------------------------------------------------------------;;;
#Include ..\Includes\Constants.ahk
#Include ..\Includes\Variables.ahk
;;;-------------------------------------------------------------------------;;;
;;; Private Variable Section ;;;
;;;-------------------------------------------------------------------------;;;
global vDebug = false
global vLogLevel = kLogWarn
global vTargetLanguageCode = "en"
global vSplashCounter = 0
global vLastImage
global vVideoPlayer
global vSongIsPlaying = false
global vProgressIsOpen = false
global vProgressBar
global vProgressTitle
global vProgressMessage
global vEventHandlers = Object()
global vIncomingMessages = []
global vOutgoingMessages = []
global vPendingTrayMessages = []
global vTrayMessageDuration = 1500
;;;-------------------------------------------------------------------------;;;
;;; Private Function Declaration Section ;;;
;;;-------------------------------------------------------------------------;;;
ftpUpload(server, user, password, localFile, remoteFile) {
static a := "AHK-FTP-UL"
m := DllCall("LoadLibrary", "str", "wininet.dll", "ptr")
h := DllCall("wininet\InternetOpen", "ptr", &a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")
if (!m || !h)
return false
f := DllCall("wininet\InternetConnect", "ptr", h, "ptr", &server, "ushort", 21, "ptr", &user, "ptr", &password, "uint", 1, "uint", 0x08000000, "uptr", 0, "ptr")
if f {
if !DllCall("wininet\FtpPutFile", "ptr", f, "ptr", &localFile, "ptr", &remoteFile, "uint", 0, "uptr", 0)
return false, (DllCall("wininet\InternetCloseHandle", "ptr", h) && DllCall("FreeLibrary", "ptr", m))
DllCall("wininet\InternetCloseHandle", "ptr", f)
}
DllCall("wininet\InternetCloseHandle", "ptr", h) && DllCall("FreeLibrary", "ptr", m)
return true
}
createMessageReceiver() {
Gui MR:-Border -Caption
Gui MR:Color, D0D0D0
Gui MR:Add, Text, X10 Y10, % translate("Modular Simulator Controller System")
Gui MR:Add, Text, , % A_ScriptName
Gui MR:Margin, 10, 10
Gui MR:Show, Hide AutoSize X0 Y0
}
consentDialog(id) {
static consentDropDown
static closed
if (id = "Close") {
closed := true
return
}
else
closed := false
language := getLanguage()
if ((language != "en") && (language != "de"))
language := "en"
texts := readConfiguration(kConfigDirectory . "Consent.ini")
Gui CNS:-Border ; -Caption
Gui CNS:Color, D0D0D0
Gui CNS:Font, s10 Bold
Gui CNS:Add, Text, x0 y8 w800 +0x200 +0x1 BackgroundTrans gmoveConsentDialog, % translate("Modular Simulator Controller System")
Gui CNS:Font, Norm, Arial
Gui CNS:Add, Text, x0 y32 w800 h23 +0x200 +0x1 BackgroundTrans, % translate("Declaration of consent")
Gui CNS:Add, Text, x8 y70 w784 h180 -VScroll +Wrap ReadOnly, % StrReplace(StrReplace(getConfigurationValue(texts, language, "Introduction"), "``n", "`n"), "\<>", "=")
Gui CNS:Add, Text, x8 y260 w450 h23 +0x200, % translate("Your database identification key is:")
Gui CNS:Add, Edit, x460 y260 w332 h23 -VScroll ReadOnly Center, % id
Gui CNS:Add, Text, x8 y300 w450 h23 +0x200, % translate("Do you agree to the transfer of your local data to a central server?")
Gui CNS:Add, DropDownList, x460 y300 w332 AltSubmit Choose3 VconsentDropDown, % values2String("|", map(["Yes", "No", "Ask again later..."], "translate")*)
Gui CNS:Add, Text, x8 y340 w784 h60 -VScroll +Wrap ReadOnly, % StrReplace(StrReplace(getConfigurationValue(texts, language, "Information"), "``n", "`n"), "\<>", "=")
Gui CNS:Add, Link, x8 y410 w784 h60 cRed -VScroll +Wrap ReadOnly, % StrReplace(StrReplace(getConfigurationValue(texts, language, "Warning"), "``n", "`n"), "\<>", "=")
Gui CNS:Add, Button, x368 y490 w80 h23 Default gcloseConsentDialog, % translate("Save")
Gui CNS:+AlwaysOnTop
Gui CNS:Show, Center AutoSize
Gui CNS:Default
Loop
Sleep 100
until closed
GuiControlGet consentDropDown
Gui CNS:Destroy
return ["Yes", "No", "Retry"][consentDropDown]
}
closeConsentDialog() {
consentDialog("Close")
}
moveConsentDialog() {
moveByMouse("CNS")
}
changeProtection(up) {
static level := 0
level += (up ? 1 : -1)
if (level > 0) {
Critical 100
BlockInput On
}
else if (level == 0) {
BlockInput Off
Critical Off
}
else if (level <= 0)
Throw "Nesting error detected in changeProtection..."
}
playThemeSong(songFile) {
songFile := getFileName(songFile, kUserSplashMediaDirectory, kSplashMediaDirectory)
if FileExist(songFile)
SoundPlay %songFile%
}
readLanguage(targetLanguageCode) {
translations := {}
Loop Read, % getFileName("Translations." . targetLanguageCode, kUserConfigDirectory, kConfigDirectory)
{
translation := StrSplit(A_LoopReadLine, "=>")
if (translation[1] = targetLanguageCode)
return translation[2]
}
Throw "Inconsistent translation encountered for """ . targetLanguageCode . """ in readLanguage..."
}
receivePipeMessage() {
result := false
for event, handler in vEventHandlers {
if (event = "*")
continue
pipeName := "\\.\pipe\SCE" . event
if DllCall("WaitNamedPipe", "Str", pipeName, "UInt", 0xF)
Loop Read, %pipeName%
{
data := StrSplit(A_LoopReadLine, ":", , 2)
event := data[1]
eventHandler := vEventHandlers[event]
if (!eventHandler)
eventHandler := vEventHandlers["*"]
logMessage(kLogInfo, translate("Dispatching event """) . event . (data[2] ? translate(""": ") . data[2] : translate("""")))
vIncomingMessages.Push(Array(eventHandler, event, data[2]))
result := true
}
}
return result
}
sendPipeMessage(event, data) {
static ERROR_PIPE_CONNECTED := 535
static ERROR_PIPE_LISTENING := 536
static ptr
pipeName := "\\.\pipe\SCE" . event
pipe := DllCall("CreateNamedPipe", "str", "\\.\pipe\SCE" . event, "uint", 3, "uint", 0, "uint", 255, "uint", 1024, "uint", 1024, "uint", 0, ptr, 0, ptr)
DllCall("ConnectNamedPipe", ptr, pipe, ptr, 0)
if (true || (A_LastError = ERROR_PIPE_CONNECTED)) {
message := (A_IsUnicode ? chr(0xfeff) : chr(239) chr(187) chr(191)) . (event := event . ":" . data)
DllCall("WriteFile", ptr, pipe, "str", message, "uint", (StrLen(message) + 1) * (A_IsUnicode ? 2 : 1), "uint*", 0, ptr, 0)
DllCall("CloseHandle", ptr, pipe)
return true
}
else
return false
}
receiveWindowMessage(wParam, lParam) {
;---------------------------------------------------------------------------
; retrieve info from COPYDATASTRUCT
;---------------------------------------------------------------------------
dwData := NumGet(lParam + A_PtrSize * 0) ; DWORD encoded request
cbData := NumGet(lParam + A_PtrSize * 1) ; length of DATA string (incl ZERO)
lpData := NumGet(lParam + A_PtrSize * 2) ; pointer to DATA string
;---------------------------------------------------------------------------
; interpret available info
;---------------------------------------------------------------------------
request := decodeDWORD(dwData) ; 4-char decoded request
length := (cbData - 1) / (A_IsUnicode + 1) ; length of DATA string (excl ZERO)
data := StrGet(lpData, length) ; DATA string from pointer
if (request != "EVNT")
Throw % "Unhandled message received: " . request . " in dispatchEvent..."
data := StrSplit(data, ":", , 2)
event := data[1]
eventHandler := vEventHandlers[event]
if (!eventHandler)
eventHandler := vEventHandlers["*"]
logMessage(kLogInfo, translate("Dispatching event """) . event . (data[2] ? translate(""": ") . data[2] : translate("""")))
vIncomingMessages.Push(Array(eventHandler, event, data[2]))
}
sendWindowMessage(target, event, data) {
curDetectHiddenWindows := A_DetectHiddenWindows
curTitleMatchMode := A_TitleMatchMode
event := event . ":" . data
;---------------------------------------------------------------------------
; construct the message to send
;---------------------------------------------------------------------------
dwData := encodeDWORD("EVNT")
cbData := StrLen(event) * (A_IsUnicode + 1) + 1 ; length of DATA string (incl. ZERO)
lpData := &event ; pointer to DATA string
;---------------------------------------------------------------------------
; put the message in a COPYDATASTRUCT
;---------------------------------------------------------------------------
VarSetCapacity(struct, A_PtrSize * 3, 0) ; initialize COPYDATASTRUCT
NumPut(dwData, struct, A_PtrSize * 0, "UInt") ; DWORD
NumPut(cbData, struct, A_PtrSize * 1, "UInt") ; DWORD
NumPut(lpData, struct, A_PtrSize * 2, "UInt") ; 32bit pointer
;---------------------------------------------------------------------------
; parameters for SendMessage command
;---------------------------------------------------------------------------
message := 0x4a ; WM_COPYDATA
wParam := "" ; not used
lParam := &struct ; COPYDATASTRUCT
control := "" ; not needed
SetTitleMatchMode 2 ; match part of the title
DetectHiddenWindows On ; needed for sending messages
try {
SendMessage %message%, %wParam%, %lParam%, %control%, %target%
return (ErrorLevel != "FAIL")
}
catch exception {
return false
}
finally {
DetectHiddenWindows %curDetectHiddenWindows%
SetTitleMatchMode %curTitleMatchMode%
}
}
receiveFileMessage() {
result := false
Process Exist
pid := ErrorLevel
fileName := kUserHomeDirectory . "Temp\Messages\" . pid . ".msg"
if FileExist(fileName) {
file := false
try {
file := FileOpen(fileName, "rw-rwd")
}
catch exception {
return false
}
while !file.AtEOF {
line := Trim(file.ReadLine(), " `t`n`r")
if (StrLen(line) == 0)
break
data := StrSplit(line, ":", , 2)
event := data[1]
eventHandler := vEventHandlers[event]
if (!eventHandler)
eventHandler := vEventHandlers["*"]
logMessage(kLogInfo, translate("Dispatching event """) . event . (data[2] ? translate(""": ") . data[2] : translate("""")))
vIncomingMessages.Push(Array(eventHandler, event, data[2]))
result := true
}
file.Length := 0
file.Close()
}
return result
}
sendFileMessage(pid, event, data) {
text := event . ":" . data . "`n"
try {
FileAppend %text%, % kUserHomeDirectory . "Temp\Messages\" . pid . ".msg"
}
catch exception {
return false
}
return true
}
receiveMessage() {
return (receivePipeMessage() || receiveFileMessage())
}
sendMessage() {
if (vOutgoingMessages.Length() > 0) {
handler := vOutgoingMessages[1]
if %handler%()
vOutgoingMessages.RemoveAt(1)
}
}
messageDispatcher() {
try {
if (vIncomingMessages.Length() > 0) {
descriptor := vIncomingMessages.RemoveAt(1)
withProtection(descriptor[1], descriptor[2], descriptor[3])
}
}
finally {
SetTimer messageDispatcher, -200
}
}
messageQueue() {
protectionOn()
try {
if !receiveMessage()
sendMessage()
}
finally {
protectionOff()
SetTimer messageQueue, -400
}
}
trayMessageQueue() {
if (vPendingTrayMessages.Length() > 0) {
protectionOn()
try {
if (vPendingTrayMessages.Length() = 0)
return
else {
message := vPendingTrayMessages.RemoveAt(1)
protectionOff()
try {
duration := message[3]
title := message[1]
message := message[2]
TrayTip %title%, %message%
Sleep %duration%
TrayTip
}
finally {
protectionOn()
}
}
}
finally {
protectionOff()
SetTimer trayMessageQueue, -500
}
}
else
SetTimer trayMessageQueue, -500
}
encodeDWORD(string) {
result := 0
Loop % StrLen(string) {
result <<= 8
result += Asc(SubStr(string, A_Index, 1))
}
return result
}
decodeDWORD(data) {
result := ""
Loop 4 {
result := Chr(data & 0xFF) . result
data >>= 8
}
return result
}
unknownEventHandler(event, data) {
logMessage(kLogCritical, translate("Unhandled event """) . event . translate(""": ") . data)
raiseEvent(kLocalMessage, event, data)
}
stopMessageManager() {
Process Exist
pid := ErrorLevel
if FileExist(kUserHomeDirectory . "Temp\Messages\" . pid . ".msg")
FileDelete %kUserHomeDirectory%Temp\Messages\%pid%.msg
}
startMessageManager() {
OnMessage(0x4a, "receiveWindowMessage")
registerEventHandler("*", "unknownEventHandler")
Process Exist
pid := ErrorLevel
if FileExist(kUserHomeDirectory . "Temp\Messages\" . pid . ".msg")
FileDelete %kUserHomeDirectory%Temp\Messages\%pid%.msg
OnExit("stopMessageManager")
SetTimer messageQueue, -400
SetTimer messageDispatcher, -200
}
logError(exception) {
logMessage(kLogCritical, translate("Unhandled exception encountered in ") . exception.File . translate(" at line ") . exception.Line . translate(": ") . exception.Message)
return (isDebug() ? false : true)
}
initializeLoggingSystem() {
OnError("logError")
}
startTrayMessageManager() {
SetTimer trayMessageQueue, -500
}
requestConsent() {
program := StrSplit(A_ScriptName, ".")[1]
if ((program = "Simulator Startup") || (program = "Simulator Configuration")) {
idFileName := kUserConfigDirectory . "ID"
FileReadLine id, %idFileName%, 1
consent := readConfiguration(kUserConfigDirectory . "CONSENT")
request := ((consent.Count() == 0) || (id != getConfigurationValue(consent, "General", "ID")))
if !request {
countdown := getConfigurationValue(consent, "General", "Countdown", kUndefined)
if (countdown != kUndefined) {
if (--countdown <= 0)
request := true
else {
setConfigurationValue(consent, "General", "Countdown", countdown)
writeConfiguration(kUserConfigDirectory . "CONSENT", consent)
}
}
}
if request {
consent := newConfiguration()
setConfigurationValue(consent, "General", "ID", id)
setConfigurationValue(consent, "Consent", "Date", A_MM . "/" . A_DD . "/" . A_YYYY)
switch consentDialog(id) {
case "Yes":
setConfigurationValue(consent, "Consent", "Share Database", "Tyre Pressures")
case "No":
setConfigurationValue(consent, "Consent", "Share Database", false)
case "Retry":
setConfigurationValue(consent, "Consent", "Share Database", "Undecided")
setConfigurationValue(consent, "General", "Countdown", 10)
}
writeConfiguration(kUserConfigDirectory . "CONSENT", consent)
}
if (getConfigurationValue(consent, "Consent", "Share Database", false) == "Tyre Pressures") {
uploadTimeStamp := kSetupDatabaseDirectory . "Local\UPLOAD"
if FileExist(uploadTimeStamp) {
FileReadLine upload, %uploadTimeStamp%, 1
now := A_Now
EnvSub now, %upload%, days
if (now <= 7)
return
}
try {
RunWait PowerShell.exe -Command Compress-Archive -LiteralPath '%kSetupDatabaseDirectory%Local' -CompressionLevel Optimal -DestinationPath '%kUserHomeDirectory%Temp\Setup Database.%id%.zip', , Hide
ftpUpload("ftp.drivehq.com", "TheBigO", "29605343.9318.1940", kUserHomeDirectory . "Temp\Setup Database." . id . ".zip", "Simulator Controller\Setup Database Uploads\Setup Database." . id . ".zip")
try {
FileDelete %kSetupDatabaseDirectory%Local\UPLOAD
}
catch exception {
; ignore
}
FileAppend %A_Now%, %kSetupDatabaseDirectory%Local\UPLOAD
logMessage(kLogInfo, translate("Setup database successfully uploaded"))
}
catch exception {
logMessage(kLogCritical, translate("Error while uploading setup database - please check your internet connection..."))
showMessage(translate("Error while uploading setup database - please check your internet connection...")
, translate("Modular Simulator Controller System"), "Alert.png", 5000, "Center", "Bottom", 800)
}
}
}
}
checkForUpdates() {
if inList(["Simulator Startup", "Simulator Configuration", "Simulator Settings"], StrSplit(A_ScriptName, ".")[1]) {
URLDownloadToFile https://www.dropbox.com/s/txa8muw9j3g66tl/VERSION?dl=1, %kUserHomeDirectory%Temp\VERSION
version := getConfigurationValue(readConfiguration(kUserHomeDirectory . "Temp\VERSION"), "Version", "Release", false)
if version {
version := values2String("", string2Values(".", StrSplit(version, "-", , 2)[1])*)
current := values2String("", string2Values(".", StrSplit(kVersion, "-", , 2)[1])*)
if ((version[1] > current[1]) || (version[2] > current[2]) || (version[3] > current[3])) {
OnMessage(0x44, Func("translateMsgBoxButtons").Bind(["Yes", "No"]))
title := translate("Modular Simulator Controller System")
MsgBox 262436, %title%, % translate("A newer version of Simulator Controller is available. Do you want to download it now?")
OnMessage(0x44, "")
IfMsgBox Yes
{
Run https://github.com/SeriousOldMan/Simulator-Controller#latest-release-builds
ExitApp 0
}
}
}
}
toolTargets := readConfiguration(getFileName("Simulator Tools.targets", kConfigDirectory))
userToolTargetsFile := getFileName("Simulator Tools.targets", kUserConfigDirectory)
userToolTargets := readConfiguration(userToolTargetsFile)
if (userToolTargets.Count() > 0) {
setConfigurationSectionValues(userToolTargets, "Update", getConfigurationSectionValues(toolTargets, "Update", Object()))
writeConfiguration(userToolTargetsFile, userToolTargets)
}
if (StrSplit(A_ScriptName, ".")[1] != "Simulator Tools") {
updates := readConfiguration(getFileName("UPDATES", kUserConfigDirectory))
restartUpdate:
for target, arguments in getConfigurationSectionValues(toolTargets, "Update", Object())
if !getConfigurationValue(updates, "Processed", target, false) {
SoundPlay *32
OnMessage(0x44, Func("translateMsgBoxButtons").Bind(["Yes", "No", "Never"]))
title := translate("Modular Simulator Controller System")
MsgBox 262179, %title%, % translate("The local configuration database needs an update. Do you want to run the update now?")
OnMessage(0x44, "")
IfMsgBox Cancel
{
OnMessage(0x44, Func("translateMsgBoxButtons").Bind(["Yes", "No"]))
title := translate("Modular Simulator Controller System")
MsgBox 262436, %title%, % translate("Are you really sure, you want to skip the automated update procedure?")
OnMessage(0x44, "")
IfMsgBox Yes
{
for target, arguments in getConfigurationSectionValues(toolTargets, "Update", Object())
setConfigurationValue(updates, "Processed", target, true)
writeConfiguration(getFileName("UPDATES", kUserConfigDirectory), updates)
break
}
Goto restartUpdate
}
IfMsgBox Yes
{
RunWait % kBinariesDirectory . "Simulator Tools.exe -Update"
loadSimulatorConfiguration()
break
}
IfMsgBox No
{
break
}
}
}
}
loadSimulatorConfiguration() {
kSimulatorConfiguration := readConfiguration(kSimulatorConfigurationFile)
vTargetLanguageCode := getConfigurationValue(kSimulatorConfiguration, "Configuration", "Language", "en")
kVersion := getConfigurationValue(readConfiguration(kHomeDirectory . "VERSION"), "Version", "Current", "0.0.0")
Process Exist
pid := ErrorLevel
logMessage(kLogCritical, "---------------------------------------------------------------")
logMessage(kLogCritical, translate(" Running ") . StrSplit(A_ScriptName, ".")[1] . " (" . kVersion . ") [" . pid . "]")
logMessage(kLogCritical, "---------------------------------------------------------------")
if (kSimulatorConfiguration.Count() == 0)
logMessage(kLogCritical, translate("No configuration found - please run the configuration tool"))
path := getConfigurationValue(kSimulatorConfiguration, "Configuration", "Home Path")
if path {
kHomeDirectory := path . "\"
logMessage(kLogInfo, translate("Installation path set to ") . path)
}
else
logMessage(kLogWarn, translate("Installation path not set"))
path := getConfigurationValue(kSimulatorConfiguration, "Configuration", "AHK Path")
if path {
kAHKDirectory := path . "\"
logMessage(kLogInfo, translate("AutoHotkey path set to ") . path)
}
else
logMessage(kLogWarn, translate("AutoHotkey path not set"))
path := getConfigurationValue(kSimulatorConfiguration, "Configuration", "NirCmd Path")
if path {
kNirCmd := path . "\NirCmd.exe"
logMessage(kLogInfo, translate("NirCmd executable set to ") . kNirCmd)
}
else
logMessage(kLogWarn, translate("NirCmd executable not configured"))
kSilentMode := getConfigurationValue(kSimulatorConfiguration, "Configuration", "Silent Mode", false)
vDebug := (!A_IsCompiled || getConfigurationValue(kSimulatorConfiguration, "Configuration", "Debug", false))
vLogLevel := inList(["Info", "Warn", "Critical", "Off"], getConfigurationValue(kSimulatorConfiguration, "Configuration", "Log Level", "Warn"))
}
initializeEnvironment() {
virgin := !FileExist(A_MyDocuments . "\Simulator Controller")
FileCreateDir %A_MyDocuments%\Simulator Controller
FileCreateDir %kUserHomeDirectory%Config
FileCreateDir %kUserHomeDirectory%Logs
FileCreateDir %kUserHomeDirectory%Splash Media
FileCreateDir %kUserHomeDirectory%Screen Images
FileCreateDir %kUserHomeDirectory%Plugins
FileCreateDir %kUserHomeDirectory%Temp
FileCreateDir %kUserHomeDirectory%Temp\Messages
FileCreateDir %kSetupDatabaseDirectory%Global
FileCreateDir %kSetupDatabaseDirectory%Local
if !FileExist(A_MyDocuments . "\Simulator Controller\Plugins\Controller Plugins.ahk")
FileCopy %kResourcesDirectory%Templates\Controller Plugins.ahk, %A_MyDocuments%\Simulator Controller\Plugins
if !FileExist(A_MyDocuments . "\Simulator Controller\Plugins\Configuration Plugins.ahk")
FileCopy %kResourcesDirectory%Templates\Configuration Plugins.ahk, %A_MyDocuments%\Simulator Controller\Plugins
if !FileExist(kUserConfigDirectory . "Controller Plugin Labels.ini")
FileCopy %kResourcesDirectory%Templates\Controller Plugin Labels.ini, %kUserConfigDirectory%
if !FileExist(kUserConfigDirectory . "Race Engineer.settings")
FileCopy %kResourcesDirectory%Templates\Race Engineer.settings, %kUserConfigDirectory%
if !FileExist(kUserConfigDirectory . "ID") {
ticks := A_TickCount
Random wait, 0, 100
Random, , % Min(4294967295, A_TickCount)
Random major, 0, 10000
Sleep %wait%
Random, , % Min(4294967295, A_TickCount)
Random minor, 0, 10000
id := values2String(".", A_TickCount, major, minor)
FileAppend %id%, % kUserConfigDirectory . "ID"
}
try {
start := 20210402000000
end := 20210406000000
if ((A_Now >= start) && (A_Now <= end)) {
if !FileExist(kUserHomeDirectory . "Temp\RE.data") {
file := "https://www.infoguard.ch/hubfs/infoguard-blog-ea" . "ster-e" . "gg.jpg"
URLDownloadToFile %file%, %kUserHomeDirectory%Temp\RE.data
}
}
else if FileExist(kUserHomeDirectory . "Temp\RE.data")
FileDelete % kUserHomeDirectory . "Temp\RE.data"
}
catch exception {
; ignore
}
if virgin
FileCopy %kResourcesDirectory%Templates\UPDATES, %kUserConfigDirectory%
}
;;;-------------------------------------------------------------------------;;;
;;; Public Function Declaration Section ;;;
;;;-------------------------------------------------------------------------;;;
showSplash(image, alwaysOnTop := true, video := false) {
image := getFileName(image, kUserSplashMediaDirectory, kSplashMediaDirectory)
lastSplash := vSplashCounter
vSplashCounter += 1
vLastImage := image
if (vSplashCounter > 10)
vSplashCounter := 1
title := substituteVariables(translate(getConfigurationValue(kSimulatorConfiguration, "Splash Window", "Title", "")))
subtitle := substituteVariables(translate(getConfigurationValue(kSimulatorConfiguration, "Splash Window", "Subtitle", "")))
SplitPath image, , , extension
Gui %vSplashCounter%:-Border -Caption
Gui %vSplashCounter%:Color, D0D0D0
Gui %vSplashCounter%:Font, s10 Bold, Arial
Gui %vSplashCounter%:Add, Text, x10 w780 Center, %title%
if (extension = "GIF") {
Gui %vSplashCounter%:Add, ActiveX, x10 y30 w780 h439 vvVideoPlayer, shell explorer
vVideoPlayer.Navigate("about:blank")
html := "<html><body style='background-color: #000000' style='overflow:hidden' leftmargin='0' topmargin='0' rightmargin='0' bottommargin='0'><img src='" image "' width=780 height=438 border=0 padding=0></body></html>"
vVideoPlayer.document.write(html)
}
else
Gui %vSplashCounter%:Add, Picture, x10 y30 w780 h439, %image%
Gui %vSplashCounter%:Font, s8 Norm, Arial
Gui %vSplashCounter%:Add, Text, x10 y474 w780 Center, %subtitle%
options := "x" . Round((A_ScreenWidth - 800) / 2) . " y" . Round(A_ScreenHeight / 4)
if alwaysOnTop
Gui %vSplashCounter%:+AlwaysOnTop
Gui %vSplashCounter%:Show, %options% AutoSize NoActivate
if (lastSplash > 0)
hideSplash(lastSplash)
}
hideSplash(splashCounter := false) {
if !splashCounter
splashCounter := vSplashCounter
Gui %splashCounter%:Destroy
}
rotateSplash(alwaysOnTop := true) {
static number := 1
static images := false
static numImages := 0
if !images {
images := getFileNames("*.jpg", kUserSplashMediaDirectory, kSplashMediaDirectory)
numImages := images.Length()
}
if (number > numImages)
number := 1
if (number <= numImages)
showSplash(images[number++], alwaysOnTop)
}
showSplashTheme(theme := "__Undefined__", songHandler := false, alwaysOnTop := true) {
static images := false
static number := 1
static numImages := 0
static onTop := false
vSongIsPlaying := false
if !songHandler
songHandler := "playThemeSong"
if (theme == kUndefined) {
if (number > numImages)
number := 1
if (number <= numImages)
showSplash(images[number++], onTop)
return
}
song := false
duration := 3000
type := getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Type", false)
if (type == "Video") {
song := getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Song", false)
video := getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Video")
showSplash(video, true)
if song {
vSongIsPlaying := true
%songHandler%(song)
}
return
}
else if (type == "Picture Carousel") {
duration := getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Duration", 5000)
song := getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Song", false)
images := string2Values(",", getConfigurationValue(kSimulatorConfiguration, "Splash Themes", theme . ".Images", false))
}
else {
logMessage(kLogCritical, translate("Theme """) . theme . translate(""" not found - please check the configuration"))
images := getFileNames("*.jpg", kUserSplashMediaDirectory, kSplashMediaDirectory)
}
numImages := images.Length()
onTop := alwaysOnTop
showSplashTheme()
SetTimer showSplashTheme, %duration%
if song {
vSongIsPlaying := true
%songHandler%(song)
}
}
hideSplashTheme() {
SetTimer showSplashTheme, Off
if vSongIsPlaying
try {
SoundPlay NonExistent.avi
}
catch ignore {
; Ignore
}
hideSplash()
}
showProgress(options) {
if !vProgressIsOpen {
x := options.X
y := options.Y
if options.HasKey("Width")
w := (options.Width - 20)
else
w := 280
color := options.HasKey("color") ? options.color : "Green"
Gui Progress:Default
Gui Progress:-Border -Caption
Gui Progress:Color, D0D0D0
Gui Progress:Font, s10 Bold, Arial
Gui Progress:Add, Text, x10 w%w% Center vvProgressTitle
Gui Progress:Add, Progress, x10 y30 w%w% h20 c%color% BackgroundGray vvProgressBar, 50
Gui Progress:Font, s8 Norm, Arial
Gui Progress:Add, Text, x10 y55 w%w% Center vvProgressMessage
Gui Progress:+AlwaysOnTop
Gui Progress:Show, x%x% y%y% AutoSize NoActivate
vProgressIsOpen := true
}
if options.HasKey("title")
GuiControl, , vProgressTitle, % options.title
if options.HasKey("message")
GuiControl, , vProgressMessage, % options.message