<< | Page list | >>
Notes on J's launcher of LyX, i.e. the wrapper application used to start LyX on Windows. This page was primarily created to make it easy for Christian to ask Joost questions.
LyxJoostInst:../../launcher/launcher.nsi
1. The commented code of launcher.nsi
Below is a version of launcher.nsi
that Christian has modified, primarily
by adding (lots of) comments.
#
# Wrapper for launching LyX on Windows
# Author: Joost Verburg
#
# This application (wrapper) will be installed as lyx.exe.
#
# This application will setup the environment variables based on
# registry settings, execute lyxc.exe, and capture any debug output of
# from lyxc.exe. If the comman line contains '-dbg', the debug output
# is shown in a separate window during the execution of LyX. If LyX
# crashes, the user is asked about seeing the debug output. Version
# information and an icon are also included in this application.
#
# Include standard NSIS libraries
!include "MUI.nsh" # http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html
!include "LogicLib.nsh" # http://nsis.sourceforge.net/LogicLib
!include "FileFunc.nsh" # http://nsis.sourceforge.net/Docs/AppendixE.html#E.1
!include "StrFunc.nsh" # http://nsis.sourceforge.net/StrFunc
# The next two lines are needed in order to be able to use the
# corresponding functions/macros from within install sections.
!insertmacro GetParameters # See ?
${StrStr} # See http://nsis.sourceforge.net/StrFunc
# Include version information from the LyX installer application in the
# form of compile-time defines such as ${APP_NAME}, ${APP_VERSION} etc.
!include "..\packaging\installer\settings.nsh"
# Set version information of this application (this information is
# shown by displaying the properties of lyx.exe in Windows)
VIProductVersion "${APP_VERSION_NUMBER}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${APP_NAME}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${APP_INFO}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${APP_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${APP_COPYRIGHT}"
Caption "${APP_NAME} ${APP_VERSION}" # E.g. "LyX 1.5.0"
OutFile lyx.exe # Set name of resulting binary
BrandingText " " # Needed to supress unwanted text
# Variables
Var Parameters # Command line parameters
Var Debug # True when to show debug log
Var LyXLanguage # LyX UI language ?? Joost?
Var ReturnValue # Temporary use, for Windows API etc
Var ResultText # Temporary use, for Windows API etc
Var ResultSubText # Temporary use, for Windows API etc
#
# Define application page (window) and configure it for showing debug
# output
#
# This application uses the MUI page 'MUI_PAGE_INSTFILES' that is
# normally used for showing logged details of the installation
# process. Here, that page will instead be used to show the debug
# output from running LyX.
# - Set icon in start menu for wrapper application
!define MUI_ICON "..\packaging\icons\lyx_32x32.ico"
# - Set the function InitInterface() to be invoked before showing any
# window or dialog.
!define MUI_CUSTOMFUNCTION_GUIINIT InitInterface
# - Set ??? to be stored in $ResultText
# - Set ??? to be stored in $ResultText
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT $ResultText
!define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT $ResultSubText
# Add the page 'MUI_PAGE_INSTFILES' (this will be the only page)
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English # Set the page languge to English
ShowInstDetails show # Set the page to be shown by default
# Windows API constants
!define SWP_NOSIZE 0x1 # Windows API constant meaning ???
#
# Main application
#
# Prepare environment variables etc and then start LyX.
# Finally show debug output if desired or in the event of a crash.
#
Section -"LyX wrapper application"
# Hide debug window if there was no debug flag on command line
# Note that InitInterface() had placed the window outside the screen,
# but not hidden it.
# Joost, why didn't InitInterface() hide the window???
${if} $Debug == ${FALSE}
HideWindow
${endif}
# Hide standard control(s ??) not need for just showing debug output,
# e.g. the progress bar. See NSIS UI for meaning of numbers.
# E.g. #32770 is the Windows number for a child dialog.
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R0 $R0 1004
ShowWindow $R0 ${SW_HIDE} # SW_HIDE is defined in a NSIS library
# Set header text of debug window
!insertmacro MUI_HEADER_TEXT "Debugging LyX" "The events you have chosen \
are being logged."
SetDetailsPrint textonly # Set log output mode to text only
DetailPrint "Debug log:" # Prepend "Debug log:" to the log
SetDetailsPrint listonly # Set mode (back?) to listing
# Check registory (first current user, then local machine) for
# desired LyX Language and store the result in $LyXLanguage.
ReadRegStr $LyXLanguage HKCU ${APP_REGKEY_SETTINGS} "Language"
${if} $LyXLanguage == ""
ReadRegStr $LyXLanguge HKLM ${APP_REGKEY_SETTINGS} "Language"
${endif}
# Tell LyX what language to use through the environment variable 'LC_ALL'
${if} $LyXLanguage != ""
Push LC_ALL
Push $LyXLanguage
Call SetEnvironmentVariable
${endif}
# Apparently the output charset needs to be set to some value,
# otherwise no non-ASCII characters will be displayed
Push OUTPUT_CHARSET
Push -
Call SetEnvironmentVariable
# Point to the Aiksaurus data in the LyX folder
Push AIK_DATA_DIR
Push "$EXEDIR\..\aiksaurus"
Call SetEnvironmentVariable
#
# Start the real LyX executable and capture its output for logging
#
Push '"$EXEDIR\lyxc.exe" $Parameters'
CallInstDLL "$EXEDIR\Console.dll" ExecToLog
Pop $ReturnValue # Return value
#
#
#
${if} $Debug == ${FALSE} # Hide debug output if possible?
${if} $ReturnValue == "error" # Something wrong?
# The LyX executable probably does not exist.
MessageBox MB_OK|MB_ICONSTOP "Failed to start LyX."
${elseif} $ReturnValue != 0 # Did LyX crash?
MessageBox MB_YESNO|MB_ICONSTOP \
"LyX has been closed because of an unexpected situation.$\n\
This is most likely caused by a flaw in the software.$\n$\n\
When you open your documents again, you will be able$\n\
to restore an emergency save and continue working.$\n$\n\
Would you like to view detailed information about this error?" \
IDYES debug IDNO no_debug
${endif}
no_debug: # No error, just quit
Quit
debug: # An error occured, show debug log
ShowWindow $R0 ${SW_HIDE} # Hmm... hides or shows? Joost?
${endif}
# Set text ??? depending on the error status.
${if} $ReturnValue != 0
StrCpy $ResultText "Error Information"
StrCpy $ResultSubText "See Chapter 3 of the LyX Introduction \
(Help > Introduction) for information about reporting this issue."
# ToDo: Add link to alternative way to read chapter 3 if it is
# impossible to start LyX.
${else}
StrCpy $ResultText "Debugging Completed"
StrCpy $ResultSubText "The events you have chosen are logged below."
${endif}
# If we arrive here and are not normally showing debug output, LyX has
# crashed so put the output log back on the screen again.
${if} $Debug == ${FALSE}
Push "user32::SetWindowPos(i $HWNDPARENT, i 0, i 133, i 100, i 0, \
i 0, i ${SWP_NOSIZE})"
CallInstDLL "$EXEDIR\System.dll" Call
BringToFront
${endif}
SectionEnd
#--------------------------------
# Functions
#
# Function: Extract the command line parameters, check for any '-dbg'
# parameter and set the variable ${DEBUG} accordingly.
# Note: This function is invoked before any dialog/window is shown.
# In: -
# Out: -
# Sets: $Parameters = String with command line parameters
# $Debug = Set to ${FALSE} by default, and only set
# to ${TRUE} when the command line contains '-dbg'
# Bug: This code doesn't really parse the command line, does it?
# Wouldn't the command
# lyx.exe somefile-dbg.lyx
# result in $Debug = ${TRUE} ?
#
Function InitInterface
Call GetParameters # Get command line parameters
Pop $Parameters # Set $Parameters to command line pars.
${StrStr} $R0 $Parameters "-dbg" # Search string for '-dbg'
${if} $R0 == ""
StrCpy $Debug ${FALSE} # Hide debug window unless a crash etc
${else}
StrCpy $Debug ${TRUE} # Show debug window
${endif}
${if} $Debug == ${FALSE} # Hide debug window?
# Place the debug log window outside the screen to avoid flickering
Push "user32::SetWindowPos(i $HWNDPARENT, i 0, i -32000, i -32000, \
i 0, i 0, i ${SWP_NOSIZE})"
CallInstDLL "$EXEDIR\System.dll" Call
${endif}
FunctionEnd
#
# Function: Set environment variable.
# In (ToS): <name-of-environment-variable>
# <value>
# Example:
# Push OUTPUT_CHARSET
# Push -
# Call SetEnvironmentVariable
Function SetEnvironmentVariable
Exch $R0
Exch 1
Exch $R1
Push 'kernel32::SetEnvironmentVariable(t, t) i("$R1", "$R0")'
CallInstDLL "$EXEDIR\System.dll" Call
Pop $R1
Pop $R0
FunctionEnd
1.1 Comments
- The function SetEnvironmentVariable could possibly be replaced with a macro? /C
Category: Development, Windows installer