svn-gvsig-desktop / tags / v1_1_Build_1008 / install / launcher / izpack-launcher-1.3_linux / src / launcher.cpp @ 12520
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 | 12452 | jmvivo | bool run_external_withOut(wxString cmd,wxArrayString& out, wxArrayString& errors){
|
58 | 6834 | jmvivo | //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 | 12452 | jmvivo | |
62 | 6834 | jmvivo | /*
|
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 | 12452 | jmvivo | |
72 | 6834 | jmvivo | 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 | 12452 | jmvivo | ) |
86 | 6834 | jmvivo | { |
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 | 12452 | jmvivo | |
115 | 6834 | jmvivo | } |
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 | 12452 | jmvivo | |
153 | 6834 | jmvivo | 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 | 12452 | jmvivo | void LauncherApp::echo(const wxString &msg) |
168 | 6834 | jmvivo | { |
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 | 12452 | jmvivo | void LauncherApp::notifyToUser(const wxString &msg) |
177 | 6834 | jmvivo | { |
178 | wxMessageDialog dlg(0, msg, _(APPLICATION_NAME), wxOK | wxICON_INFORMATION);
|
||
179 | //applyFont(&dlg,font);
|
||
180 | dlg.ShowModal(); |
||
181 | } |
||
182 | |||
183 | 12452 | jmvivo | void LauncherApp::notifyErrorToUser(const wxString &msg) |
184 | 6834 | jmvivo | { |
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 | 12452 | jmvivo | cfg.Read( "launchJarAsync", &launchJarAsync, wxEmptyString);
|
217 | |||
218 | 6834 | jmvivo | //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 | 12452 | jmvivo | |
223 | 6834 | jmvivo | 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 | 12452 | jmvivo | maskDefault = wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_QUESTION; |
259 | 6834 | jmvivo | } |
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 | 12452 | jmvivo | |
269 | 6834 | jmvivo | } |
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 | 12452 | jmvivo | |
291 | 6834 | jmvivo | 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 | 12452 | jmvivo | if (requireVersion.Len() > localVersion.Len() ) {
|
302 | |||
303 | 6834 | jmvivo | result = (localVersion.Find(requireVersion) == 0);
|
304 | }
|
||
305 | 12452 | jmvivo | else
|
306 | 6834 | jmvivo | {
|
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 | 12452 | jmvivo | |
319 | 6834 | jmvivo | 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 | 12452 | jmvivo | wxString cmd = "export JAVA_HOME=\"" +
|
332 | getJavaExecFileHome(javaExecPath) + "\"; unset LD_LIBRARY_PATH ; exec " +
|
||
333 | 8765 | jjdelcerro | 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 | 12452 | jmvivo | } |
345 | 6834 | jmvivo | } |
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 | 12452 | jmvivo | |
385 | 6834 | jmvivo | if (filePath == wxEmptyString) {
|
386 | return false; |
||
387 | } |
||
388 | 12452 | jmvivo | |
389 | 6834 | jmvivo | 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 | 12452 | jmvivo | wxFileName fileName(filePath); |
406 | wxFileName fileDir(fileName.GetPath()); |
||
407 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
416 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
431 | 6834 | jmvivo | //echo("dir create ok");
|
432 | }
|
||
433 | }
|
||
434 | */
|
||
435 | 12452 | jmvivo | |
436 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
444 | 6834 | jmvivo | while (!in_stream->Eof()) {
|
445 | 12452 | jmvivo | in_stream->Read(&buffer,nbytes); |
446 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
459 | |||
460 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
470 | 6834 | jmvivo | //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 | 12452 | jmvivo | if (paramsEnabledDownload)
|
479 | 6834 | jmvivo | { |
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 | 12452 | jmvivo | if (!downloadFileHttp(urlDownload,filePath,msg))
|
485 | 6834 | jmvivo | { |
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 | 12452 | jmvivo | |
521 | 6834 | jmvivo | 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 | 12452 | jmvivo | } else {
|
542 | 6834 | jmvivo | //echo("checking..." + mJavaFileName);
|
543 | 12452 | jmvivo | errorMsg = checkJava(mJavaFileName); |
544 | 6834 | jmvivo | //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 | 12452 | jmvivo | ok=true;
|
553 | 6834 | jmvivo | } |
554 | } |
||
555 | } |
||
556 | } |
||
557 | runJRE(); |
||
558 | |||
559 | 12452 | jmvivo | exit(0);
|
560 | |||
561 | 6834 | jmvivo | } |
562 | |||
563 | 12452 | jmvivo | void LauncherApp::OnTimer(wxTimerEvent& event) {
|
564 | 6834 | jmvivo | run(); |
565 | } |
||
566 | |||
567 | 12452 | jmvivo | wxString LauncherApp::selectJavaExecFileManualy() { |
568 | wxString msgDir = _("Manually select the Java VM");
|
||
569 | 6834 | jmvivo | wxFileDialog dlg( |
570 | 0,
|
||
571 | msgDir, |
||
572 | 12452 | jmvivo | wxEmptyString, |
573 | 6834 | jmvivo | 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 | 12452 | jmvivo | wxArrayString output, errors; |
592 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
602 | 6834 | jmvivo | } |
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 | 12452 | jmvivo | } |
613 | 6834 | jmvivo | return output[0]; |
614 | 12452 | jmvivo | |
615 | 6834 | jmvivo | } |
616 | |||
617 | |||
618 | wxString LauncherApp::checkJava(const wxString aJavaFileName) {
|
||
619 | wxString msg = "";
|
||
620 | wxString version; |
||
621 | 12452 | jmvivo | wxString home; |
622 | |||
623 | |||
624 | 6834 | jmvivo | if (!wxFileExists(aJavaFileName)){
|
625 | return wxString::Format(_("File %s not found."),aJavaFileName.c_str());//_("File %s not found."), javaFileName); |
||
626 | }; |
||
627 | 12452 | jmvivo | |
628 | |||
629 | 6834 | jmvivo | version = getJavaExecFileVersion(aJavaFileName); |
630 | 12452 | jmvivo | |
631 | 6834 | jmvivo | if (version.Cmp("") == 0){ |
632 | return wxString::Format(_("Can't identify version of %s."), aJavaFileName.c_str()); |
||
633 | } |
||
634 | 12452 | jmvivo | |
635 | version = version.Left(paramsJreVersion.Len()); |
||
636 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
640 | 6834 | jmvivo | 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 | 12452 | jmvivo | } |
652 | |||
653 | 6834 | jmvivo | 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 | 12452 | jmvivo | |
683 | 6834 | jmvivo | } |
684 | |||
685 | |||
686 | bool LauncherApp::checkPreviousJRE() {
|
||
687 | wxFileName appHomeJre = paramsJreInstalledRootDirectory; |
||
688 | 12452 | jmvivo | |
689 | 6834 | jmvivo | appHomeJre.MakeAbsolute(); |
690 | 12452 | jmvivo | |
691 | 6834 | jmvivo | if (!appHomeJre.DirExists()) {
|
692 | return false; |
||
693 | } |
||
694 | 12452 | jmvivo | wxString theDir; |
695 | if (paramsJreVersion.Len() > 5){ |
||
696 | theDir = wxString(paramsJreVersion); |
||
697 | } else {
|
||
698 | theDir = paramsJreVersion+"*";
|
||
699 | } |
||
700 | |||
701 | return (!wxFindFirstFile(appHomeJre.GetFullPath()+"/"+theDir,wxDIR).IsEmpty()); |
||
702 | 6834 | jmvivo | } |
703 | |||
704 | wxString LauncherApp::previousJRE() { |
||
705 | 12452 | jmvivo | if (!paramsJreVersionPrefered.IsEmpty()) {
|
706 | 6834 | jmvivo | wxFileName prefered = paramsJreInstalledRootDirectory+"/"+paramsJreVersionPrefered+"/bin/java"; |
707 | prefered.Normalize(); |
||
708 | if (prefered.FileExists()){
|
||
709 | return prefered.GetFullPath();
|
||
710 | } |
||
711 | } |
||
712 | 12452 | jmvivo | wxFileName current; |
713 | |||
714 | |||
715 | 6834 | jmvivo | wxString mask = paramsJreInstalledRootDirectory+"/" + paramsJreVersion + "_%02d/bin/java"; |
716 | for(unsigned i=20;i>1;i--) { |
||
717 | 12452 | jmvivo | |
718 | 6834 | jmvivo | current = wxString::Format(mask,i); |
719 | if (current.FileExists()) {
|
||
720 | return current.GetFullPath();
|
||
721 | } |
||
722 | } |
||
723 | return ""; |
||
724 | } |
||
725 | |||
726 | /**
|
||
727 | wxArrayString getDirectoriesFromPath(wxString path){
|
||
728 | wxArrayString directories;
|
||
729 | 12452 | jmvivo | if (appHome.DirExists()) {
|
730 | 6834 | jmvivo | wxString f = wxFindFirstFile(appHomeJre+"*",wxDIR);
|
731 | while ( !f.IsEmpty() )
|
||
732 | {
|
||
733 | wxArrayString.Add(f);
|
||
734 | f = wxFindNextFile();
|
||
735 | }
|
||
736 | }
|
||
737 | return directories;
|
||
738 | }
|
||
739 | **/
|
||
740 | |||
741 |