svn-gvsig-desktop / trunk / install / launcher / izpack-launcher-1.3 / src / launcher.cpp @ 7006
History | View | Annotate | Download (20.2 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 |
#ifdef __UNIX__
|
31 |
#include <stdlib.h> |
32 |
#include <map> |
33 |
#include <list> |
34 |
#endif
|
35 |
|
36 |
|
37 |
/*
|
38 |
* Helper function to run an external program. It takes care of the subtule
|
39 |
* differences between the OS-specific implementations.
|
40 |
*
|
41 |
* @param cmd The command to run.
|
42 |
* @return <code>true</code> in case of a success, <code>false</code> otherwise.
|
43 |
*/
|
44 |
bool run_external(wxString cmd)
|
45 |
{ |
46 |
int code = wxExecute(cmd, wxEXEC_SYNC);
|
47 |
return (code == 0); |
48 |
|
49 |
} |
50 |
|
51 |
bool run_external_async(wxString cmd)
|
52 |
{ |
53 |
return (wxExecute(cmd, wxEXEC_ASYNC) != 0); |
54 |
} |
55 |
|
56 |
bool string_to_bool(wxString value, bool defaultValue){ |
57 |
bool returnValue = defaultValue;
|
58 |
if (value != wxEmptyString)
|
59 |
if (
|
60 |
value.CmpNoCase("s") == 0 || |
61 |
value.CmpNoCase("si") == 0 || |
62 |
value.CmpNoCase("1") == 0 || |
63 |
value.CmpNoCase("y") == 0 || |
64 |
value.CmpNoCase("yes") == 0 |
65 |
) |
66 |
{ |
67 |
returnValue = true;
|
68 |
} else {
|
69 |
returnValue = false;
|
70 |
} |
71 |
return returnValue;
|
72 |
} |
73 |
|
74 |
long LAUNCHAPP_TIMER_ID = wxNewId();
|
75 |
|
76 |
BEGIN_EVENT_TABLE(LauncherApp, wxApp) |
77 |
EVT_TIMER(LAUNCHAPP_TIMER_ID, LauncherApp::OnTimer) |
78 |
END_EVENT_TABLE() |
79 |
|
80 |
|
81 |
/* Main Application $Revision: 7006 $
|
82 |
*
|
83 |
* $Id: launcher.cpp 7006 2006-09-04 15:25:57Z jmvivo $
|
84 |
*/
|
85 |
LauncherApp::LauncherApp() |
86 |
: wxApp() |
87 |
{ |
88 |
APPLICATION_NAME = wxString("gvSIG Install-Launcher");
|
89 |
completed = false;
|
90 |
|
91 |
SetAppName(_( APPLICATION_NAME )); |
92 |
loadParams(); |
93 |
} |
94 |
|
95 |
void LauncherApp::echo(const wxString &msg) |
96 |
{ |
97 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK);
|
98 |
dlg.ShowModal(); |
99 |
} |
100 |
|
101 |
void LauncherApp::notifyToUser(const wxString &msg) |
102 |
{ |
103 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_INFORMATION);
|
104 |
dlg.ShowModal(); |
105 |
} |
106 |
|
107 |
|
108 |
LauncherApp::~LauncherApp() |
109 |
{ |
110 |
|
111 |
} |
112 |
|
113 |
void LauncherApp::loadParams()
|
114 |
{ |
115 |
cfgName = wxString( "launcher.ini" );
|
116 |
|
117 |
wxFileInputStream in( cfgName ); |
118 |
wxFileConfig cfg( in ); |
119 |
wxString downloadEnabled; |
120 |
wxString launchJarAsync; |
121 |
wxString askForCheckingProcess; |
122 |
|
123 |
cfg.Read( "jar", ¶msJar, wxEmptyString);
|
124 |
cfg.Read( "jre", ¶msJre, wxEmptyString);
|
125 |
cfg.Read( "downloadJre", ¶msJreDownload, wxEmptyString);
|
126 |
cfg.Read( "jai", ¶msJai, wxEmptyString);
|
127 |
cfg.Read( "downloadJai", ¶msJaiDownload, wxEmptyString);
|
128 |
cfg.Read( "jai_io", ¶msJaiIo, wxEmptyString);
|
129 |
cfg.Read( "downloadJai_io", ¶msJaiIoDownload, wxEmptyString);
|
130 |
cfg.Read( "jre_version", ¶msJreVersion, wxEmptyString);
|
131 |
cfg.Read( "jre_version_prefered", ¶msJreVersionPrefered, wxEmptyString);
|
132 |
cfg.Read( "jarParams", ¶msJarParams, wxEmptyString);
|
133 |
cfg.Read( "downloadEnabled", &downloadEnabled, wxEmptyString);
|
134 |
cfg.Read( "launchJarAsync", &launchJarAsync, wxEmptyString);
|
135 |
cfg.Read( "askForCheckingProcess", &askForCheckingProcess, wxEmptyString);
|
136 |
|
137 |
//procesamos el parametro booleano 'downloadEnabled'
|
138 |
paramsEnabledDownload =string_to_bool(downloadEnabled,false);
|
139 |
//procesamos el parametro booleano 'launchJarAsync'
|
140 |
paramsLaunchJarAsync =string_to_bool(launchJarAsync,false);
|
141 |
//procesamos el parametro booleano 'askForCheckingProcess'
|
142 |
paramsAskForCheckingProcess=string_to_bool(askForCheckingProcess,true);
|
143 |
|
144 |
if (paramsJar == wxEmptyString )
|
145 |
{ |
146 |
error(_("The configuration file '") + cfgName + _("' does not contain a jar file entry.")); |
147 |
} |
148 |
if (paramsJreVersionPrefered == wxEmptyString ) {
|
149 |
paramsJreVersionPrefered = wxString(paramsJreVersion); |
150 |
} |
151 |
} |
152 |
|
153 |
void LauncherApp::error(const wxString &msg) |
154 |
{ |
155 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_ERROR);
|
156 |
dlg.ShowModal(); |
157 |
exit(1);
|
158 |
} |
159 |
|
160 |
void LauncherApp::confirm(const wxString &msg) |
161 |
{ |
162 |
int response;
|
163 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxCANCEL | wxICON_QUESTION );
|
164 |
response = dlg.ShowModal(); |
165 |
if (response != wxID_OK) {
|
166 |
notifyToUser(_("Canceled by user"));
|
167 |
exit(1);
|
168 |
} |
169 |
} |
170 |
bool LauncherApp::confirmYesNoCancel(const wxString &msg,const int yesDefault = true) |
171 |
{ |
172 |
int response;
|
173 |
long maskDefault;
|
174 |
if (yesDefault) {
|
175 |
maskDefault = wxYES_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
176 |
} else {
|
177 |
maskDefault = wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
178 |
} |
179 |
wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), maskDefault);
|
180 |
response = dlg.ShowModal(); |
181 |
if (response != wxID_YES && response != wxID_NO) {
|
182 |
notifyToUser(_("Canceled by user"));
|
183 |
exit(1);
|
184 |
} |
185 |
return (response == wxID_YES);
|
186 |
|
187 |
} |
188 |
|
189 |
|
190 |
|
191 |
bool LauncherApp::OnInit()
|
192 |
{ |
193 |
isStatusDialogVisible = false;
|
194 |
locale.Init(); |
195 |
locale.AddCatalog("launcher");
|
196 |
|
197 |
statusDialog = new StatusDialog( APPLICATION_NAME );
|
198 |
|
199 |
statusDialog->Centre(); |
200 |
statusDialog->Show(TRUE); |
201 |
isStatusDialogVisible = true;
|
202 |
|
203 |
showStatusMsg(_("Intializing..."));
|
204 |
|
205 |
myTimer = new wxTimer(this,LAUNCHAPP_TIMER_ID); |
206 |
myTimer->Start(150,true); |
207 |
this->MainLoop();
|
208 |
return true; |
209 |
/*
|
210 |
|
211 |
if (!searchJRE())
|
212 |
{
|
213 |
jreInstall();
|
214 |
}
|
215 |
|
216 |
fixSystemJREConfig();
|
217 |
|
218 |
jaiInstall();
|
219 |
|
220 |
jaiIoInstall();
|
221 |
|
222 |
runJRE();
|
223 |
|
224 |
exit(0);
|
225 |
|
226 |
return false;
|
227 |
*/
|
228 |
} |
229 |
|
230 |
void LauncherApp::fixSystemJREConfig(){
|
231 |
showStatusMsg(_("Updating the system..."));
|
232 |
//actualizamos CurrentVersion
|
233 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
234 |
"\\Java Runtime Environment\\";
|
235 |
|
236 |
wxString genericVersion = paramsJreVersion.Left(3);
|
237 |
|
238 |
wxString baseKeyGeneric = baseKey + genericVersion + "\\";
|
239 |
wxString baseKeyVersion = baseKey + localVersionToUse + "\\";
|
240 |
|
241 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
242 |
if( !pRegKey->Exists() ) {
|
243 |
error(_("JRE not found."));
|
244 |
} |
245 |
//pRegKey->SetValue("CurrentVersion",genericVersion); // **********
|
246 |
|
247 |
// compiamos el contenido de la rama de la version
|
248 |
// que queremos a la generica (1.4 o 1.5 o ...)
|
249 |
wxRegKey *pRegKeyGeneric = new wxRegKey(baseKeyGeneric);
|
250 |
wxRegKey *pRegKeyVersion = new wxRegKey(baseKeyVersion);
|
251 |
|
252 |
if ( !pRegKeyGeneric->Exists() ){
|
253 |
pRegKeyGeneric->Create(); |
254 |
} |
255 |
wxString tempKey; |
256 |
wxString tempValue; |
257 |
size_t nValues; |
258 |
|
259 |
//pRegKeyGeneric->SetValue("hola","generico");
|
260 |
//pRegKeyVersion->SetValue("hola","version");
|
261 |
|
262 |
pRegKeyVersion->GetKeyInfo(NULL,NULL,&nValues,NULL); |
263 |
long pos = 1; |
264 |
pRegKeyVersion->GetFirstValue(tempKey,pos); |
265 |
for(unsigned i=0;i<nValues;i++) { |
266 |
//echo("copy " + tempKey);
|
267 |
pRegKeyVersion->QueryValue(tempKey,tempValue); |
268 |
pRegKeyGeneric->SetValue(tempKey,tempValue); |
269 |
pRegKeyVersion->GetNextValue(tempKey,pos); |
270 |
} |
271 |
|
272 |
|
273 |
//copiamos el java.exe a Windows/System32
|
274 |
//wxString source = javaHome + "\\bin\\java.exe";
|
275 |
//wxString target = getenv("windir");
|
276 |
//target = target + "\\system32\\java.exe";
|
277 |
|
278 |
//bool isOk = wxCopyFile(source, target, true);
|
279 |
//if (!isOk) {
|
280 |
// error(_("Error perform copy ") + source + _(" to ") + target);
|
281 |
//}
|
282 |
|
283 |
} |
284 |
|
285 |
|
286 |
bool LauncherApp::compareVersions(const wxString localVersion, const wxString requireVersion) |
287 |
{ |
288 |
bool result = (localVersion.Cmp(requireVersion) == 0); |
289 |
/*
|
290 |
if (requireVersion.Len() > localVersion.Len() ) {
|
291 |
|
292 |
result = (localVersion.Find(requireVersion) == 0);
|
293 |
}
|
294 |
else
|
295 |
{
|
296 |
result = (requireVersion.Find(localVersion) == 0);
|
297 |
}
|
298 |
*/
|
299 |
|
300 |
/*
|
301 |
if (result) {
|
302 |
echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> true");
|
303 |
} else {
|
304 |
echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> false");
|
305 |
}
|
306 |
*/
|
307 |
|
308 |
return result;
|
309 |
} |
310 |
|
311 |
|
312 |
bool LauncherApp::searchJRE()
|
313 |
{ |
314 |
showStatusMsg(_("Searching for JRE..."));
|
315 |
wxString version("");
|
316 |
|
317 |
// Windows[tm] registry lookup
|
318 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
319 |
"\\Java Runtime Environment\\";
|
320 |
|
321 |
wxRegKey bKey(baseKey); |
322 |
if (!bKey.Exists()) {
|
323 |
return false; |
324 |
} |
325 |
|
326 |
if (!bKey.QueryValue("CurrentVersion", version)){ |
327 |
return false; |
328 |
} |
329 |
|
330 |
if (version == "1.1") { |
331 |
return false; |
332 |
} |
333 |
|
334 |
if (!compareVersions(version, paramsJreVersionPrefered)){
|
335 |
//Nos recorremos las versiones instaladas
|
336 |
version = "";
|
337 |
wxString strTemp; |
338 |
wxRegKey sKey(baseKey); |
339 |
if (sKey.HasSubKey(paramsJreVersionPrefered)) {
|
340 |
version = wxString(paramsJreVersionPrefered); |
341 |
} else {
|
342 |
for(unsigned i=20;i>1;i--) { |
343 |
strTemp = wxString::Format(paramsJreVersion + "_%02d",i);
|
344 |
if (sKey.HasSubKey(strTemp)) {
|
345 |
version = strTemp; |
346 |
break;
|
347 |
} |
348 |
} |
349 |
} |
350 |
} |
351 |
|
352 |
|
353 |
if (version == "") { |
354 |
return false; |
355 |
} |
356 |
localVersionToUse = version; |
357 |
wxRegKey vKey(baseKey + version); |
358 |
|
359 |
if (!vKey.QueryValue("JavaHome", javaHome)){ |
360 |
return false; |
361 |
} |
362 |
int osVerMayor;
|
363 |
int osVerMinor;
|
364 |
|
365 |
wxGetOsVersion(&osVerMayor,&osVerMinor); |
366 |
if (osVerMayor < 5) { |
367 |
javaExecPath = javaHome + "\\bin\\java";
|
368 |
}else{
|
369 |
javaExecPath = javaHome + "\\bin\\javaw";
|
370 |
} |
371 |
/*
|
372 |
echo("paramsJreVersion=" + paramsJreVersion);
|
373 |
echo("paramsJreVersionPrefered=" + paramsJreVersionPrefered);
|
374 |
echo("localVersionToUse=" + localVersionToUse);
|
375 |
echo("javaHome=" +javaHome);
|
376 |
echo("javaExecPath=" +javaExecPath);
|
377 |
*/
|
378 |
return true; |
379 |
} |
380 |
|
381 |
void LauncherApp::runJRE()
|
382 |
{ |
383 |
showStatusMsg(_("Launching instalation..."));
|
384 |
if (!wxFile::Exists(paramsJar))
|
385 |
{ |
386 |
error(_("The jar-file in the configuration file ") + cfgName + _(" does exist.")); |
387 |
} |
388 |
|
389 |
wxString cmd = javaExecPath + paramsJarParams + wxString(" -jar ") + paramsJar;
|
390 |
if (paramsLaunchJarAsync) {
|
391 |
if (!run_external_async(cmd))
|
392 |
{ |
393 |
error(_("The jar-file ") + paramsJar + _(" could not be executed." )); |
394 |
} |
395 |
} else {
|
396 |
if (!run_external(cmd))
|
397 |
{ |
398 |
error(_("The jar-file ") + paramsJar + _(" could not be executed." )); |
399 |
} |
400 |
} |
401 |
|
402 |
completed = true;
|
403 |
} |
404 |
|
405 |
void LauncherApp::jreInstall()
|
406 |
{ |
407 |
showStatusMsg(_("Preparing to install JRE..."));
|
408 |
|
409 |
if (!checkInstallerFile(paramsJre, paramsJreDownload,_("Java JRE version ")+paramsJreVersion)) |
410 |
{ |
411 |
error(_("The JRE could not be setup."));
|
412 |
} |
413 |
|
414 |
showStatusMsg(_("Installing JRE..."));
|
415 |
if (!run_external(paramsJre))
|
416 |
{ |
417 |
error(_("The JRE could not be setup."));
|
418 |
} |
419 |
if (!searchJRE()) {
|
420 |
error(_("The JRE could not be setup."));
|
421 |
} |
422 |
} |
423 |
|
424 |
|
425 |
// Not used
|
426 |
void LauncherApp::netDownload()
|
427 |
{ |
428 |
wxString browser; |
429 |
|
430 |
#ifdef __WINDOWS__
|
431 |
// We use the default browser.
|
432 |
browser = "rundll32 url.dll,FileProtocolHandler ";
|
433 |
#endif
|
434 |
|
435 |
#ifdef __UNIX__
|
436 |
// We try some browsers and use the first successful one.
|
437 |
std::list<std::pair<wxString, wxString> > commands; |
438 |
std::pair<wxString, wxString> cmd; |
439 |
cmd.first = "konqueror "; cmd.second = "konqueror -v"; |
440 |
commands.push_back(cmd); |
441 |
cmd.first = "mozilla -splash "; cmd.second = "mozilla -v"; |
442 |
commands.push_back(cmd); |
443 |
cmd.first = "firefox -splash "; cmd.second = "firefox -v"; |
444 |
commands.push_back(cmd); |
445 |
cmd.first = "firebird -splash "; cmd.second = "firebird -v"; |
446 |
commands.push_back(cmd); |
447 |
cmd.first = "opera "; cmd.second = "opera -v"; |
448 |
commands.push_back(cmd); |
449 |
cmd.first = "netscape "; cmd.second = "netscape -v"; |
450 |
commands.push_back(cmd); |
451 |
std::list<std::pair<wxString, wxString> >::iterator it; |
452 |
for (it = commands.begin(); it != commands.end(); ++it)
|
453 |
{ |
454 |
if (wxExecute(it->second, wxEXEC_SYNC) == 0) |
455 |
{ |
456 |
browser = it->first; |
457 |
break;
|
458 |
} |
459 |
} |
460 |
#endif
|
461 |
/*
|
462 |
if (run_external(browser + paramsDownload))
|
463 |
{
|
464 |
completed = true;
|
465 |
}
|
466 |
else
|
467 |
{
|
468 |
error(_("Could not find a web browser."));
|
469 |
}
|
470 |
*/
|
471 |
} |
472 |
|
473 |
IMPLEMENT_APP(LauncherApp) |
474 |
|
475 |
|
476 |
void LauncherApp::jaiInstall()
|
477 |
{ |
478 |
bool isOK;
|
479 |
showStatusMsg(_("Checking JAI Library..."));
|
480 |
|
481 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
482 |
"\\Java Runtime Environment\\";
|
483 |
|
484 |
wxString currentVersion; |
485 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
486 |
if( !pRegKey->Exists() )
|
487 |
error(_("JRE not found."));
|
488 |
if (!pRegKey->QueryValue("CurrentVersion", currentVersion)) error(_("JRE not found.")); |
489 |
|
490 |
isOK=true;
|
491 |
if (!checksJai()) {
|
492 |
//confirm(_("JAI library is required, Install it?"));
|
493 |
|
494 |
showStatusMsg(_("Preparing to install JAI Library..."));
|
495 |
if (!checkInstallerFile(paramsJai, paramsJaiDownload, _("JAI Library"))) |
496 |
{ |
497 |
isOK=false;
|
498 |
} else {
|
499 |
pRegKey->SetValue("CurrentVersion",localVersionToUse);
|
500 |
showStatusMsg(_("Preparing to install JAI Library..."));
|
501 |
if (run_external(paramsJai))
|
502 |
{ |
503 |
isOK=(checksJai()); |
504 |
} else {
|
505 |
isOK=false;
|
506 |
} |
507 |
pRegKey->SetValue("CurrentVersion",currentVersion);
|
508 |
} |
509 |
|
510 |
} |
511 |
if (!isOK) {
|
512 |
error(_("The JAI could not be setup."));
|
513 |
} |
514 |
} |
515 |
|
516 |
void LauncherApp::jaiIoInstall()
|
517 |
{ |
518 |
bool isOK;
|
519 |
showStatusMsg(_("Checking JAI imageIO Library..."));
|
520 |
|
521 |
wxString baseKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft"
|
522 |
"\\Java Runtime Environment\\";
|
523 |
|
524 |
wxString currentVersion; |
525 |
wxRegKey *pRegKey = new wxRegKey(baseKey);
|
526 |
if( !pRegKey->Exists() )
|
527 |
error(_("JRE not found."));
|
528 |
if (!pRegKey->QueryValue("CurrentVersion", currentVersion)) error(_("JRE not found.")); |
529 |
|
530 |
|
531 |
isOK=true;
|
532 |
if (!checksJaiIo()) {
|
533 |
//confirm(_("JAI ImageIO library is required, Install it?"));
|
534 |
|
535 |
showStatusMsg(_("Preparing to install JAI imageIO Library..."));
|
536 |
if (!checkInstallerFile(paramsJaiIo, paramsJaiIoDownload,"JAI ImageIO Library")) |
537 |
{ |
538 |
isOK=false;
|
539 |
} else {
|
540 |
pRegKey->SetValue("CurrentVersion",localVersionToUse);
|
541 |
showStatusMsg(_("Installing JAI imageIO Library..."));
|
542 |
if (run_external(paramsJaiIo))
|
543 |
{ |
544 |
isOK=(checksJaiIo()); |
545 |
} else {
|
546 |
isOK=false;
|
547 |
} |
548 |
pRegKey->SetValue("CurrentVersion",currentVersion);
|
549 |
} |
550 |
|
551 |
} |
552 |
if (!isOK) {
|
553 |
error(_("The JAI imageIO could not be setup."));
|
554 |
} |
555 |
} |
556 |
|
557 |
bool LauncherApp::checksJai(){
|
558 |
return (wxFileExists(javaHome + "\\lib\\ext\\jai_core.jar")); |
559 |
} |
560 |
|
561 |
bool LauncherApp::checksJaiIo(){
|
562 |
return (wxFileExists(javaHome + "\\lib\\ext\\jai_imageio.jar")); |
563 |
} |
564 |
|
565 |
bool LauncherApp::downloadFileHttp(const wxString urlOfFile, const wxString filePath, const wxString msg){ |
566 |
|
567 |
bool isOk;
|
568 |
//echo(urlOfFile);
|
569 |
if (urlOfFile == wxEmptyString) {
|
570 |
return false; |
571 |
} |
572 |
|
573 |
if (filePath == wxEmptyString) {
|
574 |
return false; |
575 |
} |
576 |
|
577 |
showStatusMsg(msg); |
578 |
wxURL url(urlOfFile); |
579 |
//echo("url open");
|
580 |
wxInputStream *in_stream; |
581 |
|
582 |
in_stream = url.GetInputStream(); |
583 |
//echo("in_stream open");
|
584 |
if (!in_stream->IsOk()) {
|
585 |
//echo("in_stream.IsOk == false");
|
586 |
return false; |
587 |
} |
588 |
//echo("in_stream.IsOk == true");
|
589 |
//echo("filePath =" + filePath);
|
590 |
wxFileName fileName(filePath); |
591 |
|
592 |
|
593 |
// Preparamos la ruta para el fichero destino
|
594 |
wxArrayString dirs; |
595 |
|
596 |
dirs = fileName.GetDirs(); |
597 |
wxString dir; |
598 |
wxFileName curDir(".");
|
599 |
for (size_t i=0; i < dirs.GetCount(); i++) { |
600 |
dir = dirs.Item(i); |
601 |
curDir.AppendDir(dir); |
602 |
//echo("dir " + curDir.GetPath());
|
603 |
if (!curDir.DirExists()) {
|
604 |
//echo("creating dir");
|
605 |
isOk = curDir.Mkdir(); |
606 |
if (!isOk) {
|
607 |
//echo("dir create no ok");
|
608 |
return false; |
609 |
} |
610 |
|
611 |
//echo("dir create ok");
|
612 |
} |
613 |
} |
614 |
|
615 |
|
616 |
wxFileOutputStream out_stream = wxFileOutputStream(filePath); |
617 |
//echo("out_stream open");
|
618 |
|
619 |
//in_stream->Read(out_stream);
|
620 |
size_t nbytes = 10240;
|
621 |
char buffer[nbytes];
|
622 |
|
623 |
|
624 |
//while (!in_stream->Eof()) {
|
625 |
while (!in_stream->Eof()) {
|
626 |
in_stream->Read(&buffer,nbytes); |
627 |
if (in_stream->LastError() != wxSTREAM_NO_ERROR && in_stream->LastError() != wxSTREAM_EOF) {
|
628 |
return false; |
629 |
} |
630 |
out_stream.Write(&buffer,in_stream->LastRead()); |
631 |
if (out_stream.LastError() != wxSTREAM_NO_ERROR) {
|
632 |
return false; |
633 |
} |
634 |
int totalKb = out_stream.GetSize() / 1024; |
635 |
wxString totalMsg =msg.Format("%i",totalKb);
|
636 |
showStatusMsg(msg+" "+ totalMsg + " Kb"); |
637 |
|
638 |
} |
639 |
|
640 |
|
641 |
isOk = true;
|
642 |
/*
|
643 |
if (isOk) {
|
644 |
echo("isOk = true");
|
645 |
} else {
|
646 |
echo("isOk = false");
|
647 |
}
|
648 |
*/
|
649 |
delete in_stream;
|
650 |
|
651 |
//echo("end");
|
652 |
return isOk;
|
653 |
|
654 |
} |
655 |
|
656 |
bool LauncherApp::checkInstallerFile(const wxString filePath, const wxString urlDownload, const wxString fileDescription) { |
657 |
if (!wxFile::Exists(filePath))
|
658 |
{ |
659 |
if (paramsEnabledDownload)
|
660 |
{ |
661 |
wxString msg = _("Instalation require download this file:\n") +
|
662 |
fileDescription + "\n" +
|
663 |
_("Do you want to continue?");
|
664 |
confirm(msg); |
665 |
//showStatusMsg(_("Downloading ") + fileDescription + "...");
|
666 |
if (!downloadFileHttp(urlDownload,filePath,_("Downloading ") + fileDescription + "..." )) |
667 |
{ |
668 |
//FIXME: Falta msgError
|
669 |
return false; |
670 |
} |
671 |
} |
672 |
else
|
673 |
{ |
674 |
return false; |
675 |
} |
676 |
|
677 |
} |
678 |
return true; |
679 |
} |
680 |
|
681 |
void LauncherApp::showStatusMsg(const wxString msg) { |
682 |
if (isStatusDialogVisible) {
|
683 |
while (this->Pending()) { |
684 |
this->Dispatch();
|
685 |
} |
686 |
if (statusDialog->IsCanceled()) {
|
687 |
int response;
|
688 |
wxMessageDialog dlg(0, _("Are you sure to cancel instalation process?"), _(APPLICATION_NAME), wxYES_NO | wxICON_QUESTION ); |
689 |
response = dlg.ShowModal(); |
690 |
if (response == wxID_YES) {
|
691 |
notifyToUser(_("Canceled by user"));
|
692 |
exit(1);
|
693 |
} |
694 |
statusDialog->DoNotCancel(); |
695 |
} |
696 |
statusDialog->showStatus(msg); |
697 |
} |
698 |
} |
699 |
|
700 |
bool LauncherApp::checkVersion(const wxString javaexe) |
701 |
{ |
702 |
wxString cmd; |
703 |
wxArrayString out; |
704 |
wxArrayString err; |
705 |
|
706 |
cmd = cmd.Format("%s -version", javaexe.c_str());
|
707 |
if( wxExecute(cmd,out,err)!= 0 ) { |
708 |
notifyToUser("wxExecute ha petao.");
|
709 |
exit(1);
|
710 |
} |
711 |
|
712 |
if (err[0].Contains("1.4.2") && err[0].Contains("version")) { |
713 |
return true; |
714 |
} |
715 |
notifyToUser(cmd.Format(_("%s\nJava 1.4.2 recommended"), err[0].c_str())); |
716 |
return false; |
717 |
|
718 |
|
719 |
} |
720 |
|
721 |
void LauncherApp::run(){
|
722 |
bool doChecks = true; |
723 |
|
724 |
if (paramsAskForCheckingProcess) {
|
725 |
wxString msg = _("Do you want to check the application requirements?");
|
726 |
doChecks = confirmYesNoCancel(msg,true);
|
727 |
} |
728 |
|
729 |
|
730 |
if (doChecks) {
|
731 |
|
732 |
if (!searchJRE())
|
733 |
{ |
734 |
jreInstall(); |
735 |
} |
736 |
|
737 |
fixSystemJREConfig(); |
738 |
|
739 |
jaiInstall(); |
740 |
|
741 |
jaiIoInstall(); |
742 |
} else {
|
743 |
// No quiere comprobacion, por lo que solicitamos
|
744 |
wxString msgDir = _("Find de Java Virtual Machine executable file to run");
|
745 |
wxFileDialog dlg( |
746 |
0,
|
747 |
msgDir, |
748 |
wxEmptyString, |
749 |
wxString("java.exe"),
|
750 |
wxString("Java VM executable file (java.exe)|java.exe"),
|
751 |
wxOPEN | wxFILE_MUST_EXIST, |
752 |
wxDefaultPosition |
753 |
); |
754 |
int response = dlg.ShowModal();
|
755 |
if (response != wxID_OK) {
|
756 |
notifyToUser(_("Canceled by user"));
|
757 |
exit(1);
|
758 |
} |
759 |
//caragamos la variable con el eljecutable
|
760 |
javaExecPath = dlg.GetPath(); |
761 |
|
762 |
checkVersion(javaExecPath); |
763 |
|
764 |
//generamos el path para el JavaHome (por si acaso)
|
765 |
wxFileName fileName(javaExecPath); |
766 |
fileName.SetFullName("");
|
767 |
fileName.AppendDir("..");
|
768 |
fileName.Normalize(); |
769 |
javaHome = fileName.GetPath(); |
770 |
|
771 |
} |
772 |
|
773 |
runJRE(); |
774 |
|
775 |
exit(0);
|
776 |
|
777 |
} |
778 |
|
779 |
void LauncherApp::OnTimer(wxTimerEvent& event) {
|
780 |
run(); |
781 |
} |