]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/lyx_installer.nsi
67cbc4be1e07b625794b77bec6fbc136687f1723
[lyx.git] / development / Win32 / packaging / installer / lyx_installer.nsi
1 ; Lyx for Windows, NSIS v2 series installer script
2
3 ; File lyx_installer.nsi
4 ; This file is part of LyX, the document processor.
5 ; http://www.lyx.org/
6 ; Licence details can be found in the file COPYING or copy at
7 ; http://www.lyx.org/about/license.php3
8
9 ; Author Angus Leeming
10 ; Author Uwe Stöhr
11 ; Full author contact details are available in file CREDITS or copy at
12 ; http://www.lyx.org/about/credits.php
13
14 ; This script requires NSIS 2.06 and above
15 ; http://nsis.sourceforge.net/
16 ;--------------------------------
17
18 ; Do a Cyclic Redundancy Check to make sure the installer
19 ; was not corrupted by the download.
20 CRCCheck force
21
22 ; Make the installer as small as possible.
23 SetCompressor lzma
24
25 ;--------------------------------
26 ; You should need to change only these macros...
27
28 !define PRODUCT_NAME "LyX"
29 !define PRODUCT_VERSION "1.4.0"
30 !define PRODUCT_LICENSE_FILE "..\..\..\..\COPYING"
31 !define PRODUCT_SOURCEDIR "..\..\..\..\build\installprefix"
32 !define PRODUCT_EXE "$INSTDIR\bin\lyx.exe"
33 !define PRODUCT_BAT "$INSTDIR\bin\lyx.bat"
34 !define PRODUCT_EXT ".lyx"
35 !define PRODUCT_MIME_TYPE "application/lyx"
36 !define PRODUCT_UNINSTALL_EXE "$INSTDIR\uninstall.exe"
37
38 !define INSTALLER_EXE "lyx_setup_140.exe"
39 !define INSTALLER_ICON "..\icons\lyx_32x32.ico"
40
41 ; Replaced by HKLM or HKCU depending on SetShellVarContext.
42 !define PRODUCT_ROOT_KEY "SHCTX"
43
44 !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\lyx.exe"
45 !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
46
47 ;--------------------------------
48 ; Make some of the information above available to NSIS.
49
50 Name "${PRODUCT_NAME}"
51 OutFile "${INSTALLER_EXE}"
52 InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
53
54 ;--------------------------------
55 !include "MUI.nsh"
56 !include "LogicLib.nsh"
57 !include "StrFunc.nsh"
58 !include "strtrim.nsh"
59 !include "download.nsh"
60 !include "lyx_utils.nsh"
61
62 ; Grabbed from
63 ; http://nsis.sourceforge.net/archive/viewpage.php?pageid=275
64 !include "is_user_admin.nsh"
65
66 ; Grabbed from
67 ; http://abiword.pchasm.org/source/cvs/abiword-cvs/abi/src/pkg/win/setup/NSISv2/abi_util_fileassoc.nsh
68 ; Use the Abiword macros to help set up associations with the file extension.
69 ; in the Registry.
70 !include "abi_util_fileassoc.nsh"
71
72 ;--------------------------------
73 ; Declare used functions
74
75 ${StrStrAdv}
76 ${StrLoc}
77 ${StrNSISToIO}
78 ${StrRep}
79 ${StrTok}
80 ${StrTrim}
81 ${StrLTrim}
82 ${StrRTrim}
83 ${StrRTrimChar}
84 ${ReadDownloadValues}
85 ${EnableBrowseControls}
86 ${SearchRegistry}
87 ${DownloadEnter}
88 ${DownloadLeave}
89
90 ;--------------------------------
91 ; Variables
92
93 Var MinSYSPath
94 Var DownloadMinSYS
95
96 Var PythonPath
97 Var DownloadPython
98
99 Var DoNotRequireMiKTeX
100 Var MiKTeXPath
101 Var DownloadMiKTeX
102
103 Var DoNotRequireGhostscript
104 Var GhostscriptPath
105 Var DownloadGhostscript
106
107 Var DoNotRequireImageMagick
108 Var ImageMagickPath
109 Var DownloadImageMagick
110
111 Var PDFViewerPath
112
113 Var PSViewerPath
114 Var PSViewerProg
115
116 Var DoNotInstallLyX
117 Var PathPrefix
118
119 Var CreateFileAssociations
120 Var CreateDesktopIcon
121 Var StartmenuFolder
122 Var ProductRootKey
123
124 Var LangName
125 Var LangCode
126
127 ;--------------------------------
128
129 ; Remember the installer language
130 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
131 !define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
132 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
133
134 !define MUI_ABORTWARNING
135 !define MUI_ICON "${INSTALLER_ICON}"
136 !define MUI_UNICON "${INSTALLER_ICON}"
137
138 ; Welcome page
139 !insertmacro MUI_PAGE_WELCOME
140
141 Page custom DownloadMinSYS DownloadMinSYS_LeaveFunction
142 Page custom DownloadPython DownloadPython_LeaveFunction
143 Page custom DownloadMiKTeX DownloadMiKTeX_LeaveFunction
144 Page custom DownloadGhostscript DownloadGhostscript_LeaveFunction
145 Page custom DownloadImageMagick DownloadImageMagick_LeaveFunction
146 Page custom SummariseDownloads SummariseDownloads_LeaveFunction
147
148 ; Show the license.
149 !insertmacro MUI_PAGE_LICENSE "${PRODUCT_LICENSE_FILE}"
150
151 ; Specify the installation directory.
152 !insertmacro MUI_PAGE_DIRECTORY
153
154 ; Specify LyX's menu language.
155 Page custom SelectMenuLanguage SelectMenuLanguage_LeaveFunction
156
157 ; Define which components to install.
158 !insertmacro MUI_PAGE_COMPONENTS
159
160 ; Specify where to install program shortcuts.
161 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_ROOT_KEY}"
162 !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
163 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
164 !insertmacro MUI_PAGE_STARTMENU ${PRODUCT_NAME} $StartmenuFolder
165
166 ; Watch the components being installed.
167 !insertmacro MUI_PAGE_INSTFILES
168
169 !define MUI_FINISHPAGE_RUN
170 !define MUI_FINISHPAGE_TEXT_LARGE
171 !define MUI_FINISHPAGE_TEXT "$(FinishPageMessage)"
172 !define MUI_FINISHPAGE_RUN_TEXT "$(FinishPageRun)"
173 !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchProduct"
174 !insertmacro MUI_PAGE_FINISH
175
176 ; The uninstaller.
177 !insertmacro MUI_UNPAGE_INSTFILES
178
179 ;--------------------------------
180 ; Languages
181
182 !insertmacro MUI_LANGUAGE "English" # first language is the default language
183 !insertmacro MUI_LANGUAGE "Danish"
184 !insertmacro MUI_LANGUAGE "German"
185 !insertmacro MUI_LANGUAGE "Spanish"
186 !insertmacro MUI_LANGUAGE "French"
187 !insertmacro MUI_LANGUAGE "Italian"
188 !insertmacro MUI_LANGUAGE "Dutch"
189 !insertmacro MUI_LANGUAGE "Polish"
190 !insertmacro MUI_LANGUAGE "Swedish"
191
192 !include "lyx_languages\english.nsh"
193 !include "lyx_languages\danish.nsh"
194 !include "lyx_languages\dutch.nsh"
195 !include "lyx_languages\french.nsh"
196 !include "lyx_languages\german.nsh"
197 !include "lyx_languages\italian.nsh"
198 !include "lyx_languages\polish.nsh"
199 !include "lyx_languages\spanish.nsh"
200 !include "lyx_languages\swedish.nsh"
201
202 LicenseData "$(LyXLicenseData)"
203
204 ;--------------------------------
205 ; Reserve Files
206
207 ; These files should be inserted before other files in the data block
208 ; Keep these lines before any File command
209 ; Only for solid compression (by default, solid compression
210 ; is enabled for BZIP2 and LZMA)
211 ReserveFile "io_download.ini"
212 ReserveFile "io_summary.ini"
213 !insertmacro MUI_RESERVEFILE_LANGDLL
214 ReserveFile "io_ui_language.ini"
215 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
216
217 ;--------------------------------
218
219 Section "!${PRODUCT_NAME}" SecCore
220   SectionIn RO
221 SectionEnd
222
223 Section /o "$(SecAllUsersTitle)" SecAllUsers
224   SetShellVarContext all
225   StrCpy $ProductRootKey "HKLM"
226 SectionEnd
227
228 Section "$(SecFileAssocTitle)" SecFileAssoc
229   StrCpy $CreateFileAssociations "true"
230 SectionEnd
231
232 Section "$(SecDesktopTitle)" SecDesktop
233   StrCpy $CreateDesktopIcon "true"
234 SectionEnd
235
236 ; The '-' makes the section invisible.
237 ; Sections are entered in order, so the settings above are all
238 ; available to SecInstallation
239 Section "-Installation actions" SecInstallation
240   SetOverwrite on
241   SetOutPath "$INSTDIR"
242   File /r "${PRODUCT_SOURCEDIR}\Resources"
243   File /r "${PRODUCT_SOURCEDIR}\bin"
244
245   ${if} "$PathPrefix" != ""
246     lyx_configure::set_path_prefix "$INSTDIR\Resources\configure" "$PathPrefix"
247     Pop $0
248     ${if} $0 != 0
249       MessageBox MB_OK "$(ModifyingConfigureFailed)"
250     ${endif}
251   ${endif}
252
253   lyx_configure::create_lyx_bat "$INSTDIR\bin" "$LangCode"
254   Pop $0
255   ${if} $0 != 0
256     MessageBox MB_OK "$(CreateCmdFilesFailed)"
257   ${endif}
258
259   lyx_configure::run_configure "$INSTDIR\Resources\configure" "$PathPrefix"
260   Pop $0
261   ${if} $0 != 0
262     MessageBox MB_OK "$(RunConfigureFailed)"
263   ${endif}
264
265   WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "${PRODUCT_EXE}"
266   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "RootKey" "$ProductRootKey"
267   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
268   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "${PRODUCT_UNINSTALL_EXE}"
269   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "${PRODUCT_EXE}"
270   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
271   WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "StartMenu" "$SMPROGRAMS\$StartmenuFolder"
272
273   CreateDirectory "$SMPROGRAMS\$StartmenuFolder"
274   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\${PRODUCT_NAME}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
275   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\Uninstall.lnk" "${PRODUCT_UNINSTALL_EXE}"
276
277   ${if} $CreateDesktopIcon == "true"
278     CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
279   ${endif}
280
281   ${if} $CreateFileAssociations == "true"
282     ${CreateApplicationAssociation} \
283       "${PRODUCT_NAME}" \
284       "${PRODUCT_NAME}" \
285       "${PRODUCT_NAME} Document" \
286       "${PRODUCT_EXE},1" \
287       "${PRODUCT_BAT}"
288
289     ${CreateFileAssociation} "${PRODUCT_EXT}" "${PRODUCT_NAME}" "${PRODUCT_MIME_TYPE}"
290   ${endif}
291
292   WriteUninstaller "${PRODUCT_UNINSTALL_EXE}"
293 SectionEnd
294
295 ; Section descriptions
296 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
297   !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} "$(SecCoreDescription)"
298   !insertmacro MUI_DESCRIPTION_TEXT ${SecAllUsers} "$(SecAllUsersDescription)"
299   !insertmacro MUI_DESCRIPTION_TEXT ${SecFileAssoc} "$(SecFileAssocDescription)"
300   !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktop} "$(SecDesktopDescription)"
301 !insertmacro MUI_FUNCTION_DESCRIPTION_END
302
303 ;--------------------------------
304
305 !define MUI_LANGDLL_ALWAYSSHOW
306
307 ; This hook function is called internally by NSIS on installer startup
308 Function .onInit
309   !insertmacro MUI_LANGDLL_DISPLAY
310
311   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "io_download.ini"
312   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "io_summary.ini"
313   !insertmacro MUI_INSTALLOPTIONS_EXTRACT "io_ui_language.ini"
314
315   ; Default settings
316   ; These can be reset to "all" in section SecAllUsers.
317   SetShellVarContext current
318   StrCpy $ProductRootKey "HKCU"
319
320   ; This can be reset to "true" in section SecDesktop.
321   StrCpy $CreateDesktopIcon "false"
322   StrCpy $CreateFileAssociations "false"
323
324   ; If the user does *not* have administrator privileges,
325   ; then make section SecAllUsers readonly.
326   Call IsUserAdmin
327   Pop $0
328   ${if} $0 == "true"
329     !define ENABLE 0x00000001
330     SectionGetFlags ${SecAllUsers} $0
331     IntOp $0 $0 | ${ENABLE}
332     SectionSetFlags ${SecAllUsers} $0
333     !undef ENABLE
334   ${else}
335     !define READ_ONLY 0x00000010
336     SectionGetFlags ${SecAllUsers} $0
337     IntOp $0 $0 | ${READ_ONLY}
338     SectionSetFlags ${SecAllUsers} $0
339     !undef READ_ONLY
340   ${endif}
341
342   Call SearchMinSYS
343   Call SearchPython
344   Call SearchMiKTeX
345   Call SearchGhostscript
346   Call SearchImageMagick
347   Call SearchPDFViewer
348   Call SearchPSViewer
349
350   ClearErrors
351 FunctionEnd
352
353 ;--------------------------------
354
355 Function LaunchProduct
356   lyx_configure::set_env LANG $LangCode
357   Exec ${PRODUCT_EXE}
358 FunctionEnd
359
360 ;--------------------------------
361
362 ; Sets the value of the global $MinSYSPath variable.
363 Function SearchMinSYS
364   ; This function manipulates the registers $0-$3,
365   ; so push their current content onto the stack.
366   Push $0
367   Push $1
368   Push $2
369   Push $3
370
371   ; Search the registry for the MinSYS uninstaller.
372   ; If successful, put its location in $2.
373   StrCpy $3 "Software\Microsoft\Windows\CurrentVersion\Uninstall"
374   StrCpy $2 ""
375   StrCpy $0 0
376   loop:
377     EnumRegKey $1 HKLM "$3" $0
378     ${if} $1 == ""
379       Goto done
380     ${endif}
381
382     ${StrLoc} $2 "$1" "MSYS-1.0" "<"
383     ${if} $2 > 0
384       StrCpy $2 "$3\$1"
385       Goto done
386     ${else}
387       StrCpy $2 ""
388     ${endif}
389     IntOp $0 $0 + 1
390     Goto loop
391   done:
392
393   ${SearchRegistry} \
394       $MinSYSPath \
395       "$2" \
396       "Inno Setup: App Path" \
397       "" \
398       "\bin"
399
400   ; Return the $0, $1, $2 and $2 registers to their original state
401   Pop $3
402   Pop $2
403   Pop $1
404   Pop $0
405 FunctionEnd
406
407 Function DownloadMinSYS
408   StrCpy $DownloadMinSYS "0"
409
410   ${DownloadEnter} \
411       $MinSYSPath \
412       0 \
413       "$(MinSYSDownloadLabel)" \
414       "$(MinSYSFolderLabel)" \
415       "$(MinSYSHeader)" \
416       "$(MinSYSDescription)"
417 FunctionEnd
418
419 Function DownloadMinSYS_LeaveFunction
420   ; This function manipulates the $0 register
421   ; so push its current content onto the stack.
422   Push $0
423
424   ${DownloadLeave} \
425       $0 \
426       $DownloadMinSYS \
427       $MinSYSPath \
428       "http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=82721&release_id=158803" \
429       "$(EnterMinSYSFolder)" \
430       "sh.exe" \
431       "$(InvalidMinSYSFolder)"
432
433   ; Return the $0 register to its original state
434   Pop $0
435 FunctionEnd
436
437 ;--------------------------------
438
439 ; Sets the value of the global $PythonPath variable.
440 Function SearchPython
441   ${SearchRegistry} \
442       $PythonPath \
443       "Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe" \
444       "" \
445       "\Python.exe" \
446       ""
447 FunctionEnd
448
449 Function DownloadPython
450   StrCpy $DownloadPython "0"
451
452   ${DownloadEnter} \
453       $PythonPath \
454       0 \
455       "$(PythonDownloadLabel)" \
456       "$(PythonFolderLabel)" \
457       "$(PythonHeader)" \
458       "$(PythonDescription)"
459 FunctionEnd
460
461 Function DownloadPython_LeaveFunction
462   ; This function manipulates the $0 register
463   ; so push its current content onto the stack.
464   Push $0
465
466   ${DownloadLeave} \
467       $0 \
468       $DownloadPython \
469       $PythonPath \
470       "http://www.python.org/download/" \
471       "$(EnterPythonFolder)" \
472       "Python.exe" \
473       "$(InvalidPythonFolder)"
474
475   ; Return the $0 register to its original state
476   Pop $0
477 FunctionEnd
478
479 ;--------------------------------
480
481 ; Sets the value of the global $MiKTeXPath variable.
482 Function SearchMiKTeX
483   ${SearchRegistry} \
484       $MiKTeXPath \
485       "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" \
486       "Install Root" \
487       "" \
488       "\miktex\bin"
489 FunctionEnd
490
491 Function DownloadMiKTeX
492   StrCpy $DoNotRequireMiKTeX "1"
493   StrCpy $DownloadMiKTeX "0"
494
495   ${DownloadEnter} \
496       $MiKTeXPath \
497       1 \
498       "$(MiKTeXDownloadLabel)" \
499       "$(MiKTeXFolderLabel)" \
500       "$(MiKTeXHeader)" \
501       "$(MiKTeXDescription)"
502 FunctionEnd
503
504 Function DownloadMiKTeX_LeaveFunction
505   ${DownloadLeave} \
506       $DoNotRequireMiKTeX \
507       $DownloadMiKTeX \
508       $MiKTeXPath \
509       "http://www.miktex.org/setup.html" \
510       "$(EnterMiKTeXFolder)" \
511       "latex.exe" \
512       "$(InvalidMiKTeXFolder)"
513 FunctionEnd
514
515 ;--------------------------------
516
517 ; Sets the value of the global $GhostscriptPath variable.
518 Function SearchGhostscript
519   ; This function manipulates the $0 and $1 registers,
520   ; so push their current content onto the stack.
521   Push $0
522   Push $1
523
524   ; Find which version of ghostscript, if any, is installed.
525   ; Store this value in $0.
526   StrCpy $0 ""
527   EnumRegKey $1 HKLM "Software\AFPL Ghostscript" 0
528   ${if} $1 != ""
529     StrCpy $0 "Software\AFPL Ghostscript\$1"
530   ${else}
531     EnumRegKey $1 HKLM "Software\GPL Ghostscript" 0
532     ${if} $1 != ""
533       StrCpy $0 "Software\GPL Ghostscript\$1"
534     ${endif}
535   ${endif}
536
537   ${SearchRegistry} \
538       $GhostscriptPath \
539       "$0" \
540       "GS_DLL" \
541       "\gsdll32.dll" \
542       ""
543
544   ; Return the $0 and $1 registers to their original states
545   Pop $1
546   Pop $0
547 FunctionEnd
548
549 Function DownloadGhostscript
550   StrCpy $DoNotRequireGhostscript "1"
551   StrCpy $DownloadGhostscript "0"
552
553   ; Find which version of ghostscript, if any, is installed.
554   EnumRegKey $1 HKLM "Software\AFPL Ghostscript" 0
555   ${if} $1 == ""
556    EnumRegKey $1 HKLM "Software\GPL Ghostscript" 0
557    StrCpy $2 "True"
558   ${endif}
559   ${if} $1 != ""
560    ${if} $2 == "True"
561     StrCpy $0 "Software\GPL Ghostscript\$1"
562    ${else}
563     StrCpy $0 "Software\AFPL Ghostscript\$1"
564    ${endif}
565   ${else}
566     StrCpy $0 ""
567   ${endif}
568
569   ${DownloadEnter} \
570       $GhostscriptPath \
571       1 \
572       "$(GhostscriptDownloadLabel)" \
573       "$(GhostscriptFolderLabel)" \
574       "$(GhostscriptHeader)" \
575       "$(GhostscriptDescription)"
576 FunctionEnd
577
578 Function DownloadGhostscript_LeaveFunction
579   ${DownloadLeave} \
580       $DoNotRequireGhostscript \
581       $DownloadGhostscript \
582       $GhostscriptPath \
583       "http://www.cs.wisc.edu/~ghost/doc/AFPL/index.htm" \
584       "$(EnterGhostscriptFolder)" \
585       "gswin32c.exe" \
586       "$(InvalidGhostscriptFolder)"
587 FunctionEnd
588
589 ;--------------------------------
590
591 ; Sets the value of the global $ImageMagickPath variable.
592 Function SearchImageMagick
593   ${SearchRegistry} \
594       $ImageMagickPath \
595       "Software\ImageMagick\Current" \
596       "BinPath" \
597       "" \
598       ""
599 FunctionEnd
600
601 Function DownloadImageMagick
602   StrCpy $DoNotRequireImageMagick "1"
603   StrCpy $DownloadImageMagick "0"
604
605   ${DownloadEnter} \
606       $ImageMagickPath \
607       1 \
608       "$(ImageMagickDownloadLabel)" \
609       "$(ImageMagickFolderLabel)" \
610       "$(ImageMagickHeader)" \
611       "$(ImageMagickDescription)"
612 FunctionEnd
613
614 Function DownloadImageMagick_LeaveFunction
615   ${DownloadLeave} \
616       $DoNotRequireImageMagick \
617       $DownloadImageMagick \
618       $ImageMagickPath \
619       "http://www.imagemagick.org/script/binary-releases.php" \
620       "$(EnterImageMagickFolder)" \
621       "convert.exe" \
622       "$(InvalidImageMagickFolder)"
623 FunctionEnd
624
625 ;--------------------------------
626
627 ; Sets the value of the global $PDFViewerPath variable.
628 Function SearchPDFViewer
629   ; test if a pdf-viewer is installed, only test for Acrobat, Adobe Reader (AroRD32), and GSview32
630   StrCpy $PDFViewerPath ""
631   ReadRegStr $PDFViewerPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" "Path"
632   ${if} $PDFViewerPath == ""
633    ReadRegStr $PDFViewerPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe" "Path"
634   ${endif}
635   ${if} $PDFViewerPath == ""
636    ReadRegStr $PDFViewerPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\gsview32.exe" "Path"
637   ${endif}
638   StrCpy $0 $PDFViewerPath "" -1 ;remove the "\" at the end
639   ${if} $0 == "\"
640    StrCpy $PDFViewerPath $PDFViewerPath -1
641   ${endif}
642 FunctionEnd
643
644 ;--------------------------------
645
646 Function SearchPSViewer
647   ; This function manipulates the $0 register,
648   ; so push its current content onto the stack.
649   Push $0
650
651   ; test if a ps-viewer is installed, only check for GSview32
652   StrCpy $PSViewerPath ""
653   ReadRegStr $PSViewerPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\gsview32.exe" "Path"
654
655   ; Failed to find anything that way. Try another.
656   ${if} $PSViewerPath == ""
657     ReadRegStr $PSViewerProg HKCR "psfile\shell\open\command" ""
658     ; Extract the first quoted word.
659     ${StrTok} $0 "$PSViewerProg" '"' '1' '0'
660     ${if} $0 != ""
661       StrCpy $PSViewerProg $0
662     ${endif}
663
664     ${StrTrim} $PSViewerProg "$PSViewerProg"
665     ; Split into <path,exe> pair
666     ${StrStrAdv} $PSViewerPath $PSViewerProg "\" "<" "<" "0" "0" "0"
667     ${StrStrAdv} $PSViewerProg $PSViewerProg "\" "<" ">" "0" "0" "0"
668   ${endif}
669
670   ; Return the $0 register to its original states
671   Pop $0
672 FunctionEnd
673
674 ;--------------------------------
675
676 Function SummariseDownloads
677
678   StrCpy $PathPrefix ""
679   ${if} $MinSYSPath != ""
680     StrCpy $PathPrefix "$PathPrefix;$MinSYSPath"
681   ${endif}
682   ${if} $PythonPath != ""
683     StrCpy $PathPrefix "$PathPrefix;$PythonPath"
684   ${endif}
685   ${if} $MiKTeXPath != ""
686     StrCpy $PathPrefix "$PathPrefix;$MiKTeXPath"
687   ${endif}
688   ${if} $GhostscriptPath != ""
689     StrCpy $PathPrefix "$PathPrefix;$GhostscriptPath"
690   ${endif}
691   ${if} $ImageMagickPath != ""
692     StrCpy $PathPrefix "$PathPrefix;$ImageMagickPath"
693   ${endif}
694   ; Remove the leading ';'
695   StrCpy $PathPrefix "$PathPrefix" "" 1
696
697   IntOp $DoNotInstallLyX $DownloadMinSYS + $DownloadPython
698   IntOp $DoNotInstallLyX $DoNotInstallLyX + $DownloadMiKTeX
699   IntOp $DoNotInstallLyX $DoNotInstallLyX + $DownloadGhostscript
700   IntOp $DoNotInstallLyX $DoNotInstallLyX + $DownloadImageMagick
701
702   ${if} "$DoNotInstallLyX" == 1
703     !insertmacro MUI_INSTALLOPTIONS_WRITE "io_summary.ini" "Field 1" "Text" "$(SummaryPleaseInstall)"
704   ${else}
705     ${StrNSISToIO} $0 '$PathPrefix'
706     ${StrRep} $0 "$0" ";" "\r\n"
707     StrCpy $0 "$(SummaryPathPrefix)\r\n\r\n$0"
708     !insertmacro MUI_INSTALLOPTIONS_WRITE "io_summary.ini" "Field 1" "Text" "$0"
709   ${endif}
710
711   !insertmacro MUI_HEADER_TEXT "$(SummaryTitle)" ""
712   !insertmacro MUI_INSTALLOPTIONS_DISPLAY "io_summary.ini"
713 FunctionEnd
714
715 Function SummariseDownloads_LeaveFunction
716   ${if} "$DoNotInstallLyX" == 1
717     Quit
718   ${endif}
719 FunctionEnd
720
721 ;--------------------------------
722
723 Function SelectMenuLanguage
724   StrCpy $LangName ""
725
726   ;tranlate NSIS's language code to the language name; macro from lyx_utils.nsh
727   !insertmacro TranslateLangCode $LangName $Language
728
729   !insertmacro MUI_INSTALLOPTIONS_WRITE "io_ui_language.ini" "Field 1" "State" "$(UILanguageAvailableLanguages)"
730   !insertmacro MUI_INSTALLOPTIONS_WRITE "io_ui_language.ini" "Field 2" "State" "$LangName"
731
732   !insertmacro MUI_HEADER_TEXT "$(UILangageTitle)" "$(UILangageDescription)"
733   !insertmacro MUI_INSTALLOPTIONS_DISPLAY "io_ui_language.ini"
734 FunctionEnd
735
736 ;--------------------------------
737
738 Function SelectMenuLanguage_LeaveFunction
739   !insertmacro MUI_INSTALLOPTIONS_READ $LangName "io_ui_language.ini" "Field 2" "State"
740
741   ;Get the language code; macro from lyx_utils.nsh
742   StrCpy $LangCode ""
743   !insertmacro GetLangCode $LangCode $LangName
744 FunctionEnd
745
746 ;--------------------------------
747 ; The Uninstaller
748
749 Function un.onInit
750
751   !insertmacro MUI_UNGETLANGUAGE
752
753   ; Ascertain whether the user has sufficient privileges to uninstall.
754   SetShellVarContext current
755
756   ReadRegStr $0 HKCU "${PRODUCT_UNINST_KEY}" "RootKey"
757   ${if} $0 == ""
758     ReadRegStr $0 HKLM "${PRODUCT_UNINST_KEY}" "RootKey"
759     ${if} $0 == ""
760       MessageBox MB_OK "$(UnNotInRegistryLabel)"
761     ${endif}
762   ${endif}
763
764   ${if} $0 == "HKLM"
765     Call un.IsUserAdmin
766     Pop $0
767     ${if} $0 == "true"
768       SetShellVarContext all
769     ${else}
770       MessageBox MB_OK "$(UnNotAdminLabel)"
771       Abort
772     ${endif}
773   ${endif}
774
775   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" IDYES +2
776   Abort
777 FunctionEnd
778
779
780 Function un.onUninstSuccess
781   HideWindow
782   MessageBox MB_ICONINFORMATION|MB_OK "$(UnRemoveSuccessLabel)"
783 FunctionEnd
784
785
786 Section Uninstall
787   RMDir /r $INSTDIR
788
789   ReadRegStr $0 ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "StartMenu"
790   RMDir /r "$0"
791
792   Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
793
794   DeleteRegKey "HKCU" "${PRODUCT_UNINST_KEY}"
795   DeleteRegKey ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
796   DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
797   DeleteRegKey HKCR "Applications\lyx.exe"
798   DeleteRegKey HKCR "Applications\lyx.bat"
799
800   ; remove extension .lyx
801   ${RemoveFileAssociation} "${PRODUCT_EXT}" "${PRODUCT_NAME}"
802   DeleteRegKey HKCR "${PRODUCT_NAME}"
803
804   SetAutoClose true
805 SectionEnd
806
807 ; eof