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