]> git.lyx.org Git - features.git/blobdiff - development/Win32/packaging/installer/include/detection.nsh
Consider inset strings in simple find/replaceAll (#12049)
[features.git] / development / Win32 / packaging / installer / include / detection.nsh
index 5287d212de17cb5552ff54a8489dad7643ddd632..01c44ff616f572808c784a57ced4f372061c1933 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*
 
 detection.nsh
 
@@ -11,22 +11,24 @@ Detection of external component locations
 # - SearchExternal, calls the functions:
 #    LaTeXActions
 #    MissingPrograms
+#    FindDictionaries
 #
 # - MissingPrograms, (check if third-party programs are installed), uses:
 #    SEARCH_MIKTEX
 #    SEARCH_TEXLIVE
 #
+# - FindDictionaries (finds installed spellcheck and thesaurus dictionaries)
+#
 # - EditorCheck,
 #    (test if an editor with syntax-highlighting for LaTeX-files is installed)
 #
 #--------------------------
 
-#Var ReportReturn
-#Var CommandLineOutput
-
 Function SearchExternal
   Call LaTeXActions # function from LaTeX.nsh
   Call MissingPrograms
+  SetRegView ${APP_VERSION_ACHITECHTURE}
+  Call FindDictionaries # function from dictionaries.nsh
 FunctionEnd
 
 # ---------------------------------------
@@ -34,52 +36,48 @@ FunctionEnd
 Function MissingPrograms
   # check if third-party programs are installed
 
-  # initialize variable, is later set to True when a program was not found
-  ${if} $MissedProg != "True" # is already True when LaTeX is missing
-   StrCpy $MissedProg "False"
+  # test if Ghostscript is installed, check all cases:
+  # 1. 32bit Windows
+  # 2. 64bit Windows but 32bit Ghostscript
+  # 3. 64bit Windows and 64bit Ghostscript
+  StrCpy $3 0
+  StrCpy $4 "0"
+  ${if} ${RunningX64}
+   SetRegView 64
   ${endif}
-
-  # test if Ghostscript is installed
+  # case 1. and 3.
   GSloop:
-  EnumRegKey $1 HKLM "Software\AFPL Ghostscript" 0
-  ${if} $1 == ""
-   EnumRegKey $1 HKLM "Software\GPL Ghostscript" 0
-   ${if} $1 != ""
-    StrCpy $2 "True"
-   ${endif}
-  ${endif}
+  EnumRegKey $1 HKLM "Software\GPL Ghostscript" $3
   ${if} $1 != ""
-   ${if} $2 == "True"
-    ReadRegStr $3 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GPL Ghostscript $1" "DisplayName"
-    StrCpy $0 "Software\GPL Ghostscript\$1"
-   ${else}
-    ReadRegStr $3 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AFPL Ghostscript $1" "DisplayName"
-    StrCpy $0 "Software\AFPL Ghostscript\$1"
-   ${endif}
-   ${if} $3 == "" # if nothing was found in the uninstall section
-    ReadRegStr $3 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" # check if Ghostscript was installed together with LyX
+   ReadRegStr $2 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GPL Ghostscript $1" "DisplayName"
+   StrCpy $0 "Software\GPL Ghostscript\$1"
+   ${if} $2 == "" # if nothing was found in the uninstall section
+    ReadRegStr $2 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" # check if Ghostscript was installed together with LyX
    ${endif}
-   ${if} $3 == "" # if nothing was found in the uninstall section
+   ${if} $2 == "" # if nothing was found in the uninstall section
     DeleteRegKey HKLM "$0"
     goto GSloop
    ${else}
     ReadRegStr $GhostscriptPath HKLM $0 "GS_DLL"
     ${if} $GhostscriptPath != ""
      StrCpy $GhostscriptPath "$GhostscriptPath" -12 # remove ending "gsdll32.dll"
-    ${else}
-     StrCpy $MissedProg "True"
     ${endif}
-   ${endif} # if $3
-  ${else} # if $1
-   StrCpy $GhostscriptPath ""
-   StrCpy $MissedProg "True"
+    # there might be several versions installed and we want to use the newest one
+    IntOp $3 $3 + 1
+    goto GSloop
+   ${endif} # if $2
+  ${endif}
+  SetRegView 32
+  # repeat for case 2.
+  ${if} ${RunningX64}
+  ${andif} $GhostscriptPath == ""
+   StrCpy $3 0
+   # we have to assure that we only repeat once and not forever
+   ${if} $4 != "32"
+    StrCpy $4 "32"
+    goto GSloop
+   ${endif}
   ${endif}
-
-  # test if Imagemagick is installed
-  #ReadRegStr $ImageMagickPath HKLM "Software\ImageMagick\Current" "BinPath"
-  #${if} $ImageMagickPath == ""
-  # StrCpy $MissedProg "True"
-  #${endif}
 
   # test if Python is installed
   # only use an existing python when it is version 2.5 or newer because some
@@ -97,57 +95,138 @@ Function MissingPrograms
    StrCpy $PythonPath $PythonPath -1 # remove the "\" at the end
    StrCpy $DelPythonFiles "True"
   ${endif}
-
-  # test if Acrobat or Adobe Reader is used as PDF-viewer
-  ReadRegStr $String HKCR ".pdf" ""
-  ${if} $String != "AcroExch.Document" # this name is only used by Acrobat and Adobe Reader
-   StrCpy $Acrobat "None"
-  ${else}
-   StrCpy $Acrobat "Yes"
+  
+  # No test necessary for Acrobat or Adobe Reader because pdfview does this job
+  # each time it is called.
+  
+  # test if a PostScript-viewer is installed, only check for GSview
+  # check all cases:
+  # 1. 32bit Windows
+  # 2. 64bit Windows but 32bit GSview
+  # 3. 64bit Windows and 64bit GSview
+  ${if} ${RunningX64}
+   SetRegView 64
+   StrCpy $PSVPath ""
+   ReadRegStr $PSVPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\gsview64.exe" "Path"
+   SetRegView 32
+  ${endif}
+  # repeat for case 1. and 2.
+  ${if} $PSVPath == ""
+   ReadRegStr $PSVPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\gsview32.exe" "Path"
   ${endif}
-
-  # test if a PostScript-viewer is installed, only check for GSview32
-  StrCpy $PSVPath ""
-  ReadRegStr $PSVPath HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\gsview32.exe" "Path"
 
   # test if an editor with syntax-highlighting for LaTeX-files is installed
   Call EditorCheck
 
-  # test if an image editor is installed (due to LyX's bug 2654 first check for GIMP)
+  # test if an image editor is installed
   StrCpy $ImageEditorPath ""
-  ReadRegStr $ImageEditorPath HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WinGimp-2.0_is1" "DisplayIcon"
+  # first check for Gimp which is a 64bit application on x64 Windows
+  ${if} ${RunningX64}
+   SetRegView 64
+  ${endif}
+  ReadRegStr $ImageEditorPath HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GIMP-2_is1" "InstallLocation"
   ${if} $ImageEditorPath != ""
-   StrCpy $ImageEditorPath "$ImageEditorPath" -13 # delete "\gimp-2.x.exe"
+   StrCpy $ImageEditorPath "$ImageEditorPathbin" # add the bin folder
+   StrCpy $ImageEditor "Gimp"
+  ${endif}
+  ${if} ${RunningX64}
+   SetRegView 32
   ${endif}
   # check for Photoshop
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe" "Path"
+  ReadRegStr $0 HKLM "Software\Classes\Applications\Photoshop.exe\shell\open\command" ""
+  ${if} $0 != ""
+   StrCpy $0 "$0" -20 # delete '\photoshop.exe" "%1"'
+   StrCpy $0 $0 "" 1 # remove the leading quote
+   ${if} $ImageEditorPath != ""
+    StrCpy $ImageEditorPath "$ImageEditorPath;$0"
+   ${else}
+    StrCpy $ImageEditorPath $0
+   ${endif}
+   StrCpy $ImageEditor "Photoshop"
+  ${endif}
+  # check for Krita
+  ${if} ${RunningX64}
+   SetRegView 64
+  ${endif}
+  ReadRegStr $0 HKLM "SOFTWARE\Classes\Krita.Document\shell\open\command" ""
   ${if} $0 != ""
-   StrCpy $0 "$0" -1 # delete the last "\"
+   StrCpy $0 "$0" -16 # delete '\krita.exe" "%1"'
+   StrCpy $0 $0 "" 1 # remove the leading quote
    ${if} $ImageEditorPath != ""
     StrCpy $ImageEditorPath "$ImageEditorPath;$0"
    ${else}
     StrCpy $ImageEditorPath $0
    ${endif}
+   StrCpy $ImageEditor "Krita"
+  ${endif}
+  ${if} ${RunningX64}
+   SetRegView 32
   ${endif}
 
   # test if and where the BibTeX-editor JabRef is installed
-  ReadRegStr $PathBibTeXEditor HKCU "Software\JabRef" "Path"
+  ${if} ${RunningX64}
+   SetRegView 64
+  ${endif}
+  ReadRegStr $PathBibTeXEditor HKLM "SOFTWARE\JabRef" "Path"
+  # if not installed as admin, check for user
   ${if} $PathBibTeXEditor == ""
-   ReadRegStr $PathBibTeXEditor HKLM "Software\JabRef" "Path"
+   ReadRegStr $PathBibTeXEditor HKCU "Software\JabRef" "Path"
+  ${endif}
+  ${if} ${RunningX64}
+   SetRegView 32
   ${endif}
 
-  ${IfNot} ${FileExists} "$PathBibTeXEditor\${BIN_BIBTEXEDITOR}"
-    StrCpy $PathBibTeXEditor ""
-    StrCpy $JabRefInstalled == "No"
+  ${ifnot} ${FileExists} "$PathBibTeXEditor\${BIN_BIBTEXEDITOR}"
+   StrCpy $PathBibTeXEditor ""
+   StrCpy $JabRefInstalled == "No"
   ${else}
    StrCpy $JabRefInstalled == "Yes"
   ${endif}
-  
+
+  # test if and where LilyPond is installed
+  ReadRegStr $LilyPondPath HKLM "Software\LilyPond" "Install_Dir"
+  ${if} $LilyPondPath != ""
+   StrCpy $LilyPondPath "$LilyPondPath\usr\bin" # add "\usr\bin"
+  ${endif}
+
   # test if Inkscape is installed
-  ReadRegStr $SVGPath HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Inkscape" "InstallLocation"
-  
-  # test if metafile2eps is installed
-  ReadRegStr $WMFPath HKLM "Software\Microsoft\Windows NT\CurrentVersion\Print\Printers\Metafile to EPS Converter" "Name"
+  ReadRegStr $SVGPath HKLM "SOFTWARE\Classes\inkscape.svg\DefaultIcon" ""
+  ${if} $SVGPath != ""
+   StrCpy $SVGPath $SVGPath "" 1 # remove the leading quote
+   StrCpy $SVGPath $SVGPath -14 # # delete '\inkscape.exe"'
+  ${endif}
+  ${if} $SVGPath == ""
+   # this was used before Inkscape 0.91:
+   ReadRegStr $SVGPath HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Inkscape" "InstallLocation"
+  ${endif}
+
+  # test if Gnumeric is installed
+  ReadRegStr $0 HKLM "Software\Classes\Applications\gnumeric.exe\shell\Open\command" ""
+  ${if} $0 != ""
+   StrCpy $0 $0 -18 # remove "gnumeric.exe" "%1""
+   StrCpy $0 $0 "" 1 # remove the leading quote
+   StrCpy $GnumericPath $0
+  ${endif}
+
+  # test if Pandoc is installed
+  # HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\John MacFarlane\Pandoc
+  ${if} ${RunningX64}
+   SetRegView 64 # the PATH is in the 64bit registry section
+  ${endif}
+  # check for the path to the pandoc.exe in Window's PATH variable
+  StrCpy $5 ""
+  StrCpy $Search "pandoc"
+  ReadRegStr $String HKCU "Environment" "PATH"
+  !insertmacro PATHCheck $5 "pandoc.exe" # macro from LyXUtils.nsh
+  # if it is not in the user-specific PATH it might be in the global PATH
+  ${if} $5 == "False"
+   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
+   !insertmacro PATHCheck $5 "pandoc.exe" # macro from LyXUtils.nsh
+  ${endif}
+  SetRegView 32
+  ${if} $5 != "False"
+   StrCpy $PandocPath $5
+  ${endif}
 
 FunctionEnd
 
@@ -159,84 +238,67 @@ Function EditorCheck
   # (check for jEdit, PSPad, WinShell, ConTEXT, Crimson Editor, Vim, TeXnicCenter, LaTeXEditor, WinEdt, LEd, WinTeX)
   StrCpy $EditorPath ""
   StrCpy $0 ""
-  # check for jEdit
+  # check for jEdit which is a 64bit application on x64 Windows
+  ${if} ${RunningX64}
+   SetRegView 64
+  ${endif}
   ReadRegStr $EditorPath HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\jEdit_is1" "InstallLocation"
   ${if} $EditorPath != ""
    StrCpy $EditorPath $EditorPath -1 # remove "\" from the end of the string
   ${endif}
+  SetRegView 32
+  
   # check for PSPad
   StrCpy $0 ""
   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PSPad editor_is1" "InstallLocation"
   ${if} $0 != ""
-   StrCpy $0 $0 -1
+   StrCpy $0 $0 -1 # remove the "\"
    StrCpy $EditorPath "$EditorPath;$0"
   ${endif}
+  
   # check for WinShell
   StrCpy $0 ""
   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WinShell_is1" "InstallLocation"
   ${if} $0 != ""
-   StrCpy $0 $0 -1
+   StrCpy $0 $0 -1 # remove the "\"
    StrCpy $EditorPath "$EditorPath;$0"
   ${endif}
-  # check for ConTEXT
+  
+  # check for Vim which is a 64bit application on x64 Windows
   StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ConTEXTEditor_is1" "InstallLocation"
-  ${if} $0 != ""
-   StrCpy $0 $0 -1
-   StrCpy $EditorPath "$EditorPath;$0"
+  ${if} ${RunningX64}
+   SetRegView 64
   ${endif}
-  # check for Crimson Editor
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Crimson Editor" "UninstallString"
+  ReadRegStr $0 HKLM "Software\Vim\Gvim" "path"
   ${if} $0 != ""
-   StrCpy $0 $0 -14 # remove "\uninstall.exe"
+   StrCpy $0 $0 -9 # remove "\gvim.exe"
    StrCpy $EditorPath "$EditorPath;$0"
   ${endif}
-  # check for Vim 6.x
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Classes\Applications\gvim.exe\shell\edit\command" ""
-  ${if} $0 != ""
-   StrCpy $0 $0 -13 # remove "gvim.exe "%1""
-   StrCpy $EditorPath "$EditorPath;$0"
-  ${endif}
-  # check for Vim 7.0
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Vim 7.0" "UninstallString"
-  ${if} $0 != ""
-   StrCpy $0 $0 -18 # remove "\uninstall-gui.exe"
-   StrCpy $EditorPath "$EditorPath;$0"
-  ${endif}
-  # check for TeXnicCenter
+  SetRegView 32
+  
+  # check for TeXnicCenter which can be a 64bit application on x64 Windows
   StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXnicCenter_is1" "Inno Setup: App Path"
-  ${if} $0 != ""
-   StrCpy $EditorPath "$EditorPath;$0"
+  ${if} ${RunningX64}
+   SetRegView 64
   ${endif}
-  # check for LaTeXEditor
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LaTeX Editor" "InstallLocation"
+  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXnicCenter_is1" "InstallLocation"
   ${if} $0 != ""
+   StrCpy $0 $0 -1 # remove the "\"
    StrCpy $EditorPath "$EditorPath;$0"
+  ${else}
+   SetRegView 32
+   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXnicCenter_is1" "InstallLocation"
+   ${if} $0 != ""
+    StrCpy $0 $0 -1 # remove the "\"
+    StrCpy $EditorPath "$EditorPath;$0"
+   ${endif}
   ${endif}
+  SetRegView 32
+  
   # check for WinEdt
   StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WinEdt_is1" "InstallLocation"
-  ${if} $0 != ""
-   StrCpy $0 $0 -1
-   StrCpy $EditorPath "$EditorPath;$0"
-  ${endif}
-  # check for LEd
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LEd_is1" "InstallLocation"
-  ${if} $0 != ""
-   StrCpy $0 $0 -1
-   StrCpy $EditorPath "$EditorPath;$0"
-  ${endif}
-  # check for WinTeX
-  StrCpy $0 ""
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WinTeX XP" "DisplayIcon"
+  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WinEdt 7" "InstallLocation"
   ${if} $0 != ""
-   StrCpy $0 $0 -11 # remove "\wintex.exe"
    StrCpy $EditorPath "$EditorPath;$0"
   ${endif}