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