svn-gvsig-desktop / tags / v1_0_2_Build_908 / install / launcher / izpack-launcher-1.3_linux / src / launcher.cpp @ 11054
History | View | Annotate | Download (18.7 KB)
1 | 6834 | jmvivo | /* 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 | |||
27 | #include "launcher.h" |
||
28 | |||
29 | #ifdef __UNIX__
|
||
30 | #include <stdlib.h> |
||
31 | #include <stdio.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);
|
||
47 | int code = system(cmd );
|
||
48 | return (code == 0); |
||
49 | |||
50 | } |
||
51 | |||
52 | bool run_external_async(wxString cmd)
|
||
53 | { |
||
54 | return (wxExecute(cmd, wxEXEC_ASYNC) != 0); |
||
55 | } |
||
56 | |||
57 | bool run_external_withOut(wxString cmd,wxArrayString& out, wxArrayString& errors){
|
||
58 | //printf(" run_external_withOut **%s**\n",cmd.c_str());
|
||
59 | int exitCode =wxExecute(cmd, out,errors);
|
||
60 | //printf("\texitCode= %i, out.Count = %i, error.Count= %i\n",exitCode,out.Count(),errors.Count());
|
||
61 | |||
62 | /*
|
||
63 | int i;
|
||
64 | for (i=0;i<out.Count();i++){
|
||
65 | printf("\t\tout: %s\n",out[i].c_str());
|
||
66 | }
|
||
67 | for (i=0;i<errors.Count();i++){
|
||
68 | printf("\t\terrors: %s\n",errors[i].c_str());
|
||
69 | }
|
||
70 | */
|
||
71 | |||
72 | return ( exitCode == 0); |
||
73 | } |
||
74 | |||
75 | |||
76 | bool string_to_bool(wxString value, bool defaultValue){ |
||
77 | bool returnValue = defaultValue;
|
||
78 | if (value != wxEmptyString)
|
||
79 | if (
|
||
80 | value.CmpNoCase("s") == 0 || |
||
81 | value.CmpNoCase("si") == 0 || |
||
82 | value.CmpNoCase("1") == 0 || |
||
83 | value.CmpNoCase("y") == 0 || |
||
84 | value.CmpNoCase("yes") == 0 |
||
85 | ) |
||
86 | { |
||
87 | returnValue = true;
|
||
88 | } else {
|
||
89 | returnValue = false;
|
||
90 | } |
||
91 | return returnValue;
|
||
92 | } |
||
93 | |||
94 | |||
95 | void applyFont(wxWindow *dlg, wxFont font){
|
||
96 | puts("0");
|
||
97 | dlg->SetFont(font); |
||
98 | //bool tmp = win->IsKindOf(CLASSINFO(wxFrame));
|
||
99 | puts("1");
|
||
100 | wxWindowList childs =dlg->GetChildren(); |
||
101 | puts("2");
|
||
102 | if (childs.GetCount() < 1) { |
||
103 | return;
|
||
104 | } |
||
105 | puts("3");
|
||
106 | wxWindowListNode *node = childs.GetFirst(); |
||
107 | while (node)
|
||
108 | { |
||
109 | puts("4");
|
||
110 | wxWindow * win = node->GetData(); |
||
111 | try {
|
||
112 | applyFont(win,font); |
||
113 | } catch ( ... ) {
|
||
114 | |||
115 | } |
||
116 | puts("5");
|
||
117 | node = node->GetNext(); |
||
118 | puts("6");
|
||
119 | } |
||
120 | puts("7");
|
||
121 | } |
||
122 | |||
123 | /*
|
||
124 | class MyWxFileDialog : public wxDialog {
|
||
125 | public:
|
||
126 | |||
127 | MyWxFileDialog(wxWindow* parent, const wxString& message = "Choose a file", const wxString& defaultDir = "", const wxString& defaultFile = "", const wxString& wildcard = "*.*", long style = 0, const wxPoint& pos = wxDefaultPosition);
|
||
128 | |||
129 | virtual ~MyWxFileDialog();
|
||
130 | }
|
||
131 | |||
132 | MyWxFileDialog::MyWxFileDialog(): wxDialog() {
|
||
133 | |||
134 | }
|
||
135 | */
|
||
136 | long LAUNCHAPP_TIMER_ID = wxNewId();
|
||
137 | |||
138 | BEGIN_EVENT_TABLE(LauncherApp, wxApp) |
||
139 | EVT_TIMER(LAUNCHAPP_TIMER_ID, LauncherApp::OnTimer) |
||
140 | END_EVENT_TABLE() |
||
141 | |||
142 | |||
143 | /* Main Application $Revision$
|
||
144 | *
|
||
145 | * $Id$
|
||
146 | */
|
||
147 | LauncherApp::LauncherApp() |
||
148 | : wxApp() |
||
149 | { |
||
150 | 7980 | jmvivo | APPLICATION_NAME = wxString(_("gvSIG Install-Launcher"));
|
151 | 6834 | jmvivo | |
152 | |||
153 | SetAppName(_( APPLICATION_NAME )); |
||
154 | loadParams(); |
||
155 | /*
|
||
156 | wxFont font;
|
||
157 | font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
|
||
158 | puts("Fuente de sistema");
|
||
159 | printf("face: %s\n",font.GetFaceName().c_str());
|
||
160 | printf("native: %s\n",font.GetNativeFontInfoDesc().c_str());
|
||
161 | printf("size: %i\n",font.GetPointSize());
|
||
162 | printf("ok: %i\n",font.Ok());
|
||
163 | puts("/Fuente de sistema");
|
||
164 | */
|
||
165 | } |
||
166 | |||
167 | void LauncherApp::echo(const wxString &msg) |
||
168 | { |
||
169 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK);
|
||
170 | //applyFont(&dlg,font);
|
||
171 | dlg.ShowModal(); |
||
172 | //wxString m="%s";
|
||
173 | ///m.Printf(msg);
|
||
174 | } |
||
175 | |||
176 | void LauncherApp::notifyToUser(const wxString &msg) |
||
177 | { |
||
178 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_INFORMATION);
|
||
179 | //applyFont(&dlg,font);
|
||
180 | dlg.ShowModal(); |
||
181 | } |
||
182 | |||
183 | void LauncherApp::notifyErrorToUser(const wxString &msg) |
||
184 | { |
||
185 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_ERROR);
|
||
186 | //applyFont(&dlg,font);
|
||
187 | dlg.ShowModal(); |
||
188 | } |
||
189 | |||
190 | |||
191 | LauncherApp::~LauncherApp() |
||
192 | { |
||
193 | |||
194 | } |
||
195 | |||
196 | void LauncherApp::loadParams()
|
||
197 | { |
||
198 | cfgName = wxString( "launcher.ini" );
|
||
199 | |||
200 | wxFileInputStream in( cfgName ); |
||
201 | wxFileConfig cfg( in ); |
||
202 | wxString downloadEnabled; |
||
203 | wxString launchJarAsync; |
||
204 | wxString askForCheckingProcess; |
||
205 | |||
206 | cfg.Read( "jar", ¶msJar, wxEmptyString);
|
||
207 | cfg.Read( "jre", ¶msJre, wxEmptyString);
|
||
208 | cfg.Read( "downloadJre", ¶msJreDownload, wxEmptyString);
|
||
209 | cfg.Read( "installJreCmd", ¶msJreInstallCmd, wxEmptyString);
|
||
210 | cfg.Read( "installedJreJavaFile", ¶msJreInstalledJavaFile, wxEmptyString);
|
||
211 | cfg.Read( "installedJreRootDirectory", ¶msJreInstalledRootDirectory, wxEmptyString);
|
||
212 | cfg.Read( "jre_version", ¶msJreVersion, wxEmptyString);
|
||
213 | cfg.Read( "jre_version_prefered", ¶msJreVersionPrefered, wxEmptyString);
|
||
214 | cfg.Read( "jarParams", ¶msJarParams, wxEmptyString);
|
||
215 | cfg.Read( "downloadEnabled", &downloadEnabled, wxEmptyString);
|
||
216 | cfg.Read( "launchJarAsync", &launchJarAsync, wxEmptyString);
|
||
217 | |||
218 | //procesamos el parametro booleano 'downloadEnabled'
|
||
219 | paramsEnabledDownload =string_to_bool(downloadEnabled,false);
|
||
220 | //procesamos el parametro booleano 'launchJarAsync'
|
||
221 | paramsLaunchJarAsync =string_to_bool(launchJarAsync,false);
|
||
222 | |||
223 | if (paramsJar == wxEmptyString )
|
||
224 | { |
||
225 | error(_("The configuration file '") + cfgName + _("' does not contain a jar file entry.")); |
||
226 | } |
||
227 | if (paramsJreVersionPrefered == wxEmptyString ) {
|
||
228 | paramsJreVersionPrefered = wxString(paramsJreVersion); |
||
229 | } |
||
230 | } |
||
231 | |||
232 | void LauncherApp::error(const wxString &msg) |
||
233 | { |
||
234 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_ERROR);
|
||
235 | //applyFont(&dlg,font);
|
||
236 | dlg.ShowModal(); |
||
237 | exit(1);
|
||
238 | } |
||
239 | |||
240 | void LauncherApp::confirm(const wxString &msg) |
||
241 | { |
||
242 | int response;
|
||
243 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxCANCEL | wxICON_QUESTION );
|
||
244 | //applyFont(&dlg,font);
|
||
245 | response = dlg.ShowModal(); |
||
246 | if (response != wxID_OK) {
|
||
247 | notifyToUser(_("Canceled by user"));
|
||
248 | exit(1);
|
||
249 | } |
||
250 | } |
||
251 | bool LauncherApp::confirmYesNoCancel(const wxString &msg,const int yesDefault = true) |
||
252 | { |
||
253 | int response;
|
||
254 | long maskDefault;
|
||
255 | if (yesDefault) {
|
||
256 | maskDefault = wxYES_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
||
257 | } else {
|
||
258 | maskDefault = wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
||
259 | } |
||
260 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), maskDefault);
|
||
261 | //applyFont(&dlg,font);
|
||
262 | response = dlg.ShowModal(); |
||
263 | if (response != wxID_YES && response != wxID_NO) {
|
||
264 | notifyToUser(_("Canceled by user"));
|
||
265 | exit(1);
|
||
266 | } |
||
267 | return (response == wxID_YES);
|
||
268 | |||
269 | } |
||
270 | |||
271 | |||
272 | |||
273 | bool LauncherApp::OnInit()
|
||
274 | { |
||
275 | wxFont myFont; |
||
276 | myFont.SetFamily(wxDECORATIVE); |
||
277 | myFont.SetPointSize(12);
|
||
278 | isStatusDialogVisible = false;
|
||
279 | locale.Init(); |
||
280 | locale.AddCatalog("launcher");
|
||
281 | |||
282 | statusDialog = new StatusDialog( APPLICATION_NAME );
|
||
283 | |||
284 | //applyFont(statusDialog,font);
|
||
285 | statusDialog->Centre(); |
||
286 | statusDialog->Show(TRUE); |
||
287 | isStatusDialogVisible = true;
|
||
288 | |||
289 | showStatusMsg(_("Intializing..."));
|
||
290 | |||
291 | myTimer = new wxTimer(this,LAUNCHAPP_TIMER_ID); |
||
292 | myTimer->Start(150,true); |
||
293 | this->MainLoop();
|
||
294 | return true; |
||
295 | } |
||
296 | |||
297 | bool LauncherApp::compareVersions(const wxString localVersion, const wxString requireVersion) |
||
298 | { |
||
299 | bool result = (localVersion.Cmp(requireVersion) == 0); |
||
300 | /*
|
||
301 | if (requireVersion.Len() > localVersion.Len() ) {
|
||
302 | |||
303 | result = (localVersion.Find(requireVersion) == 0);
|
||
304 | }
|
||
305 | else
|
||
306 | {
|
||
307 | result = (requireVersion.Find(localVersion) == 0);
|
||
308 | }
|
||
309 | */
|
||
310 | |||
311 | /*
|
||
312 | if (result) {
|
||
313 | echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> true");
|
||
314 | } else {
|
||
315 | echo("localversion = '" + localVersion +"' requireVersion = '"+ requireVersion +"' ==> false");
|
||
316 | }
|
||
317 | */
|
||
318 | |||
319 | return result;
|
||
320 | } |
||
321 | |||
322 | |||
323 | void LauncherApp::runJRE()
|
||
324 | { |
||
325 | 7064 | jaume | showStatusMsg(_("Launching installation..."));
|
326 | 6834 | jmvivo | if (!wxFile::Exists(paramsJar))
|
327 | { |
||
328 | 7064 | jaume | error(_("The jar-file in the configuration file ") + cfgName + _(" does not exist.")); |
329 | 6834 | jmvivo | } |
330 | |||
331 | 8765 | jjdelcerro | wxString cmd = "export JAVA_HOME=\"" +
|
332 | getJavaExecFileHome(javaExecPath) + "\"; unset LD_LIBRARY_PATH ; exec " +
|
||
333 | javaExecPath + paramsJarParams + wxString(" -jar ") + paramsJar;
|
||
334 | 6834 | jmvivo | //echo(cmd);
|
335 | if (paramsLaunchJarAsync) {
|
||
336 | if (!run_external_async(cmd))
|
||
337 | { |
||
338 | error(_("The jar-file ") + paramsJar + _(" could not be executed." )); |
||
339 | } |
||
340 | } else {
|
||
341 | if (!run_external(cmd))
|
||
342 | { |
||
343 | error(_("The jar-file ") + paramsJar + _(" could not be executed." )); |
||
344 | } |
||
345 | } |
||
346 | |||
347 | } |
||
348 | |||
349 | wxString LauncherApp::installJRE(){ |
||
350 | showStatusMsg(_("Preparing to install JRE..."));
|
||
351 | |||
352 | if (!checkInstallerFile(paramsJre, paramsJreDownload,_("Java JRE version ")+paramsJreVersion)) |
||
353 | { |
||
354 | notifyErrorToUser(_("The JRE could not be setup."));
|
||
355 | return ""; |
||
356 | } |
||
357 | |||
358 | showStatusMsg(_("Installing JRE..."));
|
||
359 | |||
360 | if (!run_external(paramsJreInstallCmd))
|
||
361 | { |
||
362 | notifyErrorToUser(_("The JRE could not be setup."));
|
||
363 | return ""; |
||
364 | } |
||
365 | |||
366 | if (!wxFileExists(paramsJreInstalledJavaFile)){
|
||
367 | 7064 | jaume | notifyErrorToUser(wxString::Format(_("The file %s does not exist."),paramsJreInstalledJavaFile.c_str()));
|
368 | 6834 | jmvivo | return ""; |
369 | } |
||
370 | |||
371 | return paramsJreInstalledJavaFile;
|
||
372 | |||
373 | } |
||
374 | |||
375 | IMPLEMENT_APP(LauncherApp) |
||
376 | |||
377 | bool LauncherApp::downloadFileHttp(const wxString urlOfFile, const wxString filePath, const wxString msg){ |
||
378 | |||
379 | bool isOk;
|
||
380 | //echo(urlOfFile);
|
||
381 | if (urlOfFile == wxEmptyString) {
|
||
382 | return false; |
||
383 | } |
||
384 | |||
385 | if (filePath == wxEmptyString) {
|
||
386 | return false; |
||
387 | } |
||
388 | |||
389 | showStatusMsg(msg); |
||
390 | wxURL url(urlOfFile); |
||
391 | //echo("url open");
|
||
392 | wxInputStream *in_stream; |
||
393 | |||
394 | in_stream = url.GetInputStream(); |
||
395 | //echo("in_stream open");
|
||
396 | if (!in_stream){
|
||
397 | return false; |
||
398 | } |
||
399 | if (!in_stream->IsOk()) {
|
||
400 | //echo("in_stream.IsOk == false");
|
||
401 | return false; |
||
402 | } |
||
403 | //echo("in_stream.IsOk == true");
|
||
404 | //echo("filePath =" + filePath);
|
||
405 | wxFileName fileName(filePath); |
||
406 | wxFileName fileDir(fileName.GetPath()); |
||
407 | if (!fileDir.DirExists()) {
|
||
408 | if (!fileDir.Mkdir(0777,wxPATH_MKDIR_FULL )) { |
||
409 | return false; |
||
410 | } |
||
411 | } |
||
412 | /*
|
||
413 | // Preparamos la ruta para el fichero destino
|
||
414 | wxArrayString dirs;
|
||
415 | |||
416 | dirs = fileName.GetDirs();
|
||
417 | wxString dir;
|
||
418 | wxFileName curDir(".");
|
||
419 | for (size_t i=0; i < dirs.GetCount(); i++) {
|
||
420 | dir = dirs.Item(i);
|
||
421 | curDir.AppendDir(dir);
|
||
422 | //echo("dir " + curDir.GetPath());
|
||
423 | if (!curDir.DirExists()) {
|
||
424 | //echo("creating dir");
|
||
425 | isOk = curDir.Mkdir();
|
||
426 | if (!isOk) {
|
||
427 | //echo("dir create no ok");
|
||
428 | return false;
|
||
429 | }
|
||
430 | |||
431 | //echo("dir create ok");
|
||
432 | }
|
||
433 | }
|
||
434 | */
|
||
435 | |||
436 | wxFileOutputStream out_stream = wxFileOutputStream(filePath); |
||
437 | //echo("out_stream open");
|
||
438 | |||
439 | //in_stream->Read(out_stream);
|
||
440 | size_t nbytes = 10240;
|
||
441 | char buffer[nbytes];
|
||
442 | |||
443 | |||
444 | while (!in_stream->Eof()) {
|
||
445 | in_stream->Read(&buffer,nbytes); |
||
446 | if (in_stream->LastError() != wxSTREAM_NO_ERROR && in_stream->LastError() != wxSTREAM_EOF) {
|
||
447 | return false; |
||
448 | } |
||
449 | out_stream.Write(&buffer,in_stream->LastRead()); |
||
450 | if (out_stream.LastError() != wxSTREAM_NO_ERROR) {
|
||
451 | return false; |
||
452 | } |
||
453 | int totalKb = out_stream.GetSize() / 1024; |
||
454 | wxString totalMsg =wxString::Format("%i",totalKb);
|
||
455 | showStatusMsg(msg+" "+ totalMsg + " Kb"); |
||
456 | |||
457 | } |
||
458 | |||
459 | |||
460 | isOk = true;
|
||
461 | 6852 | jmvivo | /*
|
462 | 6834 | jmvivo | if (isOk) {
|
463 | echo("isOk = true");
|
||
464 | } else {
|
||
465 | echo("isOk = false");
|
||
466 | }
|
||
467 | 6852 | jmvivo | */
|
468 | 6834 | jmvivo | delete in_stream;
|
469 | |||
470 | //echo("end");
|
||
471 | return isOk;
|
||
472 | |||
473 | } |
||
474 | |||
475 | bool LauncherApp::checkInstallerFile(const wxString filePath, const wxString urlDownload, const wxString fileDescription) { |
||
476 | if (!wxFile::Exists(filePath))
|
||
477 | { |
||
478 | if (paramsEnabledDownload)
|
||
479 | { |
||
480 | wxString msg; |
||
481 | 7064 | jaume | msg = wxString::Format(_("The installation requires to download this file:\n%s\nDo you want to continue?"),fileDescription.c_str());
|
482 | 6834 | jmvivo | confirm(msg); |
483 | msg = wxString::Format(_("Downloading %s..."),fileDescription.c_str());
|
||
484 | if (!downloadFileHttp(urlDownload,filePath,msg))
|
||
485 | { |
||
486 | //FIXME: Falta msgError
|
||
487 | return false; |
||
488 | } |
||
489 | } |
||
490 | else
|
||
491 | { |
||
492 | return false; |
||
493 | } |
||
494 | |||
495 | } |
||
496 | return true; |
||
497 | } |
||
498 | |||
499 | void LauncherApp::showStatusMsg(const wxString msg) { |
||
500 | if (isStatusDialogVisible) {
|
||
501 | while (this->Pending()) { |
||
502 | this->Dispatch();
|
||
503 | } |
||
504 | if (statusDialog->IsCanceled()) {
|
||
505 | int response;
|
||
506 | 7064 | jaume | wxMessageDialog dlg(0, _("Are you sure you want to cancel installation?"), _(APPLICATION_NAME), wxYES_NO | wxICON_QUESTION ); |
507 | 6834 | jmvivo | response = dlg.ShowModal(); |
508 | if (response == wxID_YES) {
|
||
509 | 7064 | jaume | notifyToUser(_("Canceled by the user"));
|
510 | 6834 | jmvivo | exit(1);
|
511 | } |
||
512 | statusDialog->DoNotCancel(); |
||
513 | } |
||
514 | statusDialog->showStatus(msg); |
||
515 | } |
||
516 | } |
||
517 | |||
518 | void LauncherApp::run(){
|
||
519 | bool ok = false; |
||
520 | |||
521 | wxString mJavaFileName; |
||
522 | wxString errorMsg; |
||
523 | SelectionDialog dlg( checkPreviousJRE(),checkEnvironmentJRE() ,_(APPLICATION_NAME)); |
||
524 | while (!ok) {
|
||
525 | //applyFont(&dlg,font);
|
||
526 | if (dlg.ShowModal() != wxID_OK){
|
||
527 | 7064 | jaume | notifyToUser(_("Canceled by the user"));
|
528 | 6834 | jmvivo | exit(1);
|
529 | } |
||
530 | switch (dlg.getUserAction())
|
||
531 | { |
||
532 | case PREVIOUS_GVSIG: mJavaFileName = previousJRE(); break; |
||
533 | case PROVIDED: mJavaFileName = installJRE(); break; |
||
534 | case SELECT_MANUALY: mJavaFileName = selectJavaExecFileManualy(); break; |
||
535 | case ENVIRON: mJavaFileName = useEnvironJRE(); break; |
||
536 | default: break; |
||
537 | } |
||
538 | if (mJavaFileName.Cmp("") == 0) { |
||
539 | 7064 | jaume | wxString msg =wxString::Format(_("Error executing this installation option. Do you want to try another one?"),errorMsg.c_str());
|
540 | 6834 | jmvivo | confirm(msg); |
541 | } else {
|
||
542 | //echo("checking..." + mJavaFileName);
|
||
543 | errorMsg = checkJava(mJavaFileName); |
||
544 | //echo("check result: *"+errorMsg+"*");
|
||
545 | if (errorMsg.Cmp("") == 0) { |
||
546 | javaExecPath=mJavaFileName; |
||
547 | ok=true;
|
||
548 | } else {
|
||
549 | 7064 | jaume | wxString msg =wxString::Format(_("Problems found in the selected JRE:\n%s\n\nDo you want to continue?"),errorMsg.c_str());
|
550 | 6834 | jmvivo | if (confirmYesNoCancel(msg,false)) { |
551 | javaExecPath=mJavaFileName; |
||
552 | ok=true;
|
||
553 | } |
||
554 | } |
||
555 | } |
||
556 | } |
||
557 | runJRE(); |
||
558 | |||
559 | exit(0);
|
||
560 | |||
561 | } |
||
562 | |||
563 | void LauncherApp::OnTimer(wxTimerEvent& event) {
|
||
564 | run(); |
||
565 | } |
||
566 | |||
567 | wxString LauncherApp::selectJavaExecFileManualy() { |
||
568 | 7064 | jaume | wxString msgDir = _("Manually select the Java VM");
|
569 | 6834 | jmvivo | wxFileDialog dlg( |
570 | 0,
|
||
571 | msgDir, |
||
572 | wxEmptyString, |
||
573 | wxString("java"),
|
||
574 | 7980 | jmvivo | wxString( wxString(_("Java VM executable file")) + " (java)|java"), |
575 | 6834 | jmvivo | wxOPEN | wxFILE_MUST_EXIST, |
576 | wxDefaultPosition |
||
577 | ); |
||
578 | //applyFont(&dlg,font);
|
||
579 | |||
580 | |||
581 | int response = dlg.ShowModal();
|
||
582 | if (response != wxID_OK) {
|
||
583 | 7064 | jaume | notifyToUser(_("Canceled by the user"));
|
584 | 6834 | jmvivo | exit(1);
|
585 | } |
||
586 | return dlg.GetPath();
|
||
587 | } |
||
588 | |||
589 | |||
590 | wxString LauncherApp::getJavaExecFileVersion(wxString javaFileName) { |
||
591 | wxArrayString output, errors; |
||
592 | wxString cmd =javaFileName + " GetJavaSystemProperties java.version";
|
||
593 | //echo(cmd);
|
||
594 | if (!run_external_withOut(cmd,output, errors)) {
|
||
595 | return ""; |
||
596 | } |
||
597 | if (output.Count() == 0){ |
||
598 | return ""; |
||
599 | } |
||
600 | return output[0]; |
||
601 | |||
602 | } |
||
603 | |||
604 | wxString LauncherApp::getJavaExecFileHome(wxString javaFileName) { |
||
605 | wxArrayString output, errors; |
||
606 | wxString cmd =javaFileName + " GetJavaSystemProperties java.home";
|
||
607 | if (!run_external_withOut(cmd,output, errors)) {
|
||
608 | return ""; |
||
609 | } |
||
610 | if (output.Count() == 0){ |
||
611 | return ""; |
||
612 | } |
||
613 | return output[0]; |
||
614 | |||
615 | } |
||
616 | |||
617 | |||
618 | wxString LauncherApp::checkJava(const wxString aJavaFileName) {
|
||
619 | wxString msg = "";
|
||
620 | wxString version; |
||
621 | wxString home; |
||
622 | |||
623 | |||
624 | if (!wxFileExists(aJavaFileName)){
|
||
625 | return wxString::Format(_("File %s not found."),aJavaFileName.c_str());//_("File %s not found."), javaFileName); |
||
626 | }; |
||
627 | |||
628 | |||
629 | version = getJavaExecFileVersion(aJavaFileName); |
||
630 | |||
631 | if (version.Cmp("") == 0){ |
||
632 | return wxString::Format(_("Can't identify version of %s."), aJavaFileName.c_str()); |
||
633 | } |
||
634 | |||
635 | version = version.Left(5);
|
||
636 | if (!compareVersions(version,paramsJreVersion)) {
|
||
637 | msg = "\n" + wxString::Format(_("Java version %s is not the required %s"),version.c_str(),paramsJreVersion.c_str()); |
||
638 | } |
||
639 | |||
640 | home = getJavaExecFileHome(aJavaFileName); |
||
641 | if (home.Cmp("") == 0){ |
||
642 | return wxString::Format(_("Can't identify java_home of %s."), aJavaFileName.c_str()); |
||
643 | } |
||
644 | // comprobamos JAI
|
||
645 | if (!wxFileExists(home + "/lib/ext/jai_core.jar")) { |
||
646 | msg = msg +"\n" + _("The JAI library is not installed"); |
||
647 | } |
||
648 | // comprobamos JAI i/o
|
||
649 | if (!wxFileExists(home + "/lib/ext/jai_imageio.jar")) { |
||
650 | msg = msg +"\n" + _("The JAI I/O library is not installed"); |
||
651 | } |
||
652 | |||
653 | return msg;
|
||
654 | } |
||
655 | |||
656 | bool LauncherApp::checkEnvironmentJRE() {
|
||
657 | return (useEnvironJRE().Cmp("") != 0); |
||
658 | } |
||
659 | |||
660 | wxString LauncherApp::useEnvironJRE() { |
||
661 | wxString envJavaHome; |
||
662 | if (wxGetEnv("JAVA_HOME",&envJavaHome)){ |
||
663 | //echo("no Java Home get");
|
||
664 | if (!envJavaHome.Cmp("") == 0) { |
||
665 | return envJavaHome + "/bin/java"; |
||
666 | } |
||
667 | //echo("no Java Home blank");
|
||
668 | } |
||
669 | //echo("no Java Home");
|
||
670 | |||
671 | wxArrayString output, errors; |
||
672 | if (run_external_withOut("/bin/sh -c 'type -p java'",output, errors)) { |
||
673 | //printf("ouput.Count() = %i",output.Count());
|
||
674 | //printf("errors.Count() = %i",errors.Count());
|
||
675 | if (output.Count() != 0){ |
||
676 | return output[0]; |
||
677 | } |
||
678 | //echo("no Java in path count=0");
|
||
679 | } |
||
680 | //echo("no Java in path");
|
||
681 | return ""; |
||
682 | |||
683 | } |
||
684 | |||
685 | |||
686 | bool LauncherApp::checkPreviousJRE() {
|
||
687 | wxFileName appHomeJre = paramsJreInstalledRootDirectory; |
||
688 | |||
689 | appHomeJre.MakeAbsolute(); |
||
690 | |||
691 | if (!appHomeJre.DirExists()) {
|
||
692 | return false; |
||
693 | } |
||
694 | |||
695 | |||
696 | |||
697 | return (!wxFindFirstFile(appHomeJre.GetFullPath()+"/"+paramsJreVersion+"*",wxDIR).IsEmpty()); |
||
698 | } |
||
699 | |||
700 | wxString LauncherApp::previousJRE() { |
||
701 | if (paramsJreVersionPrefered.IsEmpty()) {
|
||
702 | wxFileName prefered = paramsJreInstalledRootDirectory+"/"+paramsJreVersionPrefered+"/bin/java"; |
||
703 | prefered.Normalize(); |
||
704 | if (prefered.FileExists()){
|
||
705 | return prefered.GetFullPath();
|
||
706 | } |
||
707 | } |
||
708 | wxString mask = paramsJreInstalledRootDirectory+"/" + paramsJreVersion + "_%02d/bin/java"; |
||
709 | for(unsigned i=20;i>1;i--) { |
||
710 | wxFileName current; |
||
711 | current = wxString::Format(mask,i); |
||
712 | if (current.FileExists()) {
|
||
713 | return current.GetFullPath();
|
||
714 | } |
||
715 | } |
||
716 | return ""; |
||
717 | } |
||
718 | |||
719 | /**
|
||
720 | wxArrayString getDirectoriesFromPath(wxString path){
|
||
721 | wxArrayString directories;
|
||
722 | if (appHome.DirExists()) {
|
||
723 | wxString f = wxFindFirstFile(appHomeJre+"*",wxDIR);
|
||
724 | while ( !f.IsEmpty() )
|
||
725 | {
|
||
726 | wxArrayString.Add(f);
|
||
727 | f = wxFindNextFile();
|
||
728 | }
|
||
729 | }
|
||
730 | return directories;
|
||
731 | }
|
||
732 | **/
|
||
733 | |||
734 |