]> git.lyx.org Git - lyx.git/blob - development/Win32/launcher/launcher.nsi
- tufte-handout: new layout
[lyx.git] / development / Win32 / launcher / launcher.nsi
1 /*
2
3 LyX for Windows Launcher
4 Author: Joost Verburg
5
6 This will be installed as lyx.exe.
7
8 The application will setup the environment variables based on registry
9 settings and obtain the command line output of lyxc.exe, which can be shown
10 while debugging or in case of a crash. Version information and an icon are
11 also included.
12
13 */
14
15 !include MUI.nsh
16 !include LogicLib.nsh
17 !include FileFunc.nsh
18 !include StrFunc.nsh
19 ${StrStr}
20
21 # Configuration from installer
22 !include "..\packaging\installer\settings.nsh"
23 !include "..\packaging\installer\include\declarations.nsh"
24
25 #--------------------------------
26 # Settings
27
28 Caption "${APP_NAME} ${APP_VERSION}"
29 OutFile LyXLauncher.exe
30 BrandingText " "
31
32 #--------------------------------
33 # Windows Vista settings
34
35 RequestExecutionLevel user
36
37 #--------------------------------
38 # Variables
39
40 Var Parameters
41 Var Debug
42 Var LyXLanguage
43 Var ReturnValue
44
45 Var ResultText
46 Var ResultSubText
47
48 Var LyXFolder
49
50 Var LyXSetting
51 Var LyXSettingValue
52
53 Var EnvironmentVariable
54 Var EnvironmentVariableValue
55
56 #--------------------------------
57 # User interface for debug output
58
59 !define MUI_ICON "..\packaging\icons\lyx.ico"
60 !define MUI_CUSTOMFUNCTION_GUIINIT InitInterface
61
62 !define MUI_INSTFILESPAGE_FINISHHEADER_TEXT $ResultText
63 !define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT $ResultSubText
64 !insertmacro MUI_PAGE_INSTFILES
65
66 !insertmacro MUI_LANGUAGE English
67
68 ShowInstDetails show
69
70 #--------------------------------
71 # Windows API constants
72
73 !define SWP_NOSIZE 0x1
74 !define MONITOR_DEFAULTTONEAREST 0x2
75
76 !define SM_CYCAPTION 4
77 !define SM_CXSIZEFRAME 32
78 !define SM_CYSIZEFRAME 33
79
80 #--------------------------------
81 # Version information
82
83 VIProductVersion "${APP_VERSION_NUMBER}"
84 VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${APP_NAME}"
85 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${APP_INFO}"
86 VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${APP_VERSION}"
87 VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${APP_COPYRIGHT}"
88
89 #--------------------------------
90 # Macros
91
92 !macro SystemCall STACK
93
94   Push "${STACK}"
95   CallInstDLL "$EXEDIR\System.dll" Call
96
97 !macroend
98
99 !macro GetLyXSetting NAME VAR
100
101   Push "${NAME}"
102   Call GetLyXSetting
103   Pop "${VAR}"
104
105 !macroend
106
107 #--------------------------------
108 # Main application
109
110 Section -Prepare
111
112   ${If} $Debug == ${FALSE}
113     HideWindow
114   ${EndIf}
115   
116   # Hide controls we don't need
117   FindWindow $R0 "#32770" "" $HWNDPARENT
118   GetDlgItem $R0 $R0 1004
119   ShowWindow $R0 ${SW_HIDE}
120   
121   # Get LyX folder
122   ${GetParent} $EXEDIR $LyXFolder  
123   
124   # Debug info
125   !insertmacro MUI_HEADER_TEXT "Debugging LyX" "The events you have chosen \
126       are being logged."
127   SetDetailsPrint textonly
128   DetailPrint "Debug log:"
129   SetDetailsPrint listonly
130   
131   # LyX Language
132   !insertmacro GetLyXSetting "Language" $LyXLanguage
133   
134   # Set language for gettext
135   ${if} $LyXLanguage != ""
136     Push LC_ALL
137     Push $LyXLanguage
138     Call SetEnvironmentVariable
139   ${endif}
140   
141   # Apparently the output charset needs to be set to some value,
142   # otherwise no non-ASCII characters will be displayed
143   Push OUTPUT_CHARSET
144   Push -
145   Call SetEnvironmentVariable
146   
147   # Location of Aiksaurus data
148   Push AIK_DATA_DIR
149   Push "$LyXFolder\aiksaurus"
150   Call SetEnvironmentVariable
151
152   # Location of Ghostscript (for ImageMagick)
153   Push LYX_GHOSTSCRIPT_EXE
154   Push "$LyXFolder\ghostscript\gswin32c.exe"
155   Call SetEnvironmentVariable
156   Push LYX_GHOSTSCRIPT_DLL
157   Push "$LyXFolder\ghostscript\gsdll32.dll"
158   Call SetEnvironmentVariable
159  
160 SectionEnd
161
162 Section -Launch
163   
164   # Start LyX and capture the command line output
165   
166   Push '"$EXEDIR\lyx.exe" $Parameters'
167   CallInstDLL "$EXEDIR\Console.dll" ExecToLog
168   Pop $ReturnValue #Return value
169   
170 SectionEnd
171
172 Section -Debug
173   
174   ${If} $Debug == ${FALSE}
175   
176     # Check whether something went wrong
177     
178     ${If} $ReturnValue == "error"
179   
180       # Probably the file does not exist
181       MessageBox MB_OK|MB_ICONSTOP "Failed to start LyX."
182     
183     ${ElseIf} $ReturnValue != 0
184     
185       # LyX has crashed
186       MessageBox MB_YESNO|MB_ICONSTOP \
187           "LyX has been closed because of an unexpected situation.$\n\
188           This is most likely caused by a flaw in the software.$\n$\n\
189           When you open your documents again, you will be able$\n\
190           to restore an emergency save and continue working.$\n$\n\
191           Would you like to view detailed information about this error?" \
192           IDYES debug IDNO no_debug
193   
194     ${EndIf}
195     
196     no_debug:
197     
198       Quit
199     
200     debug:
201     
202       ShowWindow $R0 ${SW_HIDE}
203     
204   ${EndIf}
205   
206   ${If} $ReturnValue != 0
207   
208     StrCpy $ResultText "Error Information"
209     StrCpy $ResultSubText "See Chapter 3 of the LyX Introduction \
210         (Help > Introduction) for information about reporting this issue."
211    
212    ${Else}
213    
214     StrCpy $ResultText "Debugging Completed"
215     StrCpy $ResultSubText "The events you have chosen are logged below."
216    
217    ${EndIf}
218   
219   ${If} $Debug == ${FALSE}
220
221     # Put the log window on the screen again
222     Push "user32::SetWindowPos(i $HWNDPARENT, i 0, i 133, i 100, i 0, i 0, i ${SWP_NOSIZE})"
223     CallInstDLL "$EXEDIR\System.dll" Call
224     BringToFront
225
226   ${EndIf}
227
228 SectionEnd
229
230
231 #--------------------------------
232 #Functions
233
234 Function InitInterface
235   
236   #Command line parameters
237   ${GetParameters} $Parameters
238   
239   #Check for debug mode
240   ${StrStr} $R0 $Parameters "-dbg"
241   
242   ${If} $R0 == ""
243     StrCpy $Debug ${FALSE}
244   ${Else}
245     StrCpy $Debug ${TRUE}
246   ${Endif}
247   
248   ${If} $Debug == ${FALSE}
249
250     # Keep the log window outside the screen to ensure that there will be no flickering
251     Push "user32::SetWindowPos(i $HWNDPARENT, i 0, i -32000, i -32000, i 0, i 0, i ${SWP_NOSIZE})"
252     CallInstDLL "$EXEDIR\System.dll" Call
253   
254   ${EndIf}
255
256 FunctionEnd
257
258 Function GetLyXSetting
259
260   Pop $LyxSetting
261
262   # Get a LyX setting from the registry
263   # First try a current user setting, then a system setting
264
265   ReadRegStr $LyXSettingValue HKCU ${APP_REGKEY_SETTINGS} $LyXSetting
266   
267   ${If} $LyXSettingValue == ""
268     ReadRegStr $LyXSettingValue HKLM ${APP_REGKEY_SETTINGS} $LyXSetting
269   ${EndIf}
270   
271   Push $LyXSettingValue
272
273 FunctionEnd
274
275 Function SetEnvironmentVariable
276
277   # Sets the value of an environment variable
278   # Input on stack: name of variable, value
279
280   Pop $EnvironmentVariableValue
281   Pop $EnvironmentVariable  
282   
283   Push 'kernel32::SetEnvironmentVariable(t, t) i("$EnvironmentVariable", "$EnvironmentVariableValue")'
284   CallInstDLL "$EXEDIR\System.dll" Call
285
286 FunctionEnd