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