Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / install / launcher / izpack-launcher-1.3_linux / src / launcher.cpp @ 8745

History | View | Annotate | Download (18.7 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

    
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: 8745 $
144
 *
145
 * $Id: launcher.cpp 8745 2006-11-14 13:14:23Z  $
146
 */
147
LauncherApp::LauncherApp()
148
  : wxApp()
149
{
150
  APPLICATION_NAME = wxString(_("gvSIG Install-Launcher"));
151
  
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",                    &paramsJar,                wxEmptyString);
207
  cfg.Read( "jre",                    &paramsJre,                wxEmptyString);
208
  cfg.Read( "downloadJre",            &paramsJreDownload,        wxEmptyString);
209
  cfg.Read( "installJreCmd",            &paramsJreInstallCmd,        wxEmptyString);
210
  cfg.Read( "installedJreJavaFile",            &paramsJreInstalledJavaFile,        wxEmptyString);
211
  cfg.Read( "installedJreRootDirectory",            &paramsJreInstalledRootDirectory,        wxEmptyString);
212
  cfg.Read( "jre_version",            &paramsJreVersion,         wxEmptyString);
213
  cfg.Read( "jre_version_prefered",   &paramsJreVersionPrefered, wxEmptyString);
214
  cfg.Read( "jarParams",              &paramsJarParams,          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
  showStatusMsg(_("Launching installation..."));
326
  if (!wxFile::Exists(paramsJar))
327
  {
328
    error(_("The jar-file in the configuration file ") + cfgName + _(" does not exist."));
329
  }
330

    
331
  wxString cmd = "export  JAVA_HOME=\"" +  getJavaExecFileHome(javaExecPath) + "\"; exec " + javaExecPath + paramsJarParams + wxString(" -jar ") + paramsJar;
332
  //echo(cmd);
333
  if (paramsLaunchJarAsync) {
334
      if (!run_external_async(cmd))
335
      {
336
        error(_("The jar-file ") + paramsJar + _(" could not be executed." ));
337
      }
338
  } else {
339
      if (!run_external(cmd))
340
      {
341
        error(_("The jar-file ") + paramsJar + _(" could not be executed." ));
342
      }  
343
  }
344

    
345
}
346

    
347
wxString LauncherApp::installJRE(){
348
        showStatusMsg(_("Preparing to install JRE..."));
349

    
350
        if (!checkInstallerFile(paramsJre, paramsJreDownload,_("Java JRE version ")+paramsJreVersion))
351
        {
352
                notifyErrorToUser(_("The JRE could not be setup."));
353
                return "";
354
        }
355

    
356
        showStatusMsg(_("Installing JRE..."));
357

    
358
        if (!run_external(paramsJreInstallCmd))
359
        {
360
                notifyErrorToUser(_("The JRE could not be setup."));
361
                return "";
362
        }
363

    
364
        if (!wxFileExists(paramsJreInstalledJavaFile)){
365
                notifyErrorToUser(wxString::Format(_("The file %s does not exist."),paramsJreInstalledJavaFile.c_str()));
366
                return "";
367
          }
368

    
369
  return paramsJreInstalledJavaFile;
370

    
371
}
372

    
373
IMPLEMENT_APP(LauncherApp)
374

    
375
bool LauncherApp::downloadFileHttp(const wxString urlOfFile, const wxString filePath, const wxString msg){
376

    
377
  bool isOk;
378
  //echo(urlOfFile);
379
  if (urlOfFile == wxEmptyString) {
380
     return false;
381
  }
382
  
383
  if (filePath == wxEmptyString) {
384
     return false;
385
  }
386
  
387
  showStatusMsg(msg);
388
  wxURL url(urlOfFile);
389
  //echo("url open");
390
  wxInputStream *in_stream;
391

    
392
  in_stream = url.GetInputStream();
393
  //echo("in_stream open");
394
  if (!in_stream){
395
        return false;
396
  }
397
  if (!in_stream->IsOk()) {
398
     //echo("in_stream.IsOk == false");
399
     return false;
400
  }
401
  //echo("in_stream.IsOk == true");
402
  //echo("filePath =" + filePath);
403
  wxFileName fileName(filePath); 
404
  wxFileName fileDir(fileName.GetPath()); 
405
  if (!fileDir.DirExists()) {
406
        if (!fileDir.Mkdir(0777,wxPATH_MKDIR_FULL )) {
407
                return false;
408
        }
409
  }
410
  /*
411
  // Preparamos la ruta para el fichero destino
412
  wxArrayString dirs;
413
  
414
  dirs = fileName.GetDirs();
415
  wxString dir;
416
  wxFileName curDir(".");
417
  for (size_t i=0; i < dirs.GetCount(); i++) {
418
      dir = dirs.Item(i);
419
      curDir.AppendDir(dir);
420
      //echo("dir " + curDir.GetPath());
421
      if (!curDir.DirExists()) {
422
         //echo("creating dir");
423
         isOk = curDir.Mkdir();
424
         if (!isOk) {
425
            //echo("dir create no ok");
426
            return false;
427
         }
428
         
429
         //echo("dir create ok");
430
      }
431
  }
432
  */
433
  
434
  wxFileOutputStream out_stream  = wxFileOutputStream(filePath);
435
  //echo("out_stream open");
436

    
437
  //in_stream->Read(out_stream);
438
  size_t nbytes = 10240;
439
  char buffer[nbytes];
440

    
441
 
442
  while (!in_stream->Eof()) {
443
      in_stream->Read(&buffer,nbytes);  
444
      if (in_stream->LastError() != wxSTREAM_NO_ERROR && in_stream->LastError() != wxSTREAM_EOF) {
445
          return false;
446
      }
447
      out_stream.Write(&buffer,in_stream->LastRead());
448
      if (out_stream.LastError() != wxSTREAM_NO_ERROR) {
449
         return false;
450
      }
451
      int totalKb = out_stream.GetSize() / 1024;
452
      wxString totalMsg =wxString::Format("%i",totalKb);
453
      showStatusMsg(msg+" "+ totalMsg + " Kb");
454

    
455
  }
456
 
457
  
458
  isOk = true;
459
 /*
460
  if (isOk) {
461
    echo("isOk = true");
462
  } else {
463
    echo("isOk = false");
464
  }
465
 */
466
  delete in_stream;
467
  
468
  //echo("end");
469
  return isOk;
470

    
471
}
472

    
473
bool LauncherApp::checkInstallerFile(const wxString filePath, const wxString urlDownload, const wxString fileDescription) {
474
  if (!wxFile::Exists(filePath))
475
  {
476
    if (paramsEnabledDownload) 
477
    {
478
      wxString msg;
479
      msg = wxString::Format(_("The installation requires to download this file:\n%s\nDo you want to continue?"),fileDescription.c_str());
480
      confirm(msg);
481
      msg = wxString::Format(_("Downloading %s..."),fileDescription.c_str());
482
      if (!downloadFileHttp(urlDownload,filePath,msg)) 
483
      {
484
        //FIXME: Falta msgError
485
        return false;
486
      }
487
    }
488
    else
489
    {
490
      return false;
491
    }
492

    
493
  }
494
  return true;
495
}
496

    
497
void LauncherApp::showStatusMsg(const wxString msg) {
498
  if (isStatusDialogVisible) {
499
     while (this->Pending()) {
500
           this->Dispatch();
501
     }
502
     if (statusDialog->IsCanceled()) {
503
        int response;
504
        wxMessageDialog dlg(0, _("Are you sure you want to cancel installation?"), _(APPLICATION_NAME), wxYES_NO | wxICON_QUESTION );
505
        response = dlg.ShowModal();
506
        if (response == wxID_YES) {
507
            notifyToUser(_("Canceled by the user"));
508
            exit(1);
509
        }
510
        statusDialog->DoNotCancel();
511
     }
512
     statusDialog->showStatus(msg);
513
  }
514
}
515

    
516
void LauncherApp::run(){
517
  bool ok = false;
518
  
519
  wxString mJavaFileName;
520
  wxString errorMsg;
521
  SelectionDialog  dlg( checkPreviousJRE(),checkEnvironmentJRE() ,_(APPLICATION_NAME));
522
  while (!ok) {
523
        //applyFont(&dlg,font);
524
        if (dlg.ShowModal() != wxID_OK){
525
                notifyToUser(_("Canceled by the user"));
526
                exit(1);
527
        }
528
        switch (dlg.getUserAction())
529
        {
530
                case PREVIOUS_GVSIG:  mJavaFileName = previousJRE(); break;
531
                case PROVIDED: mJavaFileName = installJRE();   break;
532
                case SELECT_MANUALY: mJavaFileName = selectJavaExecFileManualy();  break;
533
                case ENVIRON: mJavaFileName = useEnvironJRE();  break;
534
                default: break;
535
        }
536
        if (mJavaFileName.Cmp("") == 0) {
537
                wxString msg =wxString::Format(_("Error executing this installation option. Do you want to try another one?"),errorMsg.c_str());
538
                confirm(msg);
539
        } else {                
540
                //echo("checking..." + mJavaFileName);
541
                errorMsg = checkJava(mJavaFileName);                
542
                //echo("check result: *"+errorMsg+"*");
543
                if (errorMsg.Cmp("") == 0) {
544
                        javaExecPath=mJavaFileName;
545
                        ok=true;
546
                } else {
547
                        wxString msg =wxString::Format(_("Problems found in the selected JRE:\n%s\n\nDo you want to continue?"),errorMsg.c_str());
548
                        if (confirmYesNoCancel(msg,false)) {
549
                                javaExecPath=mJavaFileName;
550
                                ok=true;        
551
                        }
552
                }
553
        }
554
  }
555
  runJRE();
556

    
557
  exit(0);    
558
     
559
}
560

    
561
void LauncherApp::OnTimer(wxTimerEvent& event) {     
562
     run();
563
}
564

    
565
wxString LauncherApp::selectJavaExecFileManualy() {     
566
    wxString msgDir = _("Manually select the Java VM");   
567
    wxFileDialog dlg(
568
        0,
569
        msgDir,
570
        wxEmptyString, 
571
        wxString("java"),
572
        wxString( wxString(_("Java VM executable file")) + " (java)|java"),
573
        wxOPEN | wxFILE_MUST_EXIST,
574
        wxDefaultPosition
575
    );
576
    //applyFont(&dlg,font);
577

    
578

    
579
    int response = dlg.ShowModal();
580
    if (response != wxID_OK) {
581
       notifyToUser(_("Canceled by the user"));
582
       exit(1);
583
    }
584
    return dlg.GetPath();
585
}
586

    
587

    
588
wxString LauncherApp::getJavaExecFileVersion(wxString javaFileName) {
589
        wxArrayString output, errors;        
590
        wxString cmd =javaFileName + " GetJavaSystemProperties java.version";
591
        //echo(cmd);
592
        if (!run_external_withOut(cmd,output, errors)) {
593
                return "";
594
        }
595
        if (output.Count() == 0){
596
                return "";
597
        }
598
        return output[0];
599
        
600
}
601

    
602
wxString LauncherApp::getJavaExecFileHome(wxString javaFileName) {
603
        wxArrayString output, errors;
604
        wxString cmd =javaFileName + " GetJavaSystemProperties java.home";
605
        if (!run_external_withOut(cmd,output, errors)) {
606
                return "";
607
        }
608
        if (output.Count() == 0){
609
                return "";
610
        }        
611
        return output[0];
612
        
613
}
614

    
615

    
616
wxString LauncherApp::checkJava(const wxString aJavaFileName) {
617
        wxString msg = "";
618
        wxString version;
619
        wxString home;        
620
        
621
        
622
        if (!wxFileExists(aJavaFileName)){
623
                return wxString::Format(_("File %s not found."),aJavaFileName.c_str());//_("File %s not found."), javaFileName);
624
        };
625
        
626
        
627
        version = getJavaExecFileVersion(aJavaFileName);
628
        
629
        if (version.Cmp("") == 0){
630
                return wxString::Format(_("Can't identify version of %s."), aJavaFileName.c_str());
631
        }
632
        
633
        version = version.Left(5);
634
        if (!compareVersions(version,paramsJreVersion)) {
635
                msg = "\n" + wxString::Format(_("Java version %s is not the required %s"),version.c_str(),paramsJreVersion.c_str());
636
        }
637
        
638
        home = getJavaExecFileHome(aJavaFileName);
639
        if (home.Cmp("") == 0){
640
                return wxString::Format(_("Can't identify java_home of %s."), aJavaFileName.c_str());
641
        }
642
        // comprobamos JAI
643
        if (!wxFileExists(home + "/lib/ext/jai_core.jar")) {
644
                msg = msg +"\n" + _("The JAI library is not installed");
645
        }
646
        // comprobamos JAI i/o
647
                if (!wxFileExists(home + "/lib/ext/jai_imageio.jar")) {
648
                msg = msg +"\n" + _("The JAI I/O library is not installed");
649
        }        
650
        
651
        return msg;
652
}
653

    
654
bool LauncherApp::checkEnvironmentJRE() {
655
        return (useEnvironJRE().Cmp("") != 0);
656
}
657

    
658
wxString  LauncherApp::useEnvironJRE() {
659
        wxString envJavaHome;
660
        if (wxGetEnv("JAVA_HOME",&envJavaHome)){
661
                //echo("no Java Home get");
662
                if (!envJavaHome.Cmp("") == 0) {
663
                        return envJavaHome + "/bin/java";
664
                }
665
                //echo("no Java Home blank");
666
        }
667
        //echo("no Java Home");
668

    
669
        wxArrayString output, errors;
670
        if (run_external_withOut("/bin/sh -c 'type -p java'",output, errors)) {
671
                //printf("ouput.Count() = %i",output.Count());
672
                //printf("errors.Count() = %i",errors.Count());
673
                if (output.Count() != 0){
674
                        return output[0];
675
                }
676
                //echo("no Java in path count=0");
677
        }
678
        //echo("no Java in path");
679
        return "";
680
        
681
}
682

    
683

    
684
bool LauncherApp::checkPreviousJRE() {
685
        wxFileName appHomeJre = paramsJreInstalledRootDirectory;
686
        
687
        appHomeJre.MakeAbsolute();
688
        
689
        if (!appHomeJre.DirExists())  {
690
                return false;
691
        }
692
        
693
        
694
        
695
        return (!wxFindFirstFile(appHomeJre.GetFullPath()+"/"+paramsJreVersion+"*",wxDIR).IsEmpty()); 
696
}
697

    
698
wxString  LauncherApp::previousJRE() {
699
        if (paramsJreVersionPrefered.IsEmpty()) {
700
                wxFileName prefered = paramsJreInstalledRootDirectory+"/"+paramsJreVersionPrefered+"/bin/java";
701
                prefered.Normalize();
702
                if (prefered.FileExists()){
703
                        return prefered.GetFullPath();
704
                }
705
        }
706
        wxString mask = paramsJreInstalledRootDirectory+"/" + paramsJreVersion + "_%02d/bin/java";
707
        for(unsigned i=20;i>1;i--) {
708
                wxFileName current;
709
                current = wxString::Format(mask,i);
710
                if (current.FileExists()) {
711
                        return current.GetFullPath();
712
                }
713
        }
714
        return "";
715
}
716

    
717
/**
718
wxArrayString getDirectoriesFromPath(wxString path){
719
        wxArrayString directories;
720
        if (appHome.DirExists())  {                
721
                wxString f = wxFindFirstFile(appHomeJre+"*",wxDIR);
722
                while ( !f.IsEmpty() )
723
                {
724
                        wxArrayString.Add(f);
725
                        f = wxFindNextFile();
726
                }
727
        }
728
        return directories;
729
}
730
**/
731

    
732

    
733