root / import / ext3D / trunk / install-extension3d / launcher / izpack-launcher-1.3 / src / launcher.cpp @ 15280
History | View | Annotate | Download (28.7 KB)
1 |
/* Copyright (c) 2004 Julien Ponge - All rights reserved.
|
---|---|
2 |
* Some windows 98 debugging done by Dustin Sacks.
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 |
* of this software and associated documentation files (the "Software"), to
|
6 |
* deal in the Software without restriction, including without limitation the
|
7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
8 |
* sell copies of the Software, and to permit persons to whom the Software is
|
9 |
* furnished to do so, subject to the following conditions:
|
10 |
*
|
11 |
* The above copyright notice and this permission notice shall be included in
|
12 |
* all copies or substantial portions of the Software.
|
13 |
*
|
14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
20 |
* IN THE SOFTWARE.
|
21 |
*/
|
22 |
#include <wx/string.h> |
23 |
#include <wx/file.h> |
24 |
#include <wx/filename.h> |
25 |
#include <wx/url.h> |
26 |
#include <wx/process.h> |
27 |
|
28 |
#include "launcher.h" |
29 |
|
30 |
#include "myIniReader.h" |
31 |
|
32 |
#ifdef __UNIX__
|
33 |
#include <stdlib.h> |
34 |
#include <map> |
35 |
#include <list> |
36 |
#endif
|
37 |
|
38 |
|
39 |
/*
|
40 |
* Helper function to run an external program. It takes care of the subtule
|
41 |
* differences between the OS-specific implementations.
|
42 |
*
|
43 |
* @param cmd The command to run.
|
44 |
* @return <code>true</code> in case of a success, <code>false</code> otherwise.
|
45 |
*/
|
46 |
bool run_external(wxString cmd)
|
47 |
{ |
48 |
int code = wxExecute(cmd, wxEXEC_SYNC);
|
49 |
return (code == 0); |
50 |
|
51 |
} |
52 |
|
53 |
bool run_external_async(wxString cmd)
|
54 |
{ |
55 |
return (wxExecute(cmd, wxEXEC_ASYNC) != 0); |
56 |
} |
57 |
|
58 |
//wxString escape_backSlash(wxString aStr){
|
59 |
// aStr.Replace("\\","\\\\");
|
60 |
// return aStr;
|
61 |
//}
|
62 |
|
63 |
bool string_to_bool(wxString value, bool defaultValue){ |
64 |
bool returnValue = defaultValue;
|
65 |
if (value != wxEmptyString)
|
66 |
if (
|
67 |
value.CmpNoCase("s") == 0 || |
68 |
value.CmpNoCase("si") == 0 || |
69 |
value.CmpNoCase("1") == 0 || |
70 |
value.CmpNoCase("y") == 0 || |
71 |
value.CmpNoCase("yes") == 0 |
72 |
) |
73 |
{ |
74 |
returnValue = true;
|
75 |
} else {
|
76 |
returnValue = false;
|
77 |
} |
78 |
return returnValue;
|
79 |
} |
80 |
|
81 |
long LAUNCHAPP_TIMER_ID = wxNewId();
|
82 |
|
83 |
BEGIN_EVENT_TABLE(LauncherApp, wxApp) |
84 |
EVT_TIMER(LAUNCHAPP_TIMER_ID, LauncherApp::OnTimer) |
85 |
END_EVENT_TABLE() |
86 |
|
87 |
|
88 |
/* Main Application $Revision: 1.28 $
|
89 |
*
|
90 |
* $Id: launcher.cpp,v 1.28 2007/01/29 12:08:00 jmvivo Exp $
|
91 |
*/
|
92 |
LauncherApp::LauncherApp() |
93 |
: wxApp() |
94 |
{ |
95 |
APPLICATION_NAME = wxString(_("Launcher"));
|
96 |
completed = false;
|
97 |
|
98 |
SetAppName(_(APPLICATION_NAME)); |
99 |
//loadParams();
|
100 |
} |
101 |
|
102 |
void LauncherApp::echo(const wxString &msg) |
103 |
{ |
104 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK);
|
105 |
dlg.ShowModal(); |
106 |
} |
107 |
|
108 |
void LauncherApp::notifyToUser(const wxString &msg) |
109 |
{ |
110 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_INFORMATION);
|
111 |
dlg.ShowModal(); |
112 |
} |
113 |
|
114 |
|
115 |
LauncherApp::~LauncherApp() |
116 |
{ |
117 |
|
118 |
} |
119 |
|
120 |
void LauncherApp::loadParams()
|
121 |
{ |
122 |
//cfgName = wxString( "launcher.ini" );
|
123 |
cfgName =wxString(argv[0]);
|
124 |
wxFileName execFileName(cfgName); |
125 |
execFileName.SetExt("ini");
|
126 |
cfgName = execFileName.GetFullPath(); |
127 |
if (!wxFileExists(cfgName)) {
|
128 |
error(cfgName.Format(_("The configuration file '%s' does not exists."),cfgName.c_str()));
|
129 |
} |
130 |
|
131 |
//wxFileInputStream in( cfgName );
|
132 |
//wxFileConfig cfg( in );
|
133 |
wxString downloadEnabled; |
134 |
wxString launchJarAsync; |
135 |
wxString askForCheckingProcess; |
136 |
wxString doChecks; |
137 |
wxString checksJREExecutionTerminationCode; |
138 |
wxString checksJai; |
139 |
wxString checksJaiIo; |
140 |
|
141 |
paramsApplicationName = readPathFromINI( "appname","gvSIG"); |
142 |
paramsJar = readPathFromINI( "jar",wxEmptyString);
|
143 |
paramsCommand = readPathFromINI( "command",wxEmptyString);
|
144 |
paramsJre = readPathFromINI( "jre", wxEmptyString);
|
145 |
paramsJreDownload = readFromINI( "downloadJre", wxEmptyString);
|
146 |
checksJai = readFromINI( "checkJai",wxEmptyString);
|
147 |
paramsJai = readPathFromINI( "jai",wxEmptyString);
|
148 |
paramsJaiDownload = readFromINI( "downloadJai", wxEmptyString);
|
149 |
checksJaiIo = readFromINI( "checkJai_io",wxEmptyString);
|
150 |
paramsJaiIo = readPathFromINI( "jai_io",wxEmptyString);
|
151 |
paramsJaiIoDownload = readFromINI( "downloadJai_io",wxEmptyString);
|
152 |
paramsJreVersion = readFromINI( "jre_version",wxEmptyString);
|
153 |
paramsJreVersionPrefered = readFromINI( "jre_version_prefered",wxEmptyString);
|
154 |
downloadEnabled = readFromINI( "downloadEnabled",wxEmptyString);
|
155 |
launchJarAsync = readFromINI( "launchJarAsync", wxEmptyString);
|
156 |
askForCheckingProcess = readFromINI( "askForCheckingProcess", wxEmptyString);
|
157 |
doChecks = readFromINI( "doChecks",wxEmptyString);
|
158 |
checksJREExecutionTerminationCode = readFromINI( "checksJREExecutionTerminationCode",wxEmptyString);
|
159 |
paramsJreHome = readPathFromINI( "jre_home", wxEmptyString);
|
160 |
paramsLaunchMode = readPathFromINI( "launchMode", wxEmptyString);
|
161 |
|
162 |
|
163 |
//echo(paramsCommand);
|
164 |
|
165 |
//procesamos el parametro booleano 'downloadEnabled'
|
166 |
paramsEnabledDownload =string_to_bool(downloadEnabled,false);
|
167 |
//procesamos el parametro booleano 'launchJarAsync'
|
168 |
paramsLaunchJarAsync =string_to_bool(launchJarAsync,false);
|
169 |
//procesamos el parametro booleano 'askForCheckingProcess'
|
170 |
paramsAskForCheckingProcess=string_to_bool(askForCheckingProcess,true);
|
171 |
//procesamos el parametro booleano 'askForCheckingProcess'
|
172 |
paramsDoChecks=string_to_bool(doChecks,true);
|
173 |
//procesamos el parametro booleano 'checksJREExecutionTerminationCode'
|
174 |
paramsChecksJREExecutionTerminationCode=string_to_bool(checksJREExecutionTerminationCode,true);
|
175 |
paramsCheckJai=string_to_bool(checksJai,true);
|
176 |
paramsCheckJaiIo=string_to_bool(checksJaiIo,true);
|
177 |
|
178 |
|
179 |
if (paramsCommand == wxEmptyString )
|
180 |
{ |
181 |
error(cfgName.Format(_("The configuration file '%s' does not contain a command entry."),cfgName.c_str()));
|
182 |
} |
183 |
if (paramsLaunchMode == wxEmptyString )
|
184 |
{ |
185 |
error(cfgName.Format(_("The configuration file '%s' does not contain a mode entry."),cfgName.c_str()));
|
186 |
} |
187 |
paramsLaunchMode = paramsLaunchMode.MakeUpper(); |
188 |
if ((!paramsLaunchMode.IsSameAs("APPLICATION")) && (!paramsLaunchMode.IsSameAs("INSTALL"))) { |
189 |
error(cfgName.Format(_("The configuration file '%s' contains a invalid mode entry."),cfgName.c_str()));
|
190 |
} |
191 |
|
192 |
if (paramsJreVersionPrefered == wxEmptyString ) {
|
193 |
paramsJreVersionPrefered = wxString(paramsJreVersion); |
194 |
} |
195 |
if ((!paramsDoChecks) && paramsJreHome == wxEmptyString) {
|
196 |
error(cfgName.Format(_("The file entry 'jre_home' can not be empty when 'doChecks = No'."),cfgName.c_str()));
|
197 |
} |
198 |
|
199 |
|
200 |
|
201 |
variables = sectionKeysFromINI("Variables");
|
202 |
|
203 |
variablesValues = sectionKeysValuesFromINI("Variables",variables);
|
204 |
|
205 |
|
206 |
wxArrayString environVariables = sectionKeysFromINI("EnvironVariables");
|
207 |
wxArrayString environVariablesValues = sectionKeysValuesFromINI("EnvironVariables",environVariables);
|
208 |
//echo(paramsJreVersionPrefered.Format("count %i",environVariables.GetCount()));
|
209 |
//Las cargamos como variables de entorno
|
210 |
for (size_t i=0; i < environVariables.GetCount() ;i++) { |
211 |
wxSetEnv(environVariables[i], environVariablesValues[i]); |
212 |
} |
213 |
} |
214 |
|
215 |
void LauncherApp::error(const wxString &msg) |
216 |
{ |
217 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_ERROR);
|
218 |
dlg.ShowModal(); |
219 |
printf(msg.c_str()); |
220 |
exit(1);
|
221 |
} |
222 |
|
223 |
void LauncherApp::confirm(const wxString &msg) |
224 |
{ |
225 |
int response;
|
226 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxCANCEL | wxICON_QUESTION );
|
227 |
response = dlg.ShowModal(); |
228 |
if (response != wxID_OK) {
|
229 |
notifyToUser(_("Canceled by user"));
|
230 |
exit(1);
|
231 |
} |
232 |
} |
233 |
bool LauncherApp::confirmYesNoCancel(const wxString &msg,const int yesDefault = true) |
234 |
{ |
235 |
int response;
|
236 |
long maskDefault;
|
237 |
if (yesDefault) {
|
238 |
maskDefault = wxYES_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
239 |
} else {
|
240 |
maskDefault = wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
241 |
} |
242 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), maskDefault);
|
243 |
response = dlg.ShowModal(); |
244 |
if (response != wxID_YES && response != wxID_NO) {
|
245 |
notifyToUser(_("Canceled by user"));
|
246 |
exit(1);
|
247 |
} |
248 |
return (response == wxID_YES);
|
249 |
|
250 |
} |
251 |
|
252 |
void LauncherApp::showStatusWindow(){
|
253 |
if (isStatusDialogVisible) {
|
254 |
return;
|
255 |
} |
256 |
|
257 |
statusDialog = new StatusDialog( APPLICATION_NAME );
|
258 |
|
259 |
statusDialog->Centre(); |
260 |
statusDialog->Show(TRUE); |
261 |
isStatusDialogVisible = true;
|
262 |
} |
263 |
|
264 |
|
265 |
bool LauncherApp::OnInit()
|
266 |
{ |
267 |
isStatusDialogVisible = false;
|
268 |
wxFileName exeFileName(argv[0]);
|
269 |
wxFileName exePath = exeFileName.GetPath(); |
270 |
|
271 |
exePath.SetCwd(); |
272 |
|
273 |
locale.Init(); |
274 |
locale.AddCatalog("launcher");
|
275 |
loadParams(); |
276 |
|
277 |
|
278 |
if (paramsLaunchMode.IsSameAs("INSTALL")){ |
279 |
APPLICATION_NAME = wxString(APPLICATION_NAME.Format(_("%s Install-Launcher"),paramsApplicationName.c_str()));
|
280 |
SetAppName(_(APPLICATION_NAME)); |
281 |
showStatusWindow(); |
282 |
} else {
|
283 |
APPLICATION_NAME = wxString(APPLICATION_NAME.Format(_("%s Launcher"),paramsApplicationName.c_str()));
|
284 |
SetAppName(_(APPLICATION_NAME)); |
285 |
} |
286 |
|
287 |
showStatusMsg(_("Intializing..."));
|
288 |
|
289 |
myTimer = new wxTimer(this,LAUNCHAPP_TIMER_ID); |
290 |
myTimer->Start(150,true); |
291 |
this->MainLoop();
|
292 |
return true; |
293 |
} |
294 |
|
295 |
void LauncherApp::fixSystemJREConfig(){
|
296 |
showStatusMsg(_("Updating the system..."));
|
297 |
//actualizamos CurrentVersion
|
298 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
299 |
"\\Java Runtime Environment\\";
|
300 |
|
301 |
wxString genericVersion = paramsJreVersion.Left(3);
|
302 |
|
303 |
wxString baseKeyGeneric = baseKey + genericVersion + "\\";
|
304 |
wxString baseKeyVersion = baseKey + localVersionToUse + "\\";
|
305 |
|
306 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
307 |
if( !pRegKey->Exists() ) {
|
308 |
error(_("JRE not found."));
|
309 |
} |
310 |
|
311 |
// compiamos el contenido de la rama de la version
|
312 |
// que queremos a la generica (1.4 o 1.5 o ...)
|
313 |
wxRegKey *pRegKeyGeneric = new wxRegKey(baseKeyGeneric);
|
314 |
wxRegKey *pRegKeyVersion = new wxRegKey(baseKeyVersion);
|
315 |
|
316 |
if ( !pRegKeyGeneric->Exists() ){
|
317 |
pRegKeyGeneric->Create(); |
318 |
} |
319 |
wxString tempKey; |
320 |
wxString tempValue; |
321 |
size_t nValues; |
322 |
|
323 |
pRegKeyVersion->GetKeyInfo(NULL,NULL,&nValues,NULL); |
324 |
long pos = 1; |
325 |
pRegKeyVersion->GetFirstValue(tempKey,pos); |
326 |
for(unsigned i=0;i<nValues;i++) { |
327 |
//echo("copy " + tempKey);
|
328 |
pRegKeyVersion->QueryValue(tempKey,tempValue); |
329 |
pRegKeyGeneric->SetValue(tempKey,tempValue); |
330 |
pRegKeyVersion->GetNextValue(tempKey,pos); |
331 |
} |
332 |
|
333 |
|
334 |
} |
335 |
|
336 |
|
337 |
bool LauncherApp::compareVersions(const wxString localVersion, const wxString requireVersion) |
338 |
{ |
339 |
bool result = (localVersion.Cmp(requireVersion) == 0); |
340 |
/*
|
341 |
if (requireVersion.Len() > localVersion.Len() ) {
|
342 |
|
343 |
result = (localVersion.Find(requireVersion) == 0);
|
344 |
}
|
345 |
else
|
346 |
{
|
347 |
result = (requireVersion.Find(localVersion) == 0);
|
348 |
}
|
349 |
*/
|
350 |
|
351 |
/*
|
352 |
if (result) {
|
353 |
echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> true");
|
354 |
} else {
|
355 |
echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> false");
|
356 |
}
|
357 |
*/
|
358 |
|
359 |
return result;
|
360 |
} |
361 |
|
362 |
|
363 |
bool LauncherApp::searchJRE()
|
364 |
{ |
365 |
showStatusMsg(_("Searching JRE's..."));
|
366 |
wxString version("");
|
367 |
|
368 |
// Windows[tm] registry lookup
|
369 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
370 |
"\\Java Runtime Environment\\";
|
371 |
|
372 |
wxRegKey bKey(baseKey); |
373 |
if (!bKey.Exists()) {
|
374 |
return false; |
375 |
} |
376 |
|
377 |
if (!bKey.QueryValue("CurrentVersion", version)){ |
378 |
return false; |
379 |
} |
380 |
|
381 |
if (version == "1.1") { |
382 |
return false; |
383 |
} |
384 |
|
385 |
if (!compareVersions(version, paramsJreVersionPrefered)){
|
386 |
//Nos recorremos las versiones instaladas
|
387 |
version = "";
|
388 |
wxString strTemp; |
389 |
wxRegKey sKey(baseKey); |
390 |
if (sKey.HasSubKey(paramsJreVersionPrefered)) {
|
391 |
version = wxString(paramsJreVersionPrefered); |
392 |
} else {
|
393 |
for(unsigned i=20;i>1;i--) { |
394 |
strTemp = wxString::Format(paramsJreVersion + "_%02d",i);
|
395 |
if (sKey.HasSubKey(strTemp)) {
|
396 |
version = strTemp; |
397 |
break;
|
398 |
} |
399 |
} |
400 |
} |
401 |
} |
402 |
|
403 |
|
404 |
if (version == "") { |
405 |
return false; |
406 |
} |
407 |
localVersionToUse = version; |
408 |
wxRegKey vKey(baseKey + version); |
409 |
|
410 |
if (!vKey.QueryValue("JavaHome", javaHome)){ |
411 |
return false; |
412 |
} |
413 |
|
414 |
|
415 |
calculateJavaExePath(javaHome); |
416 |
/*
|
417 |
echo("paramsJreVersion=" + paramsJreVersion);
|
418 |
echo("paramsJreVersionPrefered=" + paramsJreVersionPrefered);
|
419 |
echo("localVersionToUse=" + localVersionToUse);
|
420 |
echo("javaHome=" +javaHome);
|
421 |
echo("javaExecPath=" +javaExecPath);
|
422 |
*/
|
423 |
return true; |
424 |
} |
425 |
|
426 |
void LauncherApp::runJRE()
|
427 |
{ |
428 |
if (paramsLaunchMode.IsSameAs("INSTALL")) { |
429 |
showStatusMsg(_("Launching installation..."));
|
430 |
} else {
|
431 |
showStatusMsg(_("Launching application..."));
|
432 |
} |
433 |
wxString cmd = parseCommand(); |
434 |
//echo(cmd);
|
435 |
bool isOk=true; |
436 |
if (paramsLaunchJarAsync) {
|
437 |
if (!run_external_async(cmd))
|
438 |
{ |
439 |
isOk=false;
|
440 |
} |
441 |
} else {
|
442 |
if (!run_external(cmd))
|
443 |
{ |
444 |
isOk=false;
|
445 |
} |
446 |
} |
447 |
|
448 |
if (!isOk) {
|
449 |
if (paramsChecksJREExecutionTerminationCode) {
|
450 |
error( |
451 |
cmd.Format( |
452 |
_("The command\n%s\ncould not be executed."),
|
453 |
cmd.c_str() |
454 |
) |
455 |
); |
456 |
} |
457 |
} |
458 |
|
459 |
completed = true;
|
460 |
} |
461 |
|
462 |
void LauncherApp::jreInstall()
|
463 |
{ |
464 |
showStatusWindow(); |
465 |
|
466 |
showStatusMsg(_("Preparing to install JRE..."));
|
467 |
|
468 |
if (!checkInstallerFile(paramsJre, paramsJreDownload,_("Java JRE version ")+paramsJreVersion)) |
469 |
{ |
470 |
error(_("The JRE could not be setup."));
|
471 |
} |
472 |
|
473 |
showStatusMsg(_("Installing JRE..."));
|
474 |
if (!run_external(paramsJre))
|
475 |
{ |
476 |
error(_("The JRE could not be setup."));
|
477 |
} |
478 |
if (!searchJRE()) {
|
479 |
error(_("The JRE could not be setup."));
|
480 |
} |
481 |
} |
482 |
|
483 |
|
484 |
// Not used
|
485 |
void LauncherApp::netDownload()
|
486 |
{ |
487 |
wxString browser; |
488 |
|
489 |
#ifdef __WINDOWS__
|
490 |
// We use the default browser.
|
491 |
browser = "rundll32 url.dll,FileProtocolHandler ";
|
492 |
#endif
|
493 |
|
494 |
/*
|
495 |
if (run_external(browser + paramsDownload))
|
496 |
{
|
497 |
completed = true;
|
498 |
}
|
499 |
else
|
500 |
{
|
501 |
error(_("Could not find a web browser."));
|
502 |
}
|
503 |
*/
|
504 |
} |
505 |
|
506 |
IMPLEMENT_APP(LauncherApp) |
507 |
|
508 |
|
509 |
void LauncherApp::jaiInstall()
|
510 |
{ |
511 |
if (!paramsCheckJai){
|
512 |
return;
|
513 |
} |
514 |
bool isOK;
|
515 |
showStatusMsg(_("Checking JAI Library..."));
|
516 |
|
517 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
518 |
"\\Java Runtime Environment\\";
|
519 |
|
520 |
wxString currentVersion; |
521 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
522 |
if( !pRegKey->Exists() )
|
523 |
error(_("JRE not found."));
|
524 |
if (!pRegKey->QueryValue("CurrentVersion", currentVersion)) error(_("JRE not found.")); |
525 |
|
526 |
isOK=true;
|
527 |
if (!checksJai()) {
|
528 |
//confirm(_("JAI library is required, Install it?"));
|
529 |
showStatusWindow(); |
530 |
|
531 |
showStatusMsg(_("Preparing to install JAI Library..."));
|
532 |
if (!checkInstallerFile(paramsJai, paramsJaiDownload, _("JAI Library"))) |
533 |
{ |
534 |
isOK=false;
|
535 |
} else {
|
536 |
pRegKey->SetValue("CurrentVersion",localVersionToUse);
|
537 |
showStatusMsg(_("Preparing to install JAI Library..."));
|
538 |
if (run_external(paramsJai))
|
539 |
{ |
540 |
isOK=(checksJai()); |
541 |
} else {
|
542 |
isOK=false;
|
543 |
} |
544 |
pRegKey->SetValue("CurrentVersion",currentVersion);
|
545 |
} |
546 |
|
547 |
} |
548 |
if (!isOK) {
|
549 |
error(_("The JAI could not be setup."));
|
550 |
} |
551 |
} |
552 |
|
553 |
void LauncherApp::jaiIoInstall()
|
554 |
{ |
555 |
if (!paramsCheckJaiIo){
|
556 |
return;
|
557 |
} |
558 |
bool isOK;
|
559 |
showStatusMsg(_("Checking JAI imageIO Library..."));
|
560 |
|
561 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
562 |
"\\Java Runtime Environment\\";
|
563 |
|
564 |
wxString currentVersion; |
565 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
566 |
if( !pRegKey->Exists() )
|
567 |
error(_("JRE not found."));
|
568 |
if (!pRegKey->QueryValue("CurrentVersion", currentVersion)) error(_("JRE not found.")); |
569 |
|
570 |
|
571 |
isOK=true;
|
572 |
if (!checksJaiIo()) {
|
573 |
//confirm(_("JAI ImageIO library is required, Install it?"));
|
574 |
showStatusWindow(); |
575 |
|
576 |
showStatusMsg(_("Preparing to install JAI imageIO Library..."));
|
577 |
if (!checkInstallerFile(paramsJaiIo, paramsJaiIoDownload,"JAI ImageIO Library")) |
578 |
{ |
579 |
isOK=false;
|
580 |
} else {
|
581 |
pRegKey->SetValue("CurrentVersion",localVersionToUse);
|
582 |
showStatusMsg(_("Installing JAI imageIO Library..."));
|
583 |
if (run_external(paramsJaiIo))
|
584 |
{ |
585 |
isOK=(checksJaiIo()); |
586 |
} else {
|
587 |
isOK=false;
|
588 |
} |
589 |
pRegKey->SetValue("CurrentVersion",currentVersion);
|
590 |
} |
591 |
|
592 |
} |
593 |
if (!isOK) {
|
594 |
error(_("The JAI imageIO could not be setup."));
|
595 |
} |
596 |
} |
597 |
|
598 |
bool LauncherApp::checksJai(){
|
599 |
return (wxFileExists(javaHome + "\\lib\\ext\\jai_core.jar")); |
600 |
} |
601 |
|
602 |
bool LauncherApp::checksJaiIo(){
|
603 |
return (wxFileExists(javaHome + "\\lib\\ext\\jai_imageio.jar")); |
604 |
} |
605 |
|
606 |
bool LauncherApp::downloadFileHttp(const wxString urlOfFile, const wxString filePath, const wxString msg){ |
607 |
|
608 |
bool isOk;
|
609 |
//echo(urlOfFile);
|
610 |
if (urlOfFile == wxEmptyString) {
|
611 |
return false; |
612 |
} |
613 |
|
614 |
if (filePath == wxEmptyString) {
|
615 |
return false; |
616 |
} |
617 |
|
618 |
showStatusMsg(msg); |
619 |
wxURL url(urlOfFile); |
620 |
//echo("url open");
|
621 |
wxInputStream *in_stream; |
622 |
|
623 |
in_stream = url.GetInputStream(); |
624 |
//echo("in_stream open");
|
625 |
if (!in_stream->IsOk()) {
|
626 |
//echo("in_stream.IsOk == false");
|
627 |
return false; |
628 |
} |
629 |
//echo("in_stream.IsOk == true");
|
630 |
//echo("filePath =" + filePath);
|
631 |
wxFileName fileName(filePath); |
632 |
|
633 |
|
634 |
// Preparamos la ruta para el fichero destino
|
635 |
wxArrayString dirs; |
636 |
|
637 |
dirs = fileName.GetDirs(); |
638 |
wxString dir; |
639 |
wxFileName curDir(".");
|
640 |
for (size_t i=0; i < dirs.GetCount(); i++) { |
641 |
dir = dirs.Item(i); |
642 |
curDir.AppendDir(dir); |
643 |
//echo("dir " + curDir.GetPath());
|
644 |
if (!curDir.DirExists()) {
|
645 |
//echo("creating dir");
|
646 |
isOk = curDir.Mkdir(); |
647 |
if (!isOk) {
|
648 |
//echo("dir create no ok");
|
649 |
return false; |
650 |
} |
651 |
|
652 |
//echo("dir create ok");
|
653 |
} |
654 |
} |
655 |
|
656 |
|
657 |
wxFileOutputStream out_stream = wxFileOutputStream(filePath); |
658 |
//echo("out_stream open");
|
659 |
|
660 |
//in_stream->Read(out_stream);
|
661 |
size_t nbytes = 10240;
|
662 |
char buffer[nbytes];
|
663 |
|
664 |
|
665 |
//while (!in_stream->Eof()) {
|
666 |
while (!in_stream->Eof()) {
|
667 |
in_stream->Read(&buffer,nbytes); |
668 |
if (in_stream->LastError() != wxSTREAM_NO_ERROR && in_stream->LastError() != wxSTREAM_EOF) {
|
669 |
return false; |
670 |
} |
671 |
out_stream.Write(&buffer,in_stream->LastRead()); |
672 |
if (out_stream.LastError() != wxSTREAM_NO_ERROR) {
|
673 |
return false; |
674 |
} |
675 |
int totalKb = out_stream.GetSize() / 1024; |
676 |
wxString totalMsg =msg.Format("%i",totalKb);
|
677 |
showStatusMsg(msg+" "+ totalMsg + " Kb"); |
678 |
|
679 |
} |
680 |
|
681 |
|
682 |
isOk = true;
|
683 |
/*
|
684 |
if (isOk) {
|
685 |
echo("isOk = true");
|
686 |
} else {
|
687 |
echo("isOk = false");
|
688 |
}
|
689 |
*/
|
690 |
delete in_stream;
|
691 |
|
692 |
//echo("end");
|
693 |
return isOk;
|
694 |
|
695 |
} |
696 |
|
697 |
bool LauncherApp::checkInstallerFile(const wxString filePath, const wxString urlDownload, const wxString fileDescription) { |
698 |
if (!wxFile::Exists(filePath))
|
699 |
{ |
700 |
if (paramsEnabledDownload)
|
701 |
{ |
702 |
wxString msg = _("Installation requires to download this file:\n") +
|
703 |
fileDescription + "\n" +
|
704 |
_("Do you want to continue?");
|
705 |
confirm(msg); |
706 |
//showStatusMsg(_("Downloading ") + fileDescription + "...");
|
707 |
if (!downloadFileHttp(urlDownload,filePath,_("Downloading ") + fileDescription + "..." )) |
708 |
{ |
709 |
//FIXME: Falta msgError
|
710 |
return false; |
711 |
} |
712 |
} |
713 |
else
|
714 |
{ |
715 |
return false; |
716 |
} |
717 |
|
718 |
} |
719 |
return true; |
720 |
} |
721 |
|
722 |
void LauncherApp::showStatusMsg(const wxString msg) { |
723 |
if (isStatusDialogVisible) {
|
724 |
while (this->Pending()) { |
725 |
this->Dispatch();
|
726 |
} |
727 |
if (statusDialog->IsCanceled()) {
|
728 |
int response;
|
729 |
wxMessageDialog dlg(0, _("Do you really want to cancel the installation process?"), _(APPLICATION_NAME), wxYES_NO | wxICON_QUESTION ); |
730 |
response = dlg.ShowModal(); |
731 |
if (response == wxID_YES) {
|
732 |
notifyToUser(_("Canceled by user"));
|
733 |
exit(1);
|
734 |
} |
735 |
statusDialog->DoNotCancel(); |
736 |
} |
737 |
statusDialog->showStatus(msg); |
738 |
} |
739 |
} |
740 |
|
741 |
bool LauncherApp::checkVersion(const wxString javaexe) |
742 |
{ |
743 |
wxString cmd; |
744 |
wxArrayString out; |
745 |
wxArrayString err; |
746 |
|
747 |
cmd = cmd.Format("%s -version", javaexe.c_str());
|
748 |
if( wxExecute(cmd,out,err)!= 0 ) { |
749 |
notifyToUser(_("Failed checking JVM version."));
|
750 |
return false; |
751 |
} |
752 |
|
753 |
if (err.Count() == 0) { |
754 |
notifyToUser(_("Failed checking JVM version."));
|
755 |
return false; |
756 |
} |
757 |
|
758 |
if (err[0].Contains(paramsJreVersion.c_str()) && err[0].Contains("version")) { |
759 |
return true; |
760 |
} |
761 |
notifyToUser(cmd.Format(_("%s\nJava %s recommended"), err[0].c_str(),paramsJreVersion.c_str())); |
762 |
return false; |
763 |
|
764 |
|
765 |
} |
766 |
|
767 |
void LauncherApp::run(){
|
768 |
bool doChecks =true; |
769 |
|
770 |
if (!paramsDoChecks) {
|
771 |
javaHome = paramsJreHome; |
772 |
calculateJavaExePath(javaHome); |
773 |
} else {
|
774 |
if (paramsAskForCheckingProcess) {
|
775 |
wxString msg = _("Do you want to check the application requirements? \nThis will install missing components.");
|
776 |
doChecks = confirmYesNoCancel(msg,true);
|
777 |
if (!doChecks) {
|
778 |
// No quiere comprobacion, por lo que solicitamos
|
779 |
wxString msgDir = _("Please, select the Java VM.");
|
780 |
wxFileDialog dlg( |
781 |
0,
|
782 |
msgDir, |
783 |
wxEmptyString, |
784 |
wxString("java.exe"),
|
785 |
wxString("Java VM executable file (java.exe)|java.exe"),
|
786 |
wxOPEN | wxFILE_MUST_EXIST, |
787 |
wxDefaultPosition |
788 |
); |
789 |
int response = dlg.ShowModal();
|
790 |
if (response != wxID_OK) {
|
791 |
notifyToUser(_("Canceled by user"));
|
792 |
exit(1);
|
793 |
} |
794 |
//caragamos la variable con el eljecutable
|
795 |
javaExecPath = dlg.GetPath(); |
796 |
|
797 |
checkVersion(javaExecPath); |
798 |
|
799 |
//generamos el path para el JavaHome (por si acaso)
|
800 |
wxFileName fileName(javaExecPath); |
801 |
fileName.SetFullName("");
|
802 |
fileName.AppendDir("..");
|
803 |
fileName.Normalize(); |
804 |
javaHome = fileName.GetPath(); |
805 |
|
806 |
} |
807 |
} |
808 |
|
809 |
|
810 |
if (doChecks) {
|
811 |
|
812 |
if (!searchJRE())
|
813 |
{ |
814 |
jreInstall(); |
815 |
} |
816 |
|
817 |
fixSystemJREConfig(); |
818 |
|
819 |
jaiInstall(); |
820 |
|
821 |
jaiIoInstall(); |
822 |
} |
823 |
} |
824 |
|
825 |
copyRequiredFiles(); |
826 |
|
827 |
runJRE(); |
828 |
|
829 |
exit(0);
|
830 |
|
831 |
} |
832 |
|
833 |
void LauncherApp::OnTimer(wxTimerEvent& event) {
|
834 |
run(); |
835 |
} |
836 |
|
837 |
void LauncherApp::calculateJavaExePath(const wxString aJavaHome){ |
838 |
int osVerMayor;
|
839 |
int osVerMinor;
|
840 |
|
841 |
wxGetOsVersion(&osVerMayor,&osVerMinor); |
842 |
if (osVerMayor < 5) { |
843 |
javaExecPath = aJavaHome + "\\bin\\java";
|
844 |
}else{
|
845 |
javaExecPath = aJavaHome + "\\bin\\javaw";
|
846 |
} |
847 |
|
848 |
} |
849 |
|
850 |
|
851 |
wxString LauncherApp::parseCommand(){ |
852 |
|
853 |
return parseString(paramsCommand);
|
854 |
} |
855 |
|
856 |
wxString LauncherApp::parseString(const wxString theString){
|
857 |
wxString resultCommand(theString); |
858 |
|
859 |
// #JAVA#
|
860 |
resultCommand.Replace("#JAVA#",javaExecPath.c_str());
|
861 |
|
862 |
// #JAVA_HOME#
|
863 |
resultCommand.Replace("#JAVA_HOME#",javaHome.c_str());
|
864 |
|
865 |
// #JAR#
|
866 |
resultCommand.Replace("#JAR#",paramsJar.c_str());
|
867 |
|
868 |
// calculamos la cadena args y sustituimos los #ARG?#
|
869 |
wxString theArgs("");
|
870 |
wxString theArg("");
|
871 |
int i;
|
872 |
for (i=1;i<this->argc;i++) { |
873 |
theArg = argv[i]; |
874 |
if (i!=1){ |
875 |
theArgs = theArgs + " \"" + theArg + "\""; |
876 |
}else{
|
877 |
theArgs = "\"" + theArg + "\""; |
878 |
} |
879 |
|
880 |
resultCommand.Replace(theArg.Format("\"#ARG%i#\"",i),theArg.c_str());
|
881 |
} |
882 |
// Dejamos a blanco los argumento que no hemos recivido y existen en el comando
|
883 |
theArg = "";
|
884 |
for (i=i;i<10;i++) { |
885 |
resultCommand.Replace(theArg.Format("#ARG%i#",i),theArg.c_str());
|
886 |
} |
887 |
//echo(theArgs);
|
888 |
|
889 |
// #ARGS#
|
890 |
resultCommand.Replace("#ARGS#",theArgs.c_str());
|
891 |
|
892 |
// #ARG0#
|
893 |
resultCommand.Replace("#ARG0#",argv[0]); |
894 |
|
895 |
// variables de la seccion variables
|
896 |
|
897 |
//echo(resultCommand);
|
898 |
|
899 |
//
|
900 |
if (!variables.IsEmpty()){
|
901 |
//echo(theArg.Format("No empty: count =%i",keys.GetCount()));
|
902 |
unsigned int i; |
903 |
for (i=0;i<variables.GetCount();i++){ |
904 |
//echo("#"+variables[i]+"#="+variablesValues[i]);
|
905 |
resultCommand.Replace("#"+variables[i]+"#",variablesValues[i]); |
906 |
} |
907 |
|
908 |
//echo(resultCommand);
|
909 |
|
910 |
} |
911 |
|
912 |
|
913 |
|
914 |
return resultCommand;
|
915 |
} |
916 |
|
917 |
|
918 |
|
919 |
bool LauncherApp::copyRequiredFiles(){
|
920 |
int i = 0; |
921 |
//wxFileInputStream in( cfgName );
|
922 |
//wxFileConfig cfg( in );
|
923 |
//cfg.SetPath("/CopyRequiredFiles");
|
924 |
|
925 |
wxString source; |
926 |
wxString target; |
927 |
wxString msg; |
928 |
wxFileName fileName; |
929 |
|
930 |
while (true) { |
931 |
i++; |
932 |
|
933 |
source = readPathFromINI("CopyRequiredFiles",source.Format("source%i",i),wxEmptyString); |
934 |
target = readPathFromINI("CopyRequiredFiles",target.Format("target%i",i),wxEmptyString); |
935 |
if (source == wxEmptyString && target == wxEmptyString) {
|
936 |
return true; |
937 |
} |
938 |
if (source == wxEmptyString || target == wxEmptyString) {
|
939 |
error(source.Format(_("Error copying the file number %i:\n missing source or target entry"),i));
|
940 |
return false; |
941 |
} |
942 |
source = parseString(source); |
943 |
target = parseString(target); |
944 |
if (wxFileExists(target)){
|
945 |
continue;
|
946 |
} else {
|
947 |
if (wxDirExists(target)) {
|
948 |
fileName = wxFileName(target); |
949 |
wxFileName tempFileName(source); |
950 |
fileName.SetFullName(tempFileName.GetFullName()); |
951 |
if (fileName.FileExists()) {
|
952 |
continue;
|
953 |
} |
954 |
} |
955 |
|
956 |
} |
957 |
if (!wxFileExists(source)){
|
958 |
error(source.Format(_("Error copying the file number %i:\n source file '%s' does not exists."),i,source.c_str()));
|
959 |
return false; |
960 |
} |
961 |
|
962 |
fileName = wxFileName(source); |
963 |
msg = msg.Format(_("copying %s..."), fileName.GetFullName().c_str());
|
964 |
//echo(msg);
|
965 |
//echo(msg.Format("%s --> %s",source.c_str(),target.c_str()));
|
966 |
if (!copyFile(source,target, msg)){
|
967 |
error(source.Format(_("Error copying the file number %i:\n '%s' --> '%s'."),i,source.c_str(),target.c_str()));
|
968 |
return false; |
969 |
} |
970 |
|
971 |
} |
972 |
} |
973 |
|
974 |
bool LauncherApp::copyFile(const wxString source, const wxString target, const wxString msg){ |
975 |
|
976 |
bool isOk;
|
977 |
//echo(source);
|
978 |
if (source == wxEmptyString) {
|
979 |
return false; |
980 |
} |
981 |
|
982 |
//echo(target);
|
983 |
if (target == wxEmptyString) {
|
984 |
return false; |
985 |
} |
986 |
|
987 |
showStatusMsg(msg); |
988 |
|
989 |
wxFileName targetFileName(target); |
990 |
|
991 |
|
992 |
// Preparamos la ruta para el fichero destino
|
993 |
wxArrayString dirs; |
994 |
|
995 |
dirs = targetFileName.GetDirs(); |
996 |
wxString dir; |
997 |
wxFileName curDir; |
998 |
if (targetFileName.IsAbsolute()) {
|
999 |
curDir.Assign("\\");
|
1000 |
curDir.SetVolume(targetFileName.GetVolume()); |
1001 |
}else{
|
1002 |
curDir.Assign(".");
|
1003 |
} |
1004 |
for (size_t i=0; i < dirs.GetCount(); i++) { |
1005 |
dir = dirs.Item(i); |
1006 |
curDir.AppendDir(dir); |
1007 |
//echo("dir " + curDir.GetPath());
|
1008 |
if (!curDir.DirExists()) {
|
1009 |
//echo("creating dir");
|
1010 |
isOk = curDir.Mkdir(); |
1011 |
if (!isOk) {
|
1012 |
//echo("dir create no ok");
|
1013 |
return false; |
1014 |
} |
1015 |
|
1016 |
//echo("dir create ok");
|
1017 |
} |
1018 |
} |
1019 |
|
1020 |
wxString finalTarget; |
1021 |
if (targetFileName.IsDir() || targetFileName.DirExists()) {
|
1022 |
//echo("targetFileName.IsDir -> true " + targetFileName.GetFullPath());
|
1023 |
wxFileName sourceFileName(source); |
1024 |
targetFileName.SetFullName(sourceFileName.GetFullName()); |
1025 |
finalTarget = targetFileName.GetFullPath(); |
1026 |
} else {
|
1027 |
//echo("targetFileName.IsDir -> false " + targetFileName.GetFullPath());
|
1028 |
finalTarget = target; |
1029 |
} |
1030 |
|
1031 |
|
1032 |
//echo(msg.Format("%s --> %s",source.c_str(),finalTarget.c_str()));
|
1033 |
isOk = wxCopyFile(source,finalTarget,false);
|
1034 |
|
1035 |
|
1036 |
return isOk;
|
1037 |
|
1038 |
} |
1039 |
|
1040 |
wxString LauncherApp::readPathFromINI(wxString section, wxString key, const wxString defaultValue){
|
1041 |
char* charResult;
|
1042 |
|
1043 |
charResult =myGetPrivateProfileString(section.c_str(),key.c_str(),defaultValue.c_str(),cfgName.c_str()); |
1044 |
|
1045 |
//Remplazamos \ por /
|
1046 |
|
1047 |
register char* s = charResult; |
1048 |
for (;*s;s++) {
|
1049 |
if (*s == '\\') { |
1050 |
*s = '/';
|
1051 |
} |
1052 |
} |
1053 |
|
1054 |
wxString result(charResult); |
1055 |
return result;
|
1056 |
|
1057 |
|
1058 |
} |
1059 |
|
1060 |
|
1061 |
|
1062 |
wxString LauncherApp::readPathFromINI(wxString key, const wxString defaultValue){
|
1063 |
return readPathFromINI("default",key,defaultValue); |
1064 |
|
1065 |
} |
1066 |
|
1067 |
wxString LauncherApp::readFromINI(wxString section, wxString key, const wxString defaultValue){
|
1068 |
char* charResult;
|
1069 |
|
1070 |
charResult =myGetPrivateProfileString(section.c_str(),key.c_str(),defaultValue.c_str(),cfgName.c_str()); |
1071 |
|
1072 |
wxString result(charResult); |
1073 |
return result;
|
1074 |
} |
1075 |
|
1076 |
wxString LauncherApp::readFromINI(wxString key, const wxString defaultValue){
|
1077 |
return readFromINI("default",key,defaultValue); |
1078 |
} |
1079 |
|
1080 |
wxArrayString LauncherApp::sectionKeysFromINI(const wxString section){
|
1081 |
char* charResult;
|
1082 |
|
1083 |
charResult =myGetPrivateProfileString(section.c_str(),NULL,NULL,cfgName.c_str()); |
1084 |
|
1085 |
|
1086 |
wxArrayString rvalue; |
1087 |
wxString token = wxString("");
|
1088 |
|
1089 |
for (int i=0; i < 2048;i++){ |
1090 |
if (charResult[i] == 0){ |
1091 |
if (token == ""){ |
1092 |
return rvalue;
|
1093 |
} |
1094 |
rvalue.Add(token); |
1095 |
token = wxString("");
|
1096 |
}else{
|
1097 |
token.Append(charResult[i]); |
1098 |
} |
1099 |
} |
1100 |
return rvalue;
|
1101 |
} |
1102 |
|
1103 |
|
1104 |
wxArrayString LauncherApp::sectionKeysValuesFromINI(const wxString section,wxArrayString keys) {
|
1105 |
wxArrayString rvalue; |
1106 |
unsigned int i; |
1107 |
wxString key; |
1108 |
wxString value; |
1109 |
for (i=0;i < keys.GetCount(); i++){ |
1110 |
rvalue.Add(readPathFromINI( section, keys[i], ""));
|
1111 |
} |
1112 |
return rvalue;
|
1113 |
} |
1114 |
|