]> git.lyx.org Git - features.git/blobdiff - development/Win32/packaging/installer2/src/main.nsh
Consider inset strings in simple find/replaceAll (#12049)
[features.git] / development / Win32 / packaging / installer2 / src / main.nsh
index 410f5c1617a427c78f872bbef514aaee9fabe56e..76263cbd28bc3c07563035ce23a6d21c984cb292 100644 (file)
@@ -19,6 +19,7 @@
 
     Var LatexPath # Used to store path to "latex.exe"
     Var StartMenuFolder # Used to store the start menu folder
+    Var pathPrefix
 
     # FIXME Variables needed due to "old" set of language strings, delete
     Var LaTeXInstalled
     Exch $9 # resultRegIdx
   FunctionEnd
   
-  !macro CreatePrepareShellCTXFun UnPrefix
-    Function ${UnPrefix}PrepareShellCTX
-      ${if} $MultiUser.InstallMode == "CurrentUser"
-        SetShellVarContext current
-      ${Else}
-        SetShellVarContext all
-      ${EndIf}
-      !if ${APP_ARCHITECTURE} <> 32
-        SetRegView ${APP_ARCHITECTURE}
-      !endif
-    FunctionEnd
+  !macro PrepareShellCTX
+    ${if} $MultiUser.InstallMode == "CurrentUser"
+      SetShellVarContext current
+    ${Else}
+      SetShellVarContext all
+    ${EndIf}
+    ${If} ${RunningX64}
+      SetRegView ${APP_ARCHITECTURE}
+    ${EndIf}
   !macroend
-  
-  !insertmacro CreatePrepareShellCTXFun ""
-  !insertmacro CreatePrepareShellCTXFun "un."
+
+  Function PrepareShellCTX
+    !insertmacro PrepareShellCTX
+  FunctionEnd
+
+  Function un.PrepareShellCTX
+    !insertmacro PrepareShellCTX
+  FunctionEnd
 
 #-------------------------------------------------------------
 # - - - - - - - - - - - - Sections - - - - - - - - - - - - - -
@@ -367,6 +371,12 @@ FunctionEnd
 Function RetrieveSMState # Custom function, called after the Startmenu page has been created
   ${IfNot} ${FileExists} "$INSTDIR\Uninstall-LyX.exe"
     Return # Not over-installing
+  ${Else}
+    ${GetFileVersion} "$INSTDIR\Uninstall-LyX.exe" $0
+    StrCpy $0 $0 3 # get only the first 3 chars, e.g. "2.3"
+    ${If} $0 != "${VERSION_MAJOR}.${VERSION_MINOR}"
+      Return # Installing over a wrong version
+    ${EndIf}
   ${EndIf}
 
   Call PrepareShellCTX # Helper function from above
@@ -376,7 +386,10 @@ Function RetrieveSMState # Custom function, called after the Startmenu page has
       StrCpy $StartMenuFolder ">$StartMenuFolder"
     ${Else}
       GetDlgItem $0 $mui.StartMenuPage 1005 # Get the HWND of the checkbox, MUI2 does not provide variable for that
-      SendMessage $0 ${BM_CLICK} 0 0 # NSIS delivers no other possibility here other than to send a click event to the checkbox
+      ${NSD_GetState} $0 $1
+      ${If} $1 = ${BST_UNCHECKED}
+        SendMessage $0 ${BM_CLICK} 0 0 # NSIS delivers no other possibility here other than to send a click event to the checkbox
+      ${EndIf}
     ${EndIf}
   ${EndIf}
 FunctionEnd
@@ -518,6 +531,17 @@ Section -CheckSilent # This section checks if it's a silent install and calls ne
   Call DefaultDesktopFileAssoc
 SectionEnd
 
+Section -UninstallOld
+  ${If} ${FileExists} "$INSTDIR\Uninstall-LyX.exe"
+    ${GetFileVersion} "$INSTDIR\Uninstall-LyX.exe" $0
+    StrCpy $0 $0 3 # get only the first 3 chars, e.g. "2.3"
+    ${If} $0 != "${VERSION_MAJOR}.${VERSION_MINOR}"
+      ExecWait "$INSTDIR\Uninstall-LyX.exe /S _?=$INSTDIR" # silently uninstall old LyX
+      Delete "$INSTDIR\Uninstall-LyX.exe"
+    ${EndIf}
+  ${EndIf}
+SectionEnd
+
 Section -OverInstallReg # If over-installing, we need to delete the registry keys written by the previous installment
   Call PrepareShellCTX # Helper function from above
   StrCpy $1 0
@@ -548,6 +572,7 @@ Section -ProgramFiles
   # Visual C++ redistributable (if native build)
   File "${FILES_DEPS}\bin\concrt140.dll"
   File "${FILES_DEPS}\bin\msvcp140.dll"
+  File "${FILES_DEPS}\bin\msvcp140_1.dll"
   File "${FILES_DEPS}\bin\vcamp140.dll"
   File "${FILES_DEPS}\bin\vccorlib140.dll"
   File "${FILES_DEPS}\bin\vcomp140.dll"
@@ -651,7 +676,7 @@ Section -TexRessources # Section installs cls files from Ressources\tex and upda
     ${If} ${FileExists} "$0\broadway.cls"
       Return
     ${EndIf}
-    CopyFiles "$INSTDIR\Resources\tex\*.*" $0
+    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" $0
     ExecWait '$LatexPath\texhash' # Update package file list
 
   ${Else} # Miktex
@@ -700,14 +725,7 @@ Section -CompilePython
 SectionEnd
 
 Section -LyxrcDist
-  FileOpen $R0 "$INSTDIR\Resources\lyxrc.dist" a
-  FileSeek $R0 0 END
-  # set some general things
-  FileWrite $R0 '\screen_zoom 120$\r$\n'
-  FileWrite $R0 '\path_prefix "$LatexPath;$$LyXDir\bin;$$LyXDir\Python;$$LyXDir\Python\Lib;$$LyXDir\imagemagick;$$LyXDir\ghostscript'
-
-  # Do not overwrite $R0 in this Section!!!
-  # =======================================
+  StrCpy $pathPrefix "$LatexPath;$$LyXDir\bin;$$LyXDir\Python;$$LyXDir\Python\Lib;$$LyXDir\imagemagick;$$LyXDir\ghostscript\bin"
 
   # Find additional software and add their install locations to the path_prefix
   # This list contains all software, which write the string value "InstallLocation" in their corresponding keys in "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
@@ -725,7 +743,7 @@ Section -LyxrcDist
       ${If} $1 == "\" # If ends with "\"
         StrCpy $0 $0 -1 # Remove "\"
       ${EndIf}
-      FileWrite $R0 ";$0"
+      StrCpy $pathPrefix "$pathPrefix;$0"
     ${EndIf}
   ${Next}
   ${List.Destroy} editors
@@ -736,7 +754,7 @@ Section -LyxrcDist
   ReadRegStr $0 SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$0" "DisplayIcon"
   ${StrStrAdv} $0 $0 "\gvim.exe" ">" "<" "0" "0" "0" # get everything before "\gvim.exe"
   ${If} $0 != ""
-    FileWrite $R0 ";$0"
+    StrCpy $pathPrefix "$pathPrefix;$0"
   ${EndIf}
 
   # JabRef, Hard to locate, JabRef uses MSI installer, lets try to find it through the .bib extension
@@ -750,7 +768,7 @@ Section -LyxrcDist
     ${StrRep} $0 $0 '"' "" # Remove quotes
     ${StrStrAdv} $0 $0 "\JabRef.exe" ">" "<" "0" "0" "0" # Get everything before "\JabRef.exe"
     ${If} ${FileExists} "$0\JabRef.exe"
-      FileWrite $R0 ";$0"
+      StrCpy $pathPrefix "$pathPrefix;$0"
       ${Break}
     ${EndIf}
     SetShellVarContext current # Retry as user
@@ -766,7 +784,7 @@ Section -LyxrcDist
     ${StrRep} $0 $0 '"' "" # Remove quotes
     ${StrStrAdv} $0 $0 "\gnumeric.exe" ">" "<" "0" "0" "0" # Get everything before "\gnumeric.exe"
     ${If} $0 != ""
-      FileWrite $R0 ";$0"
+      StrCpy $pathPrefix "$pathPrefix;$0"
       ${Break}
     ${EndIf}
     SetShellVarContext current # Retry as user
@@ -779,7 +797,7 @@ Section -LyxrcDist
   ${If} $1 = 0
     ${StrStrAdv} $0 $0 "\pandoc.exe" ">" "<" "0" "0" "0" # Get everything before "\pandoc.exe"
     ${If} $0 != ""
-      FileWrite $R0 ";$0"
+      StrCpy $pathPrefix "$pathPrefix;$0"
     ${EndIf}
   ${EndIf}
 
@@ -789,7 +807,7 @@ Section -LyxrcDist
   ${SearchAllRegistry} $0 $1 $1 "SOFTWARE" "LilyPond" 0 0 # Helper Function from above
   ReadRegStr $0 SHCTX "SOFTWARE\$0" "Install_Dir"
   ${If} $0 != ""
-    FileWrite $R0 ";$0\usr\bin"
+    StrCpy $pathPrefix "$pathPrefix;$0\usr\bin"
     ${Map.Set} softwarePathsMap "LilyPond" "$0\usr\bin"
   ${EndIf}
 
@@ -797,7 +815,7 @@ Section -LyxrcDist
   ${SearchAllRegistry} $2 $1 $1 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" "GIMP" 0 0 # Helper Function from above
   ReadRegStr $0 SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$2" "InstallLocation"
   ${If} $0 != ""
-    FileWrite $R0 ";$0bin" # Install Location ends with '\' for Gimp in Registry
+    StrCpy $pathPrefix "$pathPrefix;$0bin" # Install Location ends with '\' for Gimp in Registry
     ReadRegStr $0 SHCTX "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$2" "DisplayIcon"
     ${StrStrAdv} $0 $0 ".exe" ">" "<" "0" "0" "0" # Get everything before the ".exe"
     ${StrStrAdv} $0 $0 "\" "<" ">" "0" "0" "0" # Get everything after the last "\", $0 contains "gimp-10" now
@@ -808,7 +826,7 @@ Section -LyxrcDist
   ${SearchAllRegistry} $0 $1 $1 "SOFTWARE" "Krita" 0 0 # Helper Function from above
   ReadRegStr $0 SHCTX "SOFTWARE\$0" "InstallLocation"
   ${If} $0 != ""
-    FileWrite $R0 ";$0\bin"
+    StrCpy $pathPrefix "$pathPrefix;$0\bin"
     ${Map.Set} softwarePathsMap "ImageEditor" "krita"
   ${EndIf}
 
@@ -822,15 +840,20 @@ Section -LyxrcDist
     ${StrRep} $0 $0 '"' "" # Remove quotes
     ${StrStrAdv} $0 $0 "\photoshop.exe" ">" "<" "0" "0" "0" # Get everything before "\photoshop.exe"
     ${If} $0 != ""
-      FileWrite $R0 ";$0"
+      StrCpy $pathPrefix "$pathPrefix;$0"
       ${Break}
     ${EndIf}
     SetShellVarContext current # Retry as user
   ${Next}
 
-  FileWrite $R0 '"$\r$\n'
-
   ClearErrors
+
+  FileOpen $R0 "$INSTDIR\Resources\lyxrc.dist" a
+  FileSeek $R0 0 END
+  # set some general things
+  FileWrite $R0 '\screen_zoom 120$\r$\n'
+
+  FileWrite $R0 '\path_prefix "$pathPrefix"$\r$\n'
   
   # use pdfview for all types of PDF files
   FileWrite $R0 '\format "pdf5" "pdf" "PDF (LuaTeX)" "u" "pdfview" "" "document,vector,menu=export" "application/pdf"$\r$\n\
@@ -880,7 +903,7 @@ Section "$(SecFileAssocTitle)" SecFileAssoc # Registry information to assiciate
   WriteRegStr SHCTX "Software\Classes\.lyx" "Content Type" "application/lyx"
 
   WriteRegStr SHCTX "Software\Classes\LyX.Document" "" "LyX Document"
-  WriteRegStr SHCTX "Software\Classes\LyX.Document\DefaultIcon" "" "$INSTDIR\bin\LyX.exe,0"
+  WriteRegStr SHCTX "Software\Classes\LyX.Document\DefaultIcon" "" "$INSTDIR\bin\LyX.exe,1"
   WriteRegStr SHCTX "Software\Classes\LyX.Document\Shell\open\command" "" '"$INSTDIR\bin\LyX.exe" "%1"'
 
   # we need to update also the automatically created entry about the lyx.exe
@@ -954,7 +977,30 @@ Section -UninstallInfoRegistry # Registry information in "SOFTWARE\Microsoft\Win
   WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\LyX${APP_VERSION_DOTLESS}" "EstimatedSize" $0
 SectionEnd
 
+!if ${VERSION_MINOR} > 0 # Only valid for minor releases of the same major release (e.g. not valid for 3.0)
+  Section -CopyOldPreferences # Searches user's preferences (userdir) from previous minor release and copies it if necessary
+    Call PrepareShellCTX
+    SetShellVarContext current # Otherwise $APPDATA would return C:\ProgrammData instead of C:\Users\username\AppData\Roaming
+    
+    IntOp $0 ${VERSION_MINOR} - 1 # only check the direct previous minor release
+    ${If} ${FileExists} "$APPDATA\LyX${VERSION_MAJOR}.$0\lyxrc.defaults"
+    ${AndIfNot} ${FileExists} "$APPDATA\LyX${VERSION_MAJOR}.${VERSION_MINOR}\lyxrc.defaults"
+      CopyFiles /SILENT "$APPDATA\LyX${VERSION_MAJOR}.$0\*.*" "$APPDATA\LyX${VERSION_MAJOR}.${VERSION_MINOR}"
+    ${EndIf}
+  SectionEnd
+!endif
+
 Section -ConfigureScript # Runs the configure.py script
+
+  # Manipulate PATH environment of the running installer process, so that configure.py can find all the stuff needed
+  ReadEnvStr $0 "PATH"
+  ${StrRep} $pathPrefix $pathPrefix "$$LyXDir" "$INSTDIR"
+  System::Call 'Kernel32::SetEnvironmentVariable(t "PATH", t "$pathPrefix;$0")'
+  
+  Call PrepareShellCTX
+  SetShellVarContext current # Otherwise $APPDATA would return C:\ProgrammData instead of C:\Users\username\AppData\Roaming
+  SetOutPath "$APPDATA\LyX${VERSION_MAJOR}.${VERSION_MINOR}" # Need to run configure from the user dir, because it creates .lst files and some folders.
+
   ${StrStr} $0 $LatexPath "\miktex\bin"
   # R9 is used in $(TEXT_CONFIGURE_LYX)
   ${If} $0 == "" # TexLive
@@ -965,16 +1011,22 @@ Section -ConfigureScript # Runs the configure.py script
   StrCpy $LaTeXInstalled $R9 # FIXME remove
   DetailPrint $(TEXT_CONFIGURE_LYX) # Uses R9 to display the name of the installed latex distribution
   
-  Call PrepareShellCTX
-  SetShellVarContext current # Otherwise $APPDATA would return C:\ProgrammData instead of C:\Users\username\AppData\Roaming
-  SetOutPath "$APPDATA\LyX${VERSION_MAJOR}.${VERSION_MINOR}" # Need to run configure from the user dir, because it creates .lst files and some folders.
   nsExec::ExecToLog '"$INSTDIR\Python\python.exe" "$INSTDIR\Resources\configure.py"'
   Pop $0 # Return value
 SectionEnd
 
 Function DefaultDesktopFileAssoc # Custom function, called before the components page, reads the states of SecDesktop and SecFileAssoc from registry (if overinstalling) and sets them
+
+  Call CheckDictionaries # Search for already installed dictionaries, in dictionaries.nsh
+
   ${IfNot} ${FileExists} "$INSTDIR\Uninstall-LyX.exe"
     Return # Not over-installing
+  ${Else}
+    ${GetFileVersion} "$INSTDIR\Uninstall-LyX.exe" $0
+    StrCpy $0 $0 3 # get only the first 3 chars, e.g. "2.3"
+    ${If} $0 != "${VERSION_MAJOR}.${VERSION_MINOR}"
+      Return # Installing over a wrong version
+    ${EndIf}
   ${EndIf}
 
   Call PrepareShellCTX
@@ -986,12 +1038,10 @@ Function DefaultDesktopFileAssoc # Custom function, called before the components
   ${If} $0 == ""
     SectionSetFlags ${SecDesktop} 0 # 0 means unselected
   ${EndIf}
-
-  Call CheckDictionaries # Also search for already installed dictionaries, in dictionaries.nsh
 FunctionEnd
 
 Function StartLyX
-  Exec "$INSTDIR\bin\LyX.exe"
+  ShellExecAsUser::ShellExecAsUser "" "$INSTDIR\bin\LyX.exe"
 FunctionEnd
 
 # Installer Section Descriptions