-
Notifications
You must be signed in to change notification settings - Fork 0
/
AZT_Installer_UI.nsi
2230 lines (1878 loc) · 73.2 KB
/
AZT_Installer_UI.nsi
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
;--------------------------------
!include MUI2.nsh ;Include Modern UI
!include LogicLib.nsh
!include WordFunc.nsh
!include FileFunc.nsh
!include StrFunc.nsh
!include WinMessages.nsh ; For SendMessage
!include Locate.nsh
; Used to reposition the installer window
!ifndef SPI_GETWORKAREA
!define SPI_GETWORKAREA 0x0030
!endif
; Define the installer icon
!define MUI_ICON "azt.ico"
; Initialize plugins from StrFunc
${StrStr}
${StrRep}
${StrLoc}
${StrTrimNewLines}
; Show all the DetailsPrint to the user while installation is in progress
ShowInstDetails show
;--------------------------------
; Constants
!define NEWLINE "$\r$\n"
!define TITLENAME "A-Z+T Installer"
!define APPNAME "A-Z+T"
!define INSTALLERNAME "AZT_Installer" ; original name
!define WAITTIME 5000 ; Milliseconds to wait for system calls and retries
;--------------------------------
; Global variables (Ref: See "Function .onInit" for initialization of values)
Var /GLOBAL pythonversion
Var /GLOBAL pythonfilename
Var /GLOBAL pythonsize
Var /GLOBAL pythonurl
Var /GLOBAL pythonPath
Var /GLOBAL pythonExe
Var /GLOBAL gitversion
Var /GLOBAL gitfilename
Var /GLOBAL gitsize
Var /GLOBAL giturl
Var /GLOBAL gitExe
Var /GLOBAL gitPath
Var /GLOBAL praatversion
Var /GLOBAL praatfilename
Var /GLOBAL praaturl
Var /GLOBAL xlpversion
Var /GLOBAL xlpfilename
Var /GLOBAL xlpurl
Var /GLOBAL hgversion
Var /GLOBAL hgfilename
Var /GLOBAL hgurl
Var /GLOBAL charisversion
Var /GLOBAL charisfilename
Var /GLOBAL chariszipfile
Var /GLOBAL charisurl
Var /GLOBAL filepath
Var /GLOBAL filename
var /GLOBAL azt
var /GLOBAL aztRepoName
var /GLOBAL aztRepoURL
var /GLOBAL aztfilename
var /GLOBAL transcriberfilename
; Use 0 for current user and 1 for admin user
Var /GLOBAL withadmin
var /GLOBAL logfile
Var /GLOBAL log0
var /GLOBAL logstring
Var /GLOBAL found
Var /GLOBAL downloadName
Var /GLOBAL ReturnError
Var /GLOBAL tempLogFile
Var /Global cmdFile
Var /Global pathFile
Var /GLOBAL desiredVersion
;------------------------------------------------------------------------------
;General
;------------------------------------------------------------------------------
;Name and file
Name ${APPNAME}
OutFile "${INSTALLERNAME}.exe"
Unicode True
;Request application privileges for Windows
RequestExecutionLevel admin
;Default installation folder (sets INSTDIR)
InstallDir "$DESKTOP\azt"
;--------------------------------
;Descriptions - if setting up multiple languages
;Language strings
;LangString DESC_pythonId ${LANG_ENGLISH} "Python"
;Assign language strings to sections
; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
; !insertmacro MUI_DESCRIPTION_TEXT ${pythonId} $(DESC_pythonId)
; !insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------I
;Interface Settings
!define MUI_ABORTWARNING
#!define MUI_INSTFILESPAGE_COLORS "FFFFFF 000000" ;Two colors
;--------------------------------
;Pages
; Invoke the custom positioning function on GUI start
!define MUI_CUSTOMFUNCTION_GUIINIT positionInstWindow
; Enable MUI_PAGE_LICENSE to display the license page for user to accept
;!insertmacro MUI_PAGE_LICENSE ".\License.txt"
; Disable MUI_PAGE_COMPONENTS if you do not want the user to select which sections to install
; Every "Section" will appear on the list.
; Required Sections are checked and set to Read/Only in .onInit using SectionSetFlags
!insertmacro MUI_PAGE_COMPONENTS
; Enable MUI_PAGE_DIRECTORY to permit user to change the installationi target directory
;!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; FINISHPAGE macros are used to display a successful completion page with a "Launch Application" option
; Disabling for now since we are launching the page conditionally in .onInstSuccess
; !define MUI_FINISHPAGE_RUN "cmd /c python $INSTDIR\main.py"
; !define MUI_FINISHPAGE_RUN_TEXT "Launch A-Z+T now ($INSTDIR\main.py)"
;!define MUI_FINISHPAGE_TEXT "${APPNAME} finished installing at${NEWLINE}${NEWLINE}$aztfilename.${NEWLINE}${NEWLINE}Click Finish to close setup."
;!insertmacro MUI_PAGE_FINISH
; Uninstaller macros
;!insertmacro MUI_UNPAGE_CONFIRM
;!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;======================================================================================
;======================================================================================
;Installer Sections
;***************************************************************************************
Section "Python" pythonId
;----------------------------------------------------------------
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Installing Python..."
StrCpy $logstring "${NEWLINE}----- Python Installer ----- "
Call logMessage
StrCpy $downloadName "python"
Var /GLOBAL tempString
; Check if desired or later version is already installed
StrCpy $desiredVersion $pythonVersion
Call checkVersion
Pop $0 ; get exit code
${If} $0 == "0"
Pop $1 ; get version
StrCpy $tempString $1
StrCpy $logstring "$downloadName is already installed, version is <$tempString>, skipping installation."
Call logMessage
goto pythonEnd
${EndIf}
; If there is an older version, remove it from the path before installing the new one
; This should prevent the first run of azt from picking up the wrong version
${If} $0 == "2"
Pop $1 ; get version
StrCpy $tempString $1
StrCpy $logstring "$downloadName version <$tempString> found. Removing from path..."
Call logMessage
call getPythonPath
StrCpy $logstring "getPythonPath returned pythonExe: $pythonExe"
Call logMessage
; if only the name was set, it must be in the path so use "where" to get the real path
${If} $pythonExe == "python"
StrCpy $pathFile "pythonpath.txt"
Delete $pathFile
ClearErrors
ExecWait 'cmd /C where python >$pathFile' $0
StrCpy $logstring "'where python' RC = $0"
Call logMessage
${If} $0 == 0
; Read the path from the path file
FileOpen $0 $pathFile r
FileRead $0 $tempString
FileClose $0
${StrTrimNewLines} $pythonExe $tempString
StrCpy $logstring "Python path from path file: $pythonExe"
Call logMessage
${EndIf}
${EndIf}
${If} $pythonExe != ""
${If} $pythonExe != "py"
${If} $pythonExe != "python"
StrCpy $logstring "Old python path found: $pythonExe"
Call logMessage
; Get the path portion by stripping off the exe file name.
; It will be used to remove from registry environment path
StrLen $R1 $pythonExe ; Get the length of the string
StrCpy $R0 -1 ; Initialize the position variable to -1 (not found)
; Loop through the string from the end to the beginning
${ForEach} $R3 $R1 0 - 1
StrCpy $R4 $pythonExe 1 $R3 ; Get the character at position $R3
;StrCpy $logstring "R4: $R4"
;Call logMessage
StrCmp $R4 "\" 0 +3
StrCpy $R0 $R3 ; Update the position if backslash is found
${Break}
${Next}
StrCpy $logstring "Offset: $R0"
Call logMessage
Var /GLOBAL oldPath
StrCpy $oldPath $pythonExe $R0
StrCpy $logstring "Old Python path: $oldPath"
Call logMessage
; Remove the old python path from the system path
; For info on Envar plugin, see https://nsis.sourceforge.io/EnVar_plug-in
EnVar::SetHKLM
; Check for path set in HKLM (Local Machine)
EnVar::Check "Path" "NULL"
Pop $0
StrCpy $logstring "EnVar::Read Registry 'Path' RC = $0"
Call logMessage
${If} $0 == 0
; Remove from path (with and without terminating backslash)
EnVar::DeleteValue "Path" "$oldPath"
Pop $0
StrCpy $logstring "Registry attempt to remove '$oldPath' from HKLM Path Environment variable. RC = $0"
Call logMessage
EnVar::DeleteValue "Path" "$oldPath\"
Pop $0
StrCpy $logstring "Registry attempt to remove '$oldPath\' from HKLM Path Environment variable. RC = $0"
Call logMessage
${Else}
StrCpy $logstring "Unable to update registry HKLM to remove $oldPath."
Call logMessage
${EndIf}
; Remove the old python path from the current user's path
EnVar::SetHKCU
; Check for path set in HKCU (Current User)
EnVar::Check "Path" "NULL"
Pop $0
StrCpy $logstring "EnVar::Read Registry 'Path' RC = $0"
Call logMessage
${If} $0 == 0
; Remove from path (with and without terminating backslash)
EnVar::DeleteValue "Path" "$oldPath"
Pop $0
StrCpy $logstring "Registry attempt to remove '$oldPath' from HKCU Path Environment variable. RC = $0"
Call logMessage
EnVar::DeleteValue "Path" "$oldPath\"
Pop $0
StrCpy $logstring "Registry attempt to remove '$oldPath\' from HKCU Path Environment variable. RC = $0"
Call logMessage
${Else}
StrCpy $logstring "Unable to update registry HKCU to remove $oldPath."
Call logMessage
${EndIf}
${EndIf}
${EndIf}
${EndIf}
${EndIf}
;---------------------------------------------------------------
; Install Python
;---------------------------------------------------------------
; Check if Python Installer file was already downloaded previously
StrCpy $logstring "----- Must install python -----"
Call logMessage
FindFirst $0 $1 "$pythonfilename"
StrCpy $logstring "$downloadName file search results: $0 $1"
Call logMessage
FindClose $0
${If} $1 == $pythonfilename
StrCpy $logstring "$pythonfilename already exists, using this version."
Call logMessage
${Else}
# Download Python Installer file
StrCpy $logstring "Downloading Python from $pythonurl"
Call logMessage
; For inetc plugin ref: https://nsis.sourceforge.io/Inetc_plug-in
inetc::get "$pythonurl" "$pythonfilename" /end
Pop $0 ;Get the return value
${If} $0 != 'OK'
StrCpy $logstring "ERROR: $0. Unable to download Python. Installation aborted."
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Call logMessage
Abort
${Else}
StrCpy $logstring "Python downloaded successfully."
Call logMessage
${EndIf}
${EndIf}
; Install Python
StrCpy $logstring "Python installing...."
Call logMessage
ExecWait "$pythonfilename /silent PrependPath=1 Include_pip=1 InstallAllUsers=$withadmin Include_launcher=1 InstallLauncherAllUsers=$withadmin Include_test=0" $0
StrCpy $logstring "Installation return code: $0"
Call logMessage
${If} $0 != 0
${If} $0 == 1603
StrCpy $logstring "Python is already installed."
Call logMessage
; consider using these to uninstall old versions of python??
;wmic product where "name like 'Python%'" get version
;wmic product where "version='X.X.X'" call uninstall
; Uninstall existing Python
; MessageBox MB_YESNO "Python is already installed. Do you want to uninstall it?" IDYES uninstall_python
; uninstall_python:
; StrCpy $logstring "Finding filepath where python is installed..."
; Call logMessage
; FindFirst $0 $1 "$pythonfilename"
; StrCpy $logstring "Python file search: $0 $1"
; Call logMessage
; FindClose $0
; ${If} $1 == $pythonfilename
; StrCpy $logstring "Uninstalling python...."
; Call logMessage
; ; Locate the uninstaller and run it
; ExecWait '$0\Uninstall.exe /silent'
${Else}
StrCpy $logstring "ERROR: Python $pythonversion Installation failed with return code: $0"
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${EndIf}
${Else}
StrCpy $logstring "Python installed successfully."
Call logMessage
${EndIf}
;----------------------------------------------------------------
; Enable readLongPathsEnabled in Registry for use with Python
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Updating Registry LongPathsEnabled"
StrCpy $logstring "${NEWLINE}----- Registry LongPathsEnabled Test/Set ----- "
Call logMessage
; Ensure LongPathsEnabled is already set in the Windows Registry else set it now
; Cases 1 - 5 map to HKLM,HKCU,HKCR,HKU,HKCC (no easy way to do a for with strings)
StrCpy $found "false"
StrCpy $R2 HKLM
${For} $R1 1 5
${If} $found == "false"
Call readLongPathsEnabled
ifErrors loopRegistryNext
StrCpy $logstring "Registry LongPathsEnabled found: $R0"
Call logMessage
${If} $R0 == 1
StrCpy $logstring "LongPathsEnabled registry already set for $R2."
Call logMessage
StrCpy $found "true"
${Else}
; Entry found but needs to be changed to 1
StrCpy $logstring "LongPathsEnabled registry found for $R2, updating to 1."
Call logMessage
Call writeLongPathsEnabled
ifErrors errorExitLongPaths
StrCpy $found "true"
${EndIf}
${endIf}
loopRegistryNext:
ClearErrors
${Next}
${If} $found == "false"
; Not found so try to set in HKLM
StrCpy $R2 HKLM
StrCpy $R1 "1"
Call addLongPathsEnabled
ifErrors errorExitLongPaths pythonEnd
errorExitLongPaths:
ClearErrors
StrCpy $logstring "ERROR: Error setting Registry LongPathsEnabled"
Call logMessage
; Does this need to abort or can it continue?
;MessageBox MB_OK $logstring
;Abort
${EndIf}
;--------------------------------
pythonEnd:
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Locating Python..."
StrCpy $logstring "${NEWLINE}----- Get Final Python Path ----- "
Call logMessage
call getPythonPath
${If} $pythonExe == ""
StrCpy $logstring "Unable to find python. You may need to run this installer again to complete the full installation."
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${Else}
StrCpy $logstring "Using Python path: $pythonExe"
${EndIf}
SectionEnd
;***************************************************************************************
Section "Git" gitId
;----------------------------------------------------------------
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Installing Git..."
StrCpy $logstring "${NEWLINE}----- Git Installer ----- "
Call logMessage
StrCpy $downloadName "git"
; Check if desired or later Git is already installed
StrCpy $desiredVersion $gitVersion
Call checkVersion
Pop $0
${If} $0 == "0"
Pop $1
StrCpy $logstring "$downloadName is already installed, version is <$1>, skipping installation."
Call logMessage
goto gitEnd
${EndIf}
; Check if Installer file was already downloaded previously
FindFirst $0 $1 "$gitfilename"
StrCpy $logstring "$downloadName file search: $0 $1"
Call logMessage
FindClose $0
${If} $1 == $gitfilename
StrCpy $logstring "$gitfilename already exists, using this version."
Call logMessage
${Else}
# Download Installer file
StrCpy $logstring "Downloading giturl $gitversion $gitsize..."
Call logMessage
inetc::get "$giturl" "$gitfilename" /end
Pop $0 ;Get the return value
${If} $0 != 'OK'
StrCpy $logstring "ERROR: $0. Unable to download $downloadName. Installation aborted."
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${Else}
StrCpy $logstring "$downloadName downloaded successfully."
Call logMessage
${EndIf}
${EndIf}
; Install
StrCpy $logstring "$downloadName installing...."
Call logMessage
ExecWait "$gitfilename /SILENT /NORESTART /NOCANCEL /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS=$\"icons,ext\shellhere,assoc,assoc_sh$\"" $0
StrCpy $logstring "Installation return code: $0"
Call logMessage
${If} $0 != 0
${If} $0 == 1603
StrCpy $logstring "$downloadName is already installed, skipping installation."
Call logMessage
${Else}
StrCpy $logstring "ERROR: $downloadName $gitversion Installation failed with return code: $0"
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${EndIf}
${Else}
StrCpy $logstring "$downloadName installed successfully."
Call logMessage
${EndIf}
;--------------------------------
gitEnd:
call getGitPath
${If} $gitExe == ""
StrCpy $logstring "Unable to find git. You may need to run this installer again to complete the full installation."
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${Else}
StrCpy $logstring "Using Git path: $gitExe"
${EndIf}
SectionEnd
;***************************************************************************************
Section "AZT" aztId
;----------------------------------------------------------------
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Installing AZT from Git repository..."
StrCpy $logstring "${NEWLINE}----- AZT Installer ----- "
Call logMessage
StrCpy $azt ""
; Show a message that we're starting to look for the repo
StrCpy $logstring "Looking for a USB with the $aztRepoName on it"
Call logMessage
Push "EndStack" ; Mark end of stack to check on Pop
ClearErrors
StrCpy $logstring "Executing wmic logicaldisk get deviceid..."
Call logMessage
nsExec::ExecToStack 'wmic logicaldisk get deviceid'
ifErrors errorExitAzt
Pop $0 ; Pop the return code
StrCpy $logstring " RC = $0"
call logMessage
Pop $0 ; Pop the results
StrCpy $logstring " Results = $0"
call logMessage
${If} $0 == "EndStack"
StrCpy $logstring "No logical drives found for searching"
Call logMessage
${Else}
; parse string with drive letters, newlines, and blanks
StrLen $R1 $0 ; Get the length of the string
; Initialize a loop to go through each character
StrCpy $2 0
${Do}
; Get the current character
StrCpy $3 $0 1 $2
; Check if the character is a newline or a blank
${If} $3 == $\n
; Skip newline
Goto SkipChar
${EndIf}
${If} $3 == ' '
; Skip blank space
Goto SkipChar
${EndIf}
; Check if this is a drive letter with a colon
StrCpy $3 $0 2 $2
StrCpy $4 $3 1 1 ; Get the second character to see if it's a colon
${If} $4 != ":"
Goto SkipChar
${EndIf}
; Search this drive
StrCpy $logstring "Drive: $3"
call logMessage
StrCpy $R3 "$3\*$aztRepoName"
FindFirst $R4 $R5 "$R3"
StrCpy $logstring "$R3 file search: $R4 $R5"
Call logMessage
FindClose $R4
${If} $1 == $aztRepoName
StrCpy $logstring "found repo in $R3"
Call logMessage
StrCpy $azt "$R3"
Goto exitFileLoop
${EndIf}
; Increment the index by 2 to skip to the next drive letter
IntOp $2 $2 + 2
Goto EndOfLoop
SkipChar:
; Increment index by 1 to move to the next character
IntOp $2 $2 + 1
EndOfLoop:
${LoopUntil} $2 >= $R1
${EndIf}
exitFileLoop:
${If} $azt != ""
StrCpy $logstring "azt is defined (local repo found): $azt"
Call logMessage
${Else}
StrCpy $azt $aztRepoURL
StrCpy $logstring "Local file not found; using github: $azt"
Call logMessage
${EndIf}
StrCpy $logstring "Cloning A-Z+T source to $INSTDIR"
Call logMessage
; Convert the path to the installer to a path that git can use
Var /GLOBAL newPathString
StrCpy $0 $INSTDIR ; Original path
StrCpy $newPathString "" ; Result string
StrLen $2 $0 ; Length of the original string
StrCpy $3 0 ; Index
; Loop through each character in the string
${Do}
StrCpy $4 $0 1 $3 ; Extract one character at position $3
${If} $4 == "\"
StrCpy $4 "/"
${EndIf}
StrCpy $newPathString "$newPathString$4" ; Append to result string
IntOp $3 $3 + 1 ; Move to the next character
${LoopUntil} $3 == $2
StrCpy $logstring "git config path: $newPathString"
ClearErrors
Var /GLOBAL cmd
; Set the safe.directory in both --system and --global, using both "\" and "/" paths to be safe
; Developer Notes: To validate in a windows command prompt, use:
; git config --system --get-all safe.directory
; To clear them:
; git config --system --unset-all safe.directory
; Define the path to the log file
StrCpy $tempLogFile "git_error.log"
${If} $gitExe == "" ; Should have been set during git install, else assume path is in env.
StrCpy $logstring "gitExe variable is not set - using 'git'"
StrCpy $gitExe "git"
${EndIf}
StrCpy $cmd `$\"$gitExe$\" config --system --add safe.directory $\"$INSTDIR$\"`
StrCpy $logstring "Executing $cmd ..."
Call logMessage
ExecWait `cmd /C $\"$cmd$\" 2>$tempLogFile` $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Git config error: $ReturnError"
Call logMessage
abort
${EndIf}
StrCpy $cmd `$\"$gitExe$\" config --system --add safe.directory $\"$newPathString$\"`
StrCpy $logstring "Executing $cmd ..."
Call logMessage
ExecWait `cmd /C $\"$cmd$\" 2>$tempLogFile` $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Git config error: $ReturnError"
Call logMessage
abort
${EndIf}
StrCpy $cmd `$\"$gitExe$\" config --global --add safe.directory $\"$INSTDIR$\"`
StrCpy $logstring "Executing $cmd ..."
Call logMessage
ExecWait `cmd /C $\"$cmd$\" 2>$tempLogFile` $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Git config error: $ReturnError"
Call logMessage
abort
${EndIf}
StrCpy $cmd `$\"$gitExe$\" config --global --add safe.directory $\"$newPathString$\"`
StrCpy $logstring "Executing $cmd ..."
Call logMessage
ExecWait `cmd /C $\"$cmd$\" 2>$tempLogFile` $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Git config error: $ReturnError"
Call logMessage
abort
${EndIf}
StrCpy $cmd `$\"$gitExe$\" clone $azt $\"$INSTDIR$\"`
StrCpy $logstring "Executing $cmd ..."
Call logMessage
ClearErrors
; Use ExecToStack instead of ExecWait to prevent the windows command prompt from showing
nsExec::ExecToStack 'cmd /C $\"$cmd$\" 2>$tempLogFile'
Pop $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Git clone error: $ReturnError"
Call logMessage
; If the error says repo already exists, just update it.
${StrStr} $2 $ReturnError "exists and is not an empty directory"
${If} $2 != ""
StrCpy $logstring "AZT Repo already exists, updating..."
Call logMessage
Call gitPullAZT
${Else}
; Display the error message
StrCpy $logstring "There was an error getting the repository:${NEWLINE}${NEWLINE}$ReturnError${NEWLINE}${NEWLINE}Make sure your internet (or USB repository) is connected."
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
${EndIf}
${EndIf}
;----------------------------------------------------------------
; Successful install of AZT, set up shortcuts
;
StrCpy $logstring "Creating shortcut to AZT..."
Call logMessage
; Create Shortcut
StrCpy $0 "$DESKTOP\A-Z+T.lnk" ; The shortcut name
StrCpy $1 "$DESKTOP\azt\main.py" ; The target file
StrCpy $logstring "Executable : $EXEDIR\$EXEFILE"
Call logMessage
StrCpy $2 "$EXEDIR\$EXEFILE" ; icon file is embedded in installer executable
; Create application shortcut (switch to installation dir to have the correct "start in" target)
SetOutPath "$INSTDIR"
CreateShortcut "$0" "$1" "" "$2" 0
; Check for errors
IfErrors 0 +3
StrCpy $logstring "ERROR: Failed to create shortcut for AZT."
Call logMessage
SetOutPath "$EXEDIR"
StrCpy $logstring "Creating shortcut to Transcriber tool..."
Call logMessage
StrCpy $0 "$DESKTOP\Transcriber.lnk" ; The shortcut name
StrCpy $1 "$transcriberfilename" ; The target file
StrCpy $2 "$EXEDIR\Transcribe-Tone.ico" ; icon file is embedded in installer executable
; Create application shortcut (first in installation dir to have the correct "start in" target)
SetOutPath "$INSTDIR"
CreateShortcut "$0" "$1" "" "$2" 0
; Check for errors
IfErrors 0 +3
StrCpy $logstring "ERROR: Failed to create shortcut for Transcriber."
Call logMessage
SetOutPath "$EXEDIR"
goto AZTEnd
errorExitAzt:
ClearErrors
${If} $tempLogFile == "git_error.log"
; Read the error log file content into a variable
FileOpen $0 $tempLogFile r
FileRead $0 $1
FileClose $0
StrCpy $logstring "ERROR: $1"
Call logMessage
${EndIf}
StrCpy $logstring "Error cloning AZT"
Call logMessage
MessageBox MB_OK|MB_ICONEXCLAMATION $logstring /SD IDOK
Abort
;--------------------------------
AZTEnd:
StrCpy $logstring "A-Z+T installed successfully."
Call logMessage
SectionEnd
;***************************************************************************************
Section "Charis" charisId
;----------------------------------------------------------------
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Installing Charis SIL Fonts..."
StrCpy $logstring "${NEWLINE}----- Charis Installer ----- "
Call logMessage
StrCpy $downloadName "Charis"
; Check if Installer file was already downloaded previously
StrCpy $logstring "$downloadName FindFirst: $chariszipfile"
FindFirst $0 $1 "$chariszipfile"
StrCpy $logstring "$downloadName file search: $0 $1"
Call logMessage
FindClose $0
${If} $1 == $chariszipfile
StrCpy $logstring "$chariszipfile already exists, using this version."
Call logMessage
${Else}
# Download Installer file
StrCpy $logstring "Downloading $downloadName $chariszipfile from $charisurl"
Call logMessage
inetc::get "$charisurl" "$chariszipfile" /end
Pop $0 ;Get the return value
${If} $0 != 'OK'
StrCpy $logstring "$0. Error downloading $downloadName. Skipping Charis installation."
Call logMessage
goto charisEnd ; skip installation
${Else}
StrCpy $logstring "$downloadName downloaded successfully."
Call logMessage
${EndIf}
${EndIf}
; Unzip
StrCpy $logstring "$downloadName unzipping $chariszipfile...."
Call logMessage
; Run the tar command to extract the ZIP file
StrCpy $tempLogFile "charis_error.log"
ClearErrors
ExecWait 'cmd /C tar -xf "$chariszipfile" -C "$OUTDIR" 2>$tempLogFile' $0
StrCpy $logstring " Return value: $0"
Call logMessage
${If} $0 != 0
; Read the error log file content into a variable
FileOpen $0 $tempLogFile r
FileRead $0 $ReturnError
FileClose $0
StrCpy $logstring "ERROR: Unable to extract $chariszipfile: ${NEWLINE}$ReturnError ${NEWLINE} Skipping Charis installation."
Call logMessage
goto charisEnd ; skip installation
${EndIf}
;----------------------------------
; Install fonts
; If file was downloaded and unzipped successfuly, we will continue here to install the fonts
; Scroll through each .ttf file in the extracted folder and copy them to the system/fonts folder
StrCpy $logstring "Installing Fonts $charisfilename...."
Call logMessage
# Define some variables only used here
Var /GLOBAL TTFFileName
Var /GLOBAL NOEXT
Var /GLOBAL FACE
Var /GLOBAL FACEMOD
Var /GLOBAL TTF
StrCpy $TTF "$EXEDIR\$charisfilename\*.ttf"
StrCpy $logstring "TTF: $TTF"
Call logMessage
ClearErrors
# Start the loop
FindFirst $0 $1 "$TTF"
StrCpy $logstring " File search: $0 $1"
Call logMessage
${DoWhile} $1 != ""
# Copy the font file to the Fonts directory
StrCpy $TTF $EXEDIR\$charisfilename\$1
;StrCpy $logstring "Copying $TTF to $WINDIR\Fonts..."
StrCpy $logstring "Copying $TTF to $FONTS..."
Call logMessage
CopyFiles "$TTF" "$FONTS"
ifErrors 0 continueCharis
StrCpy $logstring "Error copying $TTF to $FONTS"
Call logMessage
goto errorExitCharis
continueCharis:
# Set the TTFFileName variable
StrCpy $TTFFileName $1
# Remove the .ttf extension to get NOEXT
StrCpy $NOEXT $TTFFileName -4
# Remove 'CharisSIL-' from NOEXT to get FACE
${If} $NOEXT != ""
${StrRep} $FACE $NOEXT "CharisSIL-" ""
${EndIf}
# Replace 'BoldItalic' with 'Bold Italic' in FACE to get FACEMOD
StrCpy $FACEMOD $FACE
${StrRep} $FACEMOD $FACEMOD "BoldItalic" "Bold Italic"
StrCpy $logstring "Installing $TTFFileName as $FACEMOD"
Call logMessage
# Write to the registry
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Charis SIL $FACEMOD (TrueType)" "$TTFFileName"
ifErrors 0 continueCharis2
StrCpy $logstring "Error writing updating registry for font: $FACEMOD"
Call logMessage
goto errorExitCharis
continueCharis2:
; Validate and write to log
; To validate directly, copy and paste this into windows prompt:
; reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Charis SIL*"
ReadRegStr $R9 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Charis SIL $FACEMOD (TrueType)"
StrCpy $logstring "Registry read for $FACEMOD: $R9"
Call logMessage
# Loop to the next file
FindNext $0 $1
${Loop}
; Notify windows about the font updates
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=${WAITTIME}
FindClose $0
goto charisEnd
errorExitCharis:
ClearErrors
StrCpy $logstring "Error installing Charis SIL Fonts - they may already be installed."
Call logMessage
;--------------------------------
charisEnd:
SectionEnd
;***************************************************************************************
Section "XLingPaper" xlpId
;----------------------------------------------------------------
!insertmacro MUI_HEADER_TEXT_PAGE "${TITLENAME}" "Installing XLingPaper. Answer prompts in that installer to complete."
StrCpy $logstring "${NEWLINE}----- XLP Installer ----- "
Call logMessage
StrCpy $logstring "Checking if XLingPaper is already installed..."
Call logMessage
; Check if XLingPaper is already installed to skip the installation
StrCpy $R0 "XLingPaper"
StrCpy $R2 $PROGRAMFILES32 ; Program Files (x86)
Push $R2
Push $R0
Call LocatePrograms
Pop $R1
${If} $R1 != ""
StrCpy $logstring "$R0 found: $R1. Skipping installation."
Call logMessage
Goto xlpEnd
${Else}
StrCpy $R0 "XLingPaper"
StrCpy $R2 $PROGRAMFILES64 ; Program Files (64-bit)
Push $R2