]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/init.nsh
installer:
[features.git] / development / Win32 / packaging / installer / include / init.nsh
1 /*
2
3 init.nsh
4
5 Initialization function
6
7 */
8
9 #--------------------------------
10 # Installer initialization
11
12 !macro PRINTER_INIT
13
14   ${If} ${AtLeastWinVista}
15     StrCpy $PrinterConf "printui.exe"
16   ${Else}
17     StrCpy $PrinterConf "rundll32.exe printui.dll,PrintUIEntry"
18   ${EndIf}
19
20 !macroend
21
22 Function .onInit
23
24   ${IfNot} ${IsNT}
25   ${OrIfNot} ${AtLeastWinXP}
26     MessageBox MB_OK|MB_ICONSTOP "${APP_NAME} ${APP_VERSION} requires Windows XP or later."
27     Quit
28   ${EndIf}
29   
30   # check that the installer is not currently running
31   System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${BundleExeFile}.Instance") i .r1 ?e'
32   Pop $R0
33   ${if} $R0 != "0"
34    MessageBox MB_OK|MB_ICONSTOP "$(InstallRunning)"
35    Abort
36   ${endif}
37   System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${ExeFile}.Instance") i .r1 ?e'
38   Pop $R0
39   ${if} $R0 != "0"
40    MessageBox MB_OK|MB_ICONSTOP "$(InstallRunning)"
41    Abort
42   ${endif}
43
44   # check if LyX is already installed
45   ReadRegStr $0 HKLM "${APP_UNINST_KEY}" "Publisher"
46   ${if} $0 != ""
47    MessageBox MB_OK|MB_ICONSTOP "$(StillInstalled)"
48    Abort
49   ${endif}
50
51   !insertmacro PRINTER_INIT
52   !insertmacro MULTIUSER_INIT
53   
54   # this can be reset to "true" in section SecDesktop
55   StrCpy $CreateDesktopIcon "false"
56   StrCpy $CreateFileAssociations "false"
57  
58   ${IfNot} ${Silent}
59   
60     !ifndef BUNDLE_IMAGEMAGICK & BUNDLE_GHOSTSCRIPT
61     # Warn the user when no Administrator or Power user privileges are available
62     # These privileges are required to install ImageMagick or Ghostscript
63     ${If} $MultiUser.Privileges != "Admin"
64     ${AndIf} $MultiUser.Privileges != "Power"
65       MessageBox MB_OK|MB_ICONEXCLAMATION $(TEXT_NO_PRIVILEDGES)
66     ${EndIf}
67     !endif
68     
69     # Show banner while installer is intializating 
70     Banner::show /NOUNLOAD "Checking system"
71   ${EndIf}
72  
73   Call SearchExternal
74   #Call InitExternal
75   
76   !if ${SETUPTYPE} == BUNDLE
77    # don't let the installer sections appear when the programs are already installed
78    ${if} $PathBibTeXEditor != ""
79     SectionSetText 3 "" # hides the corresponding uninstaller section, ${SecInstJabRef}
80    ${endif}
81   !endif
82   
83   ${IfNot} ${Silent}
84     Banner::destroy
85   ${EndIf}
86
87 FunctionEnd
88
89 # this function is called at first after starting the uninstaller
90 Function un.onInit
91
92   !insertmacro PRINTER_INIT
93   !insertmacro MULTIUSER_UNINIT
94
95   # Check that LyX is not currently running
96   FindProcDLL::FindProc "lyx.exe"
97   ${if} $R0 == "1"
98    MessageBox MB_OK|MB_ICONSTOP "$(UnInstallRunning)"
99    Abort
100   ${endif}
101
102   # set registry root key
103   ${if} $MultiUser.Privileges == "Admin"
104   ${orif} $MultiUser.Privileges == "Power"
105     SetShellVarContext all
106   ${else}
107    SetShellVarContext current
108   ${endif}
109
110   # Ascertain whether the user has sufficient privileges to uninstall.
111   # abort when LyX was installed with admin permissions but the user doesn't have administrator privileges
112   ReadRegStr $0 HKLM "${APP_UNINST_KEY}" "DisplayVersion"
113   ${if} $0 != ""
114   ${andif} $MultiUser.Privileges != "Admin"
115   ${andif} $MultiUser.Privileges != "Power"
116    MessageBox MB_OK|MB_ICONSTOP "$(UnNotAdminLabel)"
117    Abort
118   ${endif}
119   # abort when LyX couldn't be found in the registry
120   ${if} $0 == "" # check in HKCU
121    ReadRegStr $0 HKCU "${APP_UNINST_KEY}" "DisplayVersion"
122    ${if} $0 == ""
123      MessageBox MB_OK|MB_ICONEXCLAMATION "$(UnNotInRegistryLabel)"
124    ${endif}
125   ${endif}
126   
127   # Macro to investigate name of LyX's preferences folders to be able remove them
128   !insertmacro UnAppPreSuff $AppPre $AppSuff # macro from LyXUtils.nsh
129
130   # test if MiKTeX was installed together with LyX
131   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
132   ${if} $0 == "Yes${APP_SERIES_KEY}"
133    SectionSetText 2 "MiKTeX" # names the corersponding uninstaller section
134    StrCpy $LaTeXInstalled "MiKTeX"
135    DeleteRegValue HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
136   ${else}
137    SectionSetText 2 "" # hides the corresponding uninstaller section
138   ${endif}
139   
140   # test if JabRef was installed together with LyX
141   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
142   ${if} $0 == "Yes${APP_SERIES_KEY}"
143    SectionSetText 3 "JabRef" # names the corersponding uninstaller section
144    StrCpy $JabRefInstalled "Yes"
145    DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
146   ${else}
147    SectionSetText 3 "" # hides the corresponding uninstaller section
148   ${endif}
149
150   # question message if the user really wants to uninstall LyX
151   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" IDYES +2 # continue if yes
152   Abort
153
154 FunctionEnd
155
156 #--------------------------------
157 # User initialization
158
159 Var ComponentPath
160 Var LyXLangName
161
162 # COMPONENT can be LaTeX, ImageMagick and Ghostscript
163 !macro EXTERNAL_INIT COMPONENT
164
165   # APP_REGKEY_SETUP = "Software\${APP_NAME}${APP_SERIES_KEY}\Setup"
166   # where ${APP_NAME}${APP_SERIES_KEY} is something like LyX16
167   ReadRegStr $ComponentPath SHELL_CONTEXT "${APP_REGKEY_SETUP}" "${COMPONENT} Path"
168   
169   # BIN_LATEX etc are defined in settings.nsh
170   ${If} ${FileExists} "$ComponentPath\${BIN_${COMPONENT}}"
171     # set variables like PathLaTeX
172     StrCpy $Path${COMPONENT} $ComponentPath
173   ${EndIf}
174
175 !macroend
176
177 Function InitUser
178
179   # Get directories of components from registry
180   
181   !insertmacro EXTERNAL_INIT LaTeX
182   
183   # Get LyX language
184   
185   ReadRegStr $LyXLangName SHELL_CONTEXT "${APP_REGKEY_SETUP}" "LyX Language"
186   
187   ${If} $LyXLangName != ""
188     StrCpy $LangName $LyXLangName
189   ${EndIf}
190   
191 FunctionEnd
192
193 #--------------------------------
194 # visible installer sections
195
196 Section "!${APP_NAME}" SecCore
197   SectionIn RO
198 SectionEnd
199 Section "$(SecFileAssocTitle)" SecFileAssoc
200   StrCpy $CreateFileAssociations "true"
201 SectionEnd
202 Section /o "$(SecDesktopTitle)" SecDesktop
203   StrCpy $CreateDesktopIcon "true"
204 SectionEnd
205
206 !if ${SETUPTYPE} == BUNDLE
207  Section /o "$(SecInstJabRefTitle)" SecInstJabRef
208   AddSize 5000
209   StrCpy $InstallJabRef "true"
210  SectionEnd
211 !endif
212
213 # Section descriptions
214 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
215 !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} "$(SecCoreDescription)"
216 !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssoc} "$(SecFileAssocDescription)"
217 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktop} "$(SecDesktopDescription)"
218 !if ${SETUPTYPE} == BUNDLE
219  !insertmacro MUI_DESCRIPTION_TEXT ${SecInstJabRef} "$(SecInstJabRefDescription)"
220 !endif
221 !insertmacro MUI_FUNCTION_DESCRIPTION_END
222