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