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