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