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