Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

NSIS.template.in 33 KB

You have to be logged in to leave a comment. Sign 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  1. ; CPack install script designed for a nmake build
  2. ;--------------------------------
  3. ; You must define these values
  4. !define VERSION "@CPACK_PACKAGE_VERSION@"
  5. !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
  6. !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
  7. ;--------------------------------
  8. ;Variables
  9. Var MUI_TEMP
  10. Var STARTMENU_FOLDER
  11. Var SV_ALLUSERS
  12. Var START_MENU
  13. Var DO_NOT_ADD_TO_PATH
  14. Var ADD_TO_PATH_ALL_USERS
  15. Var ADD_TO_PATH_CURRENT_USER
  16. Var INSTALL_DESKTOP
  17. Var IS_DEFAULT_INSTALLDIR
  18. ;--------------------------------
  19. ;Include Modern UI
  20. !include "MUI.nsh"
  21. ;Default installation folder
  22. InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  23. ;--------------------------------
  24. ;General
  25. ;Name and file
  26. Name "@CPACK_NSIS_PACKAGE_NAME@"
  27. OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
  28. ;Set compression
  29. SetCompressor @CPACK_NSIS_COMPRESSOR@
  30. ;Require administrator access
  31. RequestExecutionLevel admin
  32. @CPACK_NSIS_DEFINES@
  33. !include Sections.nsh
  34. ;--- Component support macros: ---
  35. ; The code for the add/remove functionality is from:
  36. ; http://nsis.sourceforge.net/Add/Remove_Functionality
  37. ; It has been modified slightly and extended to provide
  38. ; inter-component dependencies.
  39. Var AR_SecFlags
  40. Var AR_RegFlags
  41. @CPACK_NSIS_SECTION_SELECTED_VARS@
  42. ; Loads the "selected" flag for the section named SecName into the
  43. ; variable VarName.
  44. !macro LoadSectionSelectedIntoVar SecName VarName
  45. SectionGetFlags ${${SecName}} $${VarName}
  46. IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
  47. !macroend
  48. ; Loads the value of a variable... can we get around this?
  49. !macro LoadVar VarName
  50. IntOp $R0 0 + $${VarName}
  51. !macroend
  52. ; Sets the value of a variable
  53. !macro StoreVar VarName IntValue
  54. IntOp $${VarName} 0 + ${IntValue}
  55. !macroend
  56. !macro InitSection SecName
  57. ; This macro reads component installed flag from the registry and
  58. ;changes checked state of the section on the components page.
  59. ;Input: section index constant name specified in Section command.
  60. ClearErrors
  61. ;Reading component status from registry
  62. ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
  63. IfErrors "default_${SecName}"
  64. ;Status will stay default if registry value not found
  65. ;(component was never installed)
  66. IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
  67. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
  68. IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
  69. IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
  70. ; Note whether this component was installed before
  71. !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
  72. IntOp $R0 $AR_RegFlags & $AR_RegFlags
  73. ;Writing modified flags
  74. SectionSetFlags ${${SecName}} $AR_SecFlags
  75. "default_${SecName}:"
  76. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  77. !macroend
  78. !macro FinishSection SecName
  79. ; This macro reads section flag set by user and removes the section
  80. ;if it is not selected.
  81. ;Then it writes component installed flag to registry
  82. ;Input: section index constant name specified in Section command.
  83. SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
  84. ;Checking lowest bit:
  85. IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
  86. IntCmp $AR_SecFlags 1 "leave_${SecName}"
  87. ;Section is not selected:
  88. ;Calling Section uninstall macro and writing zero installed flag
  89. !insertmacro "Remove_${${SecName}}"
  90. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  91. "Installed" 0
  92. Goto "exit_${SecName}"
  93. "leave_${SecName}:"
  94. ;Section is selected:
  95. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
  96. "Installed" 1
  97. "exit_${SecName}:"
  98. !macroend
  99. !macro RemoveSection_CPack SecName
  100. ; This macro is used to call section's Remove_... macro
  101. ;from the uninstaller.
  102. ;Input: section index constant name specified in Section command.
  103. !insertmacro "Remove_${${SecName}}"
  104. !macroend
  105. ; Determine whether the selection of SecName changed
  106. !macro MaybeSelectionChanged SecName
  107. !insertmacro LoadVar ${SecName}_selected
  108. SectionGetFlags ${${SecName}} $R1
  109. IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
  110. ; See if the status has changed:
  111. IntCmp $R0 $R1 "${SecName}_unchanged"
  112. !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
  113. IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
  114. !insertmacro "Deselect_required_by_${SecName}"
  115. goto "${SecName}_unchanged"
  116. "${SecName}_was_selected:"
  117. !insertmacro "Select_${SecName}_depends"
  118. "${SecName}_unchanged:"
  119. !macroend
  120. ;--- End of Add/Remove macros ---
  121. ;--------------------------------
  122. ;Interface Settings
  123. !define MUI_HEADERIMAGE
  124. !define MUI_ABORTWARNING
  125. ;--------------------------------
  126. ; path functions
  127. !verbose 3
  128. !include "WinMessages.NSH"
  129. !verbose 4
  130. ;----------------------------------------
  131. ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
  132. ;----------------------------------------
  133. !verbose 3
  134. !include "WinMessages.NSH"
  135. !verbose 4
  136. ;====================================================
  137. ; get_NT_environment
  138. ; Returns: the selected environment
  139. ; Output : head of the stack
  140. ;====================================================
  141. !macro select_NT_profile UN
  142. Function ${UN}select_NT_profile
  143. StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
  144. DetailPrint "Selected environment for all users"
  145. Push "all"
  146. Return
  147. environment_single:
  148. DetailPrint "Selected environment for current user only."
  149. Push "current"
  150. Return
  151. FunctionEnd
  152. !macroend
  153. !insertmacro select_NT_profile ""
  154. !insertmacro select_NT_profile "un."
  155. ;----------------------------------------------------
  156. !define NT_current_env 'HKCU "Environment"'
  157. !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  158. !ifndef WriteEnvStr_RegKey
  159. !ifdef ALL_USERS
  160. !define WriteEnvStr_RegKey \
  161. 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
  162. !else
  163. !define WriteEnvStr_RegKey 'HKCU "Environment"'
  164. !endif
  165. !endif
  166. ; AddToPath - Adds the given dir to the search path.
  167. ; Input - head of the stack
  168. ; Note - Win9x systems requires reboot
  169. Function AddToPath
  170. Exch $0
  171. Push $1
  172. Push $2
  173. Push $3
  174. # don't add if the path doesn't exist
  175. IfFileExists "$0\*.*" "" AddToPath_done
  176. ReadEnvStr $1 PATH
  177. ; if the path is too long for a NSIS variable NSIS will return a 0
  178. ; length string. If we find that, then warn and skip any path
  179. ; modification as it will trash the existing path.
  180. StrLen $2 $1
  181. IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
  182. CheckPathLength_ShowPathWarning:
  183. Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
  184. Goto AddToPath_done
  185. CheckPathLength_Done:
  186. Push "$1;"
  187. Push "$0;"
  188. Call StrStr
  189. Pop $2
  190. StrCmp $2 "" "" AddToPath_done
  191. Push "$1;"
  192. Push "$0\;"
  193. Call StrStr
  194. Pop $2
  195. StrCmp $2 "" "" AddToPath_done
  196. GetFullPathName /SHORT $3 $0
  197. Push "$1;"
  198. Push "$3;"
  199. Call StrStr
  200. Pop $2
  201. StrCmp $2 "" "" AddToPath_done
  202. Push "$1;"
  203. Push "$3\;"
  204. Call StrStr
  205. Pop $2
  206. StrCmp $2 "" "" AddToPath_done
  207. Call IsNT
  208. Pop $1
  209. StrCmp $1 1 AddToPath_NT
  210. ; Not on NT
  211. StrCpy $1 $WINDIR 2
  212. FileOpen $1 "$1\autoexec.bat" a
  213. FileSeek $1 -1 END
  214. FileReadByte $1 $2
  215. IntCmp $2 26 0 +2 +2 # DOS EOF
  216. FileSeek $1 -1 END # write over EOF
  217. FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
  218. FileClose $1
  219. SetRebootFlag true
  220. Goto AddToPath_done
  221. AddToPath_NT:
  222. StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
  223. ReadRegStr $1 ${NT_current_env} "PATH"
  224. Goto DoTrim
  225. ReadAllKey:
  226. ReadRegStr $1 ${NT_all_env} "PATH"
  227. DoTrim:
  228. StrCmp $1 "" AddToPath_NTdoIt
  229. Push $1
  230. Call Trim
  231. Pop $1
  232. StrCpy $0 "$1;$0"
  233. AddToPath_NTdoIt:
  234. StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
  235. WriteRegExpandStr ${NT_current_env} "PATH" $0
  236. Goto DoSend
  237. WriteAllKey:
  238. WriteRegExpandStr ${NT_all_env} "PATH" $0
  239. DoSend:
  240. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  241. AddToPath_done:
  242. Pop $3
  243. Pop $2
  244. Pop $1
  245. Pop $0
  246. FunctionEnd
  247. ; RemoveFromPath - Remove a given dir from the path
  248. ; Input: head of the stack
  249. Function un.RemoveFromPath
  250. Exch $0
  251. Push $1
  252. Push $2
  253. Push $3
  254. Push $4
  255. Push $5
  256. Push $6
  257. IntFmt $6 "%c" 26 # DOS EOF
  258. Call un.IsNT
  259. Pop $1
  260. StrCmp $1 1 unRemoveFromPath_NT
  261. ; Not on NT
  262. StrCpy $1 $WINDIR 2
  263. FileOpen $1 "$1\autoexec.bat" r
  264. GetTempFileName $4
  265. FileOpen $2 $4 w
  266. GetFullPathName /SHORT $0 $0
  267. StrCpy $0 "SET PATH=%PATH%;$0"
  268. Goto unRemoveFromPath_dosLoop
  269. unRemoveFromPath_dosLoop:
  270. FileRead $1 $3
  271. StrCpy $5 $3 1 -1 # read last char
  272. StrCmp $5 $6 0 +2 # if DOS EOF
  273. StrCpy $3 $3 -1 # remove DOS EOF so we can compare
  274. StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
  275. StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
  276. StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
  277. StrCmp $3 "" unRemoveFromPath_dosLoopEnd
  278. FileWrite $2 $3
  279. Goto unRemoveFromPath_dosLoop
  280. unRemoveFromPath_dosLoopRemoveLine:
  281. SetRebootFlag true
  282. Goto unRemoveFromPath_dosLoop
  283. unRemoveFromPath_dosLoopEnd:
  284. FileClose $2
  285. FileClose $1
  286. StrCpy $1 $WINDIR 2
  287. Delete "$1\autoexec.bat"
  288. CopyFiles /SILENT $4 "$1\autoexec.bat"
  289. Delete $4
  290. Goto unRemoveFromPath_done
  291. unRemoveFromPath_NT:
  292. StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
  293. ReadRegStr $1 ${NT_current_env} "PATH"
  294. Goto unDoTrim
  295. unReadAllKey:
  296. ReadRegStr $1 ${NT_all_env} "PATH"
  297. unDoTrim:
  298. StrCpy $5 $1 1 -1 # copy last char
  299. StrCmp $5 ";" +2 # if last char != ;
  300. StrCpy $1 "$1;" # append ;
  301. Push $1
  302. Push "$0;"
  303. Call un.StrStr ; Find `$0;` in $1
  304. Pop $2 ; pos of our dir
  305. StrCmp $2 "" unRemoveFromPath_done
  306. ; else, it is in path
  307. # $0 - path to add
  308. # $1 - path var
  309. StrLen $3 "$0;"
  310. StrLen $4 $2
  311. StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
  312. StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
  313. StrCpy $3 $5$6
  314. StrCpy $5 $3 1 -1 # copy last char
  315. StrCmp $5 ";" 0 +2 # if last char == ;
  316. StrCpy $3 $3 -1 # remove last char
  317. StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
  318. WriteRegExpandStr ${NT_current_env} "PATH" $3
  319. Goto unDoSend
  320. unWriteAllKey:
  321. WriteRegExpandStr ${NT_all_env} "PATH" $3
  322. unDoSend:
  323. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  324. unRemoveFromPath_done:
  325. Pop $6
  326. Pop $5
  327. Pop $4
  328. Pop $3
  329. Pop $2
  330. Pop $1
  331. Pop $0
  332. FunctionEnd
  333. ; ReplaceEnvVar - Adds the given value to the given environment var
  334. ; Input - head of the stack: value to add ($1)
  335. ; 2nd on stack: environement variable ($0)
  336. Function ReplaceEnvVar
  337. Exch $1 ; $1 has environment variable value
  338. Exch
  339. Exch $0 ; $0 has environment variable name
  340. Push $2
  341. StrCmp $0 "" ReplaceEnvVar_done ; empty variable name
  342. DetailPrint "Replacing environment variable $0 with $1"
  343. Call IsNT
  344. Pop $2
  345. StrCmp $2 0 ReplaceEnvVar_done ; 0 = not NT
  346. ;ReplaceEnvVar_NT:
  347. StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
  348. WriteRegExpandStr ${NT_current_env} $0 $1
  349. Goto unDoSend
  350. unWriteAllKey:
  351. WriteRegExpandStr ${NT_all_env} $0 $1
  352. unDoSend:
  353. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  354. ReplaceEnvVar_done:
  355. Pop $2
  356. Pop $0
  357. Pop $1
  358. FunctionEnd
  359. ; RemoveEnvVar - Adds the given value to the given environment var
  360. ; Input - head of the stack: environement variable to remove ($0)
  361. Function un.RemoveEnvVar
  362. Exch $0 ; $0 has environment variable name
  363. Push $1
  364. StrCmp $0 "" RemoveEnvVar_done ; empty variable name
  365. DetailPrint "Removing environment variable $0"
  366. Call un.IsNT
  367. Pop $1
  368. StrCmp $1 0 RemoveEnvVar_done ; 0 = not NT
  369. ;ReplaceEnvVar_NT:
  370. StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
  371. DeleteRegValue ${NT_current_env} $0
  372. Goto unDoSend
  373. unWriteAllKey:
  374. DeleteRegValue ${NT_all_env} $0
  375. unDoSend:
  376. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  377. RemoveEnvVar_done:
  378. Pop $1
  379. Pop $0
  380. FunctionEnd
  381. ; AddToEnvVar - Adds the given value to the given environment var
  382. ; Input - head of the stack $0 environement variable $1=value to add
  383. ; Note - Win9x systems requires reboot
  384. Function AddToEnvVar
  385. Exch $1 ; $1 has environment variable value
  386. Exch
  387. Exch $0 ; $0 has environment variable name
  388. Push $2
  389. Push $3
  390. Push $4
  391. ReadEnvStr $2 $0
  392. Push "$2;"
  393. Push "$1;"
  394. Call StrStr
  395. Pop $3
  396. StrCmp $3 "" "" AddToEnvVar_done
  397. Push "$2;"
  398. Push "$1\;"
  399. Call StrStr
  400. Pop $3
  401. StrCmp $3 "" "" AddToEnvVar_done
  402. DetailPrint "Adding $1 to environment variable $0"
  403. Call IsNT
  404. Pop $2
  405. StrCmp $2 1 AddToEnvVar_NT
  406. ; Not on NT
  407. StrCpy $2 $WINDIR 2
  408. FileOpen $2 "$2\autoexec.bat" a
  409. FileSeek $2 -1 END
  410. FileReadByte $2 $3
  411. IntCmp $3 26 0 +2 +2 # DOS EOF
  412. FileSeek $2 -1 END # write over EOF
  413. FileWrite $2 "$\r$\nSET $0=%$0%;$4$\r$\n"
  414. FileClose $2
  415. SetRebootFlag true
  416. Goto AddToEnvVar_done
  417. AddToEnvVar_NT:
  418. ReadRegStr $2 ${WriteEnvStr_RegKey} $0
  419. StrCpy $3 $2 1 -1 # copy last char
  420. StrCmp $3 ";" 0 +2 # if last char == ;
  421. StrCpy $2 $2 -1 # remove last char
  422. StrCmp $2 "" AddToEnvVar_NTdoIt
  423. StrCpy $1 "$2;$1"
  424. AddToEnvVar_NTdoIt:
  425. WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
  426. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  427. AddToEnvVar_done:
  428. Pop $4
  429. Pop $3
  430. Pop $2
  431. Pop $0
  432. Pop $1
  433. FunctionEnd
  434. ; RemoveFromEnvVar - Remove a given value from a environment var
  435. ; Input: head of the stack
  436. Function un.RemoveFromEnvVar
  437. Exch $1 ; $1 has environment variable value
  438. Exch
  439. Exch $0 ; $0 has environment variable name
  440. Push $2
  441. Push $3
  442. Push $4
  443. Push $5
  444. Push $6
  445. Push $7
  446. StrCmp $0 "" unRemoveFromEnvVar_done ; empty variable name
  447. DetailPrint "Removing $1 from environment variable $0"
  448. IntFmt $7 "%c" 26 # DOS EOF
  449. Call un.IsNT
  450. Pop $2
  451. StrCmp $2 1 unRemoveFromEnvVar_NT
  452. ; Not on NT
  453. StrCpy $2 $WINDIR 2
  454. FileOpen $2 "$2\autoexec.bat" r
  455. GetTempFileName $5
  456. FileOpen $3 $5 w
  457. GetFullPathName /SHORT $1 $1
  458. StrCpy $1 "SET $0=%$0%;$1"
  459. Goto unRemoveFromEnvVar_dosLoop
  460. unRemoveFromEnvVar_dosLoop:
  461. FileRead $2 $4
  462. StrCpy $6 $4 1 -1 # read last char
  463. StrCmp $6 $7 0 +2 # if DOS EOF
  464. StrCpy $4 $4 -1 # remove DOS EOF so we can compare
  465. StrCmp $4 "$1$\r$\n" unRemoveFromEnvVar_dosLoopRemoveLine
  466. StrCmp $4 "$1$\n" unRemoveFromEnvVar_dosLoopRemoveLine
  467. StrCmp $4 "$1" unRemoveFromEnvVar_dosLoopRemoveLine
  468. StrCmp $4 "" unRemoveFromEnvVar_dosLoopEnd
  469. FileWrite $3 $4
  470. Goto unRemoveFromEnvVar_dosLoop
  471. unRemoveFromEnvVar_dosLoopRemoveLine:
  472. SetRebootFlag true
  473. Goto unRemoveFromEnvVar_dosLoop
  474. unRemoveFromEnvVar_dosLoopEnd:
  475. FileClose $3
  476. FileClose $2
  477. StrCpy $2 $WINDIR 2
  478. Delete "$2\autoexec.bat"
  479. CopyFiles /SILENT $5 "$2\autoexec.bat"
  480. Delete $5
  481. Goto unRemoveFromEnvVar_done
  482. unRemoveFromEnvVar_NT:
  483. ReadRegStr $2 ${WriteEnvStr_RegKey} $0
  484. StrCpy $6 $2 1 -1 # copy last char
  485. StrCmp $6 ";" +2 # if last char != ;
  486. StrCpy $2 "$2;" # append ;
  487. Push $2
  488. Push "$1;"
  489. Call un.StrStr ; Find `$1;` in $2
  490. Pop $3 ; pos of our dir
  491. StrCmp $3 "" unRemoveFromEnvVar_done
  492. ; else, it is in path
  493. # $1 - path to add
  494. # $2 - path var
  495. StrLen $4 "$1;"
  496. StrLen $5 $3
  497. StrCpy $6 $2 -$5 # $6 is now the part before the path to remove
  498. StrCpy $7 $3 "" $4 # $7 is now the part after the path to remove
  499. StrCpy $4 $6$7
  500. StrCpy $6 $4 1 -1 # copy last char
  501. StrCmp $6 ";" 0 +2 # if last char == ;
  502. StrCpy $4 $4 -1 # remove last char
  503. WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $4
  504. ; delete reg value if null
  505. StrCmp $4 "" 0 +2 # if null delete reg
  506. DeleteRegValue ${WriteEnvStr_RegKey} $0
  507. SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
  508. unRemoveFromEnvVar_done:
  509. Pop $7
  510. Pop $6
  511. Pop $5
  512. Pop $4
  513. Pop $3
  514. Pop $2
  515. Pop $1
  516. Pop $0
  517. FunctionEnd
  518. ###########################################
  519. # Utility Functions #
  520. ###########################################
  521. ;====================================================
  522. ; IsNT - Returns 1 if the current system is NT, 0
  523. ; otherwise.
  524. ; Output: head of the stack
  525. ;====================================================
  526. ; IsNT
  527. ; no input
  528. ; output, top of the stack = 1 if NT or 0 if not
  529. ;
  530. ; Usage:
  531. ; Call IsNT
  532. ; Pop $R0
  533. ; ($R0 at this point is 1 or 0)
  534. !macro IsNT un
  535. Function ${un}IsNT
  536. Push $0
  537. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  538. StrCmp $0 "" 0 IsNT_yes
  539. ; we are not NT.
  540. Pop $0
  541. Push 0
  542. Return
  543. IsNT_yes:
  544. ; NT!!!
  545. Pop $0
  546. Push 1
  547. FunctionEnd
  548. !macroend
  549. !insertmacro IsNT ""
  550. !insertmacro IsNT "un."
  551. ; StrStr
  552. ; input, top of stack = string to search for
  553. ; top of stack-1 = string to search in
  554. ; output, top of stack (replaces with the portion of the string remaining)
  555. ; modifies no other variables.
  556. ;
  557. ; Usage:
  558. ; Push "this is a long ass string"
  559. ; Push "ass"
  560. ; Call StrStr
  561. ; Pop $R0
  562. ; ($R0 at this point is "ass string")
  563. !macro StrStr un
  564. Function ${un}StrStr
  565. Exch $R1 ; st=haystack,old$R1, $R1=needle
  566. Exch ; st=old$R1,haystack
  567. Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  568. Push $R3
  569. Push $R4
  570. Push $R5
  571. StrLen $R3 $R1
  572. StrCpy $R4 0
  573. ; $R1=needle
  574. ; $R2=haystack
  575. ; $R3=len(needle)
  576. ; $R4=cnt
  577. ; $R5=tmp
  578. loop:
  579. StrCpy $R5 $R2 $R3 $R4
  580. StrCmp $R5 $R1 done
  581. StrCmp $R5 "" done
  582. IntOp $R4 $R4 + 1
  583. Goto loop
  584. done:
  585. StrCpy $R1 $R2 "" $R4
  586. Pop $R5
  587. Pop $R4
  588. Pop $R3
  589. Pop $R2
  590. Exch $R1
  591. FunctionEnd
  592. !macroend
  593. !insertmacro StrStr ""
  594. !insertmacro StrStr "un."
  595. Function Trim ; Added by Pelaca
  596. Exch $R1
  597. Push $R2
  598. Loop:
  599. StrCpy $R2 "$R1" 1 -1
  600. StrCmp "$R2" " " RTrim
  601. StrCmp "$R2" "$\n" RTrim
  602. StrCmp "$R2" "$\r" RTrim
  603. StrCmp "$R2" ";" RTrim
  604. GoTo Done
  605. RTrim:
  606. StrCpy $R1 "$R1" -1
  607. Goto Loop
  608. Done:
  609. Pop $R2
  610. Exch $R1
  611. FunctionEnd
  612. Function ConditionalAddToRegisty
  613. Pop $0
  614. Pop $1
  615. StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
  616. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
  617. "$1" "$0"
  618. ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
  619. DetailPrint "Set install registry entry: '$1' to '$0'"
  620. ConditionalAddToRegisty_EmptyString:
  621. FunctionEnd
  622. ;--------------------------------
  623. !ifdef CPACK_USES_DOWNLOAD
  624. Function DownloadFile
  625. IfFileExists $INSTDIR\* +2
  626. CreateDirectory $INSTDIR
  627. Pop $0
  628. ; Skip if already downloaded
  629. IfFileExists $INSTDIR\$0 0 +2
  630. Return
  631. StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
  632. try_again:
  633. NSISdl::download "$1/$0" "$INSTDIR\$0"
  634. Pop $1
  635. StrCmp $1 "success" success
  636. StrCmp $1 "Cancelled" cancel
  637. MessageBox MB_OK "Download failed: $1"
  638. cancel:
  639. Return
  640. success:
  641. FunctionEnd
  642. !endif
  643. ;--------------------------------
  644. ; Installation types
  645. @CPACK_NSIS_INSTALLATION_TYPES@
  646. ;--------------------------------
  647. ; Component sections
  648. @CPACK_NSIS_COMPONENT_SECTIONS@
  649. ;--------------------------------
  650. ; Define some macro setting for the gui
  651. @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
  652. @CPACK_NSIS_INSTALLER_ICON_CODE@
  653. @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
  654. @CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
  655. ;--------------------------------
  656. ;Pages
  657. !insertmacro MUI_PAGE_WELCOME
  658. !if "X@CPACK_RESOURCE_FILE_LICENSE@" != "X" ; if not empty
  659. !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
  660. !endif
  661. Page custom InstallOptionsPage
  662. !insertmacro MUI_PAGE_DIRECTORY
  663. ;Start Menu Folder Page Configuration
  664. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
  665. !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  666. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
  667. !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
  668. @CPACK_NSIS_PAGE_COMPONENTS@
  669. !insertmacro MUI_PAGE_INSTFILES
  670. ; keep the InstFiles page from automatically progressing to the Finish page
  671. !define MUI_FINISHPAGE_NOAUTOCLOSE
  672. !insertmacro MUI_PAGE_FINISH
  673. !insertmacro MUI_UNPAGE_CONFIRM
  674. !insertmacro MUI_UNPAGE_INSTFILES
  675. ;--------------------------------
  676. ;Languages
  677. !insertmacro MUI_LANGUAGE "English" ;first language is the default language
  678. !insertmacro MUI_LANGUAGE "Albanian"
  679. !insertmacro MUI_LANGUAGE "Arabic"
  680. !insertmacro MUI_LANGUAGE "Basque"
  681. !insertmacro MUI_LANGUAGE "Belarusian"
  682. !insertmacro MUI_LANGUAGE "Bosnian"
  683. !insertmacro MUI_LANGUAGE "Breton"
  684. !insertmacro MUI_LANGUAGE "Bulgarian"
  685. !insertmacro MUI_LANGUAGE "Croatian"
  686. !insertmacro MUI_LANGUAGE "Czech"
  687. !insertmacro MUI_LANGUAGE "Danish"
  688. !insertmacro MUI_LANGUAGE "Dutch"
  689. !insertmacro MUI_LANGUAGE "Estonian"
  690. !insertmacro MUI_LANGUAGE "Farsi"
  691. !insertmacro MUI_LANGUAGE "Finnish"
  692. !insertmacro MUI_LANGUAGE "French"
  693. !insertmacro MUI_LANGUAGE "German"
  694. !insertmacro MUI_LANGUAGE "Greek"
  695. !insertmacro MUI_LANGUAGE "Hebrew"
  696. !insertmacro MUI_LANGUAGE "Hungarian"
  697. !insertmacro MUI_LANGUAGE "Icelandic"
  698. !insertmacro MUI_LANGUAGE "Indonesian"
  699. !insertmacro MUI_LANGUAGE "Irish"
  700. !insertmacro MUI_LANGUAGE "Italian"
  701. !insertmacro MUI_LANGUAGE "Japanese"
  702. !insertmacro MUI_LANGUAGE "Korean"
  703. !insertmacro MUI_LANGUAGE "Kurdish"
  704. !insertmacro MUI_LANGUAGE "Latvian"
  705. !insertmacro MUI_LANGUAGE "Lithuanian"
  706. !insertmacro MUI_LANGUAGE "Luxembourgish"
  707. !insertmacro MUI_LANGUAGE "Macedonian"
  708. !insertmacro MUI_LANGUAGE "Malay"
  709. !insertmacro MUI_LANGUAGE "Mongolian"
  710. !insertmacro MUI_LANGUAGE "Norwegian"
  711. !insertmacro MUI_LANGUAGE "Polish"
  712. !insertmacro MUI_LANGUAGE "Portuguese"
  713. !insertmacro MUI_LANGUAGE "PortugueseBR"
  714. !insertmacro MUI_LANGUAGE "Romanian"
  715. !insertmacro MUI_LANGUAGE "Russian"
  716. !insertmacro MUI_LANGUAGE "Serbian"
  717. !insertmacro MUI_LANGUAGE "SerbianLatin"
  718. !insertmacro MUI_LANGUAGE "SimpChinese"
  719. !insertmacro MUI_LANGUAGE "Slovak"
  720. !insertmacro MUI_LANGUAGE "Slovenian"
  721. !insertmacro MUI_LANGUAGE "Spanish"
  722. !insertmacro MUI_LANGUAGE "Swedish"
  723. !insertmacro MUI_LANGUAGE "Thai"
  724. !insertmacro MUI_LANGUAGE "TradChinese"
  725. !insertmacro MUI_LANGUAGE "Turkish"
  726. !insertmacro MUI_LANGUAGE "Ukrainian"
  727. !insertmacro MUI_LANGUAGE "Welsh"
  728. ;--------------------------------
  729. ;Reserve Files
  730. ;These files should be inserted before other files in the data block
  731. ;Keep these lines before any File command
  732. ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
  733. ReserveFile "NSIS.InstallOptions.ini"
  734. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  735. ;--------------------------------
  736. ;Installer Sections
  737. Section "-Core installation"
  738. ;Use the entire tree produced by the INSTALL target. Keep the
  739. ;list of directories here in sync with the RMDir commands below.
  740. SetOutPath "$INSTDIR"
  741. @CPACK_NSIS_FULL_INSTALL@
  742. ;Store installation folder
  743. WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
  744. ;Create uninstaller
  745. WriteUninstaller "$INSTDIR\Uninstall.exe"
  746. Push "DisplayName"
  747. Push "@CPACK_NSIS_DISPLAY_NAME@"
  748. Call ConditionalAddToRegisty
  749. Push "DisplayVersion"
  750. Push "@CPACK_PACKAGE_VERSION@"
  751. Call ConditionalAddToRegisty
  752. Push "Publisher"
  753. Push "@CPACK_PACKAGE_VENDOR@"
  754. Call ConditionalAddToRegisty
  755. Push "UninstallString"
  756. Push "$INSTDIR\Uninstall.exe"
  757. Call ConditionalAddToRegisty
  758. Push "NoRepair"
  759. Push "1"
  760. Call ConditionalAddToRegisty
  761. !ifdef CPACK_NSIS_ADD_REMOVE
  762. ;Create add/remove functionality
  763. Push "ModifyPath"
  764. Push "$INSTDIR\AddRemove.exe"
  765. Call ConditionalAddToRegisty
  766. !else
  767. Push "NoModify"
  768. Push "1"
  769. Call ConditionalAddToRegisty
  770. !endif
  771. ; Optional registration
  772. Push "DisplayIcon"
  773. Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
  774. Call ConditionalAddToRegisty
  775. Push "HelpLink"
  776. Push "@CPACK_NSIS_HELP_LINK@"
  777. Call ConditionalAddToRegisty
  778. Push "URLInfoAbout"
  779. Push "@CPACK_NSIS_URL_INFO_ABOUT@"
  780. Call ConditionalAddToRegisty
  781. Push "Contact"
  782. Push "@CPACK_NSIS_CONTACT@"
  783. Call ConditionalAddToRegisty
  784. !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
  785. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  786. ;Create shortcuts
  787. CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
  788. @CPACK_NSIS_CREATE_ICONS@
  789. @CPACK_NSIS_CREATE_ICONS_EXTRA@
  790. CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
  791. ;Read a value from an InstallOptions INI file
  792. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 2" "State"
  793. !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 3" "State"
  794. !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 4" "State"
  795. ; Write special uninstall registry entries
  796. Push "StartMenu"
  797. Push "$STARTMENU_FOLDER"
  798. Call ConditionalAddToRegisty
  799. Push "DoNotAddToPath"
  800. Push "$DO_NOT_ADD_TO_PATH"
  801. Call ConditionalAddToRegisty
  802. Push "AddToPathAllUsers"
  803. Push "$ADD_TO_PATH_ALL_USERS"
  804. Call ConditionalAddToRegisty
  805. Push "AddToPathCurrentUser"
  806. Push "$ADD_TO_PATH_CURRENT_USER"
  807. Call ConditionalAddToRegisty
  808. Push "InstallToDesktop"
  809. Push "$INSTALL_DESKTOP"
  810. Call ConditionalAddToRegisty
  811. !insertmacro MUI_STARTMENU_WRITE_END
  812. @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
  813. SectionEnd
  814. Section "-Add to path"
  815. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
  816. StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
  817. Push "$INSTDIR\bin"
  818. Call AddToPath
  819. Push "@CPACK_NSIS_ADD_ENVVAR1@"
  820. Push "@CPACK_NSIS_ADD_ENVVAL1@"
  821. Call ReplaceEnvVar
  822. Push "@CPACK_NSIS_ADD_ENVVAR2@"
  823. Push "@CPACK_NSIS_ADD_ENVVAL2@"
  824. Call AddToEnvVar
  825. Push "@CPACK_NSIS_ADD_ENVVAR3@"
  826. Push "@CPACK_NSIS_ADD_ENVVAL3@"
  827. Call AddToEnvVar
  828. doNotAddToPath:
  829. SectionEnd
  830. ;--------------------------------
  831. ; Create custom pages
  832. Function InstallOptionsPage
  833. !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
  834. !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
  835. FunctionEnd
  836. ;--------------------------------
  837. ; determine admin versus local install
  838. Function un.onInit
  839. ClearErrors
  840. UserInfo::GetName
  841. IfErrors noLM
  842. Pop $0
  843. UserInfo::GetAccountType
  844. Pop $1
  845. StrCmp $1 "Admin" 0 +3
  846. SetShellVarContext all
  847. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  848. Goto done
  849. StrCmp $1 "Power" 0 +3
  850. SetShellVarContext all
  851. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  852. Goto done
  853. noLM:
  854. ;Get installation folder from registry if available
  855. done:
  856. FunctionEnd
  857. ;--- Add/Remove callback functions: ---
  858. !macro SectionList MacroName
  859. ;This macro used to perform operation on multiple sections.
  860. ;List all of your components in following manner here.
  861. @CPACK_NSIS_COMPONENT_SECTION_LIST@
  862. !macroend
  863. Section -FinishComponents
  864. ;Removes unselected components and writes component status to registry
  865. !insertmacro SectionList "FinishSection"
  866. !ifdef CPACK_NSIS_ADD_REMOVE
  867. ; Get the name of the installer executable
  868. System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
  869. StrCpy $R3 $R0
  870. ; Strip off the last 13 characters, to see if we have AddRemove.exe
  871. StrLen $R1 $R0
  872. IntOp $R1 $R0 - 13
  873. StrCpy $R2 $R0 13 $R1
  874. StrCmp $R2 "AddRemove.exe" addremove_installed
  875. ; We're not running AddRemove.exe, so install it
  876. CopyFiles $R3 $INSTDIR\AddRemove.exe
  877. addremove_installed:
  878. !endif
  879. SectionEnd
  880. ;--- End of Add/Remove callback functions ---
  881. ;--------------------------------
  882. ; Component dependencies
  883. Function .onSelChange
  884. !insertmacro SectionList MaybeSelectionChanged
  885. FunctionEnd
  886. ;--------------------------------
  887. ;Uninstaller Section
  888. Section "Uninstall"
  889. ReadRegStr $START_MENU SHCTX \
  890. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
  891. ;MessageBox MB_OK "Start menu is in: $START_MENU"
  892. ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
  893. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
  894. ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
  895. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
  896. ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
  897. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
  898. ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
  899. ReadRegStr $INSTALL_DESKTOP SHCTX \
  900. "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
  901. ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
  902. @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
  903. ;Remove files we installed.
  904. ;Keep the list of directories here in sync with the File commands above.
  905. @CPACK_NSIS_DELETE_FILES@
  906. @CPACK_NSIS_DELETE_DIRECTORIES@
  907. !ifdef CPACK_NSIS_ADD_REMOVE
  908. ;Remove the add/remove program
  909. Delete "$INSTDIR\AddRemove.exe"
  910. !endif
  911. ;Remove the uninstaller itself.
  912. Delete "$INSTDIR\Uninstall.exe"
  913. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  914. ;Remove the installation directory if it is empty.
  915. RMDir "$INSTDIR"
  916. ; Remove the registry entries.
  917. DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  918. ; Removes all optional components
  919. !insertmacro SectionList "RemoveSection_CPack"
  920. !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
  921. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  922. @CPACK_NSIS_DELETE_ICONS@
  923. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  924. ;Delete empty start menu parent diretories
  925. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  926. startMenuDeleteLoop:
  927. ClearErrors
  928. RMDir $MUI_TEMP
  929. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  930. IfErrors startMenuDeleteLoopDone
  931. StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
  932. startMenuDeleteLoopDone:
  933. ; If the user changed the shortcut, then untinstall may not work. This should
  934. ; try to fix it.
  935. StrCpy $MUI_TEMP "$START_MENU"
  936. Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
  937. @CPACK_NSIS_DELETE_ICONS_EXTRA@
  938. ;Delete empty start menu parent diretories
  939. StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
  940. secondStartMenuDeleteLoop:
  941. ClearErrors
  942. RMDir $MUI_TEMP
  943. GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
  944. IfErrors secondStartMenuDeleteLoopDone
  945. StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
  946. secondStartMenuDeleteLoopDone:
  947. DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
  948. Push "$INSTDIR\bin"
  949. StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
  950. Push "$INSTDIR\bin"
  951. Call un.RemoveFromPath
  952. Push "@CPACK_NSIS_ADD_ENVVAR1@"
  953. Call un.RemoveEnvVar
  954. Push "@CPACK_NSIS_ADD_ENVVAR2@"
  955. Push "@CPACK_NSIS_ADD_ENVVAL2@"
  956. Call un.RemoveFromEnvVar
  957. Push "@CPACK_NSIS_ADD_ENVVAR3@"
  958. Push "@CPACK_NSIS_ADD_ENVVAL3@"
  959. Call un.RemoveFromEnvVar
  960. doNotRemoveFromPath:
  961. SectionEnd
  962. ;--------------------------------
  963. ; determine admin versus local install
  964. ; Is install for "AllUsers" or "JustMe"?
  965. ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
  966. ; This function is used for the very first "custom page" of the installer.
  967. ; This custom page does not show up visibly, but it executes prior to the
  968. ; first visible page and sets up $INSTDIR properly...
  969. ; Choose different default installation folder based on SV_ALLUSERS...
  970. ; "Program Files" for AllUsers, "My Documents" for JustMe...
  971. Function .onInit
  972. ; Reads components status for registry
  973. !insertmacro SectionList "InitSection"
  974. ; check to see if /D has been used to change
  975. ; the install directory by comparing it to the
  976. ; install directory that is expected to be the
  977. ; default
  978. StrCpy $IS_DEFAULT_INSTALLDIR 0
  979. StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
  980. StrCpy $IS_DEFAULT_INSTALLDIR 1
  981. StrCpy $SV_ALLUSERS "JustMe"
  982. ; if default install dir then change the default
  983. ; if it is installed for JustMe
  984. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  985. StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  986. ClearErrors
  987. UserInfo::GetName
  988. IfErrors noLM
  989. Pop $0
  990. UserInfo::GetAccountType
  991. Pop $1
  992. StrCmp $1 "Admin" 0 +3
  993. SetShellVarContext all
  994. ;MessageBox MB_OK 'User "$0" is in the Admin group'
  995. StrCpy $SV_ALLUSERS "AllUsers"
  996. Goto done
  997. StrCmp $1 "Power" 0 +3
  998. SetShellVarContext all
  999. ;MessageBox MB_OK 'User "$0" is in the Power Users group'
  1000. StrCpy $SV_ALLUSERS "AllUsers"
  1001. Goto done
  1002. noLM:
  1003. StrCpy $SV_ALLUSERS "AllUsers"
  1004. ;Get installation folder from registry if available
  1005. done:
  1006. StrCmp $SV_ALLUSERS "AllUsers" 0 +3
  1007. StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
  1008. StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
  1009. StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
  1010. !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
  1011. noOptionsPage:
  1012. FunctionEnd
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...