1/*-----------------------------------------------------------------------------------------------------
2NSIS Installer script for OpenCPN (Windows)
3NSIS version 2.46
4Written by Gunther Pilz (Netsurfer) netsurfer@opencpn.de
5-------------------------------------------------------------------------------------------------------
6CMake variables
7	CPACK_PACKAGE_NAME "OpenCPN"
8	CPACK_NSIS_PACKAGE_NAME_LC "opencpn"
9	CPACK_PACKAGE_VENDOR "opencpn.org"
10	CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}
11	CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}
12	CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}
13	CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}
14	CPACK_NSIS_INSTALLED_ICON_NAME "opencpn.exe"
15	CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/src/bitmaps\\\\opencpn.ico"
16	CPACK_NSIS_EXTRA_INSTALL_COMMANDS ${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
17	CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/data/license.txt"
18	CPACK_BUILDWIN_DIR "${PROJECT_SOURCE_DIR}/buildwin"
19	CPACK_NSIS_DIR "${PROJECT_SOURCE_DIR}/buildwin/NSIS_Unicode")
20
21	#CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_CURRENT_BINARY_DIR};${PACKAGE_NAME};ALL;/"
22	#CPACK_PACKAGE_EXECUTABLES ${PACKAGE_NAME} "OpenCPN"
23	#CPACK_PACKAGE_INSTALL_DIRECTORY ${PACKAGE_NAME} "OpenCPN"
24	#CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenCPN ${PACKAGE_VERSION}"
25	#CPACK_NSIS_LINK_NAME "${CPACK_PACKAGE_NAME} ${PACKAGE_VERSION}"
26	#CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME} Version ${PACKAGE_VERSION}"
27	#CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.opencpn.org"
28	#CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.opencpn.org"
29	#CPACK_NSIS_CONTACT "http:\\\\\\\\www.opencpn.org"
30	#CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}_${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_setup"
31
32----------------------------------------------------------------------------------------------------------*/
33;# Set compression
34	SetCompressor /FINAL lzma
35
36;--------------------------------
37;# You must define these values
38	!define OCPN_INSTALLER_VERSION "1.0.0"
39	/*
40	!define CPACK_NSIS_INSTALLED_ICON_NAME "opencpn.exe"
41	!define CPACK_NSIS_PACKAGE_NAME_LC "opencpn"
42	!define CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME} ${PACKAGE_VERSION}"
43	!define CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/src/bitmaps/opencpn.ico"
44	!define CPACK_BUILDWIN_DIR "${PROJECT_SOURCE_DIR}/buildwin"
45	!define CPACK_NSIS_DIR "${PROJECT_SOURCE_DIR}/buildwin/NSIS_Unicode"
46	*/
47	!define /date YEAR "%Y"
48	!define OUTPUT_FILE_NAME "@CPACK_NSIS_PACKAGE_NAME_LC@_@CPACK_PACKAGE_VERSION@_setup.exe"
49	!define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
50	!define REG_ROOT_KEY "Software"
51	!define REG_KEY "Software\s63_pi"
52	!define REG_ROOT_KEY_UN "Software\Microsoft\Windows\CurrentVersion\Uninstall"
53	!define REG_KEY_UN "Software\Microsoft\Windows\CurrentVersion\Uninstall\s63_pi @CPACK_PACKAGE_VERSION@"
54	!define CSIDL_LOCAL_APPDATA "0x1C"
55	!define Explode "!insertmacro Explode"
56	!define unExplode "!insertmacro unExplode"
57
58
59;--------------------------------
60;# Variables
61	Var INST_USER_SID
62	Var CONFIG_EXISTS
63	Var CONFIG_EMPTY
64	Var INI_EXISTS
65	Var CHARTDB_EXISTS
66	Var SENC_EXISTS
67	Var CM93_EXISTS
68	Var NAVOBJ_EXISTS
69	Var LOG_EXISTS
70	Var REG_LANG
71	Var Count_SecGrpResetConfig
72	Var SecGrpEndSetConfig_Text
73	Var RESET_CONFIG
74	Var STARTMENU_FOLDER
75	Var OLD_INSTALLS
76	Var Prev_Install_RegKey
77	Var MULTIPLE_INSTALLS
78	Var VERSION_EXISTS
79	Var VERSION_NEWER
80	Var VERSION_OLDER
81	Var CANCEL_INSTALLER
82	Var VERSION_DATE
83	Var LANG_NAME
84	Var Status_SecGrpSetConfig
85	Var MAJOR_D
86	Var MINOR_D
87	Var PATCH_D
88	Var PATCH_ND
89	Var LM_VERSION
90	Var LM_VERSION_INST
91	Var LM_VERSION_UNINST
92	Var latest_version
93	Var latest_pathexe
94	Var BU_X
95	Var BU_Y
96	Var UAT
97	Var OUAT
98	Var USERS_APPDATA
99	Var ADMIN_APPDATA
100	Var USERS_NAME
101	Var counter_tmp
102	Var CurrentDirVar
103	Var CurrentFileVar
104	Var CONTEXT
105	Var REG_CHARTDIRS
106	Var USERNAME
107	Var IS_ADMIN
108	Var Compare_Version_Result
109	Var Inst_Or_Uninst
110	Var Marquee_Handle
111	Var Banner_Text_Blink
112	Var error_tmp
113# onSelChange
114	Var ConfigSetLang
115	Var ConfigSetChartDir
116	Var SetConfig
117# Installer Pages
118	Var Skip_Page_CleanUp
119	Var Skip_Page_TypeInst
120	Var Skip_Page_SetConfig
121	Var Skip_Page_Directory
122	Var Skip_Page_Startmenu
123	Var Skip_Page_Confirm
124# Page_TypeInst
125	Var Label_TypeInst_Reinstall
126	Var RB_Reinstall
127	Var Label_TypeInst_Upgrade
128	Var RB_Upgrade
129	Var Label_TypeInst_Downgrade
130	Var RB_Downgrade
131	Var Label_TypeInst_Parallel
132	Var GroupBox_TypeInst
133	Var RB_Parallel
134	Var TI_REINSTALL
135	Var TI_UPGRADE
136	Var TI_DOWNGRADE
137	Var TI_PARALLEL
138	Var GroupBox_Size
139	Var INSTALL_TYPE
140# Page_SetConfig
141	Var Label_SetConfig
142	Var GroupBox_Language_SetConfig
143	Var CheckBox_Language_SetConfig
144	Var GroupBox_ChartDir_SetConfig
145	Var DirRequest_SetConfig
146	Var Button_Delete_SetConfig
147	Var Button_DeleteAll_SetConfig
148	Var Button_Add_SetConfig
149	Var ListBox_SetConfig
150;# Page_SetConfig_Leave
151	Var CHART_DIR_TMP_FILE
152	Var CHART_DIR_EMPTY
153	Var CONFIG_SET_LANG
154
155# Uninstaller Pages
156	Var Skip_UnPage_Components
157;--------------------------------
158;# Execution Level
159	RequestExecutionLevel highest
160
161;--------------------------------
162;# Includes
163	!addincludedir "@CPACK_NSIS_DIR@/Include"
164	!addplugindir "@CPACK_NSIS_DIR@/Plugins"
165
166	!include MUI2.nsh
167	!include LogicLib.nsh
168	!include nsDialogs.nsh
169	!include Sections.nsh
170	!include StrFunc.nsh
171	!include WordFunc.nsh
172	!include TextFunc.nsh
173	!include FileFunc.nsh
174	!include WinVer.nsh
175
176	!include UAC.nsh
177
178	!define MUI_UI "@CPACK_NSIS_DIR@/UI/opencpn_ui.exe"
179
180;--------------------------------
181;# General
182  ;# Name and file
183  Name "@CPACK_NSIS_PACKAGE_NAME@"
184  OutFile "@CPACK_TOPLEVEL_DIRECTORY@/${OUTPUT_FILE_NAME}"
185
186  ;# Default installation folder
187  InstallDir "$PROGRAMFILES\s63_pi"
188
189  BrandingText /TRIMLEFT "s63_pi $(Installer) v${OCPN_INSTALLER_VERSION}"
190;--------------------------------
191;# Interface Settings
192  !define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
193  !define MUI_CUSTOMFUNCTION_UNGUIINIT un.myGuiInit
194
195  !define MUI_ABORTWARNING
196
197  ;# MUI Settings / Header
198	!define MUI_ICON "@CPACK_PACKAGE_ICON@"
199    !define MUI_HEADERIMAGE
200    !define MUI_HEADERIMAGE_LEFT
201    !define MUI_HEADERIMAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\header-install.bmp"
202    !define MUI_HEADERIMAGE_UNBITMAP "@CPACK_NSIS_DIR@\Bitmaps\header-uninstall.bmp"
203
204  ;# MUI Settings / Wizard
205    !define MUI_WELCOMEFINISHPAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\wizard-install.bmp"
206    !define MUI_UNWELCOMEFINISHPAGE_BITMAP "@CPACK_NSIS_DIR@\Bitmaps\wizard-uninstall.bmp"
207
208  ;# Set Multi-Language settings
209	;# Language Selection Dialog Settings
210	;# Show all languages, despite user's codepage
211	!define MUI_LANGDLL_ALLLANGUAGES
212/*
213	;# Remember the installer language
214	!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
215	!define MUI_LANGDLL_REGISTRY_KEY "${REG_KEY_UN}"
216	!define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage"
217	!define MUI_LANGDLL_WINDOWTITLE "$(LangDialog_Title)"
218	!define MUI_LANGDLL_INFO "$(LangDialog_Text)"
219	*/
220;--------------------------------
221;# Calls for making respective functions available
222	${StrLoc}
223
224;--------------------------------
225;##################################################################################################
226;#                                             Macros                                             #
227;##################################################################################################
228
229!ifndef ___EnumHKU___
230	!define ___EnumHKU___
231
232	!include LogicLib.nsh
233	!include WordFunc.nsh
234
235	!define TOKEN_QUERY             0x0008
236	!define TOKEN_ADJUST_PRIVILEGES 0x0020
237
238	!define SE_RESTORE_NAME         SeRestorePrivilege
239
240	!define SE_PRIVILEGE_ENABLED    0x00000002
241
242	!define HKEY_USERS              0x80000003
243
244	Var key
245	Var logged
246	Var EnumHKU_counter
247	Var SID
248	Var USERPROFILE
249
250	!macro _EnumHKU_AdjustTokens
251		StrCpy $R1 0
252
253		System::Call "kernel32::GetCurrentProcess() i .R0"
254		System::Call "advapi32::OpenProcessToken(i R0, i ${TOKEN_QUERY}|${TOKEN_ADJUST_PRIVILEGES}, *i R1R1) i .R0"
255
256		${If} $R0 != 0
257		  System::Call "advapi32::LookupPrivilegeValue(t n, t '${SE_RESTORE_NAME}', *l .R2) i .R0"
258
259		  ${If} $R0 != 0
260			System::Call "*(i 1, l R2, i ${SE_PRIVILEGE_ENABLED}) i .R0"
261			System::Call "advapi32::AdjustTokenPrivileges(i R1, i 0, i R0, i 0, i 0, i 0)"
262			System::Free $R0
263		  ${EndIf}
264
265		  System::Call "kernel32::CloseHandle(i R1)"
266		${EndIf}
267	!macroend
268
269	!macro _EnumHKU_InvokeCallback CALLBACK SUBKEY
270		Push $0
271		Push $1
272		Push $R0
273		Push $R1
274		Push $R2
275		Push $R3
276		Push $R4
277		Push $R5
278		Push $R6
279
280		Push "${SUBKEY}"
281		Call "${CALLBACK}"
282
283		Pop $R6
284		Pop $R5
285		Pop $R4
286		Pop $R3
287		Pop $R2
288		Pop $R1
289		Pop $R0
290		Pop $1
291		Pop $0
292	!macroend
293
294	!macro _EnumHKU_Load FILE CALLBACK SUBKEY
295		GetFullPathName /SHORT $R2 ${FILE}
296		System::Call "advapi32::RegLoadKeyW(i ${HKEY_USERS}, t '${SUBKEY}', t R2) i .R3"
297		${If} $R3 == 0
298		  !insertmacro _EnumHKU_InvokeCallback ${CALLBACK} "${SUBKEY}"
299		  ;System::Call "advapi32::RegUnLoadKeyW(i ${HKEY_USERS}, t '${SUBKEY}')"
300		  IntOp $EnumHKU_counter $EnumHKU_counter + 1
301		${EndIf}
302	!macroend
303
304	!macro EnumHKU UN CALLBACK SUBKEY
305		Push $0
306		Push $1
307		StrCpy $EnumHKU_counter 0
308		GetFunctionAddress $0 "${CALLBACK}"
309		StrCpy $1 "${SUBKEY}_$EnumHKU_counter"
310		StrCpy $key ${SUBKEY}
311		Call ${UN}_EnumHKU
312		Pop $1
313		Pop $0
314	!macroend
315
316	!define EnumHKU '!insertmacro EnumHKU ""'
317	!define un.EnumHKU '!insertmacro EnumHKU "un."'
318
319	!macro _EnumHKU UN
320		Function ${UN}_EnumHKU
321			Push $R0
322			Push $R1
323			Push $R2
324			Push $R3
325			Push $R4
326			Push $R5
327			Push $R6
328
329			# enumerate logged on users
330			StrCpy $R0 0
331			${Do}
332			  EnumRegKey $R1 HKU "" $R0
333			  ${If} $R1 != ""
334				StrLen $R4 $R1
335				${If} $R4 > 8
336					StrCpy $R6 0
337					${WordFind} "$R1" "_Classes" "E*" $R6
338					IfErrors 0 cont
339
340					ReadRegStr $R5 HKU "$R1\Volatile Environment" USERPROFILE
341					ExpandEnvStrings $R5 $R5
342					StrCpy $USERPROFILE $R5
343					StrCpy $logged "on"
344					!insertmacro _EnumHKU_InvokeCallback $0 $R1
345					StrCpy $USERPROFILE ""
346					StrCpy $logged ""
347				${EndIf}
348				cont:
349				IntOp $R0 $R0 + 1
350			  ${EndIf}
351			${LoopUntil} $R1 == ""
352
353			# enumerate logged off users
354			System::Call "kernel32::GetVersion() i .R0"
355			IntOp $R0 $R0 & 0x80000000
356			${If} $R0 == 0
357				# nt
358				!insertmacro _EnumHKU_AdjustTokens
359				StrCpy $R0 0
360				${Do}
361					EnumRegKey $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $R0
362					${If} $R1 != ""
363						StrLen $R4 $R1
364						${If} $R4 > 8
365							ClearErrors
366							ReadRegStr $R5 HKU "$R1\Volatile Environment" HOMEPATH
367							IfErrors 0 cont1
368							ReadRegStr $R5 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$R1" ProfileImagePath
369							ExpandEnvStrings $R5 $R5
370							StrCpy $USERPROFILE $R5
371							StrCpy $logged "off"
372							!insertmacro _EnumHKU_Load "$R5\NTUSER.DAT" $0 $1
373							StrCpy $1 "$key_$EnumHKU_counter"
374							StrCpy $USERPROFILE ""
375							StrCpy $logged ""
376						${EndIf}
377
378						cont1:
379						IntOp $R0 $R0 + 1
380					${EndIf}
381				${LoopUntil} $R1 == ""
382			${Else}
383				# 9x
384				ClearErrors
385				FindFirst $R1 $R2 "$WINDIR\Profiles\*.*"
386				${Unless} ${Errors}
387					${Do}
388						${If} $R2 != "."
389						${AndIf} $R2 != ".."
390							${If} ${FileExists} "$WINDIR\Profiles\$R2\USER.DAT"
391								!insertmacro _EnumHKU_Load "$WINDIR\Profiles\$R2\USER.DAT" $0 $1
392							${EndIf}
393						${EndIf}
394						ClearErrors
395						FindNext $R1 $R2
396					${LoopUntil} ${Errors}
397					FindClose $R1
398				${EndUnless}
399			${Endif}
400
401			Pop $R6
402			Pop $R5
403			Pop $R4
404			Pop $R3
405			Pop $R2
406			Pop $R1
407			Pop $R0
408		FunctionEnd
409	!macroend
410
411	!insertmacro _EnumHKU ""
412	!insertmacro _EnumHKU "un."
413!endif
414
415!macro IndexOf Var Str Char
416	Push "${Char}"
417	Push "${Str}"
418	Call IndexOf
419	Pop "${Var}"
420!macroend
421!define IndexOf "!insertmacro IndexOf"
422
423!macro RIndexOf Var Str Char
424	Push "${Char}"
425	Push "${Str}"
426	Call RIndexOf
427	Pop "${Var}"
428!macroend
429!define RIndexOf "!insertmacro RIndexOf"
430
431
432!macro  Explode Length  Separator   String
433    Push    `${Separator}`
434    Push    `${String}`
435    Call    Explode
436    Pop     `${Length}`
437!macroend
438
439!macro  unExplode Length  Separator   String
440    Push    `${Separator}`
441    Push    `${String}`
442    Call    un.Explode
443    Pop     `${Length}`
444!macroend
445
446!ifndef _RecFind_Included
447	!define _RecFind_Included
448
449	Var _RecFindVar1
450	Var _RecFindVar2
451
452	!macro _RecFindOpen Dir CurrentDirVar CurrentFileVar
453		!define _Local          `${__LINE__}`
454		!define _Dir            `${Dir}`
455		!define _CurrentDirVar  `${CurrentDirVar}`
456		!define _CurrentFileVar `${CurrentFileVar}`
457
458		!define _RecFindOpenSet
459
460		StrCpy $_RecFindVar2 1
461		Push ``
462
463		`nextDir${_Local}:`
464		Pop `${_CurrentDirVar}`
465		IntOp $_RecFindVar2 $_RecFindVar2 - 1
466	!macroend
467	!define RecFindOpen `!insertmacro _RecFindOpen`
468
469	!macro _RecFindFirst
470		!ifndef _RecFindOpenSet
471			!error `Incorrect use of RecFind commands!`
472		!else
473			!define _RecFindFirstSet
474		!endif
475
476		ClearErrors
477		FindFirst $_RecFindVar1 `${_CurrentFileVar}` `${_Dir}${_CurrentDirVar}\*.*`
478		IfErrors `Done${_Local}`
479
480		`checkFile${_Local}:`
481		StrCmp ${_CurrentFileVar} .  `nextFile${_Local}`
482		StrCmp ${_CurrentFileVar} .. `nextFile${_Local}`
483
484		IfFileExists `${_Dir}${_CurrentDirVar}\${_CurrentFileVar}\*.*` 0 +4
485		Push `${_CurrentDirVar}\${_CurrentFileVar}`
486		IntOp $_RecFindVar2 $_RecFindVar2 + 1
487		Goto `nextFile${_Local}`
488	!macroend
489	!define RecFindFirst `!insertmacro _RecFindFirst`
490
491	!macro _RecFindNext
492		!ifndef _RecFindOpenSet | _RecFindFirstSet
493			!error `Incorrect use of RecFind commands!`
494		!else
495			!define _RecFindNextSet
496		!endif
497
498		`nextFile${_Local}:`
499
500		ClearErrors
501		FindNext $_RecFindVar1 `${_CurrentFileVar}`
502		IfErrors 0 `checkFile${_Local}`
503
504		StrCmp $_RecFindVar2 0 +3
505		FindClose $_RecFindVar1
506		Goto `nextDir${_Local}`
507	!macroend
508	!define RecFindNext `!insertmacro _RecFindNext`
509
510	!macro _RecFindClose
511		!ifndef _RecFindOpenSet | _RecFindFirstSet | _RecFindNextSet
512			!error `Incorrect use of RecFind commands!`
513		!else
514			!undef _RecFindOpenSet
515			!undef _RecFindFirstSet
516			!undef _RecFindNextSet
517		!endif
518
519		`Done${_Local}:`
520		FindClose $_RecFindVar1
521
522		StrCmp $_RecFindVar2 0 +4
523		Pop $_RecFindVar1
524		IntOp $_RecFindVar2 $_RecFindVar2 - 1
525		Goto -3
526
527		!undef _CurrentFileVar
528		!undef _CurrentDirVar
529		!undef _Dir
530		!undef _Local
531	!macroend
532	!define RecFindClose `!insertmacro _RecFindClose`
533!endif
534
535;--------------------------------------------------------------------------------------------------
536;##################################################################################################
537;#                                            FUNCTIONS                                           #
538;##################################################################################################
539
540; StrContains
541; This function does a case sensitive searches for an occurrence of a substring in a string.
542; It returns the substring if it is found.
543; Otherwise it returns null("").
544; Written by kenglish_hi
545; Adapted from StrReplace written by dandaman32
546
547
548Var STR_HAYSTACK
549Var STR_NEEDLE
550Var STR_CONTAINS_VAR_1
551Var STR_CONTAINS_VAR_2
552Var STR_CONTAINS_VAR_3
553Var STR_CONTAINS_VAR_4
554Var STR_RETURN_VAR
555
556Function StrContains
557  Exch $STR_NEEDLE
558  Exch 1
559  Exch $STR_HAYSTACK
560  ; Uncomment to debug
561  ;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
562    StrCpy $STR_RETURN_VAR ""
563    StrCpy $STR_CONTAINS_VAR_1 -1
564    StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
565    StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
566    loop:
567      IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
568      StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
569      StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
570      StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
571      Goto loop
572    found:
573      StrCpy $STR_RETURN_VAR $STR_NEEDLE
574      Goto done
575    done:
576   Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
577   Exch $STR_RETURN_VAR
578FunctionEnd
579
580!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
581  Push `${HAYSTACK}`
582  Push `${NEEDLE}`
583  Call StrContains
584  Pop `${OUT}`
585!macroend
586
587!define StrContains '!insertmacro "_StrContainsConstructor"'
588
589
590
591
592
593
594;--------------------------------------------------------------------------------------------------
595;##################################################################################################
596;#                                            PAGES                                               #
597;##################################################################################################
598;#                                       Installer Pages                                          #
599;##################################################################################################
600/*  Var Skip_Page_CleanUp
601	Var Skip_Page_TypeInst
602	Var Skip_Page_SetConfig
603	Var Skip_Page_Directory
604	Var Skip_Page_Startmenu
605	Var Skip_Page_Confirm
606*/
607	;# Welcome page
608	!define MUI_WELCOMEPAGE_TITLE_3LINES
609	!insertmacro MUI_PAGE_WELCOME
610
611	;# License page
612	!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_License_Leave
613	;!insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
614
615        !define MUI_LICENSEPAGE_BUTTON "$(^NextBtn)"
616        !define MUI_LICENSEPAGE_TEXT_BOTTOM $(License_Message)
617
618	!insertmacro MUI_PAGE_LICENSE $(license)
619
620/*
621	;# Clean up page - only shown if previous installation(s) <= 2.2.823 were found - checked in .onInit function
622;	Page custom Page_CleanUp Page_CleanUp_Leave
623*/
624	;# Install type page - only shown if previous installation(s) > 2.2.823 were found - checked in .onInit function
625	Page custom Page_TypeInst Page_TypeInst_Leave
626
627/*
628	;# Components page
629	!define MUI_COMPONENTSPAGE_SMALLDESC
630	!define MUI_PAGE_HEADER_TEXT $(CP_HEADER_TEXT)
631	!define MUI_PAGE_HEADER_SUBTEXT $(CP_HEADER_SUBTEXT)
632	!define MUI_COMPONENTSPAGE_TEXT_TOP $(CP_TOP)
633	!define MUI_COMPONENTSPAGE_TEXT_COMPLIST $(CP_COMPLIST)
634	!define MUI_COMPONENTSPAGE_TEXT_INSTTYPE "" ;#CHANGE $(CP_INSTTYPE)
635	;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE $(CP_DESCRIPTION_TITLE) ;# for this we can use the default text
636	;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO $(CP_DESCRIPTION_INFO) ;# for this we can use the default text
637	!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Components_Pre
638	!define MUI_PAGE_CUSTOMFUNCTION_SHOW Page_Components_Show
639	!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_Components_Leave
640	!insertmacro MUI_PAGE_COMPONENTS
641*/
642	;# Directory page - allows for changing/ selecting the install directory
643	!define MUI_DIRECTORYPAGE_VERIFYONLEAVE
644	!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Directory_Pre
645	!define MUI_PAGE_CUSTOMFUNCTION_LEAVE Page_Directory_Leave
646	!insertmacro MUI_PAGE_DIRECTORY
647
648/*
649	;# Start Menu Folder page - allows for changing/ selecting the Start Menu Folder (if Shortcuts get installed is configured on the Components page)
650	!define MUI_STARTMENUPAGE_NODISABLE
651	!define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
652	!define MUI_STARTMENUPAGE_REGISTRY_KEY "${REG_KEY_UN}"
653	!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"
654	!define MUI_STARTMENUPAGE_DEFAULTFOLDER "OpenCPN"
655	!define MUI_PAGE_CUSTOMFUNCTION_PRE Page_Startmenu_Pre
656	!insertmacro MUI_PAGE_STARTMENU "Application" $STARTMENU_FOLDER
657
658	;# 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)
659	Page custom Page_SetConfig Page_SetConfig_Leave
660*/
661	;# 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)
662	Page custom Page_Confirm
663
664	;# Install page
665	!define MUI_PAGE_CUSTOMFUNCTION_SHOW Page_Instfiles_Show
666	!insertmacro MUI_PAGE_INSTFILES
667
668	;# Finish page
669
670	#!define MUI_FINISHPAGE_RUN opencpn.exe
671#	!define MUI_FINISHPAGE_RUN
672#	!define MUI_FINISHPAGE_RUN_FUNCTION ExecAppFile
673
674	!define MUI_FINISHPAGE_SHOWREADME install.log
675	!define MUI_FINISHPAGE_SHOWREADME_TEXT $(Show_Readme_Text)
676	!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
677	!define MUI_FINISHPAGE_LINK $(Finish_Link_Text)
678	!define MUI_FINISHPAGE_LINK_LOCATION $(Finish_Link_URL)
679	!define MUI_FINISHPAGE_LINK_COLOR 000080
680	!define MUI_FINISHPAGE_NOREBOOTSUPPORT
681	!define MUI_FINISHPAGE_TITLE_3LINES
682	!insertmacro MUI_PAGE_FINISH
683
684;--------------------------------
685;##################################################################################################
686;#                                     Uninstaller Pages                                          #
687;##################################################################################################
688	;# Welcome page
689	!define MUI_WELCOMEPAGE_TITLE_3LINES
690	!insertmacro MUI_UNPAGE_WELCOME
691
692/*
693	;# Components page
694	!define MUI_PAGE_CUSTOMFUNCTION_PRE un.Page_Components_Pre
695	!insertmacro MUI_UNPAGE_COMPONENTS
696*/
697	;# Confirm page
698	!insertmacro MUI_UNPAGE_CONFIRM
699	;# Uninstall page
700	!insertmacro MUI_UNPAGE_INSTFILES
701
702	;# Finish page
703	!define MUI_FINISHPAGE_TITLE_3LINES
704	!insertmacro MUI_UNPAGE_FINISH
705
706;--------------------------------------------------------------------------------------------------
707;##################################################################################################
708;#                                        Languages                                               #
709;##################################################################################################
710;# Languages
711	!insertmacro MUI_LANGUAGE "English" ;# first language is the default language
712	!insertmacro MUI_LANGUAGE "German"
713	!include /NONFATAL "Langstrings_GERMAN.nsh"
714	!insertmacro MUI_LANGUAGE "French"
715	!include /NONFATAL "Langstrings_FRENCH.nsh"
716	!insertmacro MUI_LANGUAGE "Czech"
717	!include /NONFATAL "Langstrings_CZECH.nsh"
718	!insertmacro MUI_LANGUAGE "Danish"
719	!include /NONFATAL "Langstrings_DANISH.nsh"
720	!insertmacro MUI_LANGUAGE "Spanish"
721	!include /NONFATAL "Langstrings_SPANISH.nsh"
722	!insertmacro MUI_LANGUAGE "Italian"
723	!include /NONFATAL "Langstrings_ITALIAN.nsh"
724	!insertmacro MUI_LANGUAGE "Dutch"
725	!include /NONFATAL "Langstrings_DUTCH.nsh"
726	!insertmacro MUI_LANGUAGE "Polish"
727	!include /NONFATAL "Langstrings_POLISH.nsh"
728	!insertmacro MUI_LANGUAGE "PortugueseBR"
729	!include /NONFATAL "Langstrings_PORTUGUESEBR.nsh"
730	!insertmacro MUI_LANGUAGE "Portuguese"
731	!include /NONFATAL "Langstrings_PORTUGUESE.nsh"
732	!insertmacro MUI_LANGUAGE "Russian"
733	!include /NONFATAL "Langstrings_RUSSIAN.nsh"
734	!insertmacro MUI_LANGUAGE "Swedish"
735	!include /NONFATAL "Langstrings_SWEDISH.nsh"
736	!insertmacro MUI_LANGUAGE "Finnish"
737	!include /NONFATAL "Langstrings_FINNISH.nsh"
738	!insertmacro MUI_LANGUAGE "Norwegian"
739	!include /NONFATAL "Langstrings_NORWEGIAN.nsh"
740	!insertmacro MUI_LANGUAGE "TradChinese"
741	!include /NONFATAL "Langstrings_CHINESETW.nsh"
742	!insertmacro MUI_LANGUAGE "Turkish"
743	!include /NONFATAL "Langstrings_TURKISH.nsh"
744	;!insertmacro MUI_LANGUAGE "Hungarian"
745	;!include /NONFATAL "Langstrings_HUNGARIAN.nsh"
746
747;--------------------------------
748;# Reserve Files
749	;# If you are using solid compression, files that are required before
750	;# the actual installation should be stored first in the data block,
751	;# because this will make your installer start faster.
752	!insertmacro MUI_RESERVEFILE_LANGDLL
753
754;# Remember the installer language
755	!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
756	!define MUI_LANGDLL_REGISTRY_KEY "${REG_KEY_UN}"
757	!define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage"
758	!define MUI_LANGDLL_WINDOWTITLE $(LangDialog_Title)
759	!define MUI_LANGDLL_INFO $(LangDialog_Text)
760
761;--------------------------------------------------------------------------------------------------
762;##################################################################################################
763;#                                     S E C T I O N S                                            #
764;##################################################################################################
765;#                                    Installer Sections                                          #
766;##################################################################################################
767Section "-Topmost Section" SecTopmost ;# this needs to be always the first section to be executed!
768	SetShellVarContext all
769	SetOutPath $INSTDIR
770
771	${If} $INSTALL_TYPE == 1
772	${OrIf} $INSTALL_TYPE == 2
773	${OrIf} $INSTALL_TYPE == 3
774		ReadRegStr $0 HKLM "$Prev_Install_RegKey" "UninstallString"
775		${StrFilter} "$0" "" "" "$\"" $0
776		ClearErrors
777		ExecWait '"$0" /S /type=1 _?=$INSTDIR'
778		IfErrors 0 +2
779		DetailPrint "Error on uninstalling"
780		Sleep 100
781		Delete $0
782	${EndIf}
783SectionEnd
784
785
786;# Install Section /hidden
787Section "-Install Section" SecInstall
788	@CPACK_NSIS_FULL_INSTALL@
789
790	@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
791
792	;# Create uninstaller
793	WriteUninstaller "$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe"
794
795	;# Registry Entries
796	SetShellVarContext all ;# make sure that we write to HKLM
797	;# HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN <DisplayVersion>
798	WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayName" "@CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@"
799	WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayVersion" "@CPACK_PACKAGE_VERSION@"
800	WriteRegStr SHCTX "${REG_KEY_UN}" "CompareVersion" "$VERSION_DATE"
801	WriteRegStr SHCTX "${REG_KEY_UN}" "StartMenuPath" "$SMPROGRAMS\$STARTMENU_FOLDER"
802	WriteRegStr SHCTX "${REG_KEY_UN}" "InstallLocation" "$INSTDIR"
803	WriteRegStr SHCTX "${REG_KEY_UN}" "UninstallString" "$\"$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe$\""
804	WriteRegStr SHCTX "${REG_KEY_UN}" "QuietUninstallString" "$\"$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe /S$\""
805	WriteRegStr SHCTX "${REG_KEY_UN}" "ConfigLocation" "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
806	WriteRegStr SHCTX "${REG_KEY_UN}" "DisplayIcon" "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
807	WriteRegStr SHCTX "${REG_KEY_UN}" "Publisher" "@CPACK_PACKAGE_VENDOR@"
808	WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionMajor" $MAJOR_D
809	WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionMinor" $MINOR_D
810	WriteRegDWORD SHCTX "${REG_KEY_UN}" "VersionPatch" $PATCH_D
811	WriteRegDWORD SHCTX "${REG_KEY_UN}" "NoModify" 1
812	WriteRegDWORD SHCTX "${REG_KEY_UN}" "NoRepair" 1
813	WriteRegStr SHCTX "${REG_KEY_UN}" "HelpLink" "http://opencpn.org/"
814	WriteRegStr SHCTX "${REG_KEY_UN}" "URLInfoAbout" "http://opencpn.org/"
815	WriteRegStr SHCTX "${REG_KEY_UN}" "Contact" "http://opencpn.org/"
816	WriteRegStr SHCTX "${REG_KEY_UN}" "InstallUser" "$USERS_NAME"
817	${If} ${UAC_IsInnerInstance}
818		WriteRegStr SHCTX "${REG_KEY_UN}" "InstallAdminUser" "$USERNAME"
819	${EndIf}
820
821	;# Create the config folder if it does not exist and set full access rights to it
822;	${IfNot} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
823;		CreateDirectory "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
824;		Sleep 250
825;	${EndIf}
826;	AccessControlW::GrantOnFile "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@" "(BU)" "GenericRead + GenericExecute + GenericWrite + Delete + FullAccess"
827
828	;# Save the log file
829	StrCpy $0 "$INSTDIR\install.log"
830	Push $0
831	Call DumpLog
832SectionEnd
833
834;--------------------------------
835;##################################################################################################
836;#                                   Uninstaller Sections                                         #
837;##################################################################################################
838
839Section "-un.Delete Config RegKey" UnSecDeleteConfigRegKey
840	DeleteRegKey HKLM "${REG_KEY}"
841SectionEnd
842
843Section /o "-un.Backup Config to RegKey" UnSecBackupConfigToRegKey
844	SetShellVarContext all
845/*
846	${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
847		ClearErrors
848		StrCpy $0 ""
849		StrCpy $2 0
850		loop:
851			IntOp $2 $2 + 1
852			ReadINIStr $1 "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" "ChartDirectories" "ChartDir$2"
853			StrCmp $1 "" cont
854			${WordReplace} "$1" "\\" "\" "+" $3
855			${unExplode} $4 "^" "$3"
856			Pop $5
857			StrCmp $5 "" cont
858			StrCmp $0 "" 0 +2
859			StrCpy $0 $5
860			StrCpy $0 "$0;$5"
861			Goto loop
862		cont:
863		WriteRegStr HKLM "${REG_KEY}" "ChartDirs" "$0"
864
865		ReadINIStr $0 "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" "Settings" "Locale"
866		StrCmp $0 "" +2 0
867		WriteRegStr HKLM "${REG_KEY}" "InstallerLanguage" "$0"
868	${EndIf}
869*/
870SectionEnd
871
872Section "un.Delete Config Folder" UnSecDeleteConfigFolder
873	SetShellVarContext all
874/*
875	${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
876		RMDir /r "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
877		ClearErrors
878	${EndIf}
879*/
880SectionEnd
881
882Section "-un.Uninstall" UnSecUninstall
883
884/*
885	;# Delete all Shortcuts
886		Push $INSTDIR
887		Call un.Delete_Desktop_Shortcuts
888		Push $INSTDIR
889		Call un.Delete_Start_Menu_Shortcuts
890*/
891	;# Delete subdirs and files in INSTDIR
892		;# Remove the uninstaller itself
893		ReadRegStr $0 HKLM "${REG_KEY_UN}" "UninstallString"
894		${StrFilter} "$0" "" "" "$\"" $0
895		Delete $0
896		;# Remove the installation log file
897		Delete "$INSTDIR\install.log"
898		@CPACK_NSIS_DELETE_FILES@
899		@CPACK_NSIS_DELETE_DIRECTORIES@
900
901	;# Remove the installation directory INSTDIR if it is empty
902		ClearErrors
903		RMDir "$INSTDIR"
904		IfErrors 0 cont
905		IfSilent cont
906		MessageBox MB_OK|MB_ICONEXCLAMATION "$(Msg_Error_Remove_InstDir)"
907
908		cont:
909	;# Remove RegKey
910		DeleteRegKey HKLM "${REG_KEY_UN}"
911SectionEnd
912
913;--------------------------------------------------------------------------------------------------
914;##################################################################################################
915;#                                      F U N C T I O N S                                         #
916;##################################################################################################
917;#                                     Installer Functions                                        #
918;##################################################################################################
919;#  .onInit Function
920Function .onInit
921	;# Check if Windows version is at least XP (not Win 98, Win 2000 or older)
922	${IfNot} ${AtLeastWinXP}
923		MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Unsupported_Windows_Version)"
924		Abort
925	${Else}
926		${If} ${IsWinXP}
927		${AndIf} ${AtMostServicePack} 2
928		MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Unsupported_XP_SP_Version)"
929		Abort
930		${EndIf}
931	${EndIf}
932
933	;Prevent multiple instances of the installer
934	${IfNot} ${UAC_IsInnerInstance}
935		System::Call 'kernel32::CreateMutexW(i 0, i 0, t "ocpn_inst_@CPACK_PACKAGE_VERSION@") i .r1 ?e'
936		Pop $R0
937		StrCmp $R0 0 +3
938		MessageBox MB_OK|MB_ICONEXCLAMATION "$(Installer_Running)"
939		Abort
940	${EndIf}
941
942	Call GetUserInfo
943	StrCpy $USERS_NAME $USERNAME
944
945	;# Macros to be inserted
946	${If} $IS_ADMIN == 1
947		!insertmacro MUI_LANGDLL_DISPLAY
948	${EndIf}
949
950	SetShellVarContext current
951	StrCpy $USERS_APPDATA $APPDATA
952	StrCpy $ADMIN_APPDATA $APPDATA
953
954	;# UAC check if user has Admin privileges and prompt for elevation if not
955	uac_tryagain:
956	!insertmacro UAC_RunElevated
957	StrCpy $Inst_Or_Uninst "$(Installer)"
958	${Switch} $0
959	${Case} 0
960		${IfThen} $1 = 1 ${|} Quit ${|} ;# we are the outer process, the inner process has done its work, we are done
961		${IfThen} $3 <> 0 ${|} ${Break} ${|} ;# we are admin, let the show go on
962		${If} $1 = 3 ;# RunAs completed successfully, but with a non-admin user
963			MessageBox mb_IconExclamation|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Retry)" /SD IDNO IDOK uac_tryagain IDNO 0
964		${EndIf}
965		;# fall-through and die
966	${Case} 1223
967		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Abort)"
968		Quit
969	${Case} 1062
970		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Logon_Abort)"
971		Quit
972	${Default}
973		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_No_Elevation)"
974		Quit
975	${EndSwitch}
976
977##########  from here we can be sure to run with admin privileges  ##########
978
979	;# Delete all temporary files created during the installation
980	Delete "$TEMP\opencpn_*.tmp"
981
982	;# Check for unloaded Registry hive from previous installation attempt e.g. when installer crashed
983	StrCpy $0 0
984	!insertmacro _EnumHKU_AdjustTokens
985	${Do}
986		EnumRegKey $1 HKU "" $0
987		StrCmp $1 "" done
988		IntOp $0 $0 + 1
989		ClearErrors
990		${WordFind} "$1" "opencpn-inst-tmp-sid" "E*" $2
991		IfErrors +2 0
992		System::Call "advapi32::RegUnLoadKeyW(i ${HKEY_USERS}, t '$1') i .r3"
993	${Loop}
994	done:
995	${If} ${UAC_IsInnerInstance}
996		!insertmacro UAC_AsUser_GetGlobalVar $USERS_APPDATA
997		!insertmacro UAC_AsUser_GetGlobalVar $USERS_NAME
998	${EndIf}
999
1000	ClearErrors
1001	Var /GLOBAL INST_PARAMS
1002	Var /GLOBAL FORCE_SCAN
1003	${GetParameters} $INST_PARAMS
1004	${GetOptions} "$INST_PARAMS" "/scan" $FORCE_SCAN
1005	IfErrors +2
1006
1007	# Get the user's SID from the username
1008	ReadRegStr $0 HKCU "Volatile Environment" "USERNAME"
1009	System::Call /NOUNLOAD '*(&w${NSIS_MAX_STRLEN})i.R9'
1010	System::Call /NOUNLOAD 'advapi32::LookupAccountNameW(,t "$0",i R9,*i ${NSIS_MAX_STRLEN},w .R8,*i ${NSIS_MAX_STRLEN},*i .r4)i.r5'
1011	System::Call /NOUNLOAD 'advapi32::ConvertSidToStringSidW(i R9,*t .R8)i.r5'
1012	StrCpy $INST_USER_SID $R8
1013
1014	Call VersionDate
1015
1016	;# check for previous installed versions conforming to this installer
1017	Call Check_Prev_Installs
1018
1019	;# check for old installed versions prior to the ones that uses this installer
1020	StrCpy $OLD_INSTALLS 0
1021
1022	Call Reg_Scan_Old_Versions_HKLM
1023
1024	Call EnumProfileList
1025
1026	Call Get_Users_Values
1027
1028	${If} $OLD_INSTALLS == 0
1029		StrCpy $Skip_Page_CleanUp 1
1030	${EndIf}
1031
1032
1033	;# make sure that the DWORD values for the Registry only contain digits
1034	${StrFilter} "@CPACK_PACKAGE_VERSION_MAJOR@" "1" "" "" $MAJOR_D
1035	${StrFilter} "@CPACK_PACKAGE_VERSION_MINOR@" "1" "" "" $MINOR_D
1036	${StrFilter} "@CPACK_PACKAGE_VERSION_PATCH@" "1" "" "" $PATCH_D
1037
1038        StrCpy $INSTDIR "$PROGRAMFILES\OpenCPN\plugins\s63_pi"
1039
1040	;Call GetAllUsers
1041FunctionEnd
1042
1043;--------------------------------
1044;#  myGuiInit Function
1045/*
1046Var CONFIG_EMPTY
1047Var INI_EXISTS
1048Var CHARTDB_EXISTS
1049Var SENC_EXISTS
1050Var CM93_EXISTS
1051Var NAVOBJ_EXISTS
1052Var LOG_EXISTS
1053Var REG_LANG
1054Var Count_SecGrpResetConfig
1055Var SecGrpEndSetConfig_Text
1056*/
1057Function myGuiInit
1058	;Get chosen installer language
1059	${Switch} $LANGUAGE
1060		${Case} ${LANG_CZECH}
1061			StrCpy $LANG_NAME "Čeština"
1062			StrCpy $REG_LANG "cs_CZ"
1063			${Break}
1064		${Case} ${LANG_DANISH}
1065			StrCpy $LANG_NAME "Dansk"
1066			StrCpy $REG_LANG "da_DK"
1067			${Break}
1068		${Case} ${LANG_GERMAN}
1069			StrCpy $LANG_NAME "Deutsch"
1070			StrCpy $REG_LANG "de_DE"
1071			${Break}
1072		${Case} ${LANG_ENGLISH}
1073			StrCpy $LANG_NAME "English"
1074			StrCpy $REG_LANG "en_US"
1075			${Break}
1076		${Case} ${LANG_SPANISH}
1077			StrCpy $LANG_NAME "Español"
1078			StrCpy $REG_LANG "es_ES"
1079			${Break}
1080		${Case} ${LANG_FRENCH}
1081			StrCpy $LANG_NAME "Français"
1082			StrCpy $REG_LANG "fr_FR"
1083			${Break}
1084		${Case} ${LANG_ITALIAN}
1085			StrCpy $LANG_NAME "Italiano"
1086			StrCpy $REG_LANG "it_IT"
1087			${Break}
1088		${Case} ${LANG_DUTCH}
1089			StrCpy $LANG_NAME "Nederlandse"
1090			StrCpy $REG_LANG "nl_NL"
1091			${Break}
1092		${Case} ${LANG_POLISH}
1093			StrCpy $LANG_NAME "Polski"
1094			StrCpy $REG_LANG "pl_PL"
1095			${Break}
1096		${Case} ${LANG_PORTUGUESE}
1097			StrCpy $LANG_NAME "Português"
1098			StrCpy $REG_LANG "pt_PT"
1099			${Break}
1100		${Case} ${LANG_PORTUGUESEBR}
1101			StrCpy $LANG_NAME "Português Brasileiro"
1102			StrCpy $REG_LANG "pt_BR"
1103			${Break}
1104		${Case} ${LANG_SWEDISH}
1105			StrCpy $LANG_NAME "Svenska"
1106			StrCpy $REG_LANG "sv_SE"
1107			${Break}
1108		${Case} ${LANG_RUSSIAN}
1109			StrCpy $LANG_NAME "Русский"
1110			StrCpy $REG_LANG "ru_RU"
1111			${Break}
1112		${Case} ${LANG_NORWEGIAN}
1113			StrCpy $LANG_NAME "Norsk"
1114			StrCpy $REG_LANG "nb_NO"
1115			${Break}
1116		${Case} ${LANG_FINNISH}
1117			StrCpy $LANG_NAME "Suomalainen"
1118			StrCpy $REG_LANG "fi_FI"
1119			${Break}
1120        	${Case} ${LANG_TRADCHINESE}
1121            		StrCpy $LANG_NAME "正體中文"
1122            		StrCpy $REG_LANG "zh_TW"
1123            		${Break}
1124		${Case} ${LANG_Turkish}
1125            		StrCpy $LANG_NAME "Türkçe"
1126            		StrCpy $REG_LANG "tr_TR"
1127            		${Break}
1128		${Default}
1129			${Break}
1130	${EndSwitch}
1131
1132	;# Set Sections Text
1133	SectionSetText ${SecGrpShortcuts} $(SecGrpShortcuts_Text)
1134	SectionSetText ${SecShortcutStartmenu} $(SecShortcutStartmenu_Text)
1135	SectionSetText ${SecShortcutDesktop} $(SecShortcutDesktop_Text)
1136	SectionSetText ${SecSetConfig} $(SecSetConfig_Text)
1137
1138/*
1139	;# Look for config dir ("%APPDATA%\opencpn) and the several config files
1140	Call Check_Config_Exists
1141
1142	${If} $CONFIG_EXISTS != 1
1143	${OrIf} $CONFIG_EMPTY == 1
1144		Call Hide_SecGrpResetConfig
1145		IntOp $0 ${SF_SELECTED} | ${SF_BOLD}
1146		SectionSetFlags ${SecSetConfig} $0
1147		StrCpy $SetConfig 1
1148	${EndIf}
1149*/
1150	SetShellVarContext all ;# switch SetShellVarContext back to ALL
1151FunctionEnd
1152
1153/*
1154;--------------------------------
1155;# onSelChange
1156;Var ConfigSetLang
1157;Var ConfigSetChartDir
1158;Var SetConfig
1159Function .onSelChange
1160	;# Check if all available Sections in SecGrpResetConfig are selected => set SecGrpResetConfig to selected instead of partially selected
1161	Push $0
1162	Push $1
1163	Push $2
1164	Push $3
1165	Push $R0
1166	Push $R1
1167	StrCpy $0 ${SecGrpResetConfig}
1168	StrCpy $1 0
1169	StrCpy $2 0
1170	${Do}
1171		IntOp $0 $0 + 1
1172		${If} ${SectionIsSectionGroupEnd} $0
1173			Goto end
1174		${EndIf}
1175		SectionGetText $0 $R0
1176		${If} $R0 != ""
1177		${AndIf} ${SectionIsSelected} $0
1178			Goto found_selected
1179		${ElseIf} $R0 != ""
1180		${AndIfNot} ${SectionIsSelected} $0
1181			Goto found_unselected
1182		${EndIf}
1183	${Loop}
1184
1185	found_selected:
1186		StrCpy $0 ${SecGrpResetConfig}
1187		${Do}
1188			IntOp $0 $0 + 1
1189			${If} ${SectionIsSectionGroupEnd} $0
1190				Goto end
1191			${EndIf}
1192			SectionGetText $0 $R0
1193			${If} $R0 == ""
1194			${AndIfNot} ${SectionIsSelected} $0
1195				SectionSetFlags $0 ${SF_SELECTED}
1196			${EndIf}
1197		${Loop}
1198
1199	found_unselected:
1200		StrCpy $0 ${SecGrpResetConfig}
1201		${Do}
1202			IntOp $0 $0 + 1
1203			${If} ${SectionIsSectionGroupEnd} $0
1204				Goto end
1205			${EndIf}
1206			SectionGetText $0 $R0
1207			${If} $R0 == ""
1208			${AndIf} ${SectionIsSelected} $0
1209				!insertmacro ClearSectionFlag $0 ${SF_SELECTED}
1210			${EndIf}
1211		${Loop}
1212
1213	end:
1214	SectionGetText ${SecDeleteConfigFile} $R1
1215	${If} $R1 != ""
1216		${IfNot} ${SectionIsReadOnly} ${SecSetConfig}
1217		${AndIfNot} ${SectionIsSelected} ${SecSetConfig}
1218		${AndIf} $SetConfig == 1
1219			StrCpy $SetConfig 0
1220		${EndIf}
1221
1222		${IfNot} ${SectionIsSelected} ${SecDeleteConfigFile}
1223		${AndIf} ${SectionIsSelected} ${SecSetConfig}
1224			!insertmacro ClearSectionFlag ${SecSetConfig} ${SF_SELECTED}
1225			IntOp $0 ${SF_RO} | ${SF_BOLD}
1226			SectionSetFlags ${SecSetConfig} $0
1227			;SectionSetFlags ${SecSetConfig} ${SF_RO}
1228			StrCpy $SetConfig 1
1229		${ElseIfNot} ${SectionIsSelected} ${SecDeleteConfigFile}
1230		${AndIfNot} ${SectionIsSelected} ${SecSetConfig}
1231			IntOp $0 ${SF_RO} | ${SF_BOLD}
1232			SectionSetFlags ${SecSetConfig} $0
1233			;SectionSetFlags ${SecSetConfig} ${SF_RO}
1234			StrCpy $SetConfig 0
1235		${ElseIf} ${SectionIsSelected} ${SecDeleteConfigFile}
1236		${AndIfNot} ${SectionIsSelected} ${SecSetConfig}
1237		${AndIf} $SetConfig == 1
1238			!insertmacro ClearSectionFlag ${SecSetConfig} ${SF_RO}
1239			IntOp $0 ${SF_SELECTED} | ${SF_BOLD}
1240			SectionSetFlags ${SecSetConfig} $0
1241			;SectionSetFlags ${SecSetConfig} ${SF_SELECTED}
1242		${ElseIf} ${SectionIsSelected} ${SecDeleteConfigFile}
1243		${AndIf} $SetConfig == 0
1244			!insertmacro ClearSectionFlag ${SecSetConfig} ${SF_RO}
1245			StrCpy $SetConfig 0
1246		${EndIf}
1247	${EndIf}
1248
1249	Pop $R1
1250	Pop $R0
1251	Pop $3
1252	Pop $2
1253	Pop $1
1254	Pop $0
1255FunctionEnd
1256
1257*/
1258Function .OnInstFailed
1259	Call InstallerEnd
1260FunctionEnd
1261
1262
1263Function .OnInstSuccess
1264	Call InstallerEnd
1265FunctionEnd
1266
1267
1268Function .onGUIEnd
1269	Call InstallerEnd
1270FunctionEnd
1271
1272
1273Function InstallerEnd
1274	;# Delete all temporary files created during the installation
1275	Delete "$TEMP\opencpn_*.tmp"
1276	${If} $EnumHKU_counter > 0
1277		${ForEach} $1 $EnumHKU_counter 0 - 1
1278			System::Call "advapi32::RegUnLoadKeyW(i ${HKEY_USERS}, t '$key_$1')"
1279		${Next}
1280	${Endif}
1281FunctionEnd
1282
1283;--------------------------------
1284;##################################################################################################
1285;#                                   Installer Page Functions                                     #
1286;##################################################################################################
1287;# Page_License_Leave
1288	Function Page_License_Leave
1289/*
1290		FindWindow $mui.ComponentsPage "#32770" "" $HWNDPARENT
1291		System::Call "*(i 0, i 0, i 4, i 8) i .r1"
1292		System::Call "User32::MapDialogRect(i $mui.ComponentsPage, i r1) i .r2"
1293		System::Call "*$1(i .r2, i.r3, i.r4, i.r5)"
1294		System::Free $1
1295		StrCpy $BU_X $4
1296		StrCpy $BU_Y $5
1297*/
1298	FunctionEnd
1299
1300/*
1301;--------------------------------
1302;# Page_CleanUp
1303	Var Label_CleanUp
1304	Var Label_FullScan_CleanUp
1305	Var GroupBox_CleanUp
1306	Var ListBox_CleanUp
1307	Var Button_FullScan_CleanUp
1308	Var Button_UnselectAll_CleanUp
1309	Var Button_SelectAll_CleanUp
1310	Var Button_Uninstall_Selected_CleanUp
1311	Var Banner_Handle
1312	Var MSG_Box_Uninstall_Shown
1313	Function Page_CleanUp
1314		${If} $Skip_Page_CleanUp == 1
1315			Abort
1316		${EndIf}
1317
1318		!ifndef PBS_MARQUEE
1319			!define PBS_MARQUEE 0x08
1320		!endif
1321		!ifndef PBM_SETMARQUEE
1322			!define PBM_SETMARQUEE 0x040A
1323		!endif
1324		!ifndef GWL_STYLE
1325			!define GWL_STYLE -16
1326		!endif
1327
1328		${IfNot} $MSG_Box_Uninstall_Shown == 1
1329			MessageBox MB_YESNO|MB_ICONQUESTION "$(Msg_Uninstall_Old_Versions)" IDYES cont IDNO skip
1330		${Else}
1331			Goto cont
1332		${EndIf}
1333
1334		skip:
1335		Abort
1336
1337		cont:
1338		StrCpy $MSG_Box_Uninstall_Shown 1
1339		!insertmacro MUI_HEADER_TEXT "$(Page_CleanUp_Title)" "$(Page_CleanUp_Subtitle)"
1340
1341		nsDialogs::Create /NOUNLOAD 1018
1342		Pop $0
1343		${If} $0 == error
1344			Abort
1345		${EndIf}
1346
1347		${NSD_CreateLabel} 0 0 200u 16u "$(LAB_FullScan_CleanUp)"
1348		Pop $Label_FullScan_CleanUp
1349
1350		${NSD_CreateButton} 220u 0 70u 15u "$(BT_FullScan_CleanUp)"
1351		Pop $Button_FullScan_CleanUp
1352		GetFunctionAddress $0 Button_FullScan_CleanUp_Click
1353		nsDialogs::OnClick /NOUNLOAD $Button_FullScan_CleanUp $0
1354
1355		${NSD_CreateLabel} 0 22u 100% 24u "$(Label_CleanUp_Text)"
1356		Pop $Label_CleanUp
1357
1358		${NSD_CreateGroupBox} 0 55u 100% 85u "$(Install_Location_Default)"
1359		Pop $GroupBox_CleanUp
1360
1361		!define __NSD_ListBoxMultiselect_CLASS LISTBOX
1362		!define __NSD_ListBoxMultiselect_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LBS_DISABLENOSCROLL}|${LBS_HASSTRINGS}|${LBS_NOINTEGRALHEIGHT}|${LBS_NOTIFY}|${LBS_MULTIPLESEL}
1363		!define __NSD_ListBoxMultiselect_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
1364		!insertmacro __NSD_DefineControl ListBoxMultiselect
1365		${NSD_CreateListboxMultiselect} 10u 70u 200u 65u "$(LB_CleanUp)"
1366		Pop $ListBox_CleanUp
1367		GetFunctionAddress $0 ListBox_CleanUp_Change
1368		nsDialogs::OnChange /NOUNLOAD $ListBox_CleanUp $0
1369
1370		${NSD_CreateButton} 220u 70u 70u 15u "$(BT_UnselectAll_CleanUp)"
1371		Pop $Button_UnselectAll_CleanUp
1372		GetFunctionAddress $0 Button_UnselectAll_CleanUp_Click
1373		nsDialogs::OnClick /NOUNLOAD $Button_UnselectAll_CleanUp $0
1374
1375		${NSD_CreateButton} 220u 100u 70u 15u "$(BT_SelectAll_CleanUp)"
1376		Pop $Button_SelectAll_CleanUp
1377		GetFunctionAddress $0 Button_SelectAll_CleanUp_Click
1378		nsDialogs::OnClick /NOUNLOAD $Button_SelectAll_CleanUp $0
1379
1380		${NSD_CreateButton} 220u 120u 70u 15u "$(BT_Uninstall_Selected_CleanUp)"
1381		Pop $Button_Uninstall_Selected_CleanUp
1382		GetFunctionAddress $0 Button_Uninstall_Selected_CleanUp_Click
1383		nsDialogs::OnClick /NOUNLOAD $Button_Uninstall_Selected_CleanUp $0
1384
1385
1386		;# First check if HDD scan was already done
1387		${If} ${FileExists} "$TEMP\opencpn_hdd_full_scan.tmp"
1388			EnableWindow $Button_FullScan_CleanUp 0
1389			EnableWindow $Label_FullScan_CleanUp 0
1390			SendMessage $GroupBox_CleanUp ${WM_SETTEXT} 0 "STR:$(Install_Location_HDD_Scan)"
1391			ClearErrors
1392			FileOpen $R0 "$TEMP\opencpn_hdd_full_scan.tmp" r
1393			IfErrors done1
1394			${Do}
1395				FileReadUTF16LE $R0 $R1
1396				${If} $R1 == ""
1397					Goto done1
1398				${Else}
1399					${TrimNewLines} $R1 $R1
1400					SendMessage $ListBox_CleanUp ${LB_ADDSTRING} 0 "STR:$R1"
1401				${EndIf}
1402			${Loop}
1403			done1:
1404			FileClose $R0
1405		;# if not get values from LM_VERSION and opencpn_old_installs.tmp file
1406		${Else}
1407			${IfNot} ${FileExists} "$TEMP\opencpn_hdd_quick_scan.tmp"
1408				;# Scan the default locations for program installations on a per-user and all-users basis
1409				Banner::show /NOUNLOAD /set 76 "$(Search_old_installations)"
1410				Banner::getWindow /NOUNLOAD
1411				Pop $Banner_Handle
1412				ShowWindow $Banner_Handle ${SW_HIDE}
1413				${NSD_AddExStyle} $Banner_Handle ${WS_EX_APPWINDOW}
1414				ShowWindow $Banner_Handle ${SW_SHOW}
1415				GetDlgItem $2 $Banner_Handle 1030
1416				SendMessage $2 ${WM_SETTEXT} 0 "STR:$(text_please_wait_1)"
1417
1418				; Get progress bar handle.
1419				GetDlgItem $Marquee_Handle $Banner_Handle 1004
1420
1421				; Set PBS_MARQUEE style for the progress bar control.
1422				System::Call "user32::GetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}) i .r1"
1423				System::Call "user32::SetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}, i $1|${PBS_MARQUEE})"
1424
1425				; Send PBM_SETMARQUEE message to start the marquee.
1426				; lParam is time in milliseconds between marquee animation updates.
1427				SendMessage $Marquee_Handle ${PBM_SETMARQUEE} 1 50
1428
1429				System::Call "User32::SetWindowPos(i $Banner_Handle, i -1, i 0, i 0, i 0, i 0, i 83)"
1430
1431				HideWindow
1432
1433				Call Quick_Scan_Old_Versions
1434
1435				ShowWindow $HWNDPARENT ${SW_SHOW}
1436				BringToFront
1437				SendMessage $Marquee_Handle ${PBM_SETMARQUEE} 0 0
1438				System::Call "user32::SetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}, i $1)"
1439				Banner::destroy
1440			${EndIf}
1441
1442			ClearErrors
1443			FileOpen $R0 "$TEMP\opencpn_hdd_quick_scan.tmp" r
1444			IfErrors done2
1445			${Do}
1446				FileReadUTF16LE $R0 $R1
1447				${If} $R1 == ""
1448					Goto done2
1449				${Else}
1450					${TrimNewLines} $R1 $R1
1451					SendMessage $ListBox_CleanUp ${LB_ADDSTRING} 0 "STR:$R1"
1452				${EndIf}
1453			${Loop}
1454
1455			done2:
1456			FileClose $R0
1457		${EndIf}
1458		;# Pre-select all listbox-items
1459		${NSD_LB_GetCount} $ListBox_CleanUp $1
1460		IntOp $1 $1 - 1
1461		SendMessage $ListBox_CleanUp ${LB_SELITEMRANGEEX} 0 $1
1462		Call ListBox_CleanUp_Change
1463
1464		nsDialogs::Show
1465	FunctionEnd
1466*/
1467
1468/*
1469	Function Button_FullScan_CleanUp_Click
1470		SendMessage $ListBox_CleanUp ${LB_RESETCONTENT} 0 0
1471
1472		Banner::show /NOUNLOAD /set 76 "$(Scanning_HDD)"
1473		Banner::getWindow /NOUNLOAD
1474		Pop $Banner_Handle
1475		ShowWindow $Banner_Handle ${SW_HIDE}
1476		SendMessage $Banner_Handle ${WM_SETTEXT} 0 "STR:$(OCPN_Scanning_HDD)"
1477		${NSD_AddExStyle} $Banner_Handle ${WS_EX_APPWINDOW}
1478		ShowWindow $Banner_Handle ${SW_SHOW}
1479		GetDlgItem $2 $Banner_Handle 1030
1480		SendMessage $2 ${WM_SETTEXT} 0 "STR:$(text_please_wait_1)"
1481
1482		; Get progress bar handle.
1483		GetDlgItem $Marquee_Handle $Banner_Handle 1004
1484
1485		; Set PBS_MARQUEE style for the progress bar control.
1486		System::Call "user32::GetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}) i .r1"
1487		System::Call "user32::SetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}, i $1|${PBS_MARQUEE})"
1488
1489		; Send PBM_SETMARQUEE message to start the marquee.
1490		; lParam is time in milliseconds between marquee animation updates.
1491		SendMessage $Marquee_Handle ${PBM_SETMARQUEE} 1 50
1492
1493		System::Call "User32::SetWindowPos(i $Banner_Handle, i -1, i 0, i 0, i 0, i 0, i 83)"
1494
1495		HideWindow
1496
1497		Call Full_Scan_Old_Versions
1498
1499		${If} ${FileExists} "$TEMP\opencpn_hdd_full_scan.tmp"
1500			Delete "$TEMP\opencpn_hdd_quick_scan.tmp"
1501		${EndIf}
1502
1503		;# If install locations were found compare with Registry keys
1504		${If} $counter_tmp > 0
1505			${If} $LM_VERSION_INST != ""
1506				ClearErrors
1507				FileOpen $R0 "$TEMP\opencpn_hdd_full_scan.tmp" r
1508				IfErrors done1
1509				${Do}
1510					FileReadUTF16LE $R0 $R1
1511					${If} $R1 == ""
1512						Goto done1
1513					${Else}
1514						${TrimNewLines} $R1 $R1
1515						StrCmp $R1 $R2 done1
1516					${EndIf}
1517				${Loop}
1518				;# Path from Registry key wasn't found => delete RegKey
1519				DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1"
1520				StrCpy $LM_VERSION_INST ""
1521
1522				done1:
1523				FileClose $R0
1524			${EndIf}
1525
1526			${If} ${FileExists} "$TEMP\opencpn_old_installs.tmp"
1527				;# Clear the stack
1528				ClearErrors
1529				${Do}
1530					Pop $0
1531					IfErrors empty
1532				${Loop}
1533				empty:
1534
1535				ClearErrors
1536				FileOpen $R0 "$TEMP\opencpn_old_installs.tmp" r
1537
1538				IfErrors done3
1539				${Do}
1540					FileReadUTF16LE $R0 $R3
1541					FileReadUTF16LE $R0 $R2
1542					${If} $R3 == ""
1543						Goto done3
1544					${Else}
1545						${TrimNewLines} $R3 $R3
1546						${TrimNewLines} $R2 $R2
1547						FileReadUTF16LE $R0 $R1
1548						${TrimNewLines} $R1 $R1
1549						ClearErrors
1550						FileOpen $0 "$TEMP\opencpn_hdd_full_scan.tmp" r
1551						IfErrors next
1552						${Do}
1553							FileReadUTF16LE $0 $1
1554							${If} $1 == ""
1555								Goto next
1556							${Else}
1557								${TrimNewLines} $1 $1
1558								StrCmp $1 $R1 done2
1559							${EndIf}
1560						${Loop}
1561						;# Path from Registry key wasn't found => delete RegKey
1562						DeleteRegKey HKU $R3
1563						Goto next
1564
1565						done2:
1566						Push $R1
1567						Push $R2
1568						Push $R3
1569						next:
1570						FileClose $0
1571					${EndIf}
1572				${Loop}
1573				done3:
1574				FileClose $R0
1575
1576				ClearErrors
1577				FileOpen $R0 "$TEMP\opencpn_old_installs.tmp" w
1578				IfErrors done4
1579				${Do}
1580					Pop $R1
1581					IfErrors done4
1582					FileWriteUTF16LE $R0 $R1
1583					FileWriteUTF16LE $R0 "$\r$\n"
1584				${Loop}
1585				done4:
1586				FileClose $R0
1587			${EndIf}
1588		${EndIf}
1589
1590		EnableWindow $Button_FullScan_CleanUp 0 ;# Disable the Scan HDD button after scan was done
1591		EnableWindow $Label_FullScan_CleanUp 0 ;# Disable the Scan HDD label after scan was done
1592		SendMessage $GroupBox_CleanUp ${WM_SETTEXT} 0 "STR:$(Install_Location_HDD_Scan)"
1593
1594		ShowWindow $HWNDPARENT ${SW_SHOW}
1595		BringToFront
1596
1597		; Stop the marquee and set the old styles back for the progress bar control.
1598		SendMessage $Marquee_Handle ${PBM_SETMARQUEE} 0 0
1599		System::Call "user32::SetWindowLong(i $Marquee_Handle, i ${GWL_STYLE}, i $1)"
1600
1601		Banner::destroy
1602	FunctionEnd
1603*/
1604
1605	Function Button_UnselectAll_CleanUp_Click
1606		SendMessage $ListBox_CleanUp ${LB_SETSEL} FALSE -1
1607		Call ListBox_CleanUp_Change
1608	FunctionEnd
1609
1610	Function Button_SelectAll_CleanUp_Click
1611		${NSD_LB_GetCount} $ListBox_CleanUp $1
1612		IntOp $1 $1 - 1
1613		${If} $1 == 0
1614			IntOp $1 $1 + 1
1615		${EndIf}
1616		SendMessage $ListBox_CleanUp ${LB_SELITEMRANGEEX} 0 $1
1617		Call ListBox_CleanUp_Change
1618	FunctionEnd
1619
1620	Function ListBox_CleanUp_Change
1621		SendMessage $ListBox_CleanUp ${LB_GETSELCOUNT} 0 0 $1
1622		${NSD_LB_GetCount} $ListBox_CleanUp $2
1623		${If} $2 > 0
1624			${If} $1 == 0
1625				EnableWindow $Button_Uninstall_Selected_CleanUp 0
1626				EnableWindow $Button_UnselectAll_CleanUp 0
1627				EnableWindow $Button_SelectAll_CleanUp 1
1628			${ElseIf} $1 > 0
1629			${AndIf} $1 == $2
1630				EnableWindow $Button_Uninstall_Selected_CleanUp 1
1631				EnableWindow $Button_UnselectAll_CleanUp 1
1632				EnableWindow $Button_SelectAll_CleanUp 0
1633			${Else}
1634				EnableWindow $Button_Uninstall_Selected_CleanUp 1
1635				EnableWindow $Button_UnselectAll_CleanUp 1
1636				EnableWindow $Button_SelectAll_CleanUp 1
1637			${EndIf}
1638		${Else}
1639			EnableWindow $Button_Uninstall_Selected_CleanUp 0
1640			EnableWindow $Button_UnselectAll_CleanUp 0
1641			EnableWindow $Button_SelectAll_CleanUp 0
1642		${EndIf}
1643	FunctionEnd
1644
1645/*
1646	Var Uninstall_Path_Tmp
1647	Function Button_Uninstall_Selected_CleanUp_Click
1648		EnableWindow $Button_Uninstall_Selected_CleanUp 0
1649		SendMessage $ListBox_CleanUp ${LB_GETSELCOUNT} 0 0 $1
1650		${NSD_LB_GetCount} $ListBox_CleanUp $2
1651		ClearErrors
1652		FileOpen $R0 "$TEMP\opencpn_uninstall.tmp" w
1653		IfErrors done
1654		IntOp $2 $2 - 1
1655		${ForEach} $3 $2 0 - 1
1656			SendMessage $ListBox_CleanUp ${LB_GETSEL} $3 0 $4
1657			${If} $4 > 0
1658				System::Call "User32::SendMessage(i $ListBox_CleanUp, i ${LB_GETTEXT}, i $3, t .r5)"
1659				FileWriteUTF16LE $R0 "$5"
1660				FileWriteUTF16LE $R0 "$\r$\n"
1661				SendMessage $ListBox_CleanUp ${LB_DELETESTRING} $3 0
1662			${EndIf}
1663		${Next}
1664		done:
1665		FileClose $R0
1666
1667		Call ListBox_CleanUp_Change
1668
1669		StrCpy $R8 ""
1670		StrCpy $R7 ""
1671		StrCpy $R6 ""
1672		StrCpy $R5 ""
1673		${If} ${FileExists} "$TEMP\opencpn_uninstall.tmp"
1674			${If} ${FileExists} "$TEMP\opencpn_hdd_full_scan.tmp"
1675				StrCpy $R8 "opencpn_hdd_full_scan.tmp"
1676			${ElseIf} ${FileExists} "$TEMP\opencpn_hdd_quick_scan.tmp"
1677				StrCpy $R8 "opencpn_hdd_quick_scan.tmp"
1678			${EndIf}
1679
1680			${If} ${FileExists} "$TEMP\opencpn_old_installs.tmp"
1681				StrCpy $R7 1
1682			${EndIf}
1683
1684			${If} ${FileExists} "$TEMP\opencpn_old_uninstall_regkeys.tmp"
1685				StrCpy $R6 1
1686			${EndIf}
1687
1688			${If} ${FileExists} "$TEMP\opencpn_appdata.tmp"
1689				StrCpy $R5 1
1690			${EndIf}
1691
1692			ClearErrors
1693			FileOpen $R4 "$TEMP\opencpn_uninstall.tmp" r
1694			IfErrors end
1695			loop:
1696				ClearErrors
1697				FileReadUTF16LE $R4 $0
1698				IfErrors end
1699				StrCmp $0 "" loop
1700				StrCmp $0 "$\r$\n" loop
1701
1702				${TrimNewLines} $0 $0
1703				StrCpy $Uninstall_Path_Tmp $0
1704
1705				;# Delete installation directory
1706				ClearErrors
1707				Call Delete_Installation_Dir
1708				IfErrors 0 +2
1709				MessageBox MB_OK|MB_ICONEXCLAMATION "Error RMDir: $0" ;#ON ERROR
1710
1711				;# If deleted installation was the one in the HKLM ...\OpenCPN_is1 subkey => delete RegKey
1712				${If} $LM_VERSION_INST != ""
1713					StrCmp $0 $LM_VERSION_INST 0 cont
1714					ClearErrors
1715					DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1"
1716					IfErrors 0 +2
1717					MessageBox MB_OK|MB_ICONEXCLAMATION "Error DeleteRegKey HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1" ;#ON ERROR
1718					StrCpy $LM_VERSION ""
1719					StrCpy $LM_VERSION_INST ""
1720					StrCpy $LM_VERSION_UNINST ""
1721				${EndIf}
1722
1723				cont:
1724				;# Delete Start Menu shortcuts
1725				Push $Uninstall_Path_Tmp
1726				Call Delete_Start_Menu_Shortcuts
1727
1728				;# Delete Desktop shortcuts
1729				Push $Uninstall_Path_Tmp
1730				Call Delete_Desktop_Shortcuts
1731
1732				;# Delete RegKeys in HKU Software\opencpn.org\...
1733				${If} $R7 == 1
1734					Call Update_Old_Installs
1735				${EndIf}
1736
1737				;# Delete RegKeys in HKU Software\...\Uninstall\OpenCPN
1738				${If} $R6 == 1
1739					Call Update_Old_Uninstalls
1740				${EndIf}
1741
1742				;# Delete %APPDATA\opencpn folder
1743				${If} $R5 == 1
1744					Call Update_Appdata
1745				${EndIf}
1746
1747				${IfNot} $R8 == ""
1748					Call Update_HDD_Scan
1749				${EndIf}
1750
1751				Goto loop
1752			end:
1753			FileClose $R4
1754			Delete "$TEMP\opencpn_uninstall.tmp"
1755			StrCpy $Uninstall_Path_Tmp ""
1756		${EndIf}
1757
1758		${NSD_LB_GetCount} $ListBox_CleanUp $2
1759		${If} $2 == 0 ;# listbox is empty - all were uninstalled
1760			StrCpy $Skip_Page_CleanUp 1
1761			GetDlgItem $0 $HWNDPARENT 1
1762			SendMessage $0 ${BM_CLICK} 0 0
1763		${EndIf}
1764	FunctionEnd
1765*/
1766
1767/*
1768	Function Update_HDD_Scan
1769		Push $0
1770		Push $1
1771		Push $2
1772		Push $3
1773		Push $4
1774		Push $R0
1775		Push $R8
1776		ClearErrors
1777		FileOpen $0 "$TEMP\$R8" r          			;# open target file for reading
1778		GetTempFileName $R0                        	;# get new temp file name
1779		FileOpen $1 $R0 w                           ;# open temp file for writing
1780		IfErrors end
1781		loop:
1782			FileReadUTF16LE $0 $2                   ;# read line from target file
1783			IfErrors done                           ;# check if end of file reached
1784			${TrimNewLines} $2 $2
1785			StrCmp $2 "$Uninstall_Path_Tmp" +2      ;# compare line with search string with CR/LF
1786			FileWriteUTF16LE $1 "$2$\r$\n"          ;# write line to temp file
1787			Goto loop
1788		done:
1789			FileClose $0                            ;# close target file
1790			FileClose $1                            ;# close temp file
1791			Delete "$TEMP\$R8"             			;# delete target file
1792			CopyFiles /SILENT $R0 "$TEMP\$R8"		;# copy temp file to target file
1793			Delete $R0                              ;# delete temp file
1794		end:
1795		Pop $R8
1796		Pop $R0
1797		Pop $4
1798		Pop $3
1799		Pop $2
1800		Pop $1
1801		Pop $0
1802	FunctionEnd
1803*/
1804
1805/*
1806	Function Update_Old_Installs
1807		Push $0
1808		Push $1
1809		Push $2
1810		Push $3
1811		Push $4
1812		Push $R0
1813		Push $R1
1814		ClearErrors
1815		FileOpen $0 "$TEMP\opencpn_old_installs.tmp" r          	;# open target file for reading
1816		GetTempFileName $R0                        					;# get new temp file name
1817		FileOpen $1 $R0 w                              				;# open temp file for writing
1818		IfErrors end
1819		loop:
1820			FileReadUTF16LE $0 $4                              		;# read line from target file
1821			FileReadUTF16LE $0 $3                              		;# read line from target file
1822			FileReadUTF16LE $0 $2                              		;# read line from target file
1823			IfErrors done                               			;# check if end of file reached
1824			${TrimNewLines} $2 $2
1825			StrCmp $2 "$Uninstall_Path_Tmp" +5         				;# compare line with search string with CR/LF
1826			FileWriteUTF16LE $1 $4                             		;# write line to temp file
1827			FileWriteUTF16LE $1 $3                             		;# write line to temp file
1828			FileWriteUTF16LE $1 "$2$\r$\n"                          ;# write line to temp file
1829			Goto loop
1830			${TrimNewLines} $4 $4
1831			DeleteRegKey HKU "$4"
1832			${WordFind} "$4" "\" "-2{*" $4
1833			DeleteRegKey /ifempty HKU "$4"
1834			ClearErrors
1835			Goto loop
1836		done:
1837			FileClose $0                                			;# close target file
1838			FileClose $1                                			;# close temp file
1839			Delete "$TEMP\opencpn_old_installs.tmp"             	;# delete target file
1840			CopyFiles /SILENT $R0 "$TEMP\opencpn_old_installs.tmp"	;# copy temp file to target file
1841			Delete $R0                                				;# delete temp file
1842		end:
1843		Pop $R1
1844		Pop $R0
1845		Pop $4
1846		Pop $3
1847		Pop $2
1848		Pop $1
1849		Pop $0
1850	FunctionEnd
1851*/
1852
1853/*
1854	Function Update_Old_Uninstalls
1855		Push $0
1856		Push $1
1857		Push $2
1858		Push $3
1859		Push $4
1860		Push $R0
1861		Push $R1
1862		ClearErrors
1863		FileOpen $0 "$TEMP\opencpn_old_uninstall_regkeys.tmp" r     ;# open target file for reading
1864		GetTempFileName $R0                        					;# get new temp file name
1865		FileOpen $1 $R0 w                              				;# open temp file for writing
1866		IfErrors end
1867		loop:
1868			FileReadUTF16LE $0 $4                              		;# read line from target file
1869			FileReadUTF16LE $0 $3                              		;# read line from target file
1870			FileReadUTF16LE $0 $2                              		;# read line from target file
1871			IfErrors done                               			;# check if end of file reached
1872			${TrimNewLines} $2 $2
1873			StrCmp $2 "$Uninstall_Path_Tmp" +5         				;# compare line with search string with CR/LF
1874			FileWriteUTF16LE $1 $4                             		;# write line to temp file
1875			FileWriteUTF16LE $1 $3                             		;# write line to temp file
1876			FileWriteUTF16LE $1 "$2$\r$\n"                          ;# write line to temp file
1877			Goto loop
1878			${TrimNewLines} $3 $3
1879			DeleteRegKey HKU "$3"
1880			ClearErrors
1881			Goto loop
1882		done:
1883			FileClose $0                                					;# close target file
1884			FileClose $1                                					;# close temp file
1885			Delete "$TEMP\opencpn_old_uninstall_regkeys.tmp"             	;# delete target file
1886			CopyFiles /SILENT $R0 "$TEMP\opencpn_old_uninstall_regkeys.tmp"	;# copy temp file to target file
1887			Delete $R0                                						;# delete temp file
1888		end:
1889		Pop $R1
1890		Pop $R0
1891		Pop $4
1892		Pop $3
1893		Pop $2
1894		Pop $1
1895		Pop $0
1896	FunctionEnd
1897*/
1898
1899/*
1900	Function Update_Appdata
1901		Push $0
1902		Push $1
1903		Push $2
1904		Push $3
1905		Push $4
1906		Push $R0
1907		Push $R1
1908		ClearErrors
1909		FileOpen $0 "$TEMP\opencpn_appdata.tmp" r          			;# open target file for reading
1910		GetTempFileName $R0                        					;# get new temp file name
1911		FileOpen $1 $R0 w                              				;# open temp file for writing
1912		IfErrors end
1913		loop:
1914			FileReadUTF16LE $0 $4                              		;# read line from target file
1915			FileReadUTF16LE $0 $3                              		;# read line from target file
1916			FileReadUTF16LE $0 $2                              		;# read line from target file
1917			IfErrors done                               			;# check if end of file reached
1918			${TrimNewLines} $2 $2
1919			StrCmp $2 "$Uninstall_Path_Tmp" +5         				;# compare line with search string with CR/LF
1920			FileWriteUTF16LE $1 $4                             		;# write line to temp file
1921			FileWriteUTF16LE $1 $3                             		;# write line to temp file
1922			FileWriteUTF16LE $1 "$2$\r$\n"                          ;# write line to temp file
1923			Goto loop
1924			${TrimNewLines} $3 $3
1925			RMDir /r "$3\opencpn"
1926			ClearErrors
1927			Goto loop
1928		done:
1929			FileClose $0                                			;# close target file
1930			FileClose $1                                			;# close temp file
1931			Delete "$TEMP\opencpn_appdata.tmp"             			;# delete target file
1932			CopyFiles /SILENT $R0 "$TEMP\opencpn_appdata.tmp"		;# copy temp file to target file
1933			Delete $R0                                				;# delete temp file
1934		end:
1935		Pop $R1
1936		Pop $R0
1937		Pop $4
1938		Pop $3
1939		Pop $2
1940		Pop $1
1941		Pop $0
1942	FunctionEnd
1943*/
1944
1945/*
1946;--------------------------------
1947;# Page_CleanUp_Leave
1948	Function Page_CleanUp_Leave
1949		${NSD_LB_GetCount} $ListBox_CleanUp $2
1950		${If} $2 > 0 ;# listbox is not empty - not all old versions were uninstalled
1951			MessageBox MB_YESNO|MB_ICONQUESTION "$(Msg_Not_All_Old_Uninstalled)" IDYES leaving
1952			Abort
1953		${EndIf}
1954		leaving:
1955		SendMessage $ListBox_CleanUp ${LB_RESETCONTENT} 0 0
1956	FunctionEnd
1957
1958*/
1959
1960;--------------------------------
1961;# Page_TypeInst
1962/*	Var Label_TypeInst_Reinstall
1963	Var RB_Reinstall
1964	Var Label_TypeInst_Upgrade
1965	Var RB_Upgrade
1966	Var Label_TypeInst_Downgrade
1967	Var RB_Downgrade
1968	Var Label_TypeInst_Parallel
1969	Var GroupBox_TypeInst
1970	Var RB_Parallel
1971	Var TI_REINSTALL
1972	Var TI_UPGRADE
1973	Var TI_DOWNGRADE
1974	Var TI_PARALLEL
1975	Var GroupBox_Size
1976	Var INSTALL_TYPE
1977	*/
1978	Function Page_TypeInst
1979		${If} $Skip_Page_TypeInst == 1
1980			Abort
1981		${EndIf}
1982		${If} $VERSION_EXISTS == 1
1983			!insertmacro MUI_HEADER_TEXT $(Page_TypeInst_Title_Exists) $(Page_TypeInst_Subtitle_Exists)
1984		${ElseIf} $MULTIPLE_INSTALLS == 1
1985			!insertmacro MUI_HEADER_TEXT $(Page_TypeInst_Title_1) $(Page_TypeInst_Subtitle_1)
1986		${ElseIf} $MULTIPLE_INSTALLS > 1
1987			!insertmacro MUI_HEADER_TEXT $(Page_TypeInst_Title) $(Page_TypeInst_Subtitle)
1988		${EndIf}
1989
1990		nsDialogs::Create /NOUNLOAD 1018
1991		Pop $0
1992
1993		${If} $0 == error
1994			Abort
1995		${EndIf}
1996
1997		;Case 1: same version already installed => Option 1: Reinstall
1998		${If} $VERSION_EXISTS == 1
1999			${NSD_CreateLabel} 0 0 100% 40u "$(Label_TypeInst_Reinstall_Text)"
2000			Pop $Label_TypeInst_Reinstall
2001
2002			${NSD_CreateRadioButton} 10u 65u 100% 10u "$(RB_Reinstall_TypeInst_Text)"
2003			Pop $RB_Reinstall
2004			${NSD_AddStyle} $RB_Reinstall ${WS_GROUP}
2005			${NSD_SetState} $RB_Reinstall ${BST_CHECKED}
2006
2007			StrCpy $GroupBox_Size 1
2008		;Case 2: one older previous installation => Option 1: Upgrade Option 2: Parallel Installation
2009		${ElseIf} $MULTIPLE_INSTALLS == 1
2010		${AndIf} $VERSION_NEWER == 1
2011			${NSD_CreateLabel} 0 0 100% 32u "$(Label_TypeInst_Upgrade_Text)"
2012			Pop $Label_TypeInst_Upgrade
2013
2014			${NSD_CreateRadioButton} 10u 65u 100% 10u "$(RB_Upgrade_TypeInst_Text)"
2015			Pop $RB_Upgrade
2016			${NSD_AddStyle} $RB_Upgrade ${WS_GROUP}
2017			${If} $TI_UPGRADE != ""
2018				${NSD_SetState} $RB_Upgrade $TI_UPGRADE
2019			${ElseIf} $TI_UPGRADE == ""
2020			${AndIf} $TI_PARALLEL == ""
2021				${NSD_SetState} $RB_Upgrade ${BST_CHECKED}
2022			${EndIf}
2023/*
2024			${NSD_CreateRadioButton} 10u 85u 100% 10u "$(RB_Parallel_TypeInst_Text)"
2025			Pop $RB_Parallel
2026			${If} $TI_PARALLEL != ""
2027				${NSD_SetState} $RB_Parallel $TI_PARALLEL
2028			${EndIf}
2029*/
2030			StrCpy $GroupBox_Size 1
2031		;Case 3: one newer previous installation => Option 1: Downgrade Option 2: Parallel Installation
2032		${ElseIf} $MULTIPLE_INSTALLS == 1
2033		${AndIf} $VERSION_OLDER == 1
2034			${NSD_CreateLabel} 0 0 100% 32u "$(Label_TypeInst_Downgrade_Text)"
2035			Pop $Label_TypeInst_Downgrade
2036
2037			${NSD_CreateRadioButton} 10u 65u 100% 10u "$(RB_Downgrade_TypeInst_Text)"
2038			Pop $RB_Downgrade
2039			${NSD_AddStyle} $RB_Downgrade ${WS_GROUP}
2040			${If} $TI_DOWNGRADE != ""
2041				${NSD_SetState} $RB_Upgrade $TI_DOWNGRADE
2042			${ElseIf} $TI_DOWNGRADE == ""
2043			${AndIf} $TI_PARALLEL == ""
2044				${NSD_SetState} $RB_Downgrade ${BST_CHECKED}
2045			${EndIf}
2046/*
2047			${NSD_CreateRadioButton} 10u 85u 100% 10u "$(RB_Parallel_TypeInst_Text)"
2048			Pop $RB_Parallel
2049			${If} $TI_PARALLEL != ""
2050				${NSD_SetState} $RB_Parallel $TI_PARALLEL
2051			${EndIf}
2052*/
2053			StrCpy $GroupBox_Size 1
2054/*
2055		;Case 4: more than one previous installation => Option 1: Parallel Installation
2056		${ElseIf} $MULTIPLE_INSTALLS > 1
2057			${NSD_CreateLabel} 0 0 100% 32u "$(Label_TypeInst_Parallel_Text)"
2058			Pop $Label_TypeInst_Parallel
2059
2060			${NSD_CreateRadioButton} 10u 65u 100% 10u "$(RB_Parallel_TypeInst_Text)"
2061			Pop $RB_Parallel
2062			${NSD_AddStyle} $RB_Parallel ${WS_GROUP}
2063			${NSD_SetState} $RB_Parallel ${BST_CHECKED}
2064
2065			StrCpy $GroupBox_Size 1
2066*/
2067		${EndIf}
2068
2069		${If} $GroupBox_Size == 1
2070			${NSD_CreateGroupBox} 0 50u 100% 35u "Install Type"
2071			Pop $GroupBox_TypeInst
2072		${ElseIf} $GroupBox_Size == 2
2073			${NSD_CreateGroupBox} 0 50u 100% 55u "Install Type"
2074			Pop $GroupBox_TypeInst
2075		${EndIf}
2076
2077		nsDialogs::Show
2078	FunctionEnd
2079
2080;--------------------------------
2081;# Page_TypeInst_Leave
2082	Function Page_TypeInst_Leave
2083		${If} $RB_Reinstall != ""
2084			${NSD_GetState} $RB_Reinstall $TI_REINSTALL
2085		${EndIf}
2086		${If} $RB_Upgrade != ""
2087			${NSD_GetState} $RB_Upgrade $TI_UPGRADE
2088		${EndIf}
2089		${If} $RB_Downgrade != ""
2090			${NSD_GetState} $RB_Downgrade $TI_DOWNGRADE
2091		${EndIf}
2092		${If} $RB_Parallel != ""
2093			${NSD_GetState} $RB_Parallel $TI_PARALLEL
2094		${EndIf}
2095
2096		StrCpy $Skip_Page_Directory ""
2097		${If} $TI_REINSTALL == 1
2098			StrCpy $INSTALL_TYPE 1
2099		${ElseIf} $TI_UPGRADE == 1
2100			StrCpy $INSTALL_TYPE 2
2101		${ElseIf} $TI_DOWNGRADE == 1
2102			StrCpy $INSTALL_TYPE 3
2103		${ElseIf} $TI_PARALLEL == 1
2104			StrCpy $INSTALL_TYPE 4
2105		${EndIf}
2106
2107		${If} $INSTALL_TYPE == 1
2108		${OrIf} $INSTALL_TYPE == 2
2109		${OrIf} $INSTALL_TYPE == 3
2110			StrCpy $Skip_Page_Directory 1
2111			ReadRegStr $0 HKLM "$Prev_Install_RegKey" "InstallLocation"
2112			StrCpy $INSTDIR $0
2113		${EndIf}
2114
2115		; On Upgrade or Downgrade, tentatively trim any Package Version trailer from install location
2116                ${If} $INSTALL_TYPE == 2
2117                ${OrIf} $INSTALL_TYPE == 3
2118                    StrCpy $R1 0
2119                     Push $INSTDIR
2120                     Push "OpenCPN\plugins\s63_pi"
2121                     Push ">"
2122                     Call StrLoc
2123                     Pop $0
2124
2125                    StrCpy $R1 $INSTDIR $0
2126                    StrCpy $R1 "$R1OpenCPN\plugins\s63_pi"
2127                    StrLen $R2 $INSTDIR
2128                    StrLen $R3 $R1
2129
2130/*
2131                    ;   If Previous install dir was a parallel, make the upgrade also parallel.
2132                    ${If} $R2 > $R3
2133                        StrCpy $INSTDIR "$R1 @CPACK_PACKAGE_VERSION@"
2134                    ${Else}
2135                        StrCpy $INSTDIR $R1
2136                    ${Endif}
2137*/
2138                ${Endif}
2139
2140		${If} $INSTALL_TYPE == 4
2141			StrCpy $INSTDIR "$PROGRAMFILES\OpenCPN\plugins\s63_pi @CPACK_PACKAGE_VERSION@"
2142		${EndIf}
2143	FunctionEnd
2144
2145/*
2146;--------------------------------
2147;# Page_Components_Pre
2148	Function Page_Components_Pre
2149
2150	FunctionEnd
2151
2152;--------------------------------
2153;# Page_Components_Show
2154	Function Page_Components_Show
2155	  ;# change controls size and position on the Components Page
2156		Push $0
2157		Push $1
2158		Push $2
2159		Push $3
2160		Push $4
2161		Push $5
2162		Push $6
2163		Push $7
2164
2165		FindWindow $mui.ComponentsPage "#32770" "" $HWNDPARENT
2166
2167		;GetDlgItem $mui.ComponentsPage.Text             $mui.ComponentsPage 1006
2168		GetDlgItem $mui.ComponentsPage.InstTypesText    $mui.ComponentsPage 1021
2169		ShowWindow $mui.ComponentsPage.InstTypesText ${SW_HIDE}
2170
2171		GetDlgItem $mui.ComponentsPage.ComponentsText   $mui.ComponentsPage 1022
2172		GetDlgItem $mui.ComponentsPage.InstTypes        $mui.ComponentsPage 1017
2173		ShowWindow $mui.ComponentsPage.InstTypes ${SW_HIDE}
2174
2175		GetDlgItem $mui.ComponentsPage.Components       $mui.ComponentsPage 1032
2176		GetDlgItem $mui.ComponentsPage.DescriptionTitle $mui.ComponentsPage 1042
2177		GetDlgItem $mui.ComponentsPage.DescriptionText  $mui.ComponentsPage 1043
2178		GetDlgItem $mui.ComponentsPage.SpaceRequired    $mui.ComponentsPage 1023
2179		ShowWindow $mui.ComponentsPage.SpaceRequired ${SW_HIDE}
2180
2181		Push "198"
2182		Push "40"
2183		Push "100"
2184		Push "100"
2185		Call DU2Pix
2186		System::Call "User32::SetWindowPos(i $mui.ComponentsPage.DescriptionTitle, i 0, i $1, i $2, i $3, i $4, i 64)" ;# 1042
2187
2188		Push "203"
2189		Push "50"
2190		Push "90"
2191		Push "85"
2192		Call DU2Pix
2193		System::Call "User32::SetWindowPos(i $mui.ComponentsPage.DescriptionText, i 0, i $1, i $2, i $3, i $4, i 64)" ;# 1043
2194
2195		Push "0"
2196		Push "25"
2197		Push "300"
2198		Push "15"
2199		Call DU2Pix
2200		System::Call "User32::SetWindowPos(i $mui.ComponentsPage.ComponentsText, i 0, i $1, i $2, i $3, i $4, i 64)" ;# 1022
2201
2202		Push "0"
2203		Push "40"
2204		Push "195"
2205		Push "100"
2206		Call DU2Pix
2207		System::Call "User32::SetWindowPos(i $mui.ComponentsPage.Components, i 0, i $1, i $2, i $3, i $4, i 64)" ;# 1032
2208
2209		Pop $7
2210		Pop $6
2211		Pop $5
2212		Pop $4
2213		Pop $3
2214		Pop $2
2215		Pop $1
2216		Pop $0
2217	FunctionEnd
2218
2219;--------------------------------
2220;# Page_Components_Leave
2221	Function Page_Components_Leave
2222		${IfNot} ${SectionIsSelected} ${SecSetConfig}
2223			StrCpy $Skip_Page_SetConfig 1
2224		${Else}
2225			StrCpy $Skip_Page_SetConfig 0
2226		${EndIf}
2227
2228		${IfNot} ${SectionIsSelected} ${SecShortcutStartmenu}
2229			StrCpy $Skip_Page_Startmenu 1
2230		${Else}
2231			StrCpy $Skip_Page_Startmenu 0
2232		${EndIf}
2233	FunctionEnd
2234*/
2235;--------------------------------
2236;# Page_Directory_Pre
2237	Function Page_Directory_Pre
2238		${If} $Skip_Page_Directory == 1
2239			Abort
2240		${EndIf}
2241	FunctionEnd
2242
2243;--------------------------------
2244;# Page_Directory_Leave
2245	Function Page_Directory_Leave
2246		GetInstDirError $R0
2247		${If} $R0 > 0 ;# Invalid path entered
2248			MessageBox MB_OK|MB_ICONSTOP "$(Msg_Path_Invalid)"
2249			Abort
2250		${EndIf}
2251
2252                ${If} $INSTALL_TYPE == 4
2253		${AndIf} ${FileExists} "$INSTDIR\opencpn.exe"
2254			MessageBox MB_OK|MB_ICONSTOP "$(Msg_Path_Installation_Exists)"
2255			Abort
2256		${EndIf}
2257	FunctionEnd
2258
2259
2260
2261
2262
2263/*
2264;--------------------------------
2265;# Page_Startmenu_Pre
2266	Function Page_Startmenu_Pre
2267		${If} $Skip_Page_Startmenu == 1
2268			Abort
2269		${EndIf}
2270
2271		${If} $INSTALL_TYPE == 1
2272		${OrIf} $INSTALL_TYPE == 2
2273		${OrIf} $INSTALL_TYPE == 3
2274			ReadRegStr $0 HKLM "$Prev_Install_RegKey" "StartMenuFolder"
2275			StrCpy $STARTMENU_FOLDER $0
2276		${EndIf}
2277	FunctionEnd
2278*/
2279;--------------------------------
2280/*# Page_SetConfig
2281	Var Label_SetConfig
2282	Var GroupBox_Language_SetConfig
2283	Var CheckBox_Language_SetConfig
2284	Var GroupBox_ChartDir_SetConfig
2285	Var DirRequest_SetConfig
2286	Var Button_Delete_SetConfig
2287	Var Button_DeleteAll_SetConfig
2288	Var Button_Add_SetConfig
2289	Var ListBox_SetConfig
2290*/
2291
2292/*
2293	Function Page_SetConfig
2294		${If} $Skip_Page_SetConfig == 1
2295			Abort
2296		${EndIf}
2297		!insertmacro MUI_HEADER_TEXT $(Page_SetConfig_Title) $(Page_SetConfig_Subtitle)
2298		nsDialogs::Create /NOUNLOAD 1018
2299		Pop $0
2300		${If} $0 == error
2301			Abort
2302		${EndIf}
2303
2304		${NSD_CreateLabel} 0 0 100% 16u "$(Label_SetConfig_Text)"
2305		Pop $Label_SetConfig
2306
2307		${NSD_CreateGroupBox} 0 20u 100% 30u "$(GB_Language_SetConfig_Text)"
2308		Pop $GroupBox_Language_SetConfig
2309
2310		${NSD_CreateCheckBox} 10u 35u 100% 10u "$(CB_Language_SetConfig_Text)"
2311		Pop $CheckBox_Language_SetConfig
2312		;StrCmp $CONFIG_SET_LANG "" cont
2313		${If} $CONFIG_SET_LANG == ""
2314			${NSD_SetState} $CheckBox_Language_SetConfig ${BST_CHECKED}
2315			Goto cont
2316		${EndIf}
2317
2318		StrCmp $CONFIG_SET_LANG 0 0 +2
2319		${NSD_SetState} $CheckBox_Language_SetConfig ${BST_UNCHECKED}
2320		StrCmp $CONFIG_SET_LANG 1 0 +2
2321		${NSD_SetState} $CheckBox_Language_SetConfig ${BST_CHECKED}
2322
2323		cont:
2324		${NSD_CreateGroupBox} 0 55u 100% 85u "$(GB_ChartDir_SetConfig_Text)"
2325		Pop $GroupBox_ChartDir_SetConfig
2326
2327		${NSD_CreateButton} 220u 70u 60u 15u "$(BT_Delete_SetConfig_Text)"
2328		Pop $Button_Delete_SetConfig
2329		GetFunctionAddress $0 Button_Delete_SetConfig_Click
2330		nsDialogs::OnClick /NOUNLOAD $Button_Delete_SetConfig $0
2331
2332		${NSD_CreateButton} 220u 88u 60u 15u "$(BT_DeleteAll_SetConfig_Text)"
2333		Pop $Button_DeleteAll_SetConfig
2334		GetFunctionAddress $0 Button_DeleteAll_SetConfig_Click
2335		nsDialogs::OnClick /NOUNLOAD $Button_DeleteAll_SetConfig $0
2336
2337		${NSD_CreateButton} 220u 115u 60u 15u "$(BT_Browse_SetConfig_Text)"
2338		Pop $Button_Add_SetConfig
2339		GetFunctionAddress $0 Button_Add_SetConfig_Click
2340		nsDialogs::OnClick /NOUNLOAD $Button_Add_SetConfig $0
2341
2342		${NSD_CreateListBox} 10u 70u 200u 60u $(LB_SetConfig)
2343		Pop $ListBox_SetConfig
2344		GetFunctionAddress $0 ListBox_SetConfig_Change
2345		nsDialogs::OnChange /NOUNLOAD $ListBox_SetConfig $0
2346		${IfNot} $CHART_DIR_EMPTY == 1
2347			SetShellVarContext all
2348			${If} ${FileExists} "$TEMP\opencpn_chart_dirs.tmp"
2349				ClearErrors
2350				FileOpen $R0 "$TEMP\opencpn_chart_dirs.tmp" r
2351				IfErrors end
2352				loop:
2353					ClearErrors
2354					FileReadUTF16LE $R0 $1
2355					IfErrors end
2356					${TrimNewLines} $1 $1
2357					SendMessage $ListBox_SetConfig ${LB_ADDSTRING} 0 "STR:$1"
2358					Goto loop
2359				end:
2360					FileClose $R0
2361			${ElseIf} $INI_EXISTS == 1
2362				StrCpy $R2 0
2363				loop2:
2364					IntOp $R2 $R2 + 1
2365					ReadINIStr $R1 "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" "ChartDirectories" "ChartDir$R2"
2366					StrCmp $R1 "" cont2
2367					${WordReplace} "$R1" "\\" "\" "+" $R3
2368					${Explode} $R4 "^" "$R3"
2369					Pop $R5
2370					StrCmp $R5 "" cont2
2371					SendMessage $ListBox_SetConfig ${LB_ADDSTRING} 0 "STR:$R5"
2372					Goto loop2
2373			${Else}
2374				ReadRegStr $0 HKLM "Software\OpenCPN" "ChartDirs"
2375				StrCmp $0 "" cont2
2376				${Explode} $3 ";" "$0"
2377				${For} $1 1 $3
2378					Pop $2
2379					${TrimNewLines} $2 $2
2380					SendMessage $ListBox_SetConfig ${LB_ADDSTRING} 0 "STR:$2"
2381				${Next}
2382			${EndIf}
2383		${EndIf}
2384
2385		cont2:
2386			Call ListBox_SetConfig_Change
2387			nsDialogs::Show
2388	FunctionEnd
2389
2390	Function Button_Delete_SetConfig_Click
2391		SendMessage $ListBox_SetConfig ${LB_GETCURSEL} 0 0 $0
2392		SendMessage $ListBox_SetConfig ${LB_DELETESTRING} $0 0
2393		Call ListBox_SetConfig_Change
2394	FunctionEnd
2395
2396	Function Button_DeleteAll_SetConfig_Click
2397		SendMessage $ListBox_SetConfig ${LB_RESETCONTENT} 0 0
2398		Call ListBox_SetConfig_Change
2399	FunctionEnd
2400
2401	Function Button_Add_SetConfig_Click
2402		Var /GLOBAL Initial_Dir
2403		StrCmp $Initial_Dir "" 0 +3
2404		SetShellVarContext all
2405		StrCpy $Initial_Dir "$DOCUMENTS"
2406		nsDialogs::SelectFolderDialog /NOUNLOAD "$(Select_Chart_Directory)" "$Initial_Dir"
2407		Pop $0
2408		${If} $0 == error
2409			Abort
2410		${EndIf}
2411		StrCpy $Initial_Dir $0
2412		${NSD_LB_GetCount} $ListBox_SetConfig $2
2413		${If} $2 > 0
2414			SendMessage $ListBox_SetConfig ${LB_FINDSTRINGEXACT} -1 "STR:$0" $6
2415			${IfNot} $6 < 0
2416				Goto end
2417			${EndIf}
2418		${EndIf}
2419		SendMessage $ListBox_SetConfig ${LB_ADDSTRING} 0 "STR:$0"
2420		end:
2421		Call ListBox_SetConfig_Change
2422	FunctionEnd
2423
2424	Function ListBox_SetConfig_Change
2425		${NSD_LB_GetCount} $ListBox_SetConfig $0
2426		${If} $0 > 0
2427			StrCpy $CHART_DIR_EMPTY 0
2428			${NSD_LB_GetSelection} $ListBox_SetConfig $1
2429			${If} $1 != ""
2430				EnableWindow $Button_Delete_SetConfig 1
2431			${Else}
2432				EnableWindow $Button_Delete_SetConfig 0
2433			${EndIf}
2434			EnableWindow $Button_DeleteAll_SetConfig 1
2435		${Else}
2436			EnableWindow $Button_Delete_SetConfig 0
2437			EnableWindow $Button_DeleteAll_SetConfig 0
2438			StrCpy $CHART_DIR_EMPTY 1
2439		${EndIf}
2440	FunctionEnd
2441
2442*/
2443/*
2444;--------------------------------
2445# Page_SetConfig_Leave
2446#	Var CHART_DIR_TMP_FILE
2447
2448	Function Page_SetConfig_Leave
2449		${NSD_LB_GetCount} $ListBox_SetConfig $0
2450		${If} $0 > 0
2451			ClearErrors
2452			FileOpen $R0 "$TEMP\opencpn_chart_dirs.tmp" w
2453			IfErrors done
2454			IntOp $0 $0 - 1
2455			${For} $1 0 $0
2456				SendMessage $ListBox_SetConfig ${LB_SETCURSEL} $1 0
2457				System::Call "User32::SendMessage(i $ListBox_SetConfig, i ${LB_GETTEXT}, i $1, t .r2)"
2458				FileWriteUTF16LE $R0 $2
2459				FileWriteUTF16LE $R0 "$\r$\n"
2460			${Next}
2461			FileClose $R0
2462			StrCpy $CHART_DIR_TMP_FILE 1
2463		${Else}
2464			StrCpy $CHART_DIR_EMPTY 1
2465		${EndIf}
2466
2467		done:
2468		${NSD_GetState} $CheckBox_Language_SetConfig $0
2469		${If} $0 == ${BST_CHECKED}
2470			StrCpy $CONFIG_SET_LANG 1
2471		${Else}
2472			StrCpy $CONFIG_SET_LANG 0
2473		${EndIf}
2474	FunctionEnd
2475*/
2476;--------------------------------
2477;# Page_Confirm
2478	Var Install_Options
2479	Var TEXT_INSTALL_OPTIONS
2480	Function Page_Confirm
2481		!insertmacro MUI_HEADER_TEXT $(Page_Confirm_Title) $(Page_Confirm_Subtitle)
2482		;# gather all installation settings and prepare (string) variable '$Install_Options' to display
2483		;# add the installation type to '$Install_Options'
2484		StrCpy $Install_Options "$(Installation_Type):$\r$\n"
2485		${If} $Skip_Page_TypeInst != 1
2486			${Switch} $INSTALL_TYPE
2487				${Case} 1
2488					StrCpy $Install_Options "$Install_Options$\t$(Type_Reinstall)"
2489					${Break}
2490				${Case} 2
2491					StrCpy $Install_Options "$Install_Options$\t$(Type_Upgrade)"
2492					${Break}
2493				${Case} 3
2494					StrCpy $Install_Options "$Install_Options$\t$(Type_Downgrade)"
2495					${Break}
2496				${Case} 4
2497					StrCpy $Install_Options "$Install_Options$\t$(Type_Parallel_Installation)"
2498					${Break}
2499				${Default}
2500					${Break}
2501			${EndSwitch}
2502		${Else}
2503			StrCpy $Install_Options "$Install_Options$\t$(Type_Fresh_Installation)"
2504		${EndIf}
2505
2506		;# add the installation directory to '$Install_Options'
2507		StrCpy $Install_Options "$Install_Options$\r$\n$\r$\n$(Installation_Directory):$\r$\n$\t$INSTDIR"
2508
2509/*
2510		;# add the delete config settings to '$Install_Options'
2511		${If} $CONFIG_EXISTS == 1
2512		${AndIf} $CONFIG_EMPTY != 1
2513			StrCpy $Install_Options "$Install_Options$\r$\n$\r$\n$(Installation_Delete_Config):"
2514			SectionGetFlags ${SecGrpResetConfig} $0
2515			SectionGetFlags ${SecGrpResetConfig} $1
2516			IntOp $0 $0 & ${SF_SELECTED}
2517			IntOp $1 $1 & ${SF_PSELECTED}
2518			StrCmp $0 0 +3 0
2519			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecGrpResetConfig_Text)"
2520			Goto cont
2521
2522			StrCmp $1 0 none_selected 0
2523			SectionGetFlags ${SecDeleteConfigFile} $0
2524			IntOp $0 $0 & ${SF_SELECTED}
2525			StrCmp $0 0 +2 0
2526			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteConfigFile_Text)"
2527			SectionGetFlags ${SecDeleteChartDB} $0
2528			IntOp $0 $0 & ${SF_SELECTED}
2529			StrCmp $0 0 +2 0
2530			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteChartDB_Text)"
2531			SectionGetFlags ${SecDeleteSENC} $0
2532			IntOp $0 $0 & ${SF_SELECTED}
2533			StrCmp $0 0 +2 0
2534			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteSENC_Text)"
2535			SectionGetFlags ${SecDeleteCM93} $0
2536			IntOp $0 $0 & ${SF_SELECTED}
2537			StrCmp $0 0 +2 0
2538			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteCM93_Text)"
2539			SectionGetFlags ${SecDeleteNavobjFile} $0
2540			IntOp $0 $0 & ${SF_SELECTED}
2541			StrCmp $0 0 +2 0
2542			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteNavobjFile_Text)"
2543			SectionGetFlags ${SecDeleteLogFile} $0
2544			IntOp $0 $0 & ${SF_SELECTED}
2545			StrCmp $0 0 +2 0
2546			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(SecDeleteLogFile_Text)"
2547			Goto cont
2548
2549			none_selected:
2550			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(text_none)"
2551
2552			cont:
2553		${EndIf}
2554*/
2555
2556/*
2557		;# add the shortcut settings to '$Install_Options'
2558		StrCpy $Install_Options "$Install_Options$\r$\n$\r$\n$(Create_Shortcuts):"
2559		SectionGetFlags ${SecShortcutStartmenu} $0
2560		IntOp $0 $0 & ${SF_SELECTED}
2561		${If} $0 != 0
2562			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(Create_Shortcut_Start_Menu): $STARTMENU_FOLDER"
2563			StrCpy $2 1
2564		${Else}
2565			StrCpy $2 0
2566		${EndIf}
2567
2568		SectionGetFlags ${SecShortcutDesktop} $0
2569		IntOp $0 $0 & ${SF_SELECTED}
2570		${If} $0 != 0
2571			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(Create_Shortcut_Desktop): $DESKTOP"
2572		${Else}
2573			StrCmp $2 0 0 +2
2574			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(text_none)"
2575		${EndIf}
2576*/
2577
2578/*
2579		;# add the pre-config settings to '$Install_Options'
2580		${IfNot} ${SectionIsReadOnly} ${SecSetConfig}
2581		${AndIf} ${SectionIsSelected} ${SecSetConfig}
2582			StrCpy $Install_Options "$Install_Options$\r$\n$\r$\n$(SecSetConfig_Text):"
2583			StrCmp $CONFIG_SET_LANG 1 0 +2
2584			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(CB_Language_SetConfig_Text)"
2585			StrCmp $CHART_DIR_TMP_FILE 1 0 end
2586			IfFileExists "$TEMP\opencpn_chart_dirs.tmp" 0 end
2587			StrCpy $Install_Options "$Install_Options$\r$\n$\t$(GB_ChartDir_SetConfig_Text)"
2588			ClearErrors
2589			FileOpen $0 "$TEMP\opencpn_chart_dirs.tmp" r
2590			IfErrors end
2591			${Do}
2592				FileReadUTF16LE $0 $1
2593				IfErrors done
2594				${TrimNewLines} $1 $1
2595				StrCmp $1 "" +2
2596				StrCpy $Install_Options "$Install_Options$\r$\n$\t - $1"
2597			${Loop}
2598			done:
2599			FileClose $0
2600			end:
2601		${EndIf}
2602		;# end '$Install_Options'
2603*/
2604		nsDialogs::Create /NOUNLOAD 1018
2605		Pop $0
2606		${If} $0 == error
2607			Abort
2608		${EndIf}
2609
2610		nsDialogs::CreateControl EDIT "${__NSD_Text_STYLE}|${WS_VSCROLL}|${WS_HSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN}|${ES_READONLY}" "${__NSD_Text_EXSTYLE}" 0 0 100% 100% "$Install_Options"
2611		Pop $TEXT_INSTALL_OPTIONS
2612
2613		nsDialogs::Show
2614	FunctionEnd
2615
2616;# Page_Instfiles_Show
2617	Function Page_Instfiles_Show
2618		w7tbp::Start
2619	FunctionEnd
2620
2621;--------------------------------
2622;##################################################################################################
2623;#                                  General Installer Functions                                   #
2624;##################################################################################################
2625Function GetAllUsers
2626	ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
2627	System::Call 'netapi32::NetUserEnum(w "\\$0",i 0,i 2,*i .R0,i ${NSIS_MAX_STRLEN}, *i .R1,*i .R2,*i .r1)i .r2'
2628	StrCpy $R8 $R0
2629	IntOp $R2 $R2 - 1
2630	${ForEach} $9 0 $R2 + 1
2631		System::Call "*$R0(w.R9)"
2632		MessageBox MB_OK "[$R9]"
2633		IntOp $R0 $R0 + 4
2634	${Next}
2635	System::Call 'netapi32.dll::NetApiBufferFree(i R8)i .R1'
2636FunctionEnd
2637
2638
2639Function Hide_SecGrpResetConfig
2640	Push $0
2641	!insertmacro ClearSectionFlag ${SecDeleteConfigFile} ${SF_SELECTED}
2642	SectionSetText ${SecDeleteConfigFile} ""
2643	!insertmacro ClearSectionFlag ${SecDeleteChartDB} ${SF_SELECTED}
2644	SectionSetText ${SecDeleteChartDB} ""
2645	!insertmacro ClearSectionFlag ${SecDeleteSENC} ${SF_SELECTED}
2646	SectionSetText ${SecDeleteSENC} ""
2647	!insertmacro ClearSectionFlag ${SecDeleteCM93} ${SF_SELECTED}
2648	SectionSetText ${SecDeleteCM93} ""
2649	!insertmacro ClearSectionFlag ${SecDeleteNavobjFile} ${SF_SELECTED}
2650	SectionSetText ${SecDeleteNavobjFile} ""
2651	!insertmacro ClearSectionFlag ${SecDeleteLogFile} ${SF_SELECTED}
2652	SectionSetText ${SecDeleteLogFile} ""
2653	!insertmacro ClearSectionFlag ${SecGrpResetConfig} ${SF_SECGRP}
2654	!insertmacro ClearSectionFlag ${SecGrpResetConfig} ${SF_SELECTED}
2655	SectionSetFlags ${SecGrpResetConfig} 0
2656	SectionSetText ${SecGrpResetConfig} ""
2657	IntOp $0 ${SecDeleteLogFile} + 1
2658	!insertmacro ClearSectionFlag $0 ${SF_SECGRPEND}
2659	SectionSetText $0 ""
2660	Pop $0
2661FunctionEnd
2662
2663
2664Function Check_Config_Exists
2665	;# Look for config dir ("%APPDATA%\opencpn) and the several config files
2666	SetShellVarContext all
2667
2668	${IfNot} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
2669		${If} ${FileExists} "$USERS_APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
2670			CreateDirectory "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
2671			Sleep 250
2672			AccessControlW::GrantOnFile "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@" "(BU)" "GenericRead + GenericExecute + GenericWrite + Delete + FullAccess"
2673			CopyFiles /SILENT "$USERS_APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*" "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
2674		${ElseIf} ${FileExists} "$ADMIN_APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
2675			CreateDirectory "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
2676			Sleep 250
2677			AccessControlW::GrantOnFile "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@" "(BU)" "GenericRead + GenericExecute + GenericWrite + Delete + FullAccess"
2678			CopyFiles /SILENT "$ADMIN_APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*" "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@"
2679		${EndIf}
2680
2681		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
2682			DeleteINISec "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" Directories
2683		${EndIf}
2684	${EndIf}
2685
2686	${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\*.*"
2687		StrCpy $CONFIG_EXISTS 1
2688		SectionSetText ${SecGrpResetConfig} $(SecGrpResetConfig_Text)
2689	${EndIf}
2690	StrCpy $Count_SecGrpResetConfig 0
2691	${If} $CONFIG_EXISTS == 1
2692		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
2693			StrCpy $INI_EXISTS 1
2694			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2695			SectionSetText ${SecDeleteConfigFile} $(SecDeleteConfigFile_Text)
2696		${Else}
2697			!insertmacro ClearSectionFlag ${SecDeleteConfigFile} ${SF_SELECTED}
2698			SectionSetText ${SecDeleteConfigFile} ""
2699		${EndIf}
2700
2701		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\CHRTLIST.DAT"
2702			StrCpy $CHARTDB_EXISTS 1
2703			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2704			SectionSetText ${SecDeleteChartDB} $(SecDeleteChartDB_Text)
2705		${Else}
2706			!insertmacro ClearSectionFlag ${SecDeleteChartDB} ${SF_SELECTED}
2707			SectionSetText ${SecDeleteChartDB} ""
2708		${EndIf}
2709
2710		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\SENC\*.*"
2711			StrCpy $SENC_EXISTS 1
2712			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2713			SectionSetText ${SecDeleteSENC} $(SecDeleteSENC_Text)
2714		${Else}
2715			!insertmacro ClearSectionFlag ${SecDeleteSENC} ${SF_SELECTED}
2716			SectionSetText ${SecDeleteSENC} ""
2717		${EndIf}
2718
2719		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\cm93\*.*"
2720			StrCpy $CM93_EXISTS 1
2721			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2722			SectionSetText ${SecDeleteCM93} $(SecDeleteCM93_Text)
2723		${Else}
2724			!insertmacro ClearSectionFlag ${SecDeleteCM93} ${SF_SELECTED}
2725			SectionSetText ${SecDeleteCM93} ""
2726		${EndIf}
2727
2728		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\navobj.xml"
2729			StrCpy $NAVOBJ_EXISTS 1
2730			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2731			SectionSetText ${SecDeleteNavobjFile} $(SecDeleteNavobjFile_Text)
2732		${Else}
2733			!insertmacro ClearSectionFlag ${SecDeleteNavobjFile} ${SF_SELECTED}
2734			SectionSetText ${SecDeleteNavobjFile} ""
2735		${EndIf}
2736
2737		${If} ${FileExists} "$APPDATA\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.log"
2738			StrCpy $LOG_EXISTS 1
2739			IntOp $Count_SecGrpResetConfig $Count_SecGrpResetConfig + 1
2740			SectionSetText ${SecDeleteLogFile} $(SecDeleteLogFile_Text)
2741		${Else}
2742			!insertmacro ClearSectionFlag ${SecDeleteLogFile} ${SF_SELECTED}
2743			SectionSetText ${SecDeleteLogFile} ""
2744		${EndIf}
2745
2746		${If} $Count_SecGrpResetConfig == 0
2747			StrCpy $CONFIG_EMPTY 1
2748		${EndIf}
2749
2750		!insertmacro ClearSectionFlag ${SecSetConfig} ${SF_SELECTED}
2751		IntOp $0 ${SF_RO} | ${SF_BOLD}
2752		SectionSetFlags ${SecSetConfig} $0
2753		;SectionSetFlags ${SecSetConfig} ${SF_RO}
2754		StrCpy $SetConfig 0
2755	${EndIf}
2756FunctionEnd
2757
2758
2759Function Reg_Scan_Old_Versions_HKLM
2760	;# Registry look-up
2761	;# Versions prior to 2.2.727 write RegKey "OpenCPN_is1" to "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall"
2762	ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1 "DisplayName"
2763	${If} $0 != ""
2764		${StrFilter} "$0" "31" "." " " $1
2765		StrCpy $LM_VERSION "$1"
2766		ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1 "UninstallString"
2767		${StrFilter} "$0" "" "" "$\"" $2
2768		${If} ${FileExists} "$2"
2769			ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1 "QuietUninstallString"
2770			${StrFilter} "$0" "" "" "$\"" $3
2771			StrCpy $LM_VERSION_UNINST $3
2772			ReadRegStr $4 HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1 "InstallLocation"
2773			${TrimNewLines} $4 $4
2774			${If} ${FileExists} "$4opencpn.exe"
2775			${AndIf} ${FileExists} "$4unins*.exe"
2776				;# check if last character of $4 is a "\" and if so remove it
2777				${RIndexOf} $6 "$4" "\"
2778				${If} $6 == 1
2779					${WordReplace} "$4" "\" "" "-1" $4
2780				${EndIf}
2781
2782				StrCpy $LM_VERSION_INST $4
2783				IntOp $OLD_INSTALLS $OLD_INSTALLS + 1
2784				;StrCpy $VERSION_NEWER 1
2785			${Else}
2786				DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN_is1"
2787				StrCpy $LM_VERSION ""
2788				StrCpy $LM_VERSION_UNINST ""
2789			${EndIf}
2790		${EndIf}
2791	${EndIf}
2792FunctionEnd
2793
2794
2795Function EnumProfileList
2796	${EnumHKU} Callback_EnumProfileList opencpn-inst-tmp-sid
2797FunctionEnd
2798
2799
2800Function Callback_EnumProfileList
2801	;# Get the SID or tmpkey from the stack
2802	Pop $SID
2803	ClearErrors
2804	${If} ${FileExists} "$TEMP\opencpn_users_sid.tmp"
2805		FileOpen $R0 "$TEMP\opencpn_users_sid.tmp" a
2806		FileSeek $R0 0 END
2807	${Else}
2808		FileOpen $R0 "$TEMP\opencpn_users_sid.tmp" w
2809	${EndIf}
2810
2811	IfErrors done
2812	FileWriteUTF16LE $R0 "$SID"
2813	FileWriteUTF16LE $R0 "$\r$\n"
2814	FileWriteUTF16LE $R0 "$USERPROFILE"
2815	FileWriteUTF16LE $R0 "$\r$\n"
2816	FileClose $R0
2817	done:
2818FunctionEnd
2819
2820
2821Function Get_Users_Values
2822	Var /GLOBAL tmp_file_handle
2823	StrCpy $SID ""
2824	ClearErrors
2825	${If} ${FileExists} "$TEMP\opencpn_users_sid.tmp"
2826		FileOpen $tmp_file_handle "$TEMP\opencpn_users_sid.tmp" r
2827		IfErrors end
2828		${Do}
2829			FileReadUTF16LE $tmp_file_handle $SID
2830			FileReadUTF16LE $tmp_file_handle $USERPROFILE
2831			StrCmp $SID "" done
2832			${TrimNewLines} $SID $SID
2833			${TrimNewLines} $USERPROFILE $USERPROFILE
2834			;# List of functions to call
2835			Call Users_Appdata_Paths
2836			Call Users_StartMenu_Paths
2837			Call Users_Desktop_Paths
2838			Call Users_Personal_Paths
2839			Call Reg_Scan_Old_Versions_HKCU
2840		${Loop}
2841		done:
2842		FileClose $tmp_file_handle
2843		StrCpy $SID ""
2844		StrCpy $USERPROFILE ""
2845	${EndIf}
2846	end:
2847FunctionEnd
2848
2849
2850Function Users_Appdata_Paths
2851	ReadRegStr $1 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" AppData
2852	${WordReplace} "$1" "%USERPROFILE%" "$USERPROFILE" "+" $2
2853	ExpandEnvStrings $2 $2
2854	StrCmp $2 "" done
2855
2856	StrCpy $5 "none"
2857	;# check if an OpenCPN config folder exists in the given path
2858	${If} ${FileExists} "$2\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini"
2859		ReadINIStr $3 "$2\@CPACK_NSIS_PACKAGE_NAME_LC@\opencpn.ini" Directories S57DataLocation
2860		${WordReplace} "$3" "\\" "\" "+" $4
2861		${WordFind} "$4" "\" "-2{*" $5
2862		StrCmp $5 "" 0 +2
2863		StrCpy $5 "none"
2864	${EndIf}
2865
2866	ClearErrors
2867	${If} ${FileExists} "$TEMP\opencpn_appdata.tmp"
2868		FileOpen $R0 "$TEMP\opencpn_appdata.tmp" a
2869		FileSeek $R0 0 END
2870	${Else}
2871		FileOpen $R0 "$TEMP\opencpn_appdata.tmp" w
2872	${EndIf}
2873	IfErrors done
2874	FileWriteUTF16LE $R0 "$SID"
2875	FileWriteUTF16LE $R0 "$\r$\n"
2876	FileWriteUTF16LE $R0 "$2"
2877	FileWriteUTF16LE $R0 "$\r$\n"
2878	FileWriteUTF16LE $R0 "$5"
2879	FileWriteUTF16LE $R0 "$\r$\n"
2880	FileClose $R0
2881	done:
2882FunctionEnd
2883
2884
2885Function Users_Personal_Paths
2886	ReadRegStr $1 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" Personal
2887	${WordReplace} "$1" "%USERPROFILE%" "$USERPROFILE" "+" $2
2888	ExpandEnvStrings $2 $2
2889
2890	ClearErrors
2891	${If} ${FileExists} "$TEMP\opencpn_personal.tmp"
2892		FileOpen $R0 "$TEMP\opencpn_personal.tmp" a
2893		IfErrors done
2894		FileSeek $R0 0 END
2895	${Else}
2896		FileOpen $R0 "$TEMP\opencpn_personal.tmp" w
2897		IfErrors done
2898	${EndIf}
2899
2900	FileWriteUTF16LE $R0 "$SID"
2901	FileWriteUTF16LE $R0 "$\r$\n"
2902	FileWriteUTF16LE $R0 "$2"
2903	FileWriteUTF16LE $R0 "$\r$\n"
2904	FileClose $R0
2905	done:
2906FunctionEnd
2907
2908
2909Function Users_StartMenu_Paths
2910	ReadRegStr $1 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" "Start Menu"
2911	${WordReplace} "$1" "%USERPROFILE%" "$USERPROFILE" "+" $2
2912	ExpandEnvStrings $2 $2
2913
2914	ClearErrors
2915	${If} ${FileExists} "$TEMP\opencpn_startmenu.tmp"
2916		FileOpen $R0 "$TEMP\opencpn_startmenu.tmp" a
2917		FileSeek $R0 0 END
2918	${Else}
2919		FileOpen $R0 "$TEMP\opencpn_startmenu.tmp" w
2920	${EndIf}
2921	IfErrors done
2922	FileWriteUTF16LE $R0 "$SID"
2923	FileWriteUTF16LE $R0 "$\r$\n"
2924	FileWriteUTF16LE $R0 "$2"
2925	FileWriteUTF16LE $R0 "$\r$\n"
2926	FileClose $R0
2927	done:
2928FunctionEnd
2929
2930
2931Function Users_Desktop_Paths
2932	ReadRegStr $1 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" Desktop
2933	${WordReplace} "$1" "%USERPROFILE%" "$USERPROFILE" "+" $2
2934	ExpandEnvStrings $2 $2
2935
2936	ClearErrors
2937	${If} ${FileExists} "$TEMP\opencpn_desktop.tmp"
2938		FileOpen $R0 "$TEMP\opencpn_desktop.tmp" a
2939		FileSeek $R0 0 END
2940	${Else}
2941		FileOpen $R0 "$TEMP\opencpn_desktop.tmp" w
2942	${EndIf}
2943	IfErrors done
2944	FileWriteUTF16LE $R0 "$SID"
2945	FileWriteUTF16LE $R0 "$\r$\n"
2946	FileWriteUTF16LE $R0 "$2"
2947	FileWriteUTF16LE $R0 "$\r$\n"
2948	FileClose $R0
2949	done:
2950FunctionEnd
2951
2952
2953;Var latest_version
2954;Var latest_pathexe
2955Function Reg_Scan_Old_Versions_HKCU
2956	;# Versions from 2.2.727 up to 2.2.xxxx write RegKey "OpenCPN" to "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
2957	;# and also RegKey "OpenCPN <version>" to "HKCU\Software\opencpn.org\"
2958	;# Find latest installed version => it's the one found in "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN"
2959
2960	ReadRegStr $0 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN" "DisplayVersion"
2961	${If} $0 != ""
2962		StrCpy $latest_version $0
2963		ReadRegStr $0 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN" "DisplayIcon"
2964		StrCpy $latest_pathexe $0
2965		ReadRegStr $0 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN" "UninstallString"
2966		;StrCpy $CU_VERSION_UNINST $0
2967		${WordFind} "$0" "\" "-2{*" $1
2968		${If} ${FileExists} "$1\opencpn.exe"
2969		${AndIf} ${FileExists} "$1\unins*.exe"
2970			ClearErrors
2971			${If} ${FileExists} "$TEMP\opencpn_old_uninstall_regkeys.tmp"
2972				FileOpen $R0 "$TEMP\opencpn_old_uninstall_regkeys.tmp" a
2973				FileSeek $R0 0 END
2974			${Else}
2975				FileOpen $R0 "$TEMP\opencpn_old_uninstall_regkeys.tmp" w
2976			${EndIf}
2977
2978			IfErrors done
2979			FileWriteUTF16LE $R0 "$SID$\r$\n"
2980			FileWriteUTF16LE $R0 "$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN$\r$\n"
2981			FileWriteUTF16LE $R0 "$1$\r$\n"
2982			FileClose $R0
2983		${Else}
2984			DeleteRegKey HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenCPN"
2985		${EndIf}
2986	${EndIf}
2987
2988	done:
2989	ClearErrors
2990	${Do}
2991		Pop $0
2992		IfErrors empty
2993	${Loop}
2994	empty:
2995	StrCpy $0 0
2996	StrCpy $1 ""
2997	${Do}
2998		EnumRegKey $1 HKU "$SID\Software\opencpn.org" $0
2999		StrCmp $1 "" done1
3000		IntOp $0 $0 + 1
3001		Push $1
3002	${Loop}
3003	done1:
3004	${If} $0 > 0
3005		ClearErrors
3006		${If} ${FileExists} "$TEMP\opencpn_old_installs.tmp"
3007			FileOpen $R0 "$TEMP\opencpn_old_installs.tmp" a
3008			FileSeek $R0 0 END
3009		${Else}
3010			FileOpen $R0 "$TEMP\opencpn_old_installs.tmp" w
3011		${EndIf}
3012		IfErrors done2
3013		${Do}
3014			Pop $R1
3015			IfErrors finished
3016			${StrFilter} "$R1" "31" "." " " $R2 ;# R2 = version
3017			;StrCpy $CU_VERSION $R2
3018			ReadRegStr $R3 HKU "$SID\Software\opencpn.org\$R1" "" ;# R3 = install path
3019			ReadRegStr $R4 HKU "$SID\Software\opencpn.org\$R1" "Start Menu Folder" ;# R4 = Start Menu Folder
3020			ReadRegStr $R5 HKU "$SID\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" "Start Menu" ;# R5 = Start Menu Path
3021			${WordReplace} "$R5" "%USERPROFILE%" "$USERPROFILE" "+" $R5
3022			ExpandEnvStrings $R5 $R5
3023			;StrCpy $CU_VERSION_INST "$R3\"
3024			${If} "$R3\opencpn.exe" == $latest_pathexe
3025			${AndIf} $R2 != $latest_version
3026				DeleteRegKey HKU "$SID\Software\opencpn.org\$R1"
3027			${ElseIf} ${FileExists} "$R3\opencpn.exe"
3028			${AndIf} ${FileExists} "$R3\unins*.exe"
3029				FileWriteUTF16LE $R0 "$SID\Software\opencpn.org\$R1"
3030				FileWriteUTF16LE $R0 "$\r$\n"
3031				FileWriteUTF16LE $R0 "$R5\$R4"
3032				FileWriteUTF16LE $R0 "$\r$\n"
3033				FileWriteUTF16LE $R0 "$R3"
3034				FileWriteUTF16LE $R0 "$\r$\n"
3035				IntOp $OLD_INSTALLS $OLD_INSTALLS + 1
3036				;StrCpy $VERSION_NEWER 1
3037			${Else}
3038				DeleteRegKey HKU "$SID\Software\opencpn.org\$R1"
3039				DeleteRegKey /ifempty HKU "$SID\Software\opencpn.org"
3040			${EndIf}
3041		${Loop}
3042		finished:
3043		FileClose $R0
3044	${Else}
3045		DeleteRegKey HKU "$SID\Software\opencpn.org"
3046	${EndIf}
3047
3048	done2:
3049	StrCpy $latest_version ""
3050	StrCpy $latest_pathexe ""
3051FunctionEnd
3052
3053
3054Function Quick_Scan_Old_Versions
3055  ;# Scan the given Drive for file "opencpn.exe"
3056	${If} ${FileExists} "$TEMP\opencpn_personal.tmp"
3057		ClearErrors
3058		FileOpen $R0 "$TEMP\opencpn_personal.tmp" r
3059		IfErrors end
3060		${Do}
3061			FileReadUTF16LE $R0 $R1
3062			FileReadUTF16LE $R0 $R2
3063			IfErrors done
3064			StrCmp $R2 "" done
3065			${TrimNewLines} $R2 $R2
3066			${Locate} "$R2" "/L=F /M=opencpn.exe" "Found_OpenCPN_Installation"
3067		${Loop}
3068		done:
3069		FileClose $R0
3070	${EndIf}
3071
3072	end:
3073	${Locate} "$PROGRAMFILES" "/L=F /M=opencpn.exe" "Found_OpenCPN_Installation"
3074FunctionEnd
3075
3076
3077Function Found_OpenCPN_Installation
3078	Push $R0
3079	Push $R1
3080	${If} ${FileExists} "$R8\unins*.exe"
3081		${If} ${FileExists} "$TEMP\opencpn_prev_installs.tmp"
3082			ClearErrors
3083			FileOpen $R1 "$TEMP\opencpn_prev_installs.tmp" r
3084			IfErrors cont
3085			${Do}
3086				FileReadUTF16LE $R1 $R2
3087				FileReadUTF16LE $R1 $R3
3088				StrCmp $R2 "" done
3089				${TrimNewLines} $R2 $R2
3090				${TrimNewLines} $R3 $R3
3091				StrCmp $R3 $R8 found
3092			${LoopUntil} $R2 == ""
3093			done:
3094			FileClose $R1
3095			Goto cont
3096
3097			found:
3098			FileClose $R1
3099			Goto end
3100		${EndIf}
3101
3102		cont:
3103		IntOp $counter_tmp $counter_tmp + 1
3104		ClearErrors
3105		${IfNot} ${FileExists} "$TEMP\opencpn_hdd_quick_scan.tmp"
3106			FileOpen $R0 "$TEMP\opencpn_hdd_quick_scan.tmp" w
3107			IfErrors end
3108		${Else}
3109			FileOpen $R0 "$TEMP\opencpn_hdd_quick_scan.tmp" a
3110			IfErrors end
3111			FileSeek $R0 0 END
3112		${EndIf}
3113
3114		FileWriteUTF16LE $R0 "$R8"
3115		FileWriteUTF16LE $R0 "$\r$\n"
3116		FileClose $R0
3117	${EndIf}
3118
3119	end:
3120	Pop $R1
3121	Pop $R0
3122	Push $0
3123FunctionEnd
3124
3125
3126;Var counter_tmp
3127Function Full_Scan_Old_Versions
3128  ;# Get all HDD Drive Letters on the system
3129	StrCpy $counter_tmp 0
3130	${GetDrives} "HDD" "Scan_Drive"
3131FunctionEnd
3132
3133
3134Function Scan_Drive
3135  ;# Scan the given Drive for file "opencpn.exe"
3136	/*;#DEBUG - scan only crtain drives
3137	${IfNot} $9 == "D:\"
3138	;${AndIfNot} $9 == "F:\"
3139		Goto end
3140	${EndIf}
3141	;#DEBUG End */
3142	StrCpy $3 "$(Banner_Scan_Drive)"
3143	GetDlgItem $2 $Banner_Handle 76
3144	SendMessage $2 ${WM_SETTEXT} 0 "STR:$3"
3145	${Locate} "$9" "/L=F /M=opencpn.exe" "Found_OCPN_Exe"
3146	end:
3147	Push $0
3148FunctionEnd
3149
3150
3151Function Found_OCPN_Exe
3152	Push $1
3153	ClearErrors
3154	StrCpy $1 0
3155	StrCpy $2 0
3156	${WordFind} "$R8" "\RECYCLER\" "E*" $1
3157	${WordFind} "$R8" "\$$Recycle.Bin" "E*" $2
3158	IfErrors 0 cont1
3159	${If} $1 == 1
3160	${AndIf} $2 == 1
3161		Goto cont2
3162	${EndIf}
3163
3164	cont1:
3165	${If} $1 > 0
3166	${OrIf} $2 > 0
3167		Goto end
3168	${EndIf}
3169
3170	cont2:
3171	${If} ${FileExists} "$R8\unins*.exe"
3172		${If} ${FileExists} "$TEMP\opencpn_prev_installs.tmp"
3173			ClearErrors
3174			FileOpen $R1 "$TEMP\opencpn_prev_installs.tmp" r
3175			IfErrors cont3
3176			${Do}
3177				FileReadUTF16LE $R1 $R2
3178				FileReadUTF16LE $R1 $R3
3179				StrCmp $R2 "" done
3180				${TrimNewLines} $R2 $R2
3181				${TrimNewLines} $R3 $R3
3182				StrCmp $R3 $R8 found
3183			${LoopUntil} $R2 == ""
3184			done:
3185			FileClose $R1
3186			Goto cont3
3187
3188			found:
3189			FileClose $R1
3190			Goto end
3191		${EndIf}
3192
3193		cont3:
3194		IntOp $counter_tmp $counter_tmp + 1
3195		GetDlgItem $2 $Banner_Handle 1030
3196		StrCmp $counter_tmp 1 0 +3
3197		StrCpy $R4 "$(Banner_Installation_Found_Singular)"
3198		Goto +2
3199		StrCpy $R4 "$(Banner_Installation_Found_Plural)"
3200		SendMessage $2 ${WM_SETTEXT} 0 "STR:$R4"
3201		SendMessage $ListBox_CleanUp ${LB_ADDSTRING} 0 "STR:$R8"
3202		ClearErrors
3203		${IfNot} ${FileExists} "$TEMP\opencpn_hdd_full_scan.tmp"
3204			FileOpen $R0 "$TEMP\opencpn_hdd_full_scan.tmp" w
3205			IfErrors end
3206		${Else}
3207			FileOpen $R0 "$TEMP\opencpn_hdd_full_scan.tmp" a
3208			IfErrors end
3209			FileSeek $R0 0 END
3210		${EndIf}
3211
3212		FileWriteUTF16LE $R0 "$R8"
3213		FileWriteUTF16LE $R0 "$\r$\n"
3214		FileClose $R0
3215		end:
3216	${EndIf}
3217	Pop $1
3218	Push $0
3219FunctionEnd
3220
3221
3222Function Delete_Installation_Dir
3223	StrCmp $Uninstall_Path_Tmp "" end
3224	;# Check subdirs and remove them recursive ...
3225	${If} ${FileExists} "$Uninstall_Path_Tmp\doc\*.*"
3226		RMDir /r "$Uninstall_Path_Tmp\doc"
3227	${EndIf}
3228
3229	${If} ${FileExists} "$Uninstall_Path_Tmp\lang\*.*"
3230		RMDir /r "$Uninstall_Path_Tmp\lang"
3231	${EndIf}
3232
3233	${If} ${FileExists} "$Uninstall_Path_Tmp\Microsoft.VC80.CRT\*.*"
3234		RMDir /r "$Uninstall_Path_Tmp\Microsoft.VC80.CRT"
3235	${EndIf}
3236
3237	${If} ${FileExists} "$Uninstall_Path_Tmp\s57data\*.*"
3238		RMDir /r "$Uninstall_Path_Tmp\s57data"
3239	${EndIf}
3240
3241	${If} ${FileExists} "$Uninstall_Path_Tmp\sounds\*.*"
3242		RMDir /r "$Uninstall_Path_Tmp\sounds"
3243	${EndIf}
3244
3245	${If} ${FileExists} "$Uninstall_Path_Tmp\TCDATA\*.*"
3246		RMDir /r "$Uninstall_Path_Tmp\TCDATA"
3247	${EndIf}
3248
3249	${If} ${FileExists} "$Uninstall_Path_Tmp\gshhs\*.*"
3250		RMDir /r "$Uninstall_Path_Tmp\gshhs"
3251	${EndIf}
3252
3253	${If} ${FileExists} "$Uninstall_Path_Tmp\plugins\*.*"
3254		RMDir /r "$Uninstall_Path_Tmp\plugins"
3255	${EndIf}
3256
3257	${If} ${FileExists} "$Uninstall_Path_Tmp\share\*.*"
3258		RMDir /r "$Uninstall_Path_Tmp\share"
3259	${EndIf}
3260
3261	;# Check files and delete them ...
3262	${If} ${FileExists} "$Uninstall_Path_Tmp\opencpn.exe"
3263		Delete "$Uninstall_Path_Tmp\opencpn.exe"
3264	${EndIf}
3265
3266	${If} ${FileExists} "$Uninstall_Path_Tmp\license.txt"
3267		Delete "$Uninstall_Path_Tmp\license.txt"
3268	${EndIf}
3269
3270	${If} ${FileExists} "$Uninstall_Path_Tmp\unins000.dat"
3271		Delete "$Uninstall_Path_Tmp\unins000.dat"
3272	${EndIf}
3273
3274	${If} ${FileExists} "$Uninstall_Path_Tmp\unins000.exe"
3275		Delete "$Uninstall_Path_Tmp\unins000.exe"
3276	${EndIf}
3277
3278	${If} ${FileExists} "$Uninstall_Path_Tmp\install.log"
3279		Delete "$Uninstall_Path_Tmp\install.log"
3280	${EndIf}
3281
3282	${If} ${FileExists} "$Uninstall_Path_Tmp\install.log"
3283		Delete "$Uninstall_Path_Tmp\install.log"
3284	${EndIf}
3285
3286	Push $0
3287	Push $1
3288	Push $2
3289	Push $R9
3290	Push $R8
3291	Push $R7
3292	Push $R6
3293	;# Find the Uninstall file
3294	${Locate} "$Uninstall_Path_Tmp" "/L=F /M=Uninstall*.exe /G=0" "Delete_Located_File_Single"
3295	;# Find the wx.. DLLs
3296	${Locate} "$Uninstall_Path_Tmp" "/L=F /M=wx*.dll /G=0" "Delete_Located_File_Multi"
3297	;# Dummy call of Locate as it does not properly close its handle and so the dir cannot be deleted though it might be empty
3298	${Locate} "C:\" "/L=DE /M=*.* /G=0" "Dummy_Function"
3299
3300	;# Remove the installation dir ($Uninstall_Path_Tmp) if empty
3301	RMDir "$Uninstall_Path_Tmp"
3302	${If} ${FileExists} "$Uninstall_Path_Tmp\*.*"
3303		Sleep 250
3304		RMDir "$Uninstall_Path_Tmp"
3305	${EndIf}
3306
3307	Pop $R6
3308	Pop $R7
3309	Pop $R8
3310	Pop $R9
3311	Pop $2
3312	Pop $1
3313	Pop $0
3314	end:
3315FunctionEnd
3316	;# Helper-Functions for Delete_Installation_Dir
3317	Function Delete_Located_File_Single
3318		Delete "$R9"
3319		StrCpy $0 StopLocate
3320		Push $0
3321	FunctionEnd
3322
3323	Function Delete_Located_File_Multi
3324		Delete "$R9"
3325		Push $0
3326	FunctionEnd
3327
3328	Function Dummy_Function
3329		StrCpy $0 StopLocate
3330		Push $0
3331	FunctionEnd
3332	;# End Helper-Functions
3333
3334
3335Function ExecAppFile
3336    !insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\opencpn.exe' '' '$INSTDIR' ''
3337	loop:
3338    System::Call user32::GetForegroundWindow()i.r0
3339    Sleep 200
3340    IntCmpU $0 $hwndparent loop
3341FunctionEnd
3342
3343
3344Function DU2Pix
3345	Pop $4
3346	Pop $3
3347	Pop $2
3348	Pop $1
3349	IntOp $1 $1 * $BU_X
3350	IntOp $1 $1 / 4
3351	IntOp $2 $2 * $BU_Y
3352	IntOp $2 $2 / 8
3353	IntOp $3 $3 * $BU_X
3354	IntOp $3 $3 / 4
3355	IntOp $4 $4 * $BU_Y
3356	IntOp $4 $4 / 8
3357FunctionEnd
3358
3359
3360;!define LVM_GETITEMCOUNT 0x1004 ;# ANSI
3361;!define LVM_GETITEMTEXT 0x102D ;# ANSI
3362!define LVM_GETITEMCOUNT 0x1004
3363!define LVM_GETITEMTEXT 0x1073
3364
3365Function DumpLog
3366  Exch $5
3367  Push $0
3368  Push $1
3369  Push $2
3370  Push $3
3371  Push $4
3372  Push $6
3373
3374  FindWindow $0 "#32770" "" $HWNDPARENT
3375  GetDlgItem $0 $0 1016
3376  StrCmp $0 0 error
3377  FileOpen $5 $5 "w"
3378  FileWriteWord $5 0xfeff ; Write the BOM
3379  StrCmp $5 0 error
3380    SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
3381    System::StrAlloc ${NSIS_MAX_STRLEN}
3382    Pop $3
3383    StrCpy $2 0
3384    System::Call "*(i, i, i, i, i, i, i, i, i) i \
3385      (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
3386    loop: StrCmp $2 $6 done
3387      System::Call "User32::SendMessageW(i, i, i, i) i \
3388        ($0, ${LVM_GETITEMTEXT}, $2, r1)"
3389      System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
3390      FileWriteUTF16LE $5 "$4$\r$\n"
3391      IntOp $2 $2 + 1
3392      Goto loop
3393    done:
3394      FileClose $5
3395      System::Free $1
3396      System::Free $3
3397      Goto exit
3398  error:
3399    MessageBox MB_OK error
3400  exit:
3401    Pop $6
3402    Pop $4
3403    Pop $3
3404    Pop $2
3405    Pop $1
3406    Pop $0
3407    Exch $5
3408FunctionEnd
3409
3410
3411Function Write_Reg_ChartDirs
3412	ClearErrors
3413	FileOpen $R0 "$TEMP\opencpn_chart_dirs.tmp" r
3414	IfErrors end
3415	loop:
3416		FileReadUTF16LE $R0 $R1
3417		IfErrors done
3418		${TrimNewLines} $R1 $R1
3419		${If} $REG_CHARTDIRS == ""
3420			StrCpy $REG_CHARTDIRS "$R1"
3421		${Else}
3422			StrCpy $REG_CHARTDIRS "$REG_CHARTDIRS;$R1"
3423		${EndIf}
3424		Goto loop
3425	done:
3426		FileClose $R0
3427		WriteRegStr HKLM "Software\OpenCPN" "ChartDirs" $REG_CHARTDIRS
3428	end:
3429FunctionEnd
3430
3431
3432Function IndexOf
3433	Exch $R0
3434	Exch
3435	Exch $R1
3436	Push $R2
3437	Push $R3
3438
3439	StrCpy $R3 $R0
3440	StrCpy $R0 -1
3441	IntOp $R0 $R0 + 1
3442	StrCpy $R2 $R3 1 $R0
3443	StrCmp $R2 "" +2
3444	StrCmp $R2 $R1 +2 -3
3445
3446	StrCpy $R0 -1
3447
3448	Pop $R3
3449	Pop $R2
3450	Pop $R1
3451	Exch $R0
3452FunctionEnd
3453
3454
3455Function RIndexOf
3456	Exch $R0
3457	Exch
3458	Exch $R1
3459	Push $R2
3460	Push $R3
3461
3462	StrCpy $R3 $R0
3463	StrCpy $R0 0
3464	IntOp $R0 $R0 + 1
3465	StrCpy $R2 $R3 1 -$R0
3466	StrCmp $R2 "" +2
3467	StrCmp $R2 $R1 +2 -3
3468
3469	StrCpy $R0 -1
3470
3471	Pop $R3
3472	Pop $R2
3473	Pop $R1
3474	Exch $R0
3475FunctionEnd
3476
3477;##################################################################################################
3478;#                                   Uninstaller Functions                                        #
3479;##################################################################################################
3480;#  un.onInit Function
3481Function un.onInit
3482	;Prevent multiple instances of the uninstaller
3483	${IfNot} ${UAC_IsInnerInstance}
3484		System::Call 'kernel32::CreateMutexW(i 0, i 0, t "ocpn_uninst_@CPACK_PACKAGE_VERSION@") i .r1 ?e'
3485		Pop $R0
3486		StrCmp $R0 0 +3
3487		MessageBox MB_OK|MB_ICONEXCLAMATION "$(Uninstaller_Running)"
3488		Abort
3489	${EndIf}
3490
3491	Call un.GetUserInfo
3492	StrCpy $USERS_NAME $USERNAME
3493
3494	;# Macros to be inserted
3495	${If} $IS_ADMIN == 1
3496		!insertmacro MUI_UNGETLANGUAGE
3497	${EndIf}
3498
3499	StrCpy $USERS_APPDATA $APPDATA
3500
3501	;# UAC check if user has Admin privileges and prompt for elevation if not
3502	uac_tryagain:
3503	!insertmacro UAC_RunElevated
3504	StrCpy $Inst_Or_Uninst "$(Uninstaller)"
3505	${Switch} $0
3506	${Case} 0
3507		${IfThen} $1 = 1 ${|} Quit ${|} ;# we are the outer process, the inner process has done its work, we are done
3508		${IfThen} $3 <> 0 ${|} ${Break} ${|} ;# we are admin, let the show go on
3509		${If} $1 = 3 ;# RunAs completed successfully, but with a non-admin user
3510			MessageBox mb_IconExclamation|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Retry)" /SD IDNO IDOK uac_tryagain IDNO 0
3511		${EndIf}
3512		;# fall-through and die
3513	${Case} 1223
3514		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Admin_Abort)"
3515		Quit
3516	${Case} 1062
3517		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_Logon_Abort)"
3518		Quit
3519	${Default}
3520		MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(Msg_UAC_No_Elevation)"
3521		Quit
3522	${EndSwitch}
3523
3524##########  from here we can be sure to run with admin privileges  ##########
3525
3526    SectionSetText ${UnSecDeleteConfigFolder} $(UnSecDeleteConfigFolder_Text)
3527
3528	ClearErrors
3529	Var /GLOBAL UN_INST_PARAMS
3530	Var /GLOBAL UN_INST_HELP
3531	Var /GLOBAL UN_INST_TYPE
3532	StrCpy $UN_INST_TYPE ""
3533	${GetParameters} $UN_INST_PARAMS
3534	StrCmp $UN_INST_PARAMS "" no_params
3535
3536	${GetOptions} "$UN_INST_PARAMS" "/?" $UN_INST_HELP
3537	IfErrors +3
3538	StrCpy $UN_INST_HELP "help"
3539	Goto end
3540
3541	ClearErrors
3542	${GetOptions} "$UN_INST_PARAMS" "/type" $UN_INST_TYPE
3543	IfErrors no_type_param
3544	${Switch} $UN_INST_TYPE
3545		${Case} "=1" ;# 1 = Program Files only (Remove/ Delete: Program Files)
3546			StrCpy $UN_INST_TYPE 1
3547			!insertmacro ClearSectionFlag ${UnSecDeleteConfigFolder} ${SF_SELECTED}
3548			!insertmacro ClearSectionFlag ${UnSecDeleteConfigRegKey} ${SF_SELECTED}
3549			${Break}
3550		${Case} "=2" ;# 2 = Preserve Config folder (Remove/ Delete: Program Files + RegKey)
3551			StrCpy $UN_INST_TYPE 2
3552			!insertmacro ClearSectionFlag ${UnSecDeleteConfigFolder} ${SF_SELECTED}
3553			${Break}
3554		${Case} "=3" ;# 3 = Preserve RegKey (Remove/ Delete: Program Files + Config folder)
3555			StrCpy $UN_INST_TYPE 3
3556			!insertmacro ClearSectionFlag ${UnSecDeleteConfigRegKey} ${SF_SELECTED}
3557			SectionSetFlags ${UnSecBackupConfigToRegKey} ${SF_SELECTED}
3558			${Break}
3559		${Case} "=4" ;# 4 = Delete Config folder (Remove/ Delete: Config folder)
3560			StrCpy $UN_INST_TYPE 4
3561			!insertmacro ClearSectionFlag ${UnSecUninstall} ${SF_SELECTED}
3562			!insertmacro ClearSectionFlag ${UnSecDeleteConfigRegKey} ${SF_SELECTED}
3563			SectionSetFlags ${UnSecBackupConfigToRegKey} ${SF_SELECTED}
3564			${Break}
3565		${Case} "=5" ;# 5 = Delete RegKey (Remove/ Delete: RegKey)
3566			StrCpy $UN_INST_TYPE 5
3567			!insertmacro ClearSectionFlag ${UnSecUninstall} ${SF_SELECTED}
3568			!insertmacro ClearSectionFlag ${UnSecDeleteConfigFolder} ${SF_SELECTED}
3569			${Break}
3570		${Default}
3571			StrCpy $9 $UN_INST_TYPE
3572			StrCpy $UN_INST_TYPE "error_type" ;# unknown value given for the type parameter => MsgBox => Quit
3573			${Break}
3574	${EndSwitch}
3575
3576	StrCmp $UN_INST_TYPE "error_type" 0 cont
3577	MessageBox MB_OK|MB_ICONEXCLAMATION "$(Msg_Unknown_Type_Param)"
3578	Quit
3579
3580	no_type_param:
3581	;# If no parameter 'type' is given assume full uninstall
3582	StrCpy $UN_INST_TYPE 0 ;# 0 = Full Uninstall (Remove/ Delete: Program Files + Config folder + RegKey)
3583	Goto cont
3584
3585	no_params:
3586	;# If no parameters are given assume full uninstall
3587	StrCpy $UN_INST_TYPE 0 ;# 0 = Full Uninstall (Remove/ Delete: Program Files + Config folder + RegKey)
3588
3589	cont:
3590	;# Delete all temporary files created during the installation
3591	Delete "$TEMP\opencpn_*.tmp"
3592
3593	Call un.VersionDate
3594
3595	Call un.Check_Prev_Installs
3596
3597	;# If there are other installations of OCPN do not remove the config folder!
3598	${If} $UN_INST_TYPE == 0
3599	${AndIf} $VERSION_EXISTS == 1
3600	${AndIf} $MULTIPLE_INSTALLS > 1
3601		StrCpy $Skip_UnPage_Components 1
3602		!insertmacro ClearSectionFlag ${UnSecDeleteConfigFolder} ${SF_SELECTED}
3603	${EndIf}
3604
3605	ReadRegStr $0 HKLM "${REG_KEY_UN}" "CompareVersion"
3606
3607	end:
3608FunctionEnd
3609
3610
3611Function un.myGuiInit
3612	${If} $UN_INST_HELP == "help"
3613		MessageBox MB_OK|MB_ICONINFORMATION "$(Msg_Uninstaller_Param_Help)"
3614		Quit
3615	${EndIf}
3616FunctionEnd
3617
3618;--------------------------------
3619;##################################################################################################
3620;#                                 Uninstaller Page Functions                                     #
3621;##################################################################################################
3622/*
3623 ;# UnPage_Components_Pre
3624	Function un.Page_Components_Pre
3625		${If} $Skip_UnPage_Components == 1
3626			Abort
3627		${EndIf}
3628	FunctionEnd
3629*/
3630;--------------------------------
3631;##################################################################################################
3632;#                                 General Uninstaller Functions                                  #
3633;##################################################################################################
3634
3635
3636
3637;--------------------------------
3638;##################################################################################################
3639;#                                       Shared Functions                                         #
3640;##################################################################################################
3641!macro GetUserInfo_Macro un
3642	Function ${un}GetUserInfo
3643		ClearErrors
3644		UserInfo::GetName
3645		${If} ${Errors}
3646			StrCpy $IS_ADMIN 1
3647			Return
3648		${EndIf}
3649		Pop $USERNAME
3650
3651		UserInfo::GetAccountType
3652		Pop $R0
3653		StrCpy $UAT $R0
3654		${If} ${IsNT}
3655		${AndIf} ${IsWinNT4}
3656			${If} $R0 == "Admin"
3657				StrCpy $IS_ADMIN 1
3658			${Else}
3659				StrCpy $IS_ADMIN 0
3660			${EndIf}
3661			Goto end
3662		${EndIf}
3663
3664		${Switch} $R0
3665			${Case} "Admin"
3666			${Case} "Power"
3667				StrCpy $IS_ADMIN 1
3668				${Break}
3669			${Default}
3670				StrCpy $IS_ADMIN 0
3671			${Break}
3672		${EndSwitch}
3673
3674		UserInfo::GetOriginalAccountType
3675		Pop $OUAT
3676
3677		end:
3678	FunctionEnd
3679!macroend
3680!insertmacro GetUserInfo_Macro ""
3681!insertmacro GetUserInfo_Macro "un."
3682
3683
3684!macro Check_Prev_Installs_Macro un
3685	Function ${un}Check_Prev_Installs
3686		StrCpy $R0 0
3687		StrCpy $R1 ""
3688		StrCpy $R5 0
3689		StrCpy $VERSION_EXISTS 0
3690		SetShellVarContext all
3691		${Do}
3692			EnumRegKey $R1 SHCTX "${REG_ROOT_KEY_UN}" $R0
3693			${If} $R1 != ""
3694				StrLen $R2 $R1
3695				${WordFind} "$R1" " " "+1" $R3
3696				IntOp $R0 $R0 + 1
3697				${If} $R3 == "s63_pi"
3698				${AndIf} $R2 > 7
3699					ReadRegStr $R4 SHCTX "${REG_ROOT_KEY_UN}\$R1" "CompareVersion"
3700					ReadRegStr $R6 SHCTX "${REG_ROOT_KEY_UN}\$R1" "InstallLocation"
3701					${If} $R4 != ""
3702						${VersionCompare} $VERSION_DATE $R4 $Compare_Version_Result
3703						${Switch} $Compare_Version_Result
3704							${Case} 0 ;equal
3705								StrCpy $VERSION_EXISTS 1
3706								${Break}
3707							${Case} 1 ;version to install is newer
3708								StrCpy $VERSION_NEWER 1
3709								${Break}
3710							${Case} 2 ;version to install is older
3711								StrCpy $VERSION_OLDER 1
3712								${Break}
3713							${Default}
3714								${Break}
3715						${EndSwitch}
3716						IntOp $R5 $R5 + 1
3717						StrCpy $Prev_Install_RegKey "${REG_ROOT_KEY_UN}\$R1"
3718					${EndIf}
3719					StrCmp ${un} "" 0 uninst ;# only execute when it is the Installer function
3720					${If} $R6 != ""
3721						ClearErrors
3722						${If} ${FileExists} "$TEMP\opencpn_prev_installs.tmp"
3723							FileOpen $0 "$TEMP\opencpn_prev_installs.tmp" a
3724							FileSeek $0 0 END
3725						${Else}
3726							FileOpen $0 "$TEMP\opencpn_prev_installs.tmp" w
3727						${EndIf}
3728						IfErrors done
3729						FileWriteUTF16LE $0 "$R1$\r$\n"
3730						FileWriteUTF16LE $0 "$R6$\r$\n"
3731						FileClose $0
3732						done:
3733					${EndIf}
3734
3735					${If} $VERSION_EXISTS == 1
3736						${Break}
3737					${EndIf}
3738
3739					uninst:
3740				${EndIf}
3741			${Else}
3742				Goto done2
3743			${EndIf}
3744		${Loop}
3745		done2:
3746		${If} $R5 > 0
3747			StrCpy $MULTIPLE_INSTALLS $R5
3748		${Else}
3749			StrCpy $MULTIPLE_INSTALLS 0
3750		${EndIf}
3751		${If} $MULTIPLE_INSTALLS == 0
3752			StrCpy $Skip_Page_TypeInst 1
3753		${Else}
3754			StrCpy $Skip_Page_TypeInst 0
3755		${EndIf}
3756	FunctionEnd
3757!macroend
3758!insertmacro Check_Prev_Installs_Macro ""
3759!insertmacro Check_Prev_Installs_Macro "un."
3760
3761
3762/*  VersionDate
3763	normalizes the CPACK_PACKAGE_VERSION_PATCH to a comparable format 'yyyy.[02|19].mmdd.00'
3764	02 = Beta version
3765	19 = Stable release
3766	IN: CPACK_PACKAGE_VERSION_PATCH
3767	OUT: $VERSION_DATE
3768*/
3769Var Patch_Version
3770Var Version_Digits_Only
3771Var Version_Unified
3772Var Patch_Date
3773!macro VersionDate_Macro un
3774	Function ${un}VersionDate
3775		StrCpy $Patch_Version "@CPACK_PACKAGE_VERSION_PATCH@"
3776		${If} $Patch_Version == ""
3777			StrCpy $Patch_Version "0000"
3778		${EndIf}
3779		StrLen $0 "$Patch_Version"
3780		${StrFilter} "$Patch_Version" "1" "" "" $Version_Digits_Only
3781		StrLen $1 $Version_Digits_Only
3782		;# Patch version contains non-digit characters
3783		${If} $0 != $1
3784			${StrFilter} "$Patch_Version" "-2" "" "" $PATCH_ND
3785			${If} $1 == 3
3786				StrCpy $Version_Unified "b${YEAR}0$Patch_Version"
3787			${ElseIf} $1 == 2
3788				StrCpy $Version_Unified "s${YEAR}00$Patch_Version"
3789			${ElseIf} $1 == 1
3790				StrCpy $Version_Unified "s${YEAR}000$Patch_Version"
3791			${Else}
3792				StrCpy $Version_Unified "b${YEAR}$Patch_Version"
3793			${EndIf}
3794			${VersionConvert} $Version_Unified "" $Patch_Date
3795			StrCpy $VERSION_DATE "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.$Patch_Date"
3796		;# Patch version contains only digits
3797		${Else}
3798			${If} $0 == 3
3799				StrCpy $Version_Unified "b${YEAR}0$Patch_Version"
3800			${ElseIf} $0 == 2
3801				StrCpy $Version_Unified "s${YEAR}00$Patch_Version"
3802			${ElseIf} $0 == 1
3803				StrCpy $Version_Unified "s${YEAR}000$Patch_Version"
3804			${Else}
3805				StrCpy $Version_Unified "b${YEAR}$Patch_Version"
3806			${EndIf}
3807			${VersionConvert} $Version_Unified "" $Patch_Date
3808			StrCpy $VERSION_DATE "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.$Patch_Date.00"
3809		${EndIf}
3810	FunctionEnd
3811!macroend
3812!insertmacro VersionDate_Macro ""
3813!insertmacro VersionDate_Macro "un."
3814
3815
3816!macro Delete_Start_Menu_Shortcuts_Macro un
3817	Function ${un}Delete_Start_Menu_Shortcuts
3818		Pop $9
3819		Push $R0
3820		Push $R1
3821		Push $R2
3822		Push $R3
3823		Push $R4
3824		${TrimNewLines} $9 $9
3825		SetShellVarContext all
3826		${RecFindOpen} "$STARTMENU" $CurrentDirVar $CurrentFileVar
3827			${RecFindFirst}
3828			ClearErrors
3829			${WordFind} "$CurrentFileVar" ".lnk" "E*" $8
3830			IfErrors next
3831			IntCmp $8 1 0 next 0
3832			ShellLink::GetShortCutWorkingDirectory "$STARTMENU$CurrentDirVar\$CurrentFileVar"
3833			Pop $0
3834			StrCmp "$0" "" +2
3835			StrCmp "$0" "$9" 0 next
3836			ShellLink::GetShortCutTarget "$STARTMENU$CurrentDirVar\$CurrentFileVar"
3837			Pop $1
3838			${WordFind2X} "$1" "\" ".exe" "-1" $7
3839			ClearErrors
3840			${WordFind} "$7" "uninstall" "E*" $6
3841			IfErrors 0 +2
3842			StrCpy $6 0
3843			;#NON-DEBUG
3844			${If} $7 == "opencpn"
3845			${OrIf} $7 == "Uninstall"
3846			${OrIf} $7 == "unins000"
3847			${OrIf} $6 == 1
3848				Delete "$STARTMENU$CurrentDirVar\$CurrentFileVar"
3849				StrCmp $CurrentDirVar "" next
3850				ClearErrors
3851				RMDir "$STARTMENU$CurrentDirVar"
3852				Sleep 250
3853				IfErrors 0 check_parent
3854				${If} ${FileExists} "$STARTMENU$CurrentDirVar\*.*"
3855					ClearErrors
3856					RMDir "$STARTMENU$CurrentDirVar"
3857					Sleep 250
3858					IfErrors next check_parent
3859				${EndIf}
3860
3861				Goto next
3862
3863				check_parent:
3864				StrCpy $R3 "$STARTMENU$CurrentDirVar"
3865				Push $R3
3866				Call ${un}Parent_Dirs_Check
3867			${EndIf}
3868
3869			next:
3870			${RecFindNext}
3871		${RecFindClose}
3872
3873		${If} ${FileExists} "$TEMP\opencpn_startmenu.tmp"
3874			FileOpen $R0 "$TEMP\opencpn_startmenu.tmp" r
3875			IfErrors end
3876			${Do}
3877				FileReadUTF16LE $R0 $R1
3878				FileReadUTF16LE $R0 $R2
3879				${TrimNewLines} $R1 $R1
3880				${TrimNewLines} $R2 $R2
3881				StrCmp $R2 "" 0 +2
3882				${Break}
3883				${RecFindOpen} "$R2" $CurrentDirVar $CurrentFileVar
3884					${RecFindFirst}
3885					ClearErrors
3886					${WordFind} "$CurrentFileVar" ".lnk" "E*" $8
3887					IfErrors next1
3888					IntCmp $8 1 0 next1 0
3889					ShellLink::GetShortCutWorkingDirectory "$R2$CurrentDirVar\$CurrentFileVar"
3890					Pop $0
3891					StrCmp "$0" "$9" 0 next1
3892					ShellLink::GetShortCutTarget "$R2$CurrentDirVar\$CurrentFileVar"
3893					Pop $1
3894					${WordFind2X} "$1" "\" ".exe" "-1" $7
3895					;#NON-DEBUG
3896					${If} $7 == "opencpn"
3897					${OrIf} $7 == "Uninstall"
3898					${OrIf} $7 == "unins000"
3899						Delete "$R2$CurrentDirVar\$CurrentFileVar"
3900						StrCmp $CurrentDirVar "" next1
3901						ClearErrors
3902						RMDir "$R2$CurrentDirVar"
3903						Sleep 250
3904						IfErrors 0 check_parent1
3905						${If} ${FileExists} "$R2$CurrentDirVar\*.*"
3906							ClearErrors
3907							RMDir "$R2$CurrentDirVar"
3908							Sleep 250
3909							IfErrors next1 check_parent1
3910						${EndIf}
3911
3912						Goto next1
3913
3914						check_parent1:
3915						StrCpy $R3 "$STARTMENU$CurrentDirVar"
3916						Push $R3
3917						Call ${un}Parent_Dirs_Check
3918					${EndIf}
3919
3920					next1:
3921					${RecFindNext}
3922				${RecFindClose}
3923			${LoopUntil} $R2 == ""
3924			FileClose $R0
3925		${EndIf}
3926
3927		end:
3928		Call ${un}Delete_Empty_Parents
3929
3930		Pop $R4
3931		Pop $R3
3932		Pop $R2
3933		Pop $R1
3934		Pop $R0
3935	FunctionEnd
3936!macroend
3937!insertmacro Delete_Start_Menu_Shortcuts_Macro ""
3938!insertmacro Delete_Start_Menu_Shortcuts_Macro "un."
3939
3940
3941!macro Delete_Desktop_Shortcuts_Macro un
3942	Function ${un}Delete_Desktop_Shortcuts
3943		Pop $9
3944		Push $R0
3945		Push $R1
3946		Push $R2
3947		Push $R3
3948		${TrimNewLines} $9 $9
3949		SetShellVarContext all
3950		${RecFindOpen} "$DESKTOP" $CurrentDirVar $CurrentFileVar
3951			${RecFindFirst}
3952			ClearErrors
3953			${WordFind} "$CurrentFileVar" ".lnk" "E*" $8
3954			IfErrors next
3955			IntCmp $8 1 0 next 0
3956			ShellLink::GetShortCutWorkingDirectory "$DESKTOP$CurrentDirVar\$CurrentFileVar"
3957			Pop $0
3958			StrCmp "$0" "" +2
3959			StrCmp "$0" "$9" 0 next
3960			ShellLink::GetShortCutTarget "$DESKTOP$CurrentDirVar\$CurrentFileVar"
3961			Pop $1
3962			${WordFind2X} "$1" "\" ".exe" "-1" $7
3963			ClearErrors
3964			${WordFind} "$7" "uninstall" "E*" $6
3965			IfErrors 0 +2
3966			StrCpy $6 0
3967			;#NON-DEBUG
3968			${If} $7 == "opencpn"
3969			${OrIf} $7 == "Uninstall"
3970			${OrIf} $7 == "unins000"
3971			${OrIf} $6 == 1
3972				Delete "$DESKTOP$CurrentDirVar\$CurrentFileVar"
3973				StrCmp $CurrentDirVar "" next
3974				RMDir "$DESKTOP$CurrentDirVar"
3975				Sleep 250
3976				IfErrors 0 check_parent
3977				${If} ${FileExists} "$DESKTOP$CurrentDirVar\*.*"
3978					ClearErrors
3979					RMDir "$DESKTOP$CurrentDirVar"
3980					Sleep 250
3981					IfErrors next check_parent
3982				${EndIf}
3983
3984				Goto next
3985
3986				check_parent:
3987				StrCpy $R3 "$DESKTOP$CurrentDirVar"
3988				Push $R3
3989				Call ${un}Parent_Dirs_Check
3990			${EndIf}
3991
3992			next:
3993			${RecFindNext}
3994		${RecFindClose}
3995
3996		${If} ${FileExists} "$TEMP\opencpn_desktop.tmp"
3997			FileOpen $R0 "$TEMP\opencpn_desktop.tmp" r
3998			IfErrors end
3999			${Do}
4000				FileReadUTF16LE $R0 $R1
4001				FileReadUTF16LE $R0 $R2
4002				${TrimNewLines} $R1 $R1
4003				${TrimNewLines} $R2 $R2
4004				StrCmp $R2 "" 0 +2
4005				${Break}
4006				${RecFindOpen} "$R2" $CurrentDirVar $CurrentFileVar
4007					${RecFindFirst}
4008					ClearErrors
4009					${WordFind} "$CurrentFileVar" ".lnk" "E*" $8
4010					IfErrors next1
4011					IntCmp $8 1 0 next1 0
4012					ShellLink::GetShortCutWorkingDirectory "$R2$CurrentDirVar\$CurrentFileVar"
4013					Pop $0
4014					StrCmp "$0" "$9" 0 next1
4015					ShellLink::GetShortCutTarget "$R2$CurrentDirVar\$CurrentFileVar"
4016					Pop $1
4017					${WordFind2X} "$1" "\" ".exe" "-1" $7
4018					;#NON-DEBUG
4019					${If} $7 == "opencpn"
4020					${OrIf} $7 == "Uninstall"
4021					${OrIf} $7 == "unins000"
4022						Delete "$R2$CurrentDirVar\$CurrentFileVar"
4023						StrCmp $CurrentDirVar "" next1
4024						RMDir "$R2$CurrentDirVar"
4025						Sleep 250
4026						IfErrors 0 check_parent1
4027						${If} ${FileExists} "$R2$CurrentDirVar\*.*"
4028							ClearErrors
4029							RMDir "$R2$CurrentDirVar"
4030							Sleep 250
4031							IfErrors next1 check_parent1
4032						${EndIf}
4033
4034						Goto next1
4035
4036						check_parent1:
4037						StrCpy $R3 "$STARTMENU$CurrentDirVar"
4038						Push $R3
4039						Call ${un}Parent_Dirs_Check
4040					${EndIf}
4041
4042					next1:
4043					${RecFindNext}
4044				${RecFindClose}
4045			${LoopUntil} $R2 == ""
4046			FileClose $R0
4047		${EndIf}
4048
4049		end:
4050		Call ${un}Delete_Empty_Parents
4051
4052		Pop $R3
4053		Pop $R2
4054		Pop $R1
4055		Pop $R0
4056	FunctionEnd
4057!macroend
4058!insertmacro Delete_Desktop_Shortcuts_Macro ""
4059!insertmacro Delete_Desktop_Shortcuts_Macro "un."
4060
4061
4062!macro Parent_Dirs_Check_Macro un
4063	Function ${un}Parent_Dirs_Check
4064		Pop $R3
4065		Push $R4
4066		ClearErrors
4067		${If} ${FileExists} "$TEMP\opencpn_check_parent.tmp"
4068			FileOpen $R4 "$TEMP\opencpn_check_parent.tmp" a
4069			IfErrors end
4070		${Else}
4071			FileOpen $R4 "$TEMP\opencpn_check_parent.tmp" w
4072			IfErrors end
4073		${EndIf}
4074
4075		${WordFind} "$R3" "\" "E-2{*" $R3
4076		IfErrors close
4077		FileWriteUTF16LE $R4 "$R3$\r$\n"
4078
4079		close:
4080		FileClose $R4
4081
4082		end:
4083		Pop $R4
4084	FunctionEnd
4085!macroend
4086!insertmacro Parent_Dirs_Check_Macro ""
4087!insertmacro Parent_Dirs_Check_Macro "un."
4088
4089
4090!macro Delete_Empty_Parents_Macro un
4091	Function ${un}Delete_Empty_Parents
4092		Push $R3
4093		Push $R4
4094		Push $R5
4095		ClearErrors
4096		${If} ${FileExists} "$TEMP\opencpn_check_parent.tmp"
4097			FileOpen $R4 "$TEMP\opencpn_check_parent.tmp" r
4098			IfErrors end
4099			${Do}
4100				FileReadUTF16LE $R4 $R3
4101				IfErrors close
4102				${TrimNewLines} "$R3" $R3
4103				${DirState} $R3 $R5
4104				StrCmp $R5 0 0 next
4105				ClearErrors
4106				RMDir "$R3"
4107				Sleep 250
4108				IfErrors next
4109
4110				loop:
4111				${WordFind} "$R3" "\" "E-2{*" $R3
4112				IfErrors next
4113				StrCpy $error_tmp 0
4114				Push $R3
4115				Call ${un}Delete_Empty_Dir
4116				StrCmp $error_tmp 1 loop
4117				next:
4118			${Loop}
4119			close:
4120			FileClose $R4
4121			Delete "$TEMP\opencpn_check_parent.tmp"
4122		${EndIf}
4123		end:
4124		Pop $R5
4125		Pop $R4
4126		Pop $R3
4127	FunctionEnd
4128!macroend
4129!insertmacro Delete_Empty_Parents_Macro ""
4130!insertmacro Delete_Empty_Parents_Macro "un."
4131
4132
4133!macro Delete_Empty_Dir_Macro un
4134	Function ${un}Delete_Empty_Dir
4135		Push $R3
4136		Exch
4137		Pop $R3
4138		Push $R4
4139		${DirState} $R3 $R4
4140		StrCmp $R4 0 0 end
4141		RMDir "$R3"
4142		Sleep 100
4143		StrCpy $error_tmp 1
4144
4145		end:
4146		Pop $R4
4147		Pop $R3
4148	FunctionEnd
4149!macroend
4150!insertmacro Delete_Empty_Dir_Macro ""
4151!insertmacro Delete_Empty_Dir_Macro "un."
4152
4153
4154; Initialize variables
4155Var explString
4156Var explSeparator
4157Var explStrLen
4158Var explSepLen
4159Var explOffset
4160Var explTmp
4161Var explTmp2
4162Var explTmp3
4163Var explArrCount
4164!macro Explodes_Macro un
4165	Function ${un}Explode
4166	/*; Initialize variables
4167	  Var /GLOBAL explString
4168	  Var /GLOBAL explSeparator
4169	  Var /GLOBAL explStrLen
4170	  Var /GLOBAL explSepLen
4171	  Var /GLOBAL explOffset
4172	  Var /GLOBAL explTmp
4173	  Var /GLOBAL explTmp2
4174	  Var /GLOBAL explTmp3
4175	  Var /GLOBAL explArrCount
4176	*/
4177	  ; Get input from user
4178	  Pop $explString
4179	  Pop $explSeparator
4180
4181	  ; Calculates initial values
4182	  StrLen $explStrLen $explString
4183	  StrLen $explSepLen $explSeparator
4184	  StrCpy $explArrCount 1
4185
4186	  ${If}   $explStrLen <= 1          ;   If we got a single character
4187	  ${OrIf} $explSepLen > $explStrLen ;   or separator is larger than the string,
4188		Push    $explString             ;   then we return initial string with no change
4189		Push    1                       ;   and set array's length to 1
4190		Return
4191	  ${EndIf}
4192
4193	  ; Set offset to the last symbol of the string
4194	  StrCpy $explOffset $explStrLen
4195	  IntOp  $explOffset $explOffset - 1
4196
4197	  ; Clear temp string to exclude the possibility of appearance of occasional data
4198	  StrCpy $explTmp   ""
4199	  StrCpy $explTmp2  ""
4200	  StrCpy $explTmp3  ""
4201
4202	  ; Loop until the offset becomes negative
4203	  ${Do}
4204		;   If offset becomes negative, it is time to leave the function
4205		${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
4206
4207		;   Remove everything before and after the searched part ("TempStr")
4208		StrCpy $explTmp $explString $explSepLen $explOffset
4209
4210		${If} $explTmp == $explSeparator
4211			;   Calculating offset to start copy from
4212			IntOp   $explTmp2 $explOffset + $explSepLen ;   Offset equals to the current offset plus length of separator
4213			StrCpy  $explTmp3 $explString "" $explTmp2
4214
4215			Push    $explTmp3                           ;   Throwing array item to the stack
4216			IntOp   $explArrCount $explArrCount + 1     ;   Increasing array's counter
4217
4218			StrCpy  $explString $explString $explOffset 0   ;   Cutting all characters beginning with the separator entry
4219			StrLen  $explStrLen $explString
4220		${EndIf}
4221
4222		${If} $explOffset = 0                       ;   If the beginning of the line met and there is no separator,
4223													;   copying the rest of the string
4224			${If} $explSeparator == ""              ;   Fix for the empty separator
4225				IntOp   $explArrCount   $explArrCount - 1
4226			${Else}
4227				Push    $explString
4228			${EndIf}
4229		${EndIf}
4230
4231		IntOp   $explOffset $explOffset - 1
4232	  ${Loop}
4233
4234	  Push $explArrCount
4235	FunctionEnd
4236!macroend
4237!insertmacro Explodes_Macro ""
4238!insertmacro Explodes_Macro "un."
4239
4240
4241!macro isEmptyDir_Macro un
4242	Function ${un}isEmptyDir
4243	# Stack ->                    # Stack: <directory>
4244	Exch $0                       # Stack: $0
4245	Push $1                       # Stack: $1, $0
4246	FindFirst $0 $1 "$0\*.*"
4247	StrCmp $1 "." 0 _notempty
4248	FindNext $0 $1
4249	StrCmp $1 ".." 0 _notempty
4250	ClearErrors
4251	FindNext $0 $1
4252	IfErrors 0 _notempty
4253	FindClose $0
4254	Pop $1                  # Stack: $0
4255	StrCpy $0 1
4256	Exch $0                 # Stack: 1 (true)
4257	Goto _end
4258	_notempty:
4259	FindClose $0
4260	Pop $1                   # Stack: $0
4261	StrCpy $0 0
4262	Exch $0                  # Stack: 0 (false)
4263	_end:
4264	FunctionEnd
4265!macroend
4266!insertmacro isEmptyDir_Macro ""
4267!insertmacro isEmptyDir_Macro "un."
4268;--------------------------------------------------------------------------------------------------
4269;##################################################################################################
4270;#                                  D E S C R I P T I O N S                                       #
4271;##################################################################################################
4272;#                                  Installer Descriptions                                        #
4273;##################################################################################################
4274
4275;# License page
4276	LicenseLangString license ${LANG_ENGLISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4277	LicenseLangString license ${LANG_GERMAN} "@CPACK_RESOURCE_FILE_LICENSE@"
4278	LicenseLangString license ${LANG_FRENCH} "@CPACK_RESOURCE_FILE_LICENSE@"
4279	LicenseLangString license ${LANG_CZECH} "@CPACK_RESOURCE_FILE_LICENSE@"
4280	LicenseLangString license ${LANG_DANISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4281	LicenseLangString license ${LANG_SPANISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4282	LicenseLangString license ${LANG_ITALIAN} "@CPACK_RESOURCE_FILE_LICENSE@"
4283	LicenseLangString license ${LANG_DUTCH} "@CPACK_RESOURCE_FILE_LICENSE@"
4284	LicenseLangString license ${LANG_POLISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4285	LicenseLangString license ${LANG_PORTUGUESE} "@CPACK_RESOURCE_FILE_LICENSE@"
4286	LicenseLangString license ${LANG_PORTUGUESEBR} "@CPACK_RESOURCE_FILE_LICENSE@"
4287	LicenseLangString license ${LANG_RUSSIAN} "@CPACK_RESOURCE_FILE_LICENSE@"
4288	LicenseLangString license ${LANG_SWEDISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4289	LicenseLangString license ${LANG_FINNISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4290	LicenseLangString license ${LANG_NORWEGIAN} "@CPACK_RESOURCE_FILE_LICENSE@"
4291	LicenseLangString license ${LANG_TRADCHINESE} "@CPACK_RESOURCE_FILE_LICENSE@"
4292	LicenseLangString license ${LANG_TURKISH} "@CPACK_RESOURCE_FILE_LICENSE@"
4293        ;LicenseLangString license ${LANG_HUNGARIAN} "@CPACK_RESOURCE_FILE_LICENSE@"
4294
4295!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
4296	!insertmacro MUI_DESCRIPTION_TEXT ${SecGrpResetConfig} $(SecGrpResetConfig_Desc)
4297	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteConfigFile} $(SecDeleteConfigFile_Desc)
4298	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteChartDB} $(SecDeleteChartDB_Desc)
4299	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteSENC} $(SecDeleteSENC_Desc)
4300	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteCM93} $(SecDeleteCM93_Desc)
4301	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteNavobjFile} $(SecDeleteNavobjFile_Desc)
4302	!insertmacro MUI_DESCRIPTION_TEXT ${SecDeleteLogFile} $(SecDeleteLogFile_Desc)
4303	!insertmacro MUI_DESCRIPTION_TEXT ${SecGrpShortcuts} $(SecGrpShortcuts_Desc)
4304	!insertmacro MUI_DESCRIPTION_TEXT ${SecShortcutStartmenu} $(SecShortcutStartmenu_Desc)
4305	!insertmacro MUI_DESCRIPTION_TEXT ${SecShortcutDesktop} $(SecShortcutDesktop_Desc)
4306	!insertmacro MUI_DESCRIPTION_TEXT ${SecSetConfig} $(SecSetConfig_Desc)
4307!insertmacro MUI_FUNCTION_DESCRIPTION_END
4308
4309;--------------------------------
4310;##################################################################################################
4311;#                                  Uninstaller Descriptions                                      #
4312;##################################################################################################
4313!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
4314  !insertmacro MUI_DESCRIPTION_TEXT ${UnSecDeleteConfigFolder} $(UnSecDeleteConfigFolder_Desc)
4315!insertmacro MUI_UNFUNCTION_DESCRIPTION_END
4316
4317
4318;--------------------------------------------------------------------------------------------------
4319;##################################################################################################
4320;#                                        Language Strings                                        #
4321;##################################################################################################
4322;#DO NOT EDIT THE NEXT LINE!!! It is needed for the online generating of the translation files!
4323;#Language Strings Start as of: 2010-10-10
4324;#IMPORTANT: Do not end a multi-line with $\"
4325
4326	LangString Installer ${LANG_ENGLISH} "installer"
4327
4328	LangString Uninstaller ${LANG_ENGLISH} "uninstaller"
4329
4330  ;Installer running on unsupported version of Windows
4331	LangString Installer_Unsupported_Windows_Version ${LANG_ENGLISH} "Your Windows version is not supported (it's too old)!$\r$\nYou need at least Windows XP SP3."
4332
4333  ;Installer running on Windows XP without SP3
4334	LangString Installer_Unsupported_XP_SP_Version ${LANG_ENGLISH} "Your Windows XP Service Pack version is not supported (it's too old)!$\r$\nYou need at least Windows XP SP3."
4335
4336  ;Installer already running
4337    LangString Installer_Running ${LANG_ENGLISH} "The installer is already running."
4338
4339  ;Uninstaller already running
4340    LangString Uninstaller_Running ${LANG_ENGLISH} "The uninstaller is already running."
4341
4342  ;Language Dialog
4343	LangString LangDialog_Title ${LANG_ENGLISH} "@CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@ Installation"
4344
4345	LangString LangDialog_Text ${LANG_ENGLISH} "Please select a language:"
4346
4347   ;License dialog
4348	LangString License_Message ${LANG_ENGLISH} "OpenCPN is software libre. You are encouraged and legally \
4349        entitled to copy, reinstall, modify, and redistribute this program \
4350        for yourself and your friends under the terms of the GPL. $\r$\nSmooth sailing!"
4351
4352  ;Clean up page
4353	LangString text_please_wait_1 ${LANG_ENGLISH} "... please wait!"
4354
4355	LangString Scanning_HDD ${LANG_ENGLISH} "Scanning HDD ..."
4356
4357	LangString OCPN_Scanning_HDD ${LANG_ENGLISH} "OpenCPN: Scan HDD ..., please wait!"
4358
4359	LangString Search_old_installations ${LANG_ENGLISH} "Searching for old installations"
4360
4361	LangString Install_Location_Default ${LANG_ENGLISH} "Install Locations by default paths (may not find all)"
4362
4363	LangString Install_Location_HDD_Scan ${LANG_ENGLISH} "Install Location by full HDD scan (most reliable)"
4364
4365	LangString Label_CleanUp_Text ${LANG_ENGLISH} "Click on a list-item to select/ unselect it or Select ALL (recommended) and then Uninstall selected."
4366
4367	LangString BT_Uninstall_Selected_CleanUp ${LANG_ENGLISH} "Uninstall Selected"
4368
4369	LangString BT_SelectAll_CleanUp ${LANG_ENGLISH} "Select ALL"
4370
4371	LangString BT_UnselectAll_CleanUp ${LANG_ENGLISH} "Unselect ALL"
4372
4373	LangString LB_CleanUp ${LANG_ENGLISH} "Listbox Text"
4374
4375	LangString BT_FullScan_CleanUp ${LANG_ENGLISH} "Scan HDD ..."
4376
4377	LangString LAB_FullScan_CleanUp ${LANG_ENGLISH} "Scan the HDD for the most reliable detection.$\r$\nATTENTION: may last several minutes!"
4378
4379	LangString Page_CleanUp_Title ${LANG_ENGLISH} "Uninstall older Version"
4380
4381	LangString Page_CleanUp_Subtitle ${LANG_ENGLISH} "Incompatible version detected"
4382
4383  ;Components Page
4384	;Header
4385    LangString CP_HEADER_TEXT ${LANG_ENGLISH} "Installation Settings"
4386
4387	;Subheader
4388    LangString CP_HEADER_SUBTEXT ${LANG_ENGLISH} "Choose the settings for the installation"
4389
4390	;Top
4391    LangString CP_TOP ${LANG_ENGLISH} "Check or uncheck the options for the installation.$\r$\nClick 'Next' to continue."
4392
4393	;Installation type
4394	LangString CP_INSTTYPE ${LANG_ENGLISH} "Installation type:"
4395
4396	;Components list
4397	LangString CP_COMPLIST ${LANG_ENGLISH} "Adjust the settings individually:"
4398
4399
4400  ;Directory page
4401
4402
4403  ;Set Config page
4404	LangString Page_SetConfig_Title ${LANG_ENGLISH} "Default configuration settings"
4405
4406	LangString Page_SetConfig_Subtitle ${LANG_ENGLISH} "Preconfigure settings for OpenCPN"
4407
4408	LangString Select_Chart_Directory ${LANG_ENGLISH} "Please select a chart directory to add to OpenCPN"
4409
4410	LangString BT_Browse_SetConfig_Text ${LANG_ENGLISH} "Browse..."
4411
4412	LangString BT_DeleteAll_SetConfig_Text ${LANG_ENGLISH} "Delete ALL"
4413
4414	LangString BT_Delete_SetConfig_Text ${LANG_ENGLISH} "Delete"
4415
4416	LangString GB_ChartDir_SetConfig_Text ${LANG_ENGLISH} "Add Chart Directory"
4417
4418	LangString CB_Language_SetConfig_Text ${LANG_ENGLISH} "Set OpenCPN program language to $LANG_NAME"
4419
4420	LangString GB_Language_SetConfig_Text ${LANG_ENGLISH} "Set OpenCPN program language"
4421
4422	LangString Label_SetConfig_Text ${LANG_ENGLISH} "Configure preconfig settings for the OpenCPN program.$\r$\nThese settings are saved in the file opencpn.ini."
4423
4424  ;Confirm page
4425	LangString Page_Confirm_Title ${LANG_ENGLISH} "Ready to Install"
4426
4427	LangString Page_Confirm_Subtitle ${LANG_ENGLISH} "Check the installation options"
4428
4429	LangString Installation_Type ${LANG_ENGLISH} "Setup type"
4430
4431	LangString Installation_Directory ${LANG_ENGLISH} "Destination location"
4432
4433	LangString Create_Shortcuts ${LANG_ENGLISH} "Create shortcuts"
4434
4435	LangString Type_Reinstall ${LANG_ENGLISH} "Reinstallation"
4436
4437	LangString Type_Upgrade ${LANG_ENGLISH} "Upgrade"
4438
4439	LangString Type_Downgrade ${LANG_ENGLISH} "Downgrade"
4440
4441	LangString Type_Parallel_Installation ${LANG_ENGLISH} "Parallel installation"
4442
4443	LangString Type_Fresh_Installation ${LANG_ENGLISH} "New installation"
4444
4445	LangString Shortcuts ${LANG_ENGLISH} "Shortcuts"
4446
4447	LangString Create_Shortcut_Start_Menu ${LANG_ENGLISH} "in the Start Menu folder"
4448
4449	LangString Create_Shortcut_Desktop ${LANG_ENGLISH} "on the Desktop"
4450
4451	LangString not_selected ${LANG_ENGLISH} "not selected"
4452
4453	LangString text_none ${LANG_ENGLISH} "none"
4454
4455  ;Installer Sections
4456	;Reset config
4457	LangString SecGrpResetConfig_Text ${LANG_ENGLISH} "Reset ALL OpenCPN configuration files"
4458
4459	;Delete Config file (opencpn.ini)
4460	LangString SecDeleteConfigFile_Text ${LANG_ENGLISH} "Delete config file (opencpn.ini)"
4461
4462	;Delete Chart DB (CHRTLIST.DAT)
4463	LangString SecDeleteChartDB_Text ${LANG_ENGLISH} "Delete Chart Database file (CHRTLIST.DAT)"
4464
4465	;Delete SENC directory
4466	LangString SecDeleteSENC_Text ${LANG_ENGLISH} "Delete SENC directory"
4467
4468	;Delete CM93 directory
4469	LangString SecDeleteCM93_Text ${LANG_ENGLISH} "Delete CM93 Directory"
4470
4471	;Delete Log file (opencpn.log)
4472	LangString SecDeleteLogFile_Text ${LANG_ENGLISH} "Delete Log file (opencpn.log)"
4473
4474	;Delete navobj.xml
4475	LangString SecDeleteNavobjFile_Text ${LANG_ENGLISH} "Delete Navobject file (navobj.xml)"
4476
4477	;Set config
4478	LangString SecSetConfig_Text ${LANG_ENGLISH} "OpenCPN Configuration Settings"
4479
4480	;Set language
4481	LangString SecSetConfigLang_Text ${LANG_ENGLISH} "Set language to $LANG_NAME"
4482
4483	;Set chart dir(s)
4484	LangString SecSetConfigChartDir_Text ${LANG_ENGLISH} "Select Chart Directories"
4485
4486  ;Uninstaller Sections
4487	;Reset config
4488	LangString UnSecDeleteConfigFolder_Text ${LANG_ENGLISH} "Delete Config folder"
4489
4490  ;Installer Descriptions
4491	LangString SecGrpResetConfig_Desc ${LANG_ENGLISH} "Deletes ALL files and subdirectories in the configuration folder."
4492
4493	LangString SecDeleteConfigFile_Desc ${LANG_ENGLISH} "Deletes the configuration file. This file helds also Routes and Waypoints."
4494
4495	LangString SecDeleteChartDB_Desc ${LANG_ENGLISH} "Deletes the Chart DB file."
4496
4497	LangString SecDeleteSENC_Desc ${LANG_ENGLISH} "Deletes the SENC subfolder which helds the Bitmaps and S57 chart cache files."
4498
4499	LangString SecDeleteCM93_Desc ${LANG_ENGLISH} "Deletes the cm93 subfolder which helds the cached cm93 chart outlines."
4500
4501	LangString SecDeleteNavobjFile_Desc ${LANG_ENGLISH} "Deletes the file 'navobj.xml' in the config folder. This file contains the Tracks."
4502
4503	LangString SecDeleteLogFile_Desc ${LANG_ENGLISH} "Deletes the OpenCPN log file 'opencpn.log'."
4504
4505	LangString SecGrpShortcuts_Desc ${LANG_ENGLISH} "Creates shortcuts in both, the Start Menu and on the Desktop."
4506
4507	LangString SecShortcutStartmenu_Desc ${LANG_ENGLISH} "Creates shortcuts for OpenCPN and the Uninstaller in the Start Menu - configurable on the next page."
4508
4509	LangString SecShortcutDesktop_Desc ${LANG_ENGLISH} "Creates a shortcut for OpenCPN on the Desktop."
4510
4511	LangString SecSetConfig_Desc ${LANG_ENGLISH} "Preconfigure the language setting and the chart dir(s) for s63_pi. When selected a separate page is shown for configuration."
4512
4513  ;Uninstaller Descriptions
4514	LangString UnSecDeleteConfigFolder_Desc ${LANG_ENGLISH} "Deletes the config folder and all its files and subdirectories."
4515
4516  ;Un-install Link
4517	LangString Uninstall_Link ${LANG_ENGLISH} "Uninstall @CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@"
4518
4519  ;Multiple Install > 1
4520    ;Title
4521	LangString Page_TypeInst_Title ${LANG_ENGLISH} "Previous Installations"
4522
4523	;Subtitle
4524    LangString Page_TypeInst_Subtitle ${LANG_ENGLISH} "$MULTIPLE_INSTALLS installations of s63_pi found.$\r$\nChoose how you want to install s63_pi."
4525
4526  ;Multiple Install = 1
4527    ;Title
4528	LangString Page_TypeInst_Title_1 ${LANG_ENGLISH} "Already Installed"
4529
4530	;Subtitle
4531    LangString Page_TypeInst_Subtitle_1 ${LANG_ENGLISH} "Found installed version of s63_pi.$\r$\n"
4532
4533  ;Version exists
4534    ;Title
4535	LangString Page_TypeInst_Title_Exists ${LANG_ENGLISH} "Version Already Installed"
4536
4537	;Subtitle
4538    LangString Page_TypeInst_Subtitle_Exists ${LANG_ENGLISH} "s63_pi @CPACK_PACKAGE_VERSION@ is already installed.$\r$\nChoose how you want to install s63_pi."
4539
4540	;Label
4541	LangString Label_TypeInst_Reinstall_Text ${LANG_ENGLISH} "s63_pi @CPACK_PACKAGE_VERSION@ is already installed on your system. You can reinstall the version now using the previous settings. If you wish to install the program with different settings, cancel installation and un-install the existing version first. Click Next to continue."
4542
4543	;Radio button 'Reinstall'
4544	LangString RB_Reinstall_TypeInst_Text ${LANG_ENGLISH} "Reinstall using previous settings"
4545
4546  ;Version newer
4547	;Label
4548    LangString Label_TypeInst_Upgrade_Text ${LANG_ENGLISH} "An older version of s63_pi is installed on your system. Click Next to continue upgrade."
4549
4550	;Radio button 'Upgrade'
4551	LangString RB_Upgrade_TypeInst_Text ${LANG_ENGLISH} "Upgrade s63_pi using previous settings (recommended)"
4552
4553  ;Version older
4554	;Label
4555    LangString Label_TypeInst_Downgrade_Text ${LANG_ENGLISH} "A newer version of s63_pi is installed on your system. It is not recommended to downgrade to an older version. Select the installation type you want to perform and click Next to continue."
4556
4557	;Radio button 'Downgrade'
4558	LangString RB_Downgrade_TypeInst_Text ${LANG_ENGLISH} "Downgrade s63_pi using previous settings (recommended)"
4559
4560  ;Multiple versions
4561	;Label
4562	LangString Label_TypeInst_Parallel_Text ${LANG_ENGLISH} "Setup has detected several installed versions of s63_pi on your system. It is recommended to have only one version of s63_pi installed at a time. Select the operation you want to perform and click Next to continue."
4563
4564	;Radio button 'Parallel Installation'
4565	LangString RB_Parallel_TypeInst_Text ${LANG_ENGLISH} "Parallel Installation (advanced users)"
4566
4567  ;Empty string - needed for Components page
4568	LangString EmptyString ${LANG_ENGLISH} ""
4569
4570  ;Finish page
4571	LangString Show_Readme_Text ${LANG_ENGLISH} "Show Install Log file"
4572
4573	LangString Finish_Link_Text ${LANG_ENGLISH} "OpenCPN website (Internet connection required)"
4574
4575	LangString Finish_Link_URL ${LANG_ENGLISH} "http://opencpn.info/?ref=installer&user=$USERS_NAME&lang=$REG_LANG&version=@CPACK_PACKAGE_VERSION@"
4576
4577  ;Message Boxes
4578	LangString Msg_UAC_Admin_Retry ${LANG_ENGLISH} "This $Inst_Or_Uninst requires admin access!$\r$\nPlease log on as an Administrator and try again."
4579
4580	LangString Msg_UAC_Admin_Abort ${LANG_ENGLISH} "This $Inst_Or_Uninst requires admin privileges, aborting!"
4581
4582	LangString Msg_UAC_Logon_Abort ${LANG_ENGLISH} "Logon service not running, aborting!"
4583
4584	LangString Msg_UAC_No_Elevation ${LANG_ENGLISH} "Unable to elevate , error $0"
4585
4586	LangString Msg_Error_Remove_InstDir ${LANG_ENGLISH} "The installation directory$\r$\n'$INSTDIR'$\r$\ncould not be removed because it is not empty."
4587
4588	LangString Msg_Path_Invalid ${LANG_ENGLISH} "The entered path is invalid!$\r$\n$\r$\nPlease check your input."
4589
4590	LangString Msg_Path_Installation_Exists ${LANG_ENGLISH} "There already exists an installation of s63_pi in the given path.$\r$\nIf you wish to use this path, first uninstall the version. Or select another path for this installation."
4591
4592	LangString Msg_Uninstall_Old_Versions ${LANG_ENGLISH} "Setup has detected at least one older version of s63_pi which is not compatible with the new version control.$\r$\n\
4593		It is recommended to first uninstall all of these installations (this does not affect your Config files) and clean-up the Registry.$\r$\n\
4594		If you click Yes on the next page a listbox with all installation locations will be shown and you will have the possibility to select the installations you wish to uninstall.$\r$\n\
4595		If you are unsure about possible other previous installations than those shown in the listbox, you can also perform a scan of the entire \
4596		Harddisk (ATTENTION: This may take several minutes) to find all install locations (recommended).$\r$\n$\r$\n\
4597		Do you want to uninstall the old version(s)?"
4598
4599	LangString Msg_Not_All_Old_Uninstalled ${LANG_ENGLISH} "You have not uninstalled all previous installations.$\r$\n$\r$\nDo you want to continue anyway?"
4600
4601	LangString Msg_Uninstaller_Param_Help ${LANG_ENGLISH} "Uninstaller Help$\r$\n$\r$\nUse the command line or a shortcut to run the uninstaller:$\r$\n$INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe [/?] | [/S], [/type=X]$\r$\n$\r$\nParameters:$\r$\n/?$\tshows this help message box$\r$\n/S$\truns the uninstaller in silent mode$\r$\n$\twill do a full uninstall if called without any type parameter$\r$\n/type=X$\tX must be a digit between 1 and 5$\r$\n$\t1 = Removes only the program files$\r$\n$\t2 = Removes only the program files + preconfig RegKey$\r$\n$\t3 = Removes the program files + config folder$\r$\n$\tpreserves the preconfig RegKey$\r$\n$\t4 = Deletes only the config folder$\r$\n$\t5 = Deletes only the preconfig RegKey$\r$\n$\r$\nEntering any other number or value will quit the uninstaller with a message box without removing or deleting anything."
4602
4603	LangString Msg_Unknown_Type_Param ${LANG_ENGLISH} "The entered value '$9' for the type parameter is not valid!$\r$\nUse $INSTDIR\Uninstall @CPACK_PACKAGE_VERSION@.exe /?$\r$\nto see a list of valid values."
4604
4605  ;added on 2010-10-16
4606	LangString SecGrpShortcuts_Text ${LANG_ENGLISH} "Create Shortcuts"
4607
4608	LangString SecShortcutStartmenu_Text ${LANG_ENGLISH} "Add Shortcuts to the Start Menu"
4609
4610	LangString SecShortcutDesktop_Text ${LANG_ENGLISH} "Create Shortcut on the Desktop"
4611
4612	LangString Installation_Delete_Config ${LANG_ENGLISH} "Delete (existing) Config Subdirectories/ Files"
4613
4614  ;added on 2010-10-17
4615	LangString Banner_Scan_Drive ${LANG_ENGLISH} "Scanning Drive $9"
4616
4617	LangString Banner_Installation_Found_Singular ${LANG_ENGLISH} "Found $counter_tmp installation"
4618
4619	LangString Banner_Installation_Found_Plural ${LANG_ENGLISH} "Found $counter_tmp installations"
4620
4621  ;added on 2010-10-21
4622	LangString Uninstall_Folder_Name ${LANG_ENGLISH} "Uninstall"
4623
4624  ;added on 2011-06-13
4625	LangString ^NameDA ${LANG_ENGLISH} "@CPACK_PACKAGE_NAME@ Version @CPACK_PACKAGE_VERSION@"
4626    LangString Installer ${LANG_ENGLISH} "Installer"
4627
4628;#EOF
4629