forked from OpenCPN/OpenCPN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSIS.template.in
4585 lines (3973 loc) · 145 KB
/
NSIS.template.in
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
/*-----------------------------------------------------------------------------------------------------
NSIS Installer script for OpenCPN (Windows)
NSIS version 2.46
Written by Gunther Pilz (Netsurfer) netsurfer@opencpn.de
-------------------------------------------------------------------------------------------------------
CMake variables
CPACK_PACKAGE_NAME "OpenCPN"
CPACK_NSIS_PACKAGE_NAME_LC "opencpn"
CPACK_PACKAGE_VENDOR "opencpn.org"
CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}
CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}
CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}
CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}
CPACK_NSIS_INSTALLED_ICON_NAME "opencpn.exe"
CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/src/bitmaps\\\\opencpn.ico"
CPACK_NSIS_EXTRA_INSTALL_COMMANDS ${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/data/license.txt"
CPACK_BUILDWIN_DIR "${CMAKE_SOURCE_DIR}/buildwin"
CPACK_NSIS_DIR "${CMAKE_SOURCE_DIR}/buildwin/NSIS_Unicode")
#CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_CURRENT_BINARY_DIR};${PACKAGE_NAME};ALL;/"
#CPACK_PACKAGE_EXECUTABLES ${PACKAGE_NAME} "OpenCPN"
#CPACK_PACKAGE_INSTALL_DIRECTORY ${PACKAGE_NAME} "OpenCPN"
#CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenCPN ${PACKAGE_VERSION}"
#CPACK_NSIS_LINK_NAME "${CPACK_PACKAGE_NAME} ${PACKAGE_VERSION}"
#CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME} Version ${PACKAGE_VERSION}"
#CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.opencpn.org"
#CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.opencpn.org"
#CPACK_NSIS_CONTACT "http:\\\\\\\\www.opencpn.org"
#CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}_${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_setup"
----------------------------------------------------------------------------------------------------------*/
;# Set compression
SetCompressor /FINAL lzma
;--------------------------------
;# You must define these values
!define OCPN_INSTALLER_VERSION "1.0.0"
/*
!define CPACK_NSIS_INSTALLED_ICON_NAME "opencpn.exe"
!define CPACK_NSIS_PACKAGE_NAME_LC "opencpn"
!define CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME} ${PACKAGE_VERSION}"
!define CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/src/bitmaps/opencpn.ico"
!define CPACK_BUILDWIN_DIR "${CMAKE_SOURCE_DIR}/buildwin"
!define CPACK_NSIS_DIR "${CMAKE_SOURCE_DIR}/buildwin/NSIS_Unicode"
*/
!define /date YEAR "%Y"
!define OUTPUT_FILE_NAME "@CPACK_NSIS_PACKAGE_NAME_LC@_@CPACK_PACKAGE_VERSION@_setup.exe"
!define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
!define REG_ROOT_KEY "Software"
!define REG_KEY "Software\OpenCPN"
!define REG_ROOT_KEY_UN "Software\Microsoft\Windows\CurrentVersion\Uninstall"
!define REG_KEY_UN "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN @CPACK_PACKAGE_VERSION@"
!define CSIDL_LOCAL_APPDATA "0x1C"
!define Explode "!insertmacro Explode"
!define unExplode "!insertmacro unExplode"
;--------------------------------
;# Variables
Var INST_USER_SID
Var CONFIG_EXISTS
Var CONFIG_EMPTY
Var INI_EXISTS
Var CHARTDB_EXISTS
Var SENC_EXISTS
Var CM93_EXISTS
Var NAVOBJ_EXISTS
Var LOG_EXISTS
Var REG_LANG
Var Count_SecGrpResetConfig
Var SecGrpEndSetConfig_Text
Var RESET_CONFIG
Var STARTMENU_FOLDER
Var OLD_INSTALLS
Var Prev_Install_RegKey
Var MULTIPLE_INSTALLS
Var VERSION_EXISTS
Var VERSION_NEWER
Var VERSION_OLDER
Var CANCEL_INSTALLER
Var VERSION_DATE
Var LANG_NAME
Var Status_SecGrpSetConfig
Var MAJOR_D
Var MINOR_D
Var PATCH_D
Var PATCH_ND
Var LM_VERSION
Var LM_VERSION_INST
Var LM_VERSION_UNINST
Var latest_version
Var latest_pathexe
Var BU_X
Var BU_Y
Var UAT
Var OUAT
Var USERS_APPDATA
Var ADMIN_APPDATA
Var USERS_NAME
Var counter_tmp
Var CurrentDirVar
Var CurrentFileVar
Var CONTEXT
Var REG_CHARTDIRS
Var USERNAME
Var IS_ADMIN
Var Compare_Version_Result
Var Inst_Or_Uninst
Var Marquee_Handle
Var Banner_Text_Blink
Var error_tmp
# onSelChange
Var ConfigSetLang
Var ConfigSetChartDir
Var SetConfig
# Installer Pages
Var Skip_Page_CleanUp
Var Skip_Page_TypeInst
Var Skip_Page_SetConfig
Var Skip_Page_Directory
Var Skip_Page_Startmenu
Var Skip_Page_Confirm
# Page_TypeInst
Var Label_TypeInst_Reinstall
Var RB_Reinstall
Var Label_TypeInst_Upgrade
Var RB_Upgrade
Var Label_TypeInst_Downgrade
Var RB_Downgrade
Var Label_TypeInst_Parallel
Var GroupBox_TypeInst
Var RB_Parallel
Var TI_REINSTALL
Var TI_UPGRADE
Var TI_DOWNGRADE
Var TI_PARALLEL
Var GroupBox_Size
Var INSTALL_TYPE
# Page_SetConfig
Var Label_SetConfig
Var GroupBox_Language_SetConfig
Var CheckBox_Language_SetConfig
Var GroupBox_ChartDir_SetConfig
Var DirRequest_SetConfig
Var Button_Delete_SetConfig
Var Button_DeleteAll_SetConfig
Var Button_Add_SetConfig
Var ListBox_SetConfig
;# Page_SetConfig_Leave
Var CHART_DIR_TMP_FILE
Var CHART_DIR_EMPTY
Var CONFIG_SET_LANG
# Uninstaller Pages
Var Skip_UnPage_Components
;--------------------------------
;# Execution Level
RequestExecutionLevel highest
;--------------------------------
;# Includes
!addincludedir "@CPACK_NSIS_DIR@/Include"
!addplugindir "@CPACK_NSIS_DIR@/Plugins"
!include MUI2.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
!include Sections.nsh
!include StrFunc.nsh
!include WordFunc.nsh
!include TextFunc.nsh
!include FileFunc.nsh
!include WinVer.nsh
!include UAC.nsh
!define MUI_UI "@CPACK_NSIS_DIR@/UI/opencpn_ui.exe"
;--------------------------------
;# General
;# Name and file
Name "@CPACK_NSIS_PACKAGE_NAME@"
OutFile "@CPACK_TOPLEVEL_DIRECTORY@/${OUTPUT_FILE_NAME}"
;# Default installation folder
InstallDir "$PROGRAMFILES\OpenCPN"
BrandingText /TRIMLEFT "OpenCPN $(Installer) v${OCPN_INSTALLER_VERSION}"
;--------------------------------
;# Interface Settings
!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
!define MUI_CUSTOMFUNCTION_UNGUIINIT un.myGuiInit
!define MUI_ABORTWARNING
;# MUI Settings / Header
!define MUI_ICON "@CPACK_PACKAGE_ICON@"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_LEFT
!define MUI_HEADERIMAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\header-install.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "@CPACK_NSIS_DIR@\Bitmaps\header-uninstall.bmp"
;# MUI Settings / Wizard
!define MUI_WELCOMEFINISHPAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\wizard-install.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\wizard-uninstall.bmp"
;# Set Multi-Language settings
;# Language Selection Dialog Settings
;# Show all languages, despite user's codepage
!define MUI_LANGDLL_ALLLANGUAGES
/*
;# Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
!define MUI_LANGDLL_REGISTRY_KEY "${REG_KEY_UN}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage"
!define MUI_LANGDLL_WINDOWTITLE "$(LangDialog_Title)"
!define MUI_LANGDLL_INFO "$(LangDialog_Text)"
*/
;--------------------------------
;# Calls for making respective functions available
${StrLoc}
;--------------------------------
;##################################################################################################
;# Macros #
;##################################################################################################
!ifndef ___EnumHKU___
!define ___EnumHKU___
!include LogicLib.nsh
!include WordFunc.nsh
!define TOKEN_QUERY 0x0008
!define TOKEN_ADJUST_PRIVILEGES 0x0020
!define SE_RESTORE_NAME SeRestorePrivilege
!define SE_PRIVILEGE_ENABLED 0x00000002
!define HKEY_USERS 0x80000003
Var key
Var logged
Var EnumHKU_counter
Var SID
Var USERPROFILE
!macro _EnumHKU_AdjustTokens
StrCpy $R1 0
System::Call "kernel32::GetCurrentProcess() i .R0"
System::Call "advapi32::OpenProcessToken(i R0, i ${TOKEN_QUERY}|${TOKEN_ADJUST_PRIVILEGES}, *i R1R1) i .R0"
${If} $R0 != 0
System::Call "advapi32::LookupPrivilegeValue(t n, t '${SE_RESTORE_NAME}', *l .R2) i .R0"
${If} $R0 != 0
System::Call "*(i 1, l R2, i ${SE_PRIVILEGE_ENABLED}) i .R0"
System::Call "advapi32::AdjustTokenPrivileges(i R1, i 0, i R0, i 0, i 0, i 0)"
System::Free $R0
${EndIf}
System::Call "kernel32::CloseHandle(i R1)"
${EndIf}
!macroend
!macro _EnumHKU_InvokeCallback CALLBACK SUBKEY
Push $0
Push $1
Push $R0
Push $R1
Push $R2
Push $R3
Push $R4
Push $R5
Push $R6
Push "${SUBKEY}"
Call "${CALLBACK}"
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $1
Pop $0
!macroend
!macro _EnumHKU_Load FILE CALLBACK SUBKEY
GetFullPathName /SHORT $R2 ${FILE}
System::Call "advapi32::RegLoadKeyW(i ${HKEY_USERS}, t '${SUBKEY}', t R2) i .R3"
${If} $R3 == 0
!insertmacro _EnumHKU_InvokeCallback ${CALLBACK} "${SUBKEY}"
;System::Call "advapi32::RegUnLoadKeyW(i ${HKEY_USERS}, t '${SUBKEY}')"
IntOp $EnumHKU_counter $EnumHKU_counter + 1
${EndIf}
!macroend
!macro EnumHKU UN CALLBACK SUBKEY
Push $0
Push $1
StrCpy $EnumHKU_counter 0
GetFunctionAddress $0 "${CALLBACK}"
StrCpy $1 "${SUBKEY}_$EnumHKU_counter"
StrCpy $key ${SUBKEY}
Call ${UN}_EnumHKU
Pop $1
Pop $0
!macroend
!define EnumHKU '!insertmacro EnumHKU ""'
!define un.EnumHKU '!insertmacro EnumHKU "un."'
!macro _EnumHKU UN
Function ${UN}_EnumHKU
Push $R0
Push $R1
Push $R2
Push $R3
Push $R4
Push $R5
Push $R6
# enumerate logged on users
StrCpy $R0 0
${Do}
EnumRegKey $R1 HKU "" $R0
${If} $R1 != ""
StrLen $R4 $R1
${If} $R4 > 8
StrCpy $R6 0
${WordFind} "$R1" "_Classes" "E*" $R6
IfErrors 0 cont
ReadRegStr $R5 HKU "$R1\Volatile Environment" USERPROFILE
ExpandEnvStrings $R5 $R5
StrCpy $USERPROFILE $R5
StrCpy $logged "on"
!insertmacro _EnumHKU_InvokeCallback $0 $R1
StrCpy $USERPROFILE ""
StrCpy $logged ""
${EndIf}
cont:
IntOp $R0 $R0 + 1
${EndIf}
${LoopUntil} $R1 == ""
# enumerate logged off users
System::Call "kernel32::GetVersion() i .R0"
IntOp $R0 $R0 & 0x80000000
${If} $R0 == 0
# nt
!insertmacro _EnumHKU_AdjustTokens
StrCpy $R0 0
${Do}
EnumRegKey $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $R0
${If} $R1 != ""
StrLen $R4 $R1
${If} $R4 > 8
ClearErrors
ReadRegStr $R5 HKU "$R1\Volatile Environment" HOMEPATH
IfErrors 0 cont1
ReadRegStr $R5 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$R1" ProfileImagePath
ExpandEnvStrings $R5 $R5
StrCpy $USERPROFILE $R5
StrCpy $logged "off"
!insertmacro _EnumHKU_Load "$R5\NTUSER.DAT" $0 $1
StrCpy $1 "$key_$EnumHKU_counter"
StrCpy $USERPROFILE ""
StrCpy $logged ""
${EndIf}
cont1:
IntOp $R0 $R0 + 1
${EndIf}
${LoopUntil} $R1 == ""
${Else}
# 9x
ClearErrors
FindFirst $R1 $R2 "$WINDIR\Profiles\*.*"
${Unless} ${Errors}
${Do}
${If} $R2 != "."
${AndIf} $R2 != ".."
${If} ${FileExists} "$WINDIR\Profiles\$R2\USER.DAT"
!insertmacro _EnumHKU_Load "$WINDIR\Profiles\$R2\USER.DAT" $0 $1
${EndIf}
${EndIf}
ClearErrors
FindNext $R1 $R2
${LoopUntil} ${Errors}
FindClose $R1
${EndUnless}
${Endif}
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
!macroend
!insertmacro _EnumHKU ""
!insertmacro _EnumHKU "un."
!endif
!macro IndexOf Var Str Char
Push "${Char}"
Push "${Str}"
Call IndexOf
Pop "${Var}"
!macroend
!define IndexOf "!insertmacro IndexOf"
!macro RIndexOf Var Str Char
Push "${Char}"
Push "${Str}"
Call RIndexOf
Pop "${Var}"
!macroend
!define RIndexOf "!insertmacro RIndexOf"
!macro Explode Length Separator String
Push `${Separator}`
Push `${String}`
Call Explode
Pop `${Length}`
!macroend
!macro unExplode Length Separator String
Push `${Separator}`
Push `${String}`
Call un.Explode
Pop `${Length}`
!macroend
!ifndef _RecFind_Included
!define _RecFind_Included
Var _RecFindVar1
Var _RecFindVar2
!macro _RecFindOpen Dir CurrentDirVar CurrentFileVar
!define _Local `${__LINE__}`
!define _Dir `${Dir}`
!define _CurrentDirVar `${CurrentDirVar}`
!define _CurrentFileVar `${CurrentFileVar}`
!define _RecFindOpenSet
StrCpy $_RecFindVar2 1
Push ``
`nextDir${_Local}:`
Pop `${_CurrentDirVar}`
IntOp $_RecFindVar2 $_RecFindVar2 - 1
!macroend
!define RecFindOpen `!insertmacro _RecFindOpen`
!macro _RecFindFirst
!ifndef _RecFindOpenSet
!error `Incorrect use of RecFind commands!`
!else
!define _RecFindFirstSet
!endif
ClearErrors
FindFirst $_RecFindVar1 `${_CurrentFileVar}` `${_Dir}${_CurrentDirVar}\*.*`
IfErrors `Done${_Local}`
`checkFile${_Local}:`
StrCmp ${_CurrentFileVar} . `nextFile${_Local}`
StrCmp ${_CurrentFileVar} .. `nextFile${_Local}`
IfFileExists `${_Dir}${_CurrentDirVar}\${_CurrentFileVar}\*.*` 0 +4
Push `${_CurrentDirVar}\${_CurrentFileVar}`
IntOp $_RecFindVar2 $_RecFindVar2 + 1
Goto `nextFile${_Local}`
!macroend
!define RecFindFirst `!insertmacro _RecFindFirst`
!macro _RecFindNext
!ifndef _RecFindOpenSet | _RecFindFirstSet
!error `Incorrect use of RecFind commands!`
!else
!define _RecFindNextSet
!endif
`nextFile${_Local}:`
ClearErrors
FindNext $_RecFindVar1 `${_CurrentFileVar}`
IfErrors 0 `checkFile${_Local}`
StrCmp $_RecFindVar2 0 +3
FindClose $_RecFindVar1
Goto `nextDir${_Local}`
!macroend
!define RecFindNext `!insertmacro _RecFindNext`
!macro _RecFindClose
!ifndef _RecFindOpenSet | _RecFindFirstSet | _RecFindNextSet
!error `Incorrect use of RecFind commands!`
!else
!undef _RecFindOpenSet
!undef _RecFindFirstSet
!undef _RecFindNextSet
!endif
`Done${_Local}:`
FindClose $_RecFindVar1
StrCmp $_RecFindVar2 0 +4
Pop $_RecFindVar1
IntOp $_RecFindVar2 $_RecFindVar2 - 1
Goto -3
!undef _CurrentFileVar
!undef _CurrentDirVar
!undef _Dir
!undef _Local
!macroend
!define RecFindClose `!insertmacro _RecFindClose`
!endif
;--------------------------------------------------------------------------------------------------
;##################################################################################################
;# PAGES #
;##################################################################################################
;# Installer Pages #
;##################################################################################################
/* Var Skip_Page_CleanUp
Var Skip_Page_TypeInst
Var Skip_Page_SetConfig
Var Skip_Page_Directory
Var Skip_Page_Startmenu
Var Skip_Page_Confirm
*/
;# Welcome page
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_WELCOME
;# License page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_License_Leave
;!insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
!define MUI_LICENSEPAGE_BUTTON "$(^NextBtn)"
!define MUI_LICENSEPAGE_TEXT_BOTTOM $(License_Message)
!insertmacro MUI_PAGE_LICENSE $(license)
;# Clean up page - only shown if previous installation(s) <= 2.2.823 were found - checked in .onInit function
Page custom Page_CleanUp Page_CleanUp_Leave
;# Install type page - only shown if previous installation(s) > 2.2.823 were found - checked in .onInit function
Page custom Page_TypeInst Page_TypeInst_Leave
;# Components page
!define MUI_COMPONENTSPAGE_SMALLDESC
!define MUI_PAGE_HEADER_TEXT $(CP_HEADER_TEXT)
!define MUI_PAGE_HEADER_SUBTEXT $(CP_HEADER_SUBTEXT)
!define MUI_COMPONENTSPAGE_TEXT_TOP $(CP_TOP)
!define MUI_COMPONENTSPAGE_TEXT_COMPLIST $(CP_COMPLIST)
!define MUI_COMPONENTSPAGE_TEXT_INSTTYPE "" ;#CHANGE $(CP_INSTTYPE)
;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE $(CP_DESCRIPTION_TITLE) ;# for this we can use the default text
;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO $(CP_DESCRIPTION_INFO) ;# for this we can use the default text
!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Components_Pre
!define MUI_PAGE_CUSTOMFUNCTION_SHOW Page_Components_Show
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_Components_Leave
!insertmacro MUI_PAGE_COMPONENTS
;# Directory page - allows for changing/ selecting the install directory
!define MUI_DIRECTORYPAGE_VERIFYONLEAVE
!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Directory_Pre
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_Directory_Leave
!insertmacro MUI_PAGE_DIRECTORY
;# Start Menu Folder page - allows for changing/ selecting the Start Menu Folder (if Shortcuts get installed is configured on the Components page)
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${REG_KEY_UN}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "OpenCPN"
!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Startmenu_Pre
!insertmacro MUI_PAGE_STARTMENU "Application" $STARTMENU_FOLDER
;# Set Config page - selecting chart director[y|ies] and setting the language in opencpn.ini - only available if opencpn.ini does not exist (or is being deleted)
Page custom Page_SetConfig Page_SetConfig_Leave
;# Confirm page - shows all settings for the installation (is mainly needed to always have the 'Install' button on the right page, ie. if Start Menu page is skipped)
Page custom Page_Confirm
;# Install page
!define MUI_PAGE_CUSTOMFUNCTION_SHOW Page_Instfiles_Show
!insertmacro MUI_PAGE_INSTFILES
;# Finish page
#!define MUI_FINISHPAGE_RUN opencpn.exe
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION ExecAppFile
!define MUI_FINISHPAGE_SHOWREADME install.log
!define MUI_FINISHPAGE_SHOWREADME_TEXT $(Show_Readme_Text)
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_LINK $(Finish_Link_Text)
!define MUI_FINISHPAGE_LINK_LOCATION $(Finish_Link_URL)
!define MUI_FINISHPAGE_LINK_COLOR 000080
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
!define MUI_FINISHPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
;##################################################################################################
;# Uninstaller Pages #
;##################################################################################################
;# Welcome page
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_UNPAGE_WELCOME
;# Components page
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.Page_Components_Pre
!insertmacro MUI_UNPAGE_COMPONENTS
;# Confirm page
!insertmacro MUI_UNPAGE_CONFIRM
;# Uninstall page
!insertmacro MUI_UNPAGE_INSTFILES
;# Finish page
!define MUI_FINISHPAGE_TITLE_3LINES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------------------------------------------------------------------------
;##################################################################################################
;# Languages #
;##################################################################################################
;# Languages
!insertmacro MUI_LANGUAGE "English" ;# first language is the default language
!insertmacro MUI_LANGUAGE "German"
!include /NONFATAL "Langstrings_GERMAN.nsh"
!insertmacro MUI_LANGUAGE "French"
!include /NONFATAL "Langstrings_FRENCH.nsh"
!insertmacro MUI_LANGUAGE "Czech"
!include /NONFATAL "Langstrings_CZECH.nsh"
!insertmacro MUI_LANGUAGE "Danish"
!include /NONFATAL "Langstrings_DANISH.nsh"
!insertmacro MUI_LANGUAGE "Spanish"
!include /NONFATAL "Langstrings_SPANISH.nsh"
!insertmacro MUI_LANGUAGE "Italian"
!include /NONFATAL "Langstrings_ITALIAN.nsh"
!insertmacro MUI_LANGUAGE "Dutch"
!include /NONFATAL "Langstrings_DUTCH.nsh"
!insertmacro MUI_LANGUAGE "Polish"
!include /NONFATAL "Langstrings_POLISH.nsh"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!include /NONFATAL "Langstrings_PORTUGUESEBR.nsh"
!insertmacro MUI_LANGUAGE "Portuguese"
!include /NONFATAL "Langstrings_PORTUGUESE.nsh"
!insertmacro MUI_LANGUAGE "Russian"
!include /NONFATAL "Langstrings_RUSSIAN.nsh"
!insertmacro MUI_LANGUAGE "Swedish"
!include /NONFATAL "Langstrings_SWEDISH.nsh"
!insertmacro MUI_LANGUAGE "Finnish"
!include /NONFATAL "Langstrings_FINNISH.nsh"
!insertmacro MUI_LANGUAGE "Norwegian"
!include /NONFATAL "Langstrings_NORWEGIAN.nsh"
!insertmacro MUI_LANGUAGE "TradChinese"
!include /NONFATAL "Langstrings_CHINESETW.nsh"
!insertmacro MUI_LANGUAGE "Turkish"
!include /NONFATAL "Langstrings_TURKISH.nsh"
;!insertmacro MUI_LANGUAGE "Hungarian"
;!include /NONFATAL "Langstrings_HUNGARIAN.nsh"
;--------------------------------
;# Reserve Files
;# If you are using solid compression, files that are required before
;# the actual installation should be stored first in the data block,
;# because this will make your installer start faster.
!insertmacro MUI_RESERVEFILE_LANGDLL
;# Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
!define MUI_LANGDLL_REGISTRY_KEY "${REG_KEY_UN}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage"
!define MUI_LANGDLL_WINDOWTITLE $(LangDialog_Title)
!define MUI_LANGDLL_INFO $(LangDialog_Text)
;--------------------------------------------------------------------------------------------------
;##################################################################################################
;# S E C T I O N S #
;##################################################################################################
;# Installer Sections #
;##################################################################################################
Section "-Topmost Section" SecTopmost ;# this needs to be always the first section to be executed!
SetShellVarContext all
SetOutPath $INSTDIR
${If} $INSTALL_TYPE == 1
${OrIf} $INSTALL_TYPE == 2
${OrIf} $INSTALL_TYPE == 3
ReadRegStr $0 HKLM "$Prev_Install_RegKey" "UninstallString"
${StrFilter} "$0" "" "" "$\"" $0
ClearErrors
ExecWait '"$0" /S /type=1 _?=$INSTDIR'
IfErrors 0 +2
DetailPrint "Error on uninstalling"
Sleep 100
Delete $0
${EndIf}
SectionEnd
;# Reset/ Delete Config Section
SectionGroup "!Reset Config Section Group" SecGrpResetConfig
Section /o "Delete Config File Section" SecDeleteConfigFile
;# Delete config file (opencpn.ini)
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
Delete "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
ClearErrors
${EndIf}
SectionEnd
Section /o "Delete ChartDB Section" SecDeleteChartDB
;# Delete chart DB (CHRTLIST.DAT)
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\CHRTLIST.DAT"
Delete "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\CHRTLIST.DAT"
ClearErrors
${EndIf}
SectionEnd
Section /o "Delete SENC Section" SecDeleteSENC
;# Delete SENC directory
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\SENC\*.*"
RMDir /r "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\SENC"
ClearErrors
${EndIf}
SectionEnd
Section /o "Delete SENC Section" SecDeleteCM93
;# Delete SENC directory
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\cm93\*.*"
RMDir /r "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\cm93"
ClearErrors
${EndIf}
SectionEnd
Section /o "Delete Navobject Section" SecDeleteNavobjFile
;# Delete navobject file (navobj.xml)
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\navobj.xml"
Delete "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\navobj.xml"
ClearErrors
${EndIf}
SectionEnd
Section /o "Delete Log File Section" SecDeleteLogFile
;# Delete log file (opencpn.log)
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.log"
Delete "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.log"
ClearErrors
${EndIf}
SectionEnd
SectionGroupEnd
;# Shortcut Section
SectionGroup /e "!Shortcuts Section Group" SecGrpShortcuts
Section "Startmenu Shortcut Section" SecShortcutStartmenu
;# Start Menu
SetShellVarContext all
SetOutPath $INSTDIR
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
;# Create shortcuts
CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\OpenCPN @CPACK_PACKAGE_VERSION@.lnk" "$INSTDIR\opencpn.exe"
CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER\$(Uninstall_Folder_Name)"
CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$(Uninstall_Folder_Name)\$(Uninstall_Link).lnk" "$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "Desktop Shortcut Section" SecShortcutDesktop
SetShellVarContext all
CreateShortCut "$DESKTOP\OpenCPN @CPACK_PACKAGE_VERSION@.lnk" "$INSTDIR\opencpn.exe"
SectionEnd
SectionGroupEnd
;# Write Config Section
Section "!Set Config Section" SecSetConfig
;# Write settings for config file (opencpn.ini) to HKLM Software\OpenCPN
${If} $CONFIG_SET_LANG == 1
;Call Write_Reg_Lang
WriteRegStr HKLM "Software\OpenCPN" "InstallerLanguage" $REG_LANG
${EndIf}
${If} $CHART_DIR_TMP_FILE == 1
Call Write_Reg_ChartDirs
${EndIf}
SectionEnd
;# Install Section /hidden
Section "-Install Section" SecInstall
@CPACK_NSIS_FULL_INSTALL@
@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
;# Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe"
;# Registry Entries
SetShellVarContext all ;# make sure that we write to HKLM
;# HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN <DisplayVersion>
WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayName" "@CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@"
WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayVersion" "@CPACK_PACKAGE_VERSION@"
WriteRegStr SHCTX "${REG_KEY_UN}" "CompareVersion" "$VERSION_DATE"
WriteRegStr SHCTX "${REG_KEY_UN}" "StartMenuPath" "$SMPROGRAMS\$STARTMENU_FOLDER"
WriteRegStr SHCTX "${REG_KEY_UN}" "InstallLocation" "$INSTDIR"
WriteRegStr SHCTX "${REG_KEY_UN}" "UninstallString" "$\"$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe$\""
WriteRegStr SHCTX "${REG_KEY_UN}" "QuietUninstallString" "$\"$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe /S$\""
WriteRegStr SHCTX "${REG_KEY_UN}" "ConfigLocation" "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayIcon" "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
WriteRegStr SHCTX "${REG_KEY_UN}" "Publisher" "@CPACK_PACKAGE_VENDOR@"
WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionMajor" $MAJOR_D
WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionMinor" $MINOR_D
WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionPatch" $PATCH_D
WriteRegDWORD SHCTX "${REG_KEY_UN}" "NoModify" 1
WriteRegDWORD SHCTX "${REG_KEY_UN}" "NoRepair" 1
WriteRegStr SHCTX "${REG_KEY_UN}" "HelpLink" "http://opencpn.org/"
WriteRegStr SHCTX "${REG_KEY_UN}" "URLInfoAbout" "http://opencpn.org/"
WriteRegStr SHCTX "${REG_KEY_UN}" "Contact" "http://opencpn.org/"
WriteRegStr SHCTX "${REG_KEY_UN}" "InstallUser" "$USERS_NAME"
${If} ${UAC_IsInnerInstance}
WriteRegStr SHCTX "${REG_KEY_UN}" "InstallAdminUser" "$USERNAME"
${EndIf}
;# Create the config folder if it does not exist and set full access rights to it
${IfNot} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
CreateDirectory "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
Sleep 250
${EndIf}
AccessControlW::GrantOnFile "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@" "(BU)" "GenericRead + GenericExecute + GenericWrite + Delete + FullAccess"
;# Save the log file
StrCpy $0 "$INSTDIR\install.log"
Push $0
Call DumpLog
SectionEnd
;--------------------------------
;##################################################################################################
;# Uninstaller Sections #
;##################################################################################################
Section "-un.Delete Config RegKey" UnSecDeleteConfigRegKey
DeleteRegKey HKLM "${REG_KEY}"
SectionEnd
Section /o "-un.Backup Config to RegKey" UnSecBackupConfigToRegKey
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
ClearErrors
StrCpy $0 ""
StrCpy $2 0
loop:
IntOp $2 $2 + 1
ReadINIStr $1 "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" "ChartDirectories" "ChartDir$2"
StrCmp $1 "" cont
${WordReplace} "$1" "\\" "\" "+" $3
${unExplode} $4 "^" "$3"
Pop $5
StrCmp $5 "" cont
StrCmp $0 "" 0 +2
StrCpy $0 $5
StrCpy $0 "$0;$5"
Goto loop
cont:
WriteRegStr HKLM "${REG_KEY}" "ChartDirs" "$0"
ReadINIStr $0 "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" "Settings" "Locale"
StrCmp $0 "" +2 0
WriteRegStr HKLM "${REG_KEY}" "InstallerLanguage" "$0"
${EndIf}
SectionEnd
Section "un.Delete Config Folder" UnSecDeleteConfigFolder
SetShellVarContext all
${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
RMDir /r "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
ClearErrors
${EndIf}
SectionEnd
Section "-un.Uninstall" UnSecUninstall
;# Delete all Shortcuts
Push $INSTDIR
Call un.Delete_Desktop_Shortcuts
Push $INSTDIR
Call un.Delete_Start_Menu_Shortcuts
;# Delete subdirs and files in INSTDIR
;# Remove the uninstaller itself
ReadRegStr $0 HKLM "${REG_KEY_UN}" "UninstallString"
${StrFilter} "$0" "" "" "$\"" $0
Delete $0
;# Remove the installation log file
Delete "$INSTDIR\install.log"
@CPACK_NSIS_DELETE_FILES@
@CPACK_NSIS_DELETE_DIRECTORIES@
;# Remove the installation directory INSTDIR if it is empty
ClearErrors
RMDir "$INSTDIR"
IfErrors 0 cont
IfSilent cont
MessageBox MB_OK|MB_ICONEXCLAMATION "$(Msg_Error_Remove_InstDir)"
cont:
;# Remove RegKey
DeleteRegKey HKLM "${REG_KEY_UN}"
SectionEnd
;--------------------------------------------------------------------------------------------------
;##################################################################################################
;# F U N C T I O N S #
;##################################################################################################
;# Installer Functions #
;##################################################################################################
;# .onInit Function
Function .onInit
;# Check if Windows version is at least XP (not Win 98, Win 2000 or older)
${IfNot} ${AtLeastWinXP}
MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Unsupported_Windows_Version)"
Abort
${Else}
${If} ${IsWinXP}
${AndIf} ${AtMostServicePack} 2
MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Unsupported_XP_SP_Version)"
Abort
${EndIf}
${EndIf}
;Prevent multiple instances of the installer
${IfNot} ${UAC_IsInnerInstance}
System::Call 'kernel32::CreateMutexW(i 0, i 0, t "ocpn_inst_@CPACK_PACKAGE_VERSION@") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Running)"
Abort
${EndIf}
Call GetUserInfo
StrCpy $USERS_NAME $USERNAME
;# Macros to be inserted
${If} $IS_ADMIN == 1
!insertmacro MUI_LANGDLL_DISPLAY
${EndIf}
SetShellVarContext current
StrCpy $USERS_APPDATA $APPDATA
StrCpy $ADMIN_APPDATA $APPDATA
;# UAC check if user has Admin privileges and prompt for elevation if not
uac_tryagain:
!insertmacro UAC_RunElevated
StrCpy $Inst_Or_Uninst "$(Installer)"
${Switch} $0
${Case} 0
${IfThen} $1 = 1 ${|} Quit ${|} ;# we are the outer process, the inner process has done its work, we are done
${IfThen} $3 <> 0 ${|} ${Break} ${|} ;# we are admin, let the show go on
${If} $1 = 3 ;# RunAs completed successfully, but with a non-admin user
MessageBox mb_IconExclamation|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Retry)" /SD IDNO IDOK uac_tryagain IDNO 0
${EndIf}
;# fall-through and die
${Case} 1223
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Abort)"
Quit
${Case} 1062
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Logon_Abort)"
Quit
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_No_Elevation)"
Quit
${EndSwitch}
########## from here we can be sure to run with admin privileges ##########
;# Delete all temporary files created during the installation
Delete "$TEMP\opencpn_*.tmp"