Commit 06a9a358 authored by coppro's avatar coppro

Finished update window (YAY!)

Updates now work, and have been tested.
Made a few other updates.
To work on: aesthetics?
parent 108c9727
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
......
......@@ -18,8 +18,11 @@
#include <wx/url.h>
#include <wx/html/htmlwin.h>
#include <wx/vlbox.h>
#include <wx/zipstrm.h>
#include <wx/wfstream.h>
#include <wx/dir.h>
#include <list>
#include <set>
#include <iostream>
DECLARE_POINTER_TYPE(PackageVersionData);
DECLARE_POINTER_TYPE(Installer);
......@@ -36,6 +39,8 @@ class PackageVersionData : public IntrusivePtrBase<PackageVersionData> {
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<VersionData> {
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<String> 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();
apply_button = new wxButton(this, ID_APPLY, _MENU_("apply changes"));
h2->AddStretchSpacer(1);
h2->AddStretchSpacer();
h2->Add(install_button);
h2->AddStretchSpacer(2);
h2->AddStretchSpacer();
h2->Add(upgrade_button);
h2->AddStretchSpacer(2);
h2->AddStretchSpacer();
h2->Add(remove_button);
h2->AddStretchSpacer(2);
h2->AddStretchSpacer();
h2->Add(cancel_button);
h2->AddStretchSpacer(1);
apply_button = new wxButton(this, ID_APPLY, _MENU_("apply changes"));
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);
os.Write(*is);
os.Close();
inst->openZipStream(&zis);
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.
......
......@@ -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&);
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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 (<FILE>) {
$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 (<FILE>) {
$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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment