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