summaryrefslogtreecommitdiff
path: root/rbutil/rbutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutil.cpp')
-rw-r--r--rbutil/rbutil.cpp150
1 files changed, 69 insertions, 81 deletions
diff --git a/rbutil/rbutil.cpp b/rbutil/rbutil.cpp
index e778cf404e..d7ee3ed529 100644
--- a/rbutil/rbutil.cpp
+++ b/rbutil/rbutil.cpp
@@ -65,28 +65,28 @@ bool InstallTheme(wxString Themesrc)
65 int pos = Themesrc.Find('/',true); 65 int pos = Themesrc.Find('/',true);
66 wxString themename = Themesrc.SubString(pos+1,Themesrc.Length()); 66 wxString themename = Themesrc.SubString(pos+1,Themesrc.Length());
67 67
68 src.Printf(wxT("%s/%s"), gv->themes_url.c_str(),Themesrc.c_str()); 68 src = gv->themes_url + wxT("/") + Themesrc;
69 dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"), 69 dest = gv->stdpaths->GetUserDataDir()
70 gv->stdpaths->GetUserDataDir().c_str(),themename.c_str()); 70 + wxT("" PATH_SEP "download" PATH_SEP) + themename;
71 if( DownloadURL(src, dest) ) 71 if( DownloadURL(src, dest) )
72 { 72 {
73 wxRemoveFile(dest); 73 wxRemoveFile(dest);
74 err.Printf(wxT("Unable to download %s"), src.c_str() ); 74 ERR_DIALOG(wxT("Unable to download ") + src, wxT("Install Theme"));
75 ERR_DIALOG(err, wxT("Install Theme"));
76 return false; 75 return false;
77 } 76 }
78 77
79 if(!checkZip(dest)) 78 if(!checkZip(dest))
80 { 79 {
81 err.Printf(wxT("The Zip %s does not contain the correct dir structure"), dest.c_str()); 80 ERR_DIALOG(wxT("The Zip ") + dest
82 ERR_DIALOG(err, wxT("Install Theme")); 81 + wxT(" does not contain the correct dir structure"),
82 wxT("Install Theme"));
83 return false; 83 return false;
84 } 84 }
85 85
86 if(UnzipFile(dest,gv->curdestdir, true)) 86 if(UnzipFile(dest,gv->curdestdir, true))
87 { 87 {
88 err.Printf(wxT("Unable to unzip %s to %s"), dest.c_str(), gv->curdestdir.c_str()); 88 ERR_DIALOG(wxT("Unable to unzip ") + dest + wxT(" to ")
89 ERR_DIALOG(err, wxT("Install Theme")); 89 + gv->curdestdir, wxT("Install Theme"));
90 return false; 90 return false;
91 } 91 }
92 92
@@ -120,7 +120,7 @@ int DownloadURL(wxString src, wxString dest)
120 wxLogVerbose(wxT("=== begin DownloadURL(%s,%s)"), src.c_str(), 120 wxLogVerbose(wxT("=== begin DownloadURL(%s,%s)"), src.c_str(),
121 dest.c_str()); 121 dest.c_str());
122 122
123 buf.Printf(wxT("Fetching %s"), src.c_str()); 123 buf = wxT("Fetching ") + src;
124 wxProgressDialog* progress = new wxProgressDialog(wxT("Downloading"), 124 wxProgressDialog* progress = new wxProgressDialog(wxT("Downloading"),
125 buf, 100, NULL, wxPD_APP_MODAL | 125 buf, 100, NULL, wxPD_APP_MODAL |
126 wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_ELAPSED_TIME | 126 wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_ELAPSED_TIME |
@@ -174,8 +174,8 @@ int DownloadURL(wxString src, wxString dest)
174 } else 174 } else
175 { 175 {
176 errnum = os->GetLastError(); 176 errnum = os->GetLastError();
177 errstr.Printf(wxT("Can't write to output stream (%s)"), 177 errstr = wxT("Can't write to output stream (")
178 stream_err_str(errnum).c_str() ); 178 + stream_err_str(errnum) + wxT(")");
179 179
180 break; 180 break;
181 } 181 }
@@ -188,8 +188,8 @@ int DownloadURL(wxString src, wxString dest)
188 errnum = 0; 188 errnum = 0;
189 break; 189 break;
190 } 190 }
191 errstr.Printf(wxT("Can't read from input stream (%s)"), 191 errstr = wxT("Can't read from input stream (")
192 stream_err_str(errnum).c_str() ); 192 + stream_err_str(errnum) + wxT(")");
193 } 193 }
194 } 194 }
195 195
@@ -197,8 +197,8 @@ int DownloadURL(wxString src, wxString dest)
197 if (! errnum) 197 if (! errnum)
198 { 198 {
199 errnum = os->GetLastError(); 199 errnum = os->GetLastError();
200 errstr.Printf(wxT("Can't close output file (%s)"), 200 errstr = wxT("Can't close output file (")
201 stream_err_str(errnum).c_str() ); 201 + stream_err_str(errnum) + wxT(")");
202 202
203 input = false; 203 input = false;
204 } 204 }
@@ -208,9 +208,8 @@ int DownloadURL(wxString src, wxString dest)
208 } else 208 } else
209 { 209 {
210 errnum = is->GetLastError(); 210 errnum = is->GetLastError();
211 errstr.Printf(wxT("Can't get input stream size (%s)"), 211 errstr = wxT("Can't get input stream size (")
212 stream_err_str(errnum).c_str() ); 212 + stream_err_str(errnum) + wxT(")");
213
214 } 213 }
215 } else 214 } else
216 { 215 {
@@ -221,8 +220,8 @@ int DownloadURL(wxString src, wxString dest)
221 } else 220 } else
222 { 221 {
223 errnum = os->GetLastError(); 222 errnum = os->GetLastError();
224 errstr.Printf(wxT("Can't create output stream (%s)"), 223 errstr = wxT("Can't create output stream (")
225 stream_err_str(errnum).c_str() ); 224 + stream_err_str(errnum) + wxT(")");
226 } 225 }
227 delete os; 226 delete os;
228 } else 227 } else
@@ -240,14 +239,11 @@ int DownloadURL(wxString src, wxString dest)
240 if (errnum == 0) errnum = 999; 239 if (errnum == 0) errnum = 999;
241 if (input) 240 if (input)
242 { 241 {
243 buf.Printf(wxT("%s reading\n%s"), 242 ERR_DIALOG(errstr + wxT(" reading\n") + src, wxT("Download URL"));
244 errstr.c_str(), src.c_str());
245 ERR_DIALOG(buf, wxT("Download URL"));
246 } else 243 } else
247 { 244 {
248 buf.Printf(wxT("%s writing to download\n/%s"), 245 ERR_DIALOG(errstr + wxT("writing to download\n/") + dest,
249 errstr.c_str(), dest.c_str()); 246 wxT("Download URL"));
250 ERR_DIALOG(buf, wxT("Download URL"));
251 } 247 }
252 248
253 } 249 }
@@ -273,9 +269,9 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
273 if (! in_zip->IsOk() ) 269 if (! in_zip->IsOk() )
274 { 270 {
275 errnum = in_zip->GetLastError(); 271 errnum = in_zip->GetLastError();
276 buf.Printf(wxT("Can't open ZIP stream %s for reading (%s)"), 272 ERR_DIALOG(wxT("Can't open ZIP stream ") + src
277 src.c_str(), stream_err_str(errnum).c_str() ); 273 + wxT(" for reading (") + stream_err_str(errnum)
278 ERR_DIALOG(buf, wxT("Unzip File") ); 274 + wxT(")"), wxT("Unzip File") );
279 delete in_zip; 275 delete in_zip;
280 delete in_file; 276 delete in_file;
281 return true; 277 return true;
@@ -285,9 +281,9 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
285 if (! in_zip->IsOk() ) 281 if (! in_zip->IsOk() )
286 { 282 {
287 errnum = in_zip->GetLastError(); 283 errnum = in_zip->GetLastError();
288 buf.Printf(wxT("Error Getting total ZIP entries for %s (%s)"), 284 ERR_DIALOG( wxT("Error Getting total ZIP entries for ")
289 src.c_str(), stream_err_str(errnum).c_str() ); 285 + src + wxT(" (") + stream_err_str(errnum) + wxT(")"),
290 ERR_DIALOG(buf, wxT("Unzip File") ); 286 wxT("Unzip File") );
291 delete in_zip; 287 delete in_zip;
292 delete in_file; 288 delete in_file;
293 return true; 289 return true;
@@ -295,9 +291,8 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
295 } else 291 } else
296 { 292 {
297 errnum = in_file->GetLastError(); 293 errnum = in_file->GetLastError();
298 buf.Printf(wxT("Can't open %s (%s)"), src.c_str(), 294 ERR_DIALOG(wxT("Can't open ") + src + wxT(" (")
299 stream_err_str(errnum).c_str() ); 295 + stream_err_str(errnum) + wxT(")"), wxT("Unzip File") );
300 ERR_DIALOG(buf, wxT("Unzip File") );
301 delete in_zip; 296 delete in_zip;
302 delete in_file; 297 delete in_file;
303 return true; 298 return true;
@@ -313,8 +308,7 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
313 // We're not overly worried if the logging fails 308 // We're not overly worried if the logging fails
314 if (isInstall) 309 if (isInstall)
315 { 310 {
316 buf.Printf(wxT("%s" PATH_SEP UNINSTALL_FILE), destdir.c_str()); 311 log = new InstallLog(destdir + wxT("" PATH_SEP UNINSTALL_FILE));
317 log = new InstallLog(buf);
318 } 312 }
319 313
320 while (! errnum && 314 while (! errnum &&
@@ -323,21 +317,19 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
323 317
324 curfile++; 318 curfile++;
325 wxString name = entry->GetName(); 319 wxString name = entry->GetName();
326 progress_msg.Printf(wxT("Unpacking %s"), name.c_str()); 320 progress_msg = wxT("Unpacking ") + name;
327 if (! progress->Update(curfile, progress_msg) ) { 321 if (! progress->Update(curfile, progress_msg) ) {
328 buf.Printf(wxT("Unpacking cancelled by user")); 322 MESG_DIALOG(wxT("Unpacking cancelled by user"));
329 MESG_DIALOG(buf);
330 errnum = 1000; 323 errnum = 1000;
331 break; 324 break;
332 } 325 }
333 326
334 in_str.Printf(wxT("%s" PATH_SEP "%s"), destdir.c_str(), name.c_str()); 327 in_str = destdir + wxT("" PATH_SEP) + name;
335 328
336 if (entry->IsDir() ) { 329 if (entry->IsDir() ) {
337 if (!wxDirExists(in_str) ) { 330 if (!wxDirExists(in_str) ) {
338 if (! wxMkdir(in_str, 0777) ) { 331 if (! wxMkdir(in_str, 0777) ) {
339 buf.Printf(wxT("Unable to create directory %s"), 332 buf = wxT("Unable to create directory ") + in_str;
340 in_str.c_str() );
341 errnum = 100; 333 errnum = 100;
342 break; 334 break;
343 } 335 }
@@ -349,7 +341,7 @@ int UnzipFile(wxString src, wxString destdir, bool isInstall)
349 wxFFileOutputStream* out = new wxFFileOutputStream(in_str); 341 wxFFileOutputStream* out = new wxFFileOutputStream(in_str);
350 if (! out->IsOk() ) 342 if (! out->IsOk() )
351 { 343 {
352 buf.Printf(wxT("Can't open file %s for writing"), in_str.c_str() ); 344 buf = wxT("Can't open file ") + in_str + wxT(" for writing");
353 delete out; 345 delete out;
354 return 100; 346 return 100;
355 } else if (isInstall) 347 } else if (isInstall)
@@ -410,7 +402,7 @@ int Uninstall(const wxString dir, bool isFullUninstall) {
410 if (! isFullUninstall) 402 if (! isFullUninstall)
411 { 403 {
412 404
413 buf.Printf(wxT("%s" PATH_SEP UNINSTALL_FILE), dir.c_str()); 405 buf = dir + wxT("" PATH_SEP UNINSTALL_FILE);
414 log = new InstallLog(buf, false); // Don't create the log 406 log = new InstallLog(buf, false); // Don't create the log
415 FilesToRemove = log->GetInstalledFiles(); 407 FilesToRemove = log->GetInstalledFiles();
416 if (log) delete log; 408 if (log) delete log;
@@ -439,7 +431,7 @@ int Uninstall(const wxString dir, bool isFullUninstall) {
439 431
440 if (isFullUninstall ) 432 if (isFullUninstall )
441 { 433 {
442 buf.Printf(wxT("%s" PATH_SEP ".rockbox"), dir.c_str()); 434 buf = dir + wxT("" PATH_SEP ".rockbox");
443 if (rm_rf(buf) ) 435 if (rm_rf(buf) )
444 { 436 {
445 WARN_DIALOG(wxT("Unable to completely remove Rockbox directory"), 437 WARN_DIALOG(wxT("Unable to completely remove Rockbox directory"),
@@ -473,8 +465,8 @@ int Uninstall(const wxString dir, bool isFullUninstall) {
473 { 465 {
474 if (! wxRemoveFile((*special)[i]) ) 466 if (! wxRemoveFile((*special)[i]) )
475 { 467 {
476 buf.Printf(wxT("Can't delete %s"), (*special)[i].c_str()); 468 WARN_DIALOG(wxT("Can't delete ") + (*special)[i],
477 WARN_DIALOG(buf.c_str(), wxT("Full uninstall")); 469 wxT("Full uninstall"));
478 errflag = true; 470 errflag = true;
479 } 471 }
480 } 472 }
@@ -500,7 +492,7 @@ int Uninstall(const wxString dir, bool isFullUninstall) {
500 } 492 }
501 493
502 wxString* buf2 = new wxString; 494 wxString* buf2 = new wxString;
503 buf.Printf(wxT("%s%s"), dir.c_str() , FilesToRemove->Item(i).c_str() ); 495 buf = dir + FilesToRemove->Item(i);
504 buf2->Format(wxT("Deleting %s"), buf.c_str()); 496 buf2->Format(wxT("Deleting %s"), buf.c_str());
505 497
506 if (! progress->Update((i + 1) * 100 / totalfiles, *buf2) ) 498 if (! progress->Update((i + 1) * 100 / totalfiles, *buf2) )
@@ -514,10 +506,10 @@ int Uninstall(const wxString dir, bool isFullUninstall) {
514 { 506 {
515 // If we're about to attempt to remove .rockbox. delete 507 // If we're about to attempt to remove .rockbox. delete
516 // install data first 508 // install data first
517 buf2->Printf(wxT("%s" PATH_SEP ".rockbox"), dir.c_str() ); 509 *buf2 = dir + wxT("" PATH_SEP ".rockbox");
518 if ( buf.IsSameAs(buf2->c_str()) ) 510 if ( buf.IsSameAs(buf2->c_str()) )
519 { 511 {
520 buf2->Printf(wxT("%s" PATH_SEP UNINSTALL_FILE), dir.c_str()); 512 *buf2 = dir +wxT("" PATH_SEP UNINSTALL_FILE);
521 wxRemoveFile(*buf2); 513 wxRemoveFile(*buf2);
522 } 514 }
523 515
@@ -595,7 +587,7 @@ bool InstallRbutil(wxString dest)
595 bool copied_exe = false, made_rbdir = false; 587 bool copied_exe = false, made_rbdir = false;
596 InstallLog* log; 588 InstallLog* log;
597 589
598 buf.Printf(wxT("%s" PATH_SEP ".rockbox"), dest.c_str() ); 590 buf = dest + wxT("" PATH_SEP ".rockbox");
599 591
600 if (! wxDirExists(buf) ) 592 if (! wxDirExists(buf) )
601 { 593 {
@@ -603,18 +595,17 @@ bool InstallRbutil(wxString dest)
603 made_rbdir = true; 595 made_rbdir = true;
604 } 596 }
605 597
606 buf.Printf(wxT("%s" PATH_SEP UNINSTALL_FILE), dest.c_str() ); 598 buf = dest + wxT("" PATH_SEP UNINSTALL_FILE);
607 log = new InstallLog(buf); 599 log = new InstallLog(buf);
608 if (made_rbdir) log->WriteFile(wxT(".rockbox"), true); 600 if (made_rbdir) log->WriteFile(wxT(".rockbox"), true);
609 601
610 destdir.Printf(wxT("%s" PATH_SEP "RockboxUtility"), dest.c_str()); 602 destdir = dest + wxT("" PATH_SEP "RockboxUtility");
611 if (! wxDirExists(destdir) ) 603 if (! wxDirExists(destdir) )
612 { 604 {
613 if (! wxMkdir(destdir, 0777) ) 605 if (! wxMkdir(destdir, 0777) )
614 { 606 {
615 buf.Printf(wxT("%s (%s)"), 607 WARN_DIALOG( wxT("Unable to create directory for installer (")
616 wxT("Unable to create directory for installer"), destdir.c_str()); 608 + destdir + wxT(")"), wxT("Portable install") );
617 WARN_DIALOG(buf , wxT("Portable install") );
618 return false; 609 return false;
619 } 610 }
620 log->WriteFile(wxT("RockboxUtility"), true); 611 log->WriteFile(wxT("RockboxUtility"), true);
@@ -636,13 +627,13 @@ bool InstallRbutil(wxString dest)
636 copied_exe = true; 627 copied_exe = true;
637 } 628 }
638 629
639 dstr.Printf(wxT("%s" PATH_SEP "%s"), destdir.c_str(), 630 dstr = destdir + wxT("" PATH_SEP)
640 filestocopy[i].AfterLast(PATH_SEP_CHR).c_str()); 631 + filestocopy[i].AfterLast(PATH_SEP_CHR);
641 if (! wxCopyFile(filestocopy[i], dstr) ) 632 if (! wxCopyFile(filestocopy[i], dstr) )
642 { 633 {
643 buf.Printf(wxT("%s (%s -> %s)"), 634 WARN_DIALOG( wxT("Error copying file (")
644 wxT("Error copying file"), filestocopy[i].c_str(), dstr.c_str()); 635 + filestocopy[i].c_str() + wxT(" -> ")
645 WARN_DIALOG(buf, wxT("Portable Install") ); 636 + dstr + wxT(")"), wxT("Portable Install") );
646 return false; 637 return false;
647 } 638 }
648 buf = dstr; 639 buf = dstr;
@@ -652,13 +643,12 @@ bool InstallRbutil(wxString dest)
652 643
653 if (! copied_exe) 644 if (! copied_exe)
654 { 645 {
655 str.Printf(wxT("%s" PATH_SEP EXE_NAME), gv->AppDir.c_str()); 646 str = gv->AppDir + wxT("" PATH_SEP EXE_NAME);
656 dstr.Printf(wxT("%s" PATH_SEP EXE_NAME), destdir.c_str()); 647 dstr = destdir + wxT("" PATH_SEP EXE_NAME);
657 if (! wxCopyFile(str, dstr) ) 648 if (! wxCopyFile(str, dstr) )
658 { 649 {
659 buf.Printf(wxT("Can't copy program binary %s -> %s"), 650 WARN_DIALOG(wxT("Can't copy program binary ")
660 str.c_str(), dstr.c_str() ); 651 + str + wxT(" -> ") + dstr, wxT("Portable Install") );
661 WARN_DIALOG(buf, wxT("Portable Install") );
662 return false; 652 return false;
663 } 653 }
664 buf = dstr; 654 buf = dstr;
@@ -668,13 +658,12 @@ bool InstallRbutil(wxString dest)
668 658
669 // Copy the local ini file so that it knows that it's a portable copy 659 // Copy the local ini file so that it knows that it's a portable copy
670 gv->UserConfig->Flush(); 660 gv->UserConfig->Flush();
671 dstr.Printf(wxT("%s" PATH_SEP "RockboxUtility.cfg"), destdir.c_str()); 661 dstr = destdir + wxT("" PATH_SEP "RockboxUtility.cfg");
672 if (! wxCopyFile(gv->UserConfigFile, dstr) ) 662 if (! wxCopyFile(gv->UserConfigFile, dstr) )
673 { 663 {
674 buf.Printf(wxT("%s (%s -> %s)"), 664 WARN_DIALOG(wxT("Unable to install user config file (")
675 wxT("Unable to install user config file"), gv->UserConfigFile.c_str(), 665 + gv->UserConfigFile + wxT(" -> ") + dstr + wxT(")"),
676 dstr.c_str() ); 666 wxT("Portable Install") );
677 WARN_DIALOG(buf, wxT("Portable Install") );
678 return false; 667 return false;
679 } 668 }
680 buf = dstr; 669 buf = dstr;
@@ -718,7 +707,7 @@ bool rm_rf(wxString file)
718 wxLogVerbose(selected[i]); 707 wxLogVerbose(selected[i]);
719 if (progress != NULL) 708 if (progress != NULL)
720 { 709 {
721 buf.Printf(wxT("Deleting %s"), selected[i].c_str() ); 710 buf = wxT("Deleting ") + selected[i];
722 if (! progress->Update(i, buf)) 711 if (! progress->Update(i, buf))
723 { 712 {
724 WARN_DIALOG(wxT("Cancelled by user"), wxT("Erase Files")); 713 WARN_DIALOG(wxT("Cancelled by user"), wxT("Erase Files"));
@@ -731,23 +720,22 @@ bool rm_rf(wxString file)
731 { 720 {
732 if ((rc = ! wxRmdir(selected[i])) ) 721 if ((rc = ! wxRmdir(selected[i])) )
733 { 722 {
734 buf.Printf(wxT("Can't remove directory %s"),
735 selected[i].c_str());
736 errflag = true; 723 errflag = true;
737 WARN_DIALOG(buf.c_str(), wxT("Erase files")); 724 WARN_DIALOG(wxT("Can't remove directory ") + selected[i],
725 wxT("Erase files"));
738 } 726 }
739 } else if ((rc = ! wxRemoveFile(selected[i])) ) 727 } else if ((rc = ! wxRemoveFile(selected[i])) )
740 { 728 {
741 buf.Printf(wxT("Error deleting file %s"), selected[i].c_str() );
742 errflag = true; 729 errflag = true;
743 WARN_DIALOG(buf.c_str(),wxT("Erase files")); 730 WARN_DIALOG(wxT("Error deleting file ") + selected[i],
731 wxT("Erase files"));
744 } 732 }
745 } 733 }
746 delete progress; 734 delete progress;
747 } else 735 } else
748 { 736 {
749 buf.Printf(wxT("Can't find expected file %s"), file.c_str()); 737 WARN_DIALOG(wxT("Can't find expected file ") + file,
750 WARN_DIALOG(buf.c_str(), wxT("Erase files")); 738 wxT("Erase files"));
751 return true; 739 return true;
752 } 740 }
753 741