]> git.lyx.org Git - features.git/blobdiff - development/Win32/packaging/installer/include/LaTeX.nsh
Consider inset strings in simple find/replaceAll (#12049)
[features.git] / development / Win32 / packaging / installer / include / LaTeX.nsh
index d47dabcd7e2324d7463fdefef7f88b524c9c3f4f..fa6f34daf378be9baf0da252cae706f0082986bb 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*
 LaTeX.nsh
 
 Handling of LaTeX distributions
@@ -8,46 +8,72 @@ Handling of LaTeX distributions
 #
 # - LaTeXActions (checks if MiKTeX or TeXLive is installed)
 #
-# - InstallMiKTeX (installs MiKTeX if not already installed),
-#   only for bunlde installer, uses:
-#    LaTeXCheck # function from LyXUtils.nsh
-#
 # - ConfigureMiKTeX
 #   (installs the LaTeX class files that are delivered with LyX,
-#    a Perl interpreter for splitindex
+#    a Perl interpreter for splitindex and pdfcrop
 #    and enable MiKTeX's automatic package installation)
 #
-# - UpdateMiKTeX (asks to update MiKTeX)
+# - ConfigureTeXLive
+#   (installs the LaTeX class files that are delivered with LyX)
 
 # ---------------------------------------
 
 Function LaTeXActions
  # checks if MiKTeX or TeXLive is installed
 
+  StrCpy $Is64bit "false"
+  
+  ${if} ${RunningX64}
+   SetRegView 64 # the PATH is in the 64bit registry section
+  ${endif}
   # test if MiKTeX is installed
   # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
   StrCpy $Search "miktex"
   Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
   
+  StrCpy $String $PathLaTeX
+  StrCpy $Search "x64" # search if it is 64bit MiKTeX
+  Call StrPoint # Function from LyXUtils.nsh
+  ${if} $Pointer != "-1" # if something was found
+   StrCpy $Is64bit "true"
+  ${endif}
+  
+  # check for 32bit MiKTeX
   ${if} $PathLaTeX != ""
-   # check if MiKTeX 2.7 or newer is installed
+  ${andif} $Is64bit != "true"
+   ${if} ${RunningX64}
+    SetRegView 32
+   ${endif}
+   # check if MiKTeX 2.8 or newer is installed
    StrCpy $0 0
-   loopA:
+   loop32:
     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
-    StrCmp $1 "" doneA
+    StrCmp $1 "" done32
     StrCpy $String $1
     IntOp $0 $0 + 1
-    Goto loopA
-   doneA:
-   ${if} $String == "2.7"
-    StrCpy $MiKTeXVersion "2.7"
-    StrCpy $LaTeXName "MiKTeX 2.7"
+    Goto loop32
+   done32:
+   ${if} $String == "2.9"
+    StrCpy $MiKTeXVersion "2.9"
+    StrCpy $LaTeXName "MiKTeX 2.9"
    ${endif}
-   ${if} $String == "2.8"
-    StrCpy $MiKTeXVersion "2.8"
-    StrCpy $LaTeXName "MiKTeX 2.8"
+  ${endif}
+  
+  # check for 64bit MiKTeX
+  ${if} $LaTeXName == ""
+   ${if} ${RunningX64}
+    SetRegView 64
    ${endif}
+   # check if MiKTeX 2.8 or newer is installed
+   StrCpy $0 0
+   loop64:
+    EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
+    StrCmp $1 "" done64
+    StrCpy $String $1
+    IntOp $0 $0 + 1
+    Goto loop64
+   done64:
    ${if} $String == "2.9"
     StrCpy $MiKTeXVersion "2.9"
     StrCpy $LaTeXName "MiKTeX 2.9"
@@ -57,6 +83,9 @@ Function LaTeXActions
   ${if} $PathLaTeX != ""
    StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
   ${else} # check if MiKTeX is installed only for the current user
+   ${if} ${RunningX64}
+    SetRegView 64 # the PATH is in the 64bit registry section
+   ${endif}
    ReadRegStr $String HKCU "Environment" "Path"
    StrCpy $Search "miktex"
    Call LaTeXCheck # function from LyXUtils.nsh
@@ -73,43 +102,58 @@ Function LaTeXActions
     IntOp $0 $0 + 1
     Goto loopB
    doneB:
-   ${if} $String == "2.7"
-    StrCpy $MiKTeXVersion "2.7"
-    StrCpy $LaTeXName "MiKTeX 2.7"
-   ${endif}
-   ${if} $String == "2.8"
-    StrCpy $MiKTeXVersion "2.8"
-    StrCpy $LaTeXName "MiKTeX 2.8"
-   ${endif}
    ${if} $String == "2.9"
     StrCpy $MiKTeXVersion "2.9"
     StrCpy $LaTeXName "MiKTeX 2.9"
    ${endif}
   ${endif}
-    
+  
   ${if} $PathLaTeX != ""
+   StrCpy $String $PathLaTeX
+   StrCpy $Search "x64" # search if it is 64bit MiKTeX
+   Call StrPoint # Function from LyXUtils.nsh
+   ${if} $Pointer != "-1" # if something was found
+    StrCpy $Is64bit "true"
+   ${endif}
    StrCpy $LaTeXInstalled "MiKTeX"
+   # on some installations the path ends with a "\" on some not
+   # therefore assure that we remove it if it exists
+   StrCpy $0 $PathLaTeX "" -1
+   ${if} $0 == "\"
+    StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
+   ${endif}
   ${endif}
   
   # test if TeXLive is installed
-  # as described at TeXLives' homepage there should be an entry in the PATH
+  # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
+  # The safest method is to first check for the PATH because this is independent of the TeXLive version.
+  ${if} ${RunningX64}
+   SetRegView 64 # the PATH is in the 64bit registry section
+  ${endif}
   ${if} $PathLaTeX == ""
    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
    StrCpy $Search "TeXLive"
    Call LaTeXCheck # function from LyXUtils.nsh
   ${endif}
-  # check for the current user Path variable (the case when it is a live CD/DVD)
+  # check for the current user Path variable
   ${if} $PathLaTeX == ""
    ReadRegStr $String HKCU "Environment" "Path"
    StrCpy $Search "texlive"
    StrCpy $2 "TeXLive"
    Call LaTeXCheck # function from LyXUtils.nsh
   ${endif}
-  # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
+  # check if it was installed to the system
+  ${if} ${RunningX64}
+   SetRegView 32 # TeXLive is a 32bit application
+  ${endif}
   ${if} $PathLaTeX == ""
-   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
+   ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
    ${if} $String == ""
-    ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
+    ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
+   ${endif}
+   ${if} $String != ""
+    StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
+    StrCpy $String $String "" 1 # remove the leading quote
    ${endif}
    StrCpy $PathLaTeX "$String\bin\win32"
    # check if the latex.exe exists in the $PathLaTeX folder
@@ -118,171 +162,89 @@ Function LaTeXActions
     StrCpy $PathLaTeX ""
    ${endif}
   ${endif}
+  # finally set the name
   ${if} $PathLaTeX != ""
-  ${andif} $LaTeXName != "MiKTeX 2.7"
-  ${andif} $LaTeXName != "MiKTeX 2.8"
   ${andif} $LaTeXName != "MiKTeX 2.9"
-   StrCpy $LaTeXName "TeXLive"
-  ${endif}
-
-FunctionEnd
-
-# -------------------------------------------
-
-!if ${SETUPTYPE} == BUNDLE
-
- Function InstallMiKTeX
-  # installs MiKTeX if not already installed
-  
-  ${if} $PathLaTeX == ""
-   # launch MiKTeX's installer
-   MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
-   ExecWait ${MiKTeXInstall}
-   # test if MiKTeX is installed
-   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
-   StrCpy $Search "miktex"
-   Call LaTeXCheck # function from LyXUtils.nsh
-   ${if} $PathLaTeX != ""
-    StrCpy $MiKTeXUser "HKLM"
-   ${else}
-    StrCpy $MiKTeXUser "HKCU"
-    ReadRegStr $String HKCU "Environment" "Path"
-    StrCpy $Search "miktex"
-    Call LaTeXCheck # function from LyXUtils.nsh
+   StrCpy $LaTeXInstalled "TeXLive"
+   ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
+   ${if} $String == ""
+    ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
    ${endif}
-   ${if} $PathLaTeX != ""
-    # set package repository (MiKTeX's primary package repository)
-    ${if} $MiKTeXUser == "HKCU"
-     # special entry that it was installed together with LyX
-     # so that we can later uninstall it together with LyX
-     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
-    ${else}
-     WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
-    ${endif}
-    StrCpy $LaTeXInstalled "MiKTeX"
-    StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
+   ${if} $String != ""
+    StrCpy $LaTeXName "TeXLive $String"
    ${else}
-    MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
-    SetOutPath $TEMP # to be able to delete the $INSTDIR
-    RMDir /r $INSTDIR
-    Abort
-   ${endif} # endif $PathLaTeX != ""
+    StrCpy $LaTeXName "TeXLive"
+   ${endif}
   ${endif}
 
-  FunctionEnd
-
-!endif # endif ${SETUPTYPE} == BUNDLE
+FunctionEnd
 
 # ------------------------------
 
 Function ConfigureMiKTeX
  # installs the LaTeX class files that are delivered with LyX,
- # a Perl interpreter for splitindex
+ # a Perl interpreter for splitindex and pdfcrop
  # and enable MiKTeX's automatic package installation
  
  # install LyX's LaTeX class and style files and a Perl interpreter
  ${if} $PathLaTeX != ""
   ${if} $MultiUser.Privileges == "Admin"
   ${orif} $MultiUser.Privileges == "Power"
-   StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
+   ${if} $Is64bit == "true"
+    StrCpy $PathLaTeXLocal "$PathLaTeX" -15 # delete "\miktex\bin\x64"
+   ${else}
+    StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
+   ${endif}
   ${else}
    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
   ${endif}
 
   # only install the LyX packages if they are not already installed
   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
-   # dvipost
-   SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
-   File "${FILES_DVIPOST_PKG}\dvipost.sty"
-   # LyX files in Resources\tex
+   # files in Resources\tex
    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
-  ${endif}
-  
-  # only install a Perl interpreter if it is not already installed
-  # this is only possible if miktex and LyX is installed with the same privileges
-  ${if} $MultiUser.Privileges != "Admin"
-  ${andif} $MultiUser.Privileges != "Power"
-   ${if} $PathLaTeX != "$LOCALAPPDATA\MiKTeX\$MiKTeXVersion\miktex\bin"
-    ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
-     MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
-    ${endif}
+
+   # refresh MiKTeX's file name database (do this always to assure everything is in place)
+   ${if} $MultiUser.Privileges != "Admin"
+   ${andif} $MultiUser.Privileges != "Power"
+    # call the non-admin version
+    nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
    ${else}
-    ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
-     SetOutPath "$PathLaTeXLocal"
-     File /r ${FILES_MIKTEX}
+    ${if} $MiKTeXUser != "HKCU" # call the admin version
+     nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
+    ${else}
+     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
     ${endif}
    ${endif}
-  ${else}
-   ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
-    SetOutPath "$PathLaTeXLocal"
-    File /r ${FILES_MIKTEX}
-   ${endif}
+   Pop $UpdateFNDBReturn # Return value
   ${endif}
   
-  # refresh MiKTeX's file name database (do this always to assure everything is in place)
-  ${if} $MultiUser.Privileges != "Admin"
-  ${andif} $MultiUser.Privileges != "Power"
-   # call the non-admin version
-   nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
-  ${else}
-   ${if} $MiKTeXUser != "HKCU" # call the admin version
-    nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
-   ${else}
-    nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
-   ${endif}
-  ${endif}
-  Pop $UpdateFNDBReturn # Return value
-  
- ${endif}
-  
-  # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
-  WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
-  ${if} $MiKTeXUser != "HKCU"
-   WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
-  ${endif}
-  # set package repository (MiKTeX's primary package repository)
-  WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
-  WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
-  ${if} $MiKTeXUser != "HKCU"
-   WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
-   WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
-  ${endif}
-  
-  # enable MiKTeX's automatic package installation
-  ExecWait '$PathLaTeX\mpm.exe --update-fndb'
-  # the following feature is planned to be used for a possible CD-version
-  # copy LaTeX-packages needed by LyX
-  # SetOutPath "$INSTDIR"
-  # File /r "${LaTeXPackagesDir}" 
-  
+  # install a Perl interpreter for splitindex and pdfcrop
+  SetOutPath "$INSTDIR\Perl"
+  # recursively copy all files under Perl
+  File /r "${FILES_PERL}\"
+
+  ${endif} # end if $PathLaTeX != ""  
 FunctionEnd
 
-Function UpdateMiKTeX
- # asks to update MiKTeX
+# ------------------------------
 
-  ${if} $LaTeXInstalled == "MiKTeX"
-   MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
-   UpdateNow:
-    StrCpy $0 $PathLaTeX -4 # remove "\bin"
-    # the update wizard is either started by the copystart_admin.exe
-    # or the miktex-update.exe (since MiKTeX 2.8)
-    ${if} $MultiUser.Privileges != "Admin"
-    ${andif} $MultiUser.Privileges != "Power"
-     # call the non-admin version
-     ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
-     ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
-    ${else}
-     ${if} $MiKTeXUser != "HKCU" # call the admin version
-      ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"'
-      ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
-     ${else}
-      ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
-      ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
-     ${endif}
-    ${endif}
-   UpdateLater:
+Function ConfigureTeXLive
+ # installs the LaTeX class files that are delivered with LyX
+ # (TeXLive comes already with a Perl interpreter.)
+ ${if} $PathLaTeX != ""
+  StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
+  
+  # only install the LyX packages if they are not already installed
+  ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
+   # files in Resources\tex
+   SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
+   CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
+   # update TeXLive's package file list
+   ExecWait '$PathLaTeX\texhash'
   ${endif}
-
+ ${endif}
 FunctionEnd
-