2007-04-16 22:33:53 +00:00
Function LaTeXActions
2007-05-15 01:31:19 +00:00
# check if MiKTeX or TeXLive is installed
# test if MiKTeX is installed
# reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
2007-04-16 22:33:53 +00:00
ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $Search "miktex"
2007-05-01 17:55:54 +00:00
Call LaTeXCheck # sets the path to the latex.exe to $LatexPath # Function from LyXUtils.nsh
2007-05-15 01:31:19 +00:00
${if} $LatexPath != ""
2007-12-17 22:34:35 +00:00
# check if MiKTeX 2.5 or 2.6 and newer is installed
2007-05-15 01:31:19 +00:00
StrCpy $0 0
loopA:
EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
StrCmp $1 "" doneA
StrCpy $String $1
IntOp $0 $0 + 1
Goto loopA
doneA:
${if} $String == "2.5"
StrCpy $MiKTeXVersion "2.5"
StrCpy $LaTeXName "MiKTeX 2.5"
${endif}
${if} $String == "2.6"
StrCpy $MiKTeXVersion "2.6"
StrCpy $LaTeXName "MiKTeX 2.6"
${endif}
2007-12-17 22:34:35 +00:00
${if} $String == "2.7"
StrCpy $MiKTeXVersion "2.7"
StrCpy $LaTeXName "MiKTeX 2.7"
${endif}
2007-04-16 22:33:53 +00:00
${endif}
2007-05-01 17:55:54 +00:00
${if} $LatexPath == "" # check if MiKTeX is installed only for the current user
2007-04-16 22:33:53 +00:00
ReadRegStr $String HKCU "Environment" "Path"
StrCpy $Search "miktex"
2007-05-01 17:55:54 +00:00
Call LaTeXCheck # function from LyXUtils.nsh
2007-04-16 22:33:53 +00:00
${if} $LatexPath != ""
2007-05-15 01:31:19 +00:00
StrCpy $MiKTeXUser "HKCU" # needed later to configure MiKTeX
2007-04-16 22:33:53 +00:00
${endif}
2007-12-17 22:34:35 +00:00
${endif}
${if} $LaTeXName == "" # check for the MiKTeX version
2007-05-15 01:31:19 +00:00
StrCpy $0 0
loopB:
EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
StrCmp $1 "" doneB
StrCpy $String $1
IntOp $0 $0 + 1
Goto loopB
doneB:
${if} $String == "2.5"
StrCpy $MiKTeXVersion "2.5"
StrCpy $LaTeXName "MiKTeX 2.5"
${endif}
${if} $String == "2.6"
StrCpy $MiKTeXVersion "2.6"
StrCpy $LaTeXName "MiKTeX 2.6"
${endif}
2007-12-17 22:34:35 +00:00
${if} $String == "2.7"
StrCpy $MiKTeXVersion "2.7"
StrCpy $LaTeXName "MiKTeX 2.7"
${endif}
2007-04-16 22:33:53 +00:00
${endif}
2007-12-17 22:34:35 +00:00
2007-04-16 22:33:53 +00:00
${if} $LatexPath != ""
StrCpy $MiKTeXInstalled "yes"
${endif}
2007-05-15 01:31:19 +00:00
2007-05-01 17:55:54 +00:00
# test if TeXLive is installed
# as described at TeXLives' homepage there should be an entry in the PATH
2007-04-16 22:33:53 +00:00
${if} $LatexPath == ""
ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $Search "TeXLive"
2007-05-01 17:55:54 +00:00
Call LaTeXCheck # function from LyXUtils.nsh
2007-04-16 22:33:53 +00:00
${endif}
2007-05-01 17:55:54 +00:00
# check for the current user Path variable (the case when it is a live CD/DVD)
2007-04-16 22:33:53 +00:00
${if} $LatexPath == ""
ReadRegStr $String HKCU "Environment" "Path"
StrCpy $Search "texlive"
StrCpy $2 "TeXLive"
2007-05-01 17:55:54 +00:00
Call LaTeXCheck # function from LyXUtils.nsh
2007-04-16 22:33:53 +00:00
${endif}
2007-05-01 17:55:54 +00:00
# check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
2007-04-16 22:33:53 +00:00
${if} $LatexPath == ""
ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
${if} $String == ""
2007-05-01 17:55:54 +00:00
ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
2007-04-16 22:33:53 +00:00
${endif}
StrCpy $LatexPath "$String\bin\win32"
2007-05-01 17:55:54 +00:00
# check if the latex.exe exists in the $LatexPath folder
!insertmacro FileCheck $5 "latex.exe" "$LatexPath" # macro from LyXUtils.nsh
2007-04-16 22:33:53 +00:00
${if} $5 == "False"
StrCpy $LatexPath ""
${endif}
${endif}
${if} $LatexPath != ""
${andif} $LaTeXName != "MiKTeX 2.5"
2007-05-15 01:31:19 +00:00
${andif} $LaTeXName != "MiKTeX 2.6"
2007-12-17 22:34:35 +00:00
${andif} $LaTeXName != "MiKTeX 2.7"
2007-04-16 22:33:53 +00:00
StrCpy $LaTeXName "TeXLive"
${endif}
2007-05-15 22:43:05 +00:00
${if} $LatexPath == ""
StrCpy $MissedProg "True"
${endif}
2007-05-15 01:31:19 +00:00
2007-04-16 22:33:53 +00:00
FunctionEnd
2007-05-15 01:31:19 +00:00
# -------------------------------------------
!if ${INSTALLER_VERSION} == "Complete"
Function InstallMiKTeX
# install MiKTeX if not already installed
${if} $LatexPath == ""
# 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
${if} $LatexPath == ""
StrCpy $MiKTeXUser "HKCU"
ReadRegStr $String HKCU "Environment" "Path"
StrCpy $Search "miktex"
Call LaTeXCheck
${endif}
${if} $LatexPath != ""
# set package repository (MiKTeX's primary package repository)
WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}" # special entry to tell the uninstaller that it was installed with LyX
StrCpy $MiKTeXInstalled "yes"
StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
${if} $MiKTeXUser != "HKCU"
StrCpy $MiKTeXPath "$LatexPath" -11 # delete "\miktex\bin"
#MessageBox MB_OK|MB_ICONINFORMATION "$(MiKTeXPathInfo)" # info that MiKTeX's installation folder must have write permissions for all users to work properly
${endif}
${else}
MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
SetOutPath $TEMP # to be able to delete the $INSTDIR
RMDir /r $INSTDIR
Abort
${endif} # endif $LatexPath != ""
${endif}
FunctionEnd
!endif # endif ${INSTALLER_VERSION} == "Complete"
2007-05-01 17:55:54 +00:00
# ------------------------------
2007-04-16 22:33:53 +00:00
Function ConfigureMiKTeX
2007-05-01 17:55:54 +00:00
# installs the LaTeX class files that are delivered with LyX
# and enable MiKTeX's automatic package installation
2007-04-16 22:33:53 +00:00
StrCpy $String $LatexPath
StrCpy $Search "miktex\bin"
StrLen $3 $String
2007-05-01 17:55:54 +00:00
Call StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
${if} $Pointer != "-1" # if something was found
IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
2007-05-02 19:20:12 +00:00
# install LyX's special LaTeX class files
2007-04-16 22:33:53 +00:00
CreateDirectory "$String\tex\latex\lyx"
SetOutPath "$String\tex\latex\lyx"
File "${ClassFileDir}\lyxchess.sty"
File "${ClassFileDir}\lyxskak.sty"
CreateDirectory "$String\tex\latex\revtex"
SetOutPath "$String\tex\latex\revtex"
File "${ClassFileDir}\revtex.cls"
CreateDirectory "$String\tex\latex\hollywood"
SetOutPath "$String\tex\latex\hollywood"
File "${ClassFileDir}\hollywood.cls"
CreateDirectory "$String\tex\latex\broadway"
SetOutPath "$String\tex\latex\broadway"
File "${ClassFileDir}\broadway.cls"
2007-05-01 17:55:54 +00:00
# install LaTeX-package dvipost (dvipost is not available for MiKTeX)
2007-12-17 22:34:35 +00:00
SetOutPath "$String\tex\latex"
2007-04-16 22:33:53 +00:00
File /r "${DVIPostFileDir}"
2007-05-15 01:31:19 +00:00
# refresh MiKTeX's file name database
ExecWait "$LaTeXPath\initexmf --update-fndb"
${if} $MiKTeXVersion == "2.5"
2007-05-01 17:55:54 +00:00
# enable package installation without asking (t = Yes, f = No)
2007-12-17 22:34:35 +00:00
WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
2007-05-15 01:31:19 +00:00
${if} $MiKTeXUser != "HKCU"
WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_AUTOINSTALL" "t"
${endif}
2007-05-01 17:55:54 +00:00
# set package repository (MiKTeX's primary package repository)
2007-12-17 22:34:35 +00:00
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
2007-05-15 01:31:19 +00:00
${if} $MiKTeXUser != "HKCU"
WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_REPOSITORY" "${MiKTeXRepo}"
${endif}
2007-12-17 22:34:35 +00:00
${else} # if MiKTeX 2.6 or above
# 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
2007-05-15 01:31:19 +00:00
${if} $MiKTeXUser != "HKCU"
2007-12-17 22:34:35 +00:00
WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
2007-05-15 01:31:19 +00:00
${endif}
# set package repository (MiKTeX's primary package repository)
2007-12-17 22:34:35 +00:00
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
2007-05-15 01:31:19 +00:00
${if} $MiKTeXUser != "HKCU"
2007-12-17 22:34:35 +00:00
WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
2007-05-15 01:31:19 +00:00
${endif}
2007-12-17 22:34:35 +00:00
${endif} # end if $MiKTeXVersion == "2.5"
2007-04-16 22:33:53 +00:00
2007-05-01 17:55:54 +00:00
# enable MiKTeX's automatic package installation
2007-12-17 22:34:35 +00:00
${if} $MiKTeXVersion == "2.5"
2007-05-15 01:31:19 +00:00
ExecWait '$LaTeXPath\mpm.com --update-fndb'
2007-12-17 23:13:01 +00:00
${else} # MiKTeX 2.6 or newer
2007-05-15 01:31:19 +00:00
ExecWait '$LaTeXPath\mpm.exe --update-fndb'
${endif}
2007-05-01 17:55:54 +00:00
# the following feature is planned to be used for a possible CD-version
# copy LaTeX-packages needed by LyX
# SetOutPath "$INSTDIR"
# File /r "${LaTeXPackagesDir}"
${endif} # end ${if} $Pointer
2007-04-16 22:33:53 +00:00
2007-05-15 22:43:05 +00:00
# save MiKTeX's install path to be able to remove LyX's LaTeX-files in the uninstaller
FileOpen $R1 "$INSTDIR\Resources\uninstallPaths.dat" w
FileWrite $R1 '$LaTeXPath'
FileClose $R1
2007-04-16 22:33:53 +00:00
FunctionEnd
2007-05-15 22:43:05 +00:00
Function UpdateMiKTeX
2007-05-15 23:37:34 +00:00
# ask to update MiKTeX
2007-05-15 22:43:05 +00:00
${if} $MiKTeXInstalled == "yes"
MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
UpdateNow:
StrCpy $0 $LaTeXPath -4 # remove "\bin"
2007-07-12 00:21:53 +00:00
# the update wizard is either started by the copystart.exe or the copystart_admin.exe
# the latter replaces copystart.exe since miktex-2.6.2742
2007-05-15 22:43:05 +00:00
ExecWait '"$LaTeXPath\copystart.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
2007-07-12 00:21:53 +00:00
ExecWait '"$LaTeXPath\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
2007-05-15 22:43:05 +00:00
UpdateLater:
${endif}
FunctionEnd