From 2fcf2f359d88b2091c6d2eaedef3d3c26de9daa7 Mon Sep 17 00:00:00 2001 From: coppro Date: Wed, 26 Sep 2007 22:13:39 +0000 Subject: [PATCH] Finished update window (YAY!) Updates now work, and have been tested. Made a few other updates. To work on: aesthetics? git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@759 0fc631ac-6414-0410-93d0-97cfa31319b6 --- data/en.mse-locale/locale | 3 +- src/gui/update_checker.cpp | 125 +++++++++++++++++------ src/gui/update_checker.hpp | 2 +- src/resource/common/expected_locale_keys | 1 + src/util/io/package.cpp | 11 -- src/util/io/package.hpp | 3 - tools/website/create-package-list.pl | 25 +++-- 7 files changed, 112 insertions(+), 58 deletions(-) diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index 979dc0fc..d3399689 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -1,4 +1,4 @@ -mse version: 0.3.5 +mse version: 0.3.5 full name: English version: 2007-09-23 @@ -557,6 +557,7 @@ title: # Package Update Window package list: Package Updates + package type: Package Type package name: Package Name package status: Current Status new status: New Status diff --git a/src/gui/update_checker.cpp b/src/gui/update_checker.cpp index 2c7cdeab..affb095a 100644 --- a/src/gui/update_checker.cpp +++ b/src/gui/update_checker.cpp @@ -18,8 +18,11 @@ #include #include #include -#include +#include +#include #include +#include +#include DECLARE_POINTER_TYPE(PackageVersionData); DECLARE_POINTER_TYPE(Installer); @@ -36,6 +39,8 @@ class PackageVersionData : public IntrusivePtrBase { PackageVersionData() {} String name; ///< Name of the package + String type; ///< Type of package ("magic style" or "game") + String display_name; ///< Name to show on package list. String description; ///< html description String url; ///< Where can the package be downloaded? Version version; ///< Version number of the download @@ -58,6 +63,8 @@ class VersionData : public IntrusivePtrBase { IMPLEMENT_REFLECTION(PackageVersionData) { REFLECT(name); + REFLECT(type); + REFLECT(display_name); REFLECT(description); REFLECT(url); REFLECT(version); @@ -97,7 +104,7 @@ class CheckUpdateThread : public wxThread { public: virtual void* Entry() { Work(); - return 0;; + return 0; } static void Work() { @@ -188,7 +195,7 @@ void show_update_dialog(Window* parent) { class PackageUpdateList : public wxVListBox { public: PackageUpdateList(UpdatesWindow* parent) - : wxVListBox (parent, ID_PACKAGE_LIST, wxDefaultPosition, wxSize(480,210), wxNO_BORDER | wxVSCROLL) + : wxVListBox (parent, ID_PACKAGE_LIST, wxDefaultPosition, wxSize(540,210), wxNO_BORDER | wxVSCROLL) , parent(parent) { if (!checking_updates && !update_version_data) { @@ -266,16 +273,20 @@ class PackageUpdateList : public wxVListBox { #define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color) - dc.SetClippingRegion(wxRect(rect.x, rect.y, rect.width / 2, rect.height)); + dc.SetClippingRegion(wxRect(rect.x, rect.y, 180, rect.height)); dc.SetTextForeground(SELECT_WHITE(packageFront)); - dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop()); + dc.DrawText(pack->display_name, rect.GetLeft() + 1, rect.GetTop()); + dc.DestroyClippingRegion(); + + dc.SetClippingRegion(wxRect(rect.x + 180, rect.y, 120, rect.height)); + dc.DrawText(pack->type, rect.GetLeft() + 180, rect.GetTop()); dc.DestroyClippingRegion(); dc.SetTextForeground(SELECT_WHITE(status_colors[status])); - dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop()); + dc.DrawText(status_texts[status], rect.GetLeft() + 300, rect.GetTop()); dc.SetTextForeground(SELECT_WHITE(action_colors[action])); - dc.DrawText(action_texts[action], rect.GetLeft() + 360, rect.GetTop()); + dc.DrawText(action_texts[action], rect.GetLeft() + 420, rect.GetTop()); #undef SELECT_WHITE } @@ -304,10 +315,43 @@ BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox) EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, wxID_ANY, PackageUpdateList::onUpdateCheckingFinished) END_EVENT_TABLE() +// ----------------------------------------------------------------------------- : RecursiveDelete +// Move somewhere better? + +class RecursiveDeleter : public wxDirTraverser { + public: + set to_delete; + String start_dir; + RecursiveDeleter (String start) + : start_dir (start) + { + to_delete.insert(start_dir); + } + + wxDirTraverseResult OnFile(const String& filename) { + if (!wxRemoveFile(filename)) + handle_error(_("Cannot delete ") + filename + _(". " + "The remainder of the package has still been removed, if possible." + "Other packages may have been removed, including packages that this on is dependent on. Please remove manually.")); + return wxDIR_CONTINUE; + } + + wxDirTraverseResult OnDir(const String& dirname) { + to_delete.insert(dirname); + return wxDIR_CONTINUE; + } + + void finishDelete() { + FOR_EACH_REVERSE(dir, to_delete) { + wxRmdir(dir); + } + } +}; + // ----------------------------------------------------------------------------- : UpdateWindow UpdatesWindow::UpdatesWindow() - : Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(480,440), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN) + : Frame(nullptr, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(540,440), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN) { SetIcon(wxIcon()); wxBoxSizer *v = new wxBoxSizer(wxVERTICAL); @@ -316,38 +360,40 @@ UpdatesWindow::UpdatesWindow() wxBoxSizer *h3 = new wxBoxSizer(wxHORIZONTAL); package_list = new PackageUpdateList(this); - description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(480,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); + description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(540,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); setDefaultPackageStatus(); - package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); + package_title = new wxStaticText(this, wxID_ANY, _TITLE_("package name"), wxDefaultPosition, wxSize(180,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); + type_title = new wxStaticText(this, wxID_ANY, _TITLE_("package type"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); status_title = new wxStaticText(this, wxID_ANY, _TITLE_("package status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); new_title = new wxStaticText(this, wxID_ANY, _TITLE_("new status"), wxDefaultPosition, wxSize(120,15), wxALIGN_LEFT | wxST_NO_AUTORESIZE); - h1->Add(package_title); - h1->Add(status_title); + h1->Add(package_title, 3); + h1->Add(type_title, 2); + h1->Add(status_title, 2); h1->Add(new_title, 2); (install_button = new wxButton(this, ID_INSTALL, _MENU_("install package")))->Disable(); (upgrade_button = new wxButton(this, ID_UPGRADE, _MENU_("upgrade package")))->Disable(); (remove_button = new wxButton(this, ID_REMOVE, _MENU_("remove package")))->Disable(); (cancel_button = new wxButton(this, ID_CANCEL, _MENU_("cancel changes")))->Disable(); - - h2->AddStretchSpacer(1); - h2->Add(install_button); - h2->AddStretchSpacer(2); - h2->Add(upgrade_button); - h2->AddStretchSpacer(2); - h2->Add(remove_button); - h2->AddStretchSpacer(2); - h2->Add(cancel_button); - h2->AddStretchSpacer(1); apply_button = new wxButton(this, ID_APPLY, _MENU_("apply changes")); + + h2->AddStretchSpacer(); + h2->Add(install_button); + h2->AddStretchSpacer(); + h2->Add(upgrade_button); + h2->AddStretchSpacer(); + h2->Add(remove_button); + h2->AddStretchSpacer(); + h2->Add(cancel_button); + h2->AddStretchSpacer(); - h3->AddStretchSpacer(1); + h3->AddStretchSpacer(); h3->Add(apply_button); - h3->AddStretchSpacer(1); + h3->AddStretchSpacer(); v->Add(h1); v->Add(package_list); @@ -429,12 +475,15 @@ void UpdatesWindow::onApplyChanges(wxCommandEvent& ev) { } FOR_EACH(pack, to_remove) { - wxFileName filename (packages.openAny(pack->name, true)->absoluteFilename()); - if (filename.DirExists()) { - // TODO: Recursive removal of directory. + String filename = packages.openAny(pack->name, true)->absoluteFilename(); + if (wxDirExists(filename)) { + wxDir dir(filename); + RecursiveDeleter rd (filename); + dir.Traverse(rd); + rd.finishDelete(); } else { - if (!wxRemoveFile(filename.GetFullPath())) - handle_error(_("Cannot delete ") + filename.GetFullPath() + _(" to remove package ") + pack->name + _(". " + if (!wxRemoveFile(filename)) + handle_error(_("Cannot delete ") + filename + _(" to remove package ") + pack->name + _(". " "Other packages may have been removed, including packages that this on is dependent on. Please remove manually.")); } } @@ -447,18 +496,26 @@ void UpdatesWindow::onApplyChanges(wxCommandEvent& ev) { "Other packages may have been installed, including packages that depend on this one. " "Please remove those packages manually or install this one manually.")); } - wxZipInputStream zis(is); - InstallerP inst(new Installer); + wxString filename = wxFileName::CreateTempFileName(_("")); + wxFileOutputStream os (filename); - inst->openZipStream(&zis); + os.Write(*is); + os.Close(); + + InstallerP inst(new Installer); + inst->open(filename); inst->install(isInstallLocal(settings.install_type), false); + delete is; + wxRemoveFile(filename); } setDefaultPackageStatus(); updateButtons(package_list->GetSelection()); package_list->Refresh(); + handle_pending_errors(); + packages.clearPackageCache(); } @@ -529,7 +586,7 @@ void UpdatesWindow::setDefaultPackageStatus() { */ void UpdatesWindow::SelectPackageDependencies (PackageVersionDataP pack) { FOR_EACH(dep, pack->depends) { - if (packages.checkDependency(*dep)) //It's already installed. + if (packages.checkDependency(*dep, false)) //It's already installed. continue; FOR_EACH(p, update_version_data->packages) { if (p->name == dep->package) { //We have a match. @@ -576,7 +633,7 @@ void UpdatesWindow::DowngradePackageDependencies (PackageVersionDataP pack) { PackagedP old_pack = packages.openAny(pack->name, true); FOR_EACH(dep, old_pack->dependencies) { // dependencies the old version has, but the new one might not. - if (packages.checkDependency(*dep)) //It's already installed. + if (packages.checkDependency(*dep, false)) //It's already installed. continue; FOR_EACH(p, update_version_data->packages) { if (p->name == dep->package) { //We have a match. diff --git a/src/gui/update_checker.hpp b/src/gui/update_checker.hpp index 6e47bc6a..c7e9f0bc 100644 --- a/src/gui/update_checker.hpp +++ b/src/gui/update_checker.hpp @@ -66,7 +66,7 @@ class UpdatesWindow : public Frame { PackageUpdateList* package_list; ///< List of available packages wxHtmlWindow* description_window; - wxStaticText *package_title, *status_title, *new_title; + wxStaticText *package_title, *type_title, *status_title, *new_title; wxButton *install_button, *upgrade_button, *remove_button, *cancel_button, *apply_button; void onUpdateCheckFinished(wxCommandEvent&); diff --git a/src/resource/common/expected_locale_keys b/src/resource/common/expected_locale_keys index 7b8fc482..21f1422b 100644 --- a/src/resource/common/expected_locale_keys +++ b/src/resource/common/expected_locale_keys @@ -375,6 +375,7 @@ title: package list: 0 package name: 0 package status: 0 + package type: 0 preferences: 0 print preview: 0 save changes: 0 diff --git a/src/util/io/package.cpp b/src/util/io/package.cpp index b0116a2d..13ee9c5a 100644 --- a/src/util/io/package.cpp +++ b/src/util/io/package.cpp @@ -85,17 +85,6 @@ void Package::open(const String& n) { } } -void Package::openZipStream(wxZipInputStream* input) { - // close old streams - delete fileStream; fileStream = nullptr; - delete zipStream; - - zipStream = input; - if (!zipStream->IsOk()) throw InternalError(_("Error opening package!")); - - loadZipStream(); -} - void Package::save(bool remove_unused) { assert(!needSaveAs()); saveAs(filename, remove_unused); diff --git a/src/util/io/package.hpp b/src/util/io/package.hpp index c4a3e56c..c37ae079 100644 --- a/src/util/io/package.hpp +++ b/src/util/io/package.hpp @@ -71,9 +71,6 @@ class Package : public IntrusivePtrVirtualBase { /// @pre open not called before [TODO] void open(const String& package); - /// Open a package from a zipstream that doesn't necessarily have a filename (i.e. a URL). - void openZipStream(wxZipInputStream* input); - /// Saves the package, by default saves as a zip file, unless /// it was already a directory /** If remove_unused=true all files that were in the file and diff --git a/tools/website/create-package-list.pl b/tools/website/create-package-list.pl index a4a8f651..ca6c6a19 100644 --- a/tools/website/create-package-list.pl +++ b/tools/website/create-package-list.pl @@ -7,7 +7,7 @@ $url = shift; while ($ARGV = shift) { - $f = $ARGV =~ /(([-a-z]+).mse-(game|style|symbol-font|include|export-template|locale))/; + $f = $ARGV =~ /((([a-z]+)[-a-z]*).mse-(game|style|symbol-font|include|export-template|locale))/; if (!$f) { warn "$ARGV not an appropriate package."; next; @@ -15,19 +15,17 @@ while ($ARGV = shift) { $fullname = $1; $name = $2; + $prefix = $3; + $type = $4; - open(FILE, "$ARGV/$3"); + open(FILE, "$ARGV/$type"); - $version = $msever = $dependencies = ""; + $version = $msever = $dependencies = $shortname = ""; while () { - $version = $1 if /^(?:\xef\xbb\xbf)?version: (.*)$/; - $msever = $1 if /^(?:\xef\xbb\xbf)?mse[ _]version: (.*)$/; while (/^(?:\xef\xbb\xbf)?depends[ _]on:\s*$/) { $dep = $depver = ""; while () { - $version = $1 if /^(?:\xef\xbb\xbf)?version: (.*)$/; - $msever = $1 if /^(?:\xef\xbb\xbf)?mse[ _]version: (.*)$/; last unless /^\t/; $dep = $1 if /^\tpackage: (.*)$/; $depver = $1 if /^\tversion: (.*)$/; @@ -38,6 +36,9 @@ while ($ARGV = shift) { } $dependencies .= "\tdepends on:\n\t\tpackage: $dep\n\t\tversion: $depver\n"; } + $version = $1 if /^(?:\xef\xbb\xbf)?version: (.*)$/; + $msever = $1 if /^(?:\xef\xbb\xbf)?mse[ _]version: (.*)$/; + $shortname = $1 if /^(?:\xef\xbb\xbf)?short[ _]name: (.*)$/; } close(FILE); @@ -48,5 +49,13 @@ while ($ARGV = shift) { next; } - print "package:\n\tname: $fullname\n\turl: $url$name.mse-installer\n\tversion: $version\n\tapp version: $msever\n$dependencies\tdescription:\n\n"; + $shortname = $name unless $shortname; + + if ($type ne "locale" && $type ne "game") { + $packagetype = "$prefix $type"; + } else { + $packagetype = $type; + } + + print "package:\n\tname: $fullname\n\ttype: $packagetype\n\turl: $url$name.mse-installer\n\tversion: $version\n\tapp version: $msever\n$dependencies\tdisplay name: $shortname\n\tdescription:\n\n"; } \ No newline at end of file