-
Notifications
You must be signed in to change notification settings - Fork 2
/
KOSTsimy_de.nsi
331 lines (294 loc) · 10.2 KB
/
KOSTsimy_de.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
; The name of the installer
Name "KOST-Simy v0.0.5"
; Sets the icon of the installer
Icon "simy.ico"
; remove the text 'Nullsoft Install System vX.XX' from the installer window
BrandingText "Copyright © KOST/CECO"
; The file to write
OutFile "KOST-Simy_de.exe"
; The default installation directory
; InstallDir $DESKTOP
InstallDir $EXEDIR
; Request application privileges for Windows Vista
RequestExecutionLevel user
; Sets the text for the titlebar of the installer
Caption "$(^Name)"
; Makes the installer controls use the new XP style when running on Windows XP
XPStyle on
;--------------------------------
!include WinMessages.nsh
!include FileFunc.nsh
!include LogicLib.nsh
!include getJavaHome.nsh
!include langKOSTsimy_de.nsh
!include nsDialogs.nsh
!include XML.nsh
;--------------------------------
!define INIFILE "KOSTsimy.ini"
!define KOSTHELP "doc\KOST-Simy_Anwendungshandbuch_*.pdf"
!define CONFIG "KOSTsimy.conf.xml"
!define CONFIGPATH "configuration"
!define BACKUP "~backup"
!define JARFILE "kostsimy_de.jar"
!define XTRANS "resources\XTrans_1.8.0.2\XTrans.exe"
!define JAVAPATH "resources\jre6"
;--------------------------------
Var DIALOG
Var KOSTsimyO
Var KOSTsimyR
Var LOGFILE
Var WORKDIR
Var LOG
Var HEAPSIZE
Var JAVA
Var HWND
;--------------------------------
; Pages
#LicenseData license.txt
#Page license
#Page instfiles
Page Custom ShowDialog LeaveDialog
;--------------------------------
; Functions
Function .onInit
; looking for java home directory
push ${JAVAPATH}
Call getJavaHome
pop $JAVA
DetailPrint "java home: $JAVA"
; initial setting for validation folder/file
StrCpy $KOSTsimyO $EXEDIR
StrCpy $KOSTsimyR $EXEDIR
; create configuration backup
CreateDirectory $EXEDIR\${CONFIGPATH}\${BACKUP}
CopyFiles /SILENT /FILESONLY $EXEDIR\${CONFIGPATH}\*.* $EXEDIR\${CONFIGPATH}\${BACKUP}
; Initializes the plug-ins dir ($PLUGINSDIR) if not already initialized
InitPluginsDir
; Assign to the user variable $DIALOG, the name of a temporary file
GetTempFileName $DIALOG $PLUGINSDIR
; Adds file(s) to be extracted to the current output path
; Use /oname=X switch to change the output name
File /oname=$DIALOG ${INIFILE}
FunctionEnd
Function .onGUIEnd
; reset configuration and delete backup folder
CopyFiles /SILENT /FILESONLY $EXEDIR\${CONFIGPATH}\${BACKUP}\*.* $EXEDIR\${CONFIGPATH}
RMDir /r $EXEDIR\${CONFIGPATH}\${BACKUP}
FunctionEnd
Function check4Dir
StrCpy $WORKDIR ''
StrCpy $LOG ''
${xml::LoadFile} "$EXEDIR\${CONFIGPATH}\${CONFIG}" $0
${xml::RootElement} $0 $1
${xml::XPathString} "//configuration/pathtoworkdir/text()" $WORKDIR $1
${xml::XPathString} "//configuration/pathtologfile/text()" $LOG $1
${xml::Unload}
GetFullPathName $1 $WORKDIR
IfFileExists $1 fex not_fex
fex:
StrCpy $WORKDIR ''
not_fex:
FunctionEnd
Function checkHeapsize
${If} $HEAPSIZE == '-default'
StrCpy $HEAPSIZE ''
${EndIf}
FunctionEnd
;--------------------------------
Function ShowDialog
; Writes entry_name=value into [section_name] of ini file
WriteINIStr $DIALOG "Settings" "NextButtonText" "${NextButtonText}"
;WriteINIStr $DIALOG "${INTRO}" "Text" "${INTROTXT}"
WriteINIStr $DIALOG "${HELP_Button}" "Text" "${HELP_ButtonTXT}"
WriteINIStr $DIALOG "${ORIGINAL_FolderRequest}" "Text" "${ORIGINAL_FolderRequestTXT}"
WriteINIStr $DIALOG "${ORIGINAL_FileRequest}" "Text" "${ORIGINAL_FileRequestTXT}"
WriteINIStr $DIALOG "${ORIGINAL_SEL_FileFolder}" "State" "${ORIGINAL_SEL_FileFolderTXT}"
WriteINIStr $DIALOG "${JVM_Droplist}" "Text" "${JVM_DroplistTXT}"
; WriteINIStr $DIALOG "${INPUT_Group}" "Text" "${INPUT_GroupTXT}"
WriteINIStr $DIALOG "${REPLICA_FolderRequest}" "Text" "${REPLICA_FolderRequestTXT}"
WriteINIStr $DIALOG "${REPLICA_FileRequest}" "Text" "${REPLICA_FileRequestTXT}"
WriteINIStr $DIALOG "${REPLICA_SEL_FileFolder}" "State" "${REPLICA_SEL_FileFolderTXT}"
WriteINIStr $DIALOG "${START_Validation}" "Text" "${START_ValidationTXT}"
WriteINIStr $DIALOG "${EDIT_Konfiguration}" "Text" "${EDIT_KonfigurationTXT}"
WriteINIStr $DIALOG "${RESET_Konfiguration}" "Text" "${RESET_KonfigurationTXT}"
; Display the validation options dialog
InstallOptions::initDialog $DIALOG
Pop $HWND
; set button "Cancel" active
#GetDlgItem $1 $HWNDPARENT 2
#EnableWindow $1 1
; set button "Cancel" invisible
GetDlgItem $1 $HWNDPARENT 2
ShowWindow $1 0
; set button "Back" invisible
GetDlgItem $1 $HWNDPARENT 3
ShowWindow $1 0
; change button font
GetDlgItem $1 $HWND 1209
#CreateFont $R1 "Arial" "8" "600"
#SendMessage $1 ${WM_SETFONT} $R1 0
SetCtlColors $1 0x000000 0x05D62A
; Display the validation options dialog
InstallOptions::show
FunctionEnd
;--------------------------------
Function LeaveDialog
; If file, truncate KOSTsimyO to folder name
${GetFileExt} $KOSTsimyO $R0
${If} $R0 != ''
${GetParent} $KOSTsimyO= $KOSTsimyO
${EndIf}
; If file, truncate KOSTsimyR to folder name
${GetFileExt} $KOSTsimyR $R0
${If} $R0 != ''
${GetParent} $KOSTsimyR= $KOSTsimyR
${EndIf}
; To get the input of the user, read the State value of a Field
ReadINIStr $0 $DIALOG "Settings" "State"
ReadINIStr $HEAPSIZE $DIALOG "${JVM_Value}" "State"
${Switch} "Field $0"
${Case} '${HELP_Button}'
GetFullPathName $1 ${KOSTHELP}
ExecShell "open" $1
Abort
${Break}
${Case} '${ORIGINAL_FileRequest}'
nsDialogs::SelectFileDialog 'open' '$KOSTsimyO\*' ''
Pop $R0
${If} $R0 == ''
MessageBox MB_OK "${FILE_SelectTXT}"
${Else}
ReadINIStr $1 $DIALOG '${ORIGINAL_SEL_FileFolder}' 'HWND'
SendMessage $1 ${WM_SETTEXT} 1 'STR:$R0'
StrCpy $KOSTsimyO $R0
${EndIf}
Abort
${Break}
${Case} '${REPLICA_FileRequest}'
nsDialogs::SelectFileDialog 'open' '$KOSTsimyR\*' ''
Pop $R0
${If} $R0 == ''
MessageBox MB_OK "${FILE_SelectTXT}"
${Else}
ReadINIStr $1 $DIALOG '${REPLICA_SEL_FileFolder}' 'HWND'
SendMessage $1 ${WM_SETTEXT} 1 'STR:$R0'
StrCpy $KOSTsimyR $R0
${EndIf}
Abort
${Break}
${Case} '${ORIGINAL_FolderRequest}'
nsDialogs::SelectFolderDialog "${FOLDER_SelectTXT}" "$KOSTsimyO"
Pop $R0
${If} $R0 == 'error'
MessageBox MB_OK "${FOLDER_SelectTXT}"
${Else}
ReadINIStr $1 $DIALOG '${ORIGINAL_SEL_FileFolder}' 'HWND'
SendMessage $1 ${WM_SETTEXT} 1 'STR:$R0'
StrCpy $KOSTsimyO $R0
${EndIf}
Abort
${Break}
${Case} '${REPLICA_FolderRequest}'
nsDialogs::SelectFolderDialog "${FOLDER_SelectTXT}" "$KOSTsimyR"
Pop $R0
${If} $R0 == 'error'
MessageBox MB_OK "${FOLDER_SelectTXT}"
${Else}
ReadINIStr $1 $DIALOG '${REPLICA_SEL_FileFolder}' 'HWND'
SendMessage $1 ${WM_SETTEXT} 1 'STR:$R0'
StrCpy $KOSTsimyR $R0
${EndIf}
Abort
${Break}
${Case} '${START_Validation}'
ReadINIStr $R0 $DIALOG "${ORIGINAL_SEL_FileFolder}" "State"
; Trim path or file name
StrCpy $R1 $R0 1 -1
StrCmp $R1 '\' 0 +2
StrCpy $R0 $R0 -1
GetFullPathName $KOSTsimyO $R0
ReadINIStr $R0 $DIALOG "${REPLICA_SEL_FileFolder}" "State"
; Trim path or file name
StrCpy $R1 $R0 1 -1
StrCmp $R1 '\' 0 +2
StrCpy $R0 $R0 -1
GetFullPathName $KOSTsimyR $R0
Call RunJar
Abort
${Break}
${Case} '${EDIT_Konfiguration}'
ClearErrors
ExecWait '${XTRANS} "$EXEDIR\${CONFIGPATH}\${CONFIG}"'
${If} ${Errors}
ExecWait '"notepad.exe" "$EXEDIR\${CONFIGPATH}\${CONFIG}"'
${EndIf}
; ExecWait '"notepad.exe" "$EXEDIR\${CONFIGPATH}\${CONFIG}"'
; ExecShell "open" "$EXEDIR\${CONFIGPATH}\${CONFIG}"
Abort
${Break}
${Case} '${RESET_Konfiguration}'
CopyFiles /SILENT /FILESONLY $EXEDIR\${CONFIGPATH}\${BACKUP}\*.* $EXEDIR\${CONFIGPATH}
Abort
${Break}
${Default}
; Abort prevents from leaving the current page
; Abort
${Break}
${EndSwitch}
FunctionEnd
;--------------------------------
Function RunJar
; get workdir and logdir
Call check4Dir
; normalize java heap and stack
Call checkHeapsize
; get logfile name
${GetFileName} $KOSTsimyO $LOGFILE
CreateDirectory $LOG
IfFileExists "$LOG\*.*" +2 0
CreateDirectory "$EXEDIR\$LOG"
ClearErrors
FileOpen $R0 "$LOG\$LOGFILE.kost-simy.log.tmp" w
FileClose $R0
${If} ${Errors}
Delete "$LOG\$LOGFILE.kost-simy.log.tmp"
MessageBox MB_OK|MB_ICONEXCLAMATION "${LOG_ERR} $LOG"
Abort
${EndIf}
delete "$LOG\$LOGFILE.kost-simy.log*"
; Launch java program
ClearErrors
; MessageBox MB_OK '"$JAVA\bin\java.exe" $HEAPSIZE -jar ${JARFILE} "$KOSTsimyO" "$KOSTsimyR"
ExecWait '"$JAVA\bin\java.exe" $HEAPSIZE -jar ${JARFILE} "$KOSTsimyO" "$KOSTsimyR"'
IfFileExists "$LOG\$LOGFILE.kost-simy.log*" 0 prog_err
IfErrors goto_err goto_ok
goto_err:
; validation with error
IfFileExists "$LOG\$LOGFILE.kost-simy.log*" 0 prog_err
MessageBox MB_YESNO|MB_ICONEXCLAMATION "$KOSTsimyO$\n${FORMAT_FALSE}" IDYES showlog
Goto rm_workdir
prog_err:
MessageBox MB_OK|MB_ICONEXCLAMATION "${PROG_ERR} $\n$JAVA\bin\java.exe -jar ${JARFILE} $KOSTsimyO $KOSTsimyR"
Goto rm_workdir
goto_ok:
; validation without error completed
MessageBox MB_YESNO "$KOSTsimyO$\n${FORMAT_OK}" IDYES showlog
Goto rm_workdir
showlog:
; read logfile in detail view
GetFullPathName $1 $LOG
IfFileExists "$LOG\$LOGFILE.kost-simy.log.xml" 0 +3
ExecShell "" "iexplore.exe" "$1\$LOGFILE.kost-simy.log.xml"
Goto rm_workdir
ExecShell "" "iexplore.exe" "$1\$LOGFILE.kost-simy.log"
Goto rm_workdir
; ExecShell "open" "$LOG\$LOGFILE.kost-simy.log.xml"
; ExecShell "open" "$LOG\$LOGFILE.kost-simy.log"
rm_workdir:
GetFullPathName $1 $WORKDIR
RMDir /r $1
FunctionEnd
;--------------------------------
; Sections
Section "Install"
SectionEnd