Commit 3ac67c71 authored by coppro's avatar coppro

Made it so that update window and set window can't be open simultaneously...

Made it so that update window and set window can't be open simultaneously (don't explode the set by deleting the style, say).
Made update window enforce dependencies
Added update button to welcome window (need icon still)
parent 87184ad3
......@@ -116,7 +116,7 @@ help:
export images: Export images for all cards
export apprentice: Export the set so it can be played with in Apprentice
export mws: Export the set so it can be played with in Magic Workstation
check updates: Open the update window to download new packages, such as games, styles, and locales.
check updates: Install/update packages.
print preview: Shows cards as they will be printed
print: Print cards from this set
reload data: Reload all template files (game and style) as well as the set.
......@@ -476,6 +476,7 @@ button:
# Welcome
new set: New set
open set: Open set
check updates: Check updates
last opened set: Last opened set
# Preferences
......
......@@ -374,7 +374,6 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
case ID_FILE_EXPORT_IMAGE: ev.Enable(!!current_panel->selectedCard()); break;
case ID_FILE_EXPORT_APPR: ev.Enable(set->game->isMagic()); break;
case ID_FILE_EXPORT_MWS: ev.Enable(set->game->isMagic()); break;
case ID_FILE_CHECK_UPDATES:ev.Enable(false); break; // no update checking in 0.3.5
case ID_FILE_EXIT:
// update for ID_FILE_RECENT done for a different id, because ID_FILE_RECENT may not be in the menu yet
updateRecentSets();
......@@ -538,7 +537,9 @@ void SetWindow::onFileExportMWS(wxCommandEvent&) {
}
void SetWindow::onFileCheckUpdates(wxCommandEvent&) {
if (!askSaveAndContinue()) return;
(new UpdatesWindow)->Show();
Destroy();
}
void SetWindow::onFilePrint(wxCommandEvent&) {
......
......@@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(PackageVersionData);
DECLARE_POINTER_TYPE(VersionData);
DECLARE_TYPEOF_COLLECTION(PackageVersionDataP);
DECLARE_TYPEOF_COLLECTION(PackageDependencyP);
// ----------------------------------------------------------------------------- : Update data
......@@ -105,7 +106,7 @@ class CheckUpdateThread : public wxThread {
InputStreamP is(isP);
// Read version data
VersionDataP version_data;
Reader reader(is, _("updates"));
Reader reader(is, nullptr, _("updates"));
reader.handle(version_data);
// has the updates url changed?
if (!version_data->new_updates_url.empty()) {
......@@ -261,8 +262,10 @@ 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.SetTextForeground(SELECT_WHITE(packageFront));
dc.DrawText(pack->name, rect.GetLeft() + 1, rect.GetTop());
dc.DestroyClippingRegion();
dc.SetTextForeground(SELECT_WHITE(status_colors[status]));
dc.DrawText(status_texts[status], rect.GetLeft() + 240, rect.GetTop());
......@@ -465,13 +468,102 @@ void UpdatesWindow::setDefaultPackageStatus() {
}
}
/// Select the dependencies for a package
/**
* \param pack The package data to check dependencies for.
*
* This function will select all the dependencies for the package, to ensure
* that the user can't install a package without it's dependencies.
*/
void UpdatesWindow::SelectPackageDependencies (PackageVersionDataP pack) {
FOR_EACH(dep, pack->depends) {
if (packages.checkDependency(*dep)) //It's already installed.
continue;
FOR_EACH(p, update_version_data->packages) {
if (p->name == dep->package) { //We have a match.
if (p->version >= dep->version) { //Versions line up
PackageStatus& status = package_data[p].first;
PackageAction& action = package_data[p].second;
if (status == STATUS_NOT_INSTALLED)
action = ACTION_INSTALL;
else if (status == STATUS_UPGRADEABLE)
action = ACTION_UPGRADE;
else //status == STATUS_INSTALLED
action = ACTION_NOTHING;
break;
}
}
}
// TODO: Decide what to do if a dependency can't be met.
// It shouldn't happen with a decently maintained updates list.
// But it could, and we need to decide what to do in this situation.
}
}
/// This finds all packages that depend on the one provided and marks them for removal.
void UpdatesWindow::RemovePackageDependencies (PackageVersionDataP pack) {
FOR_EACH(p, update_version_data->packages) {
FOR_EACH(dep, p->depends) {
if (pack->name == dep->package) {
PackageStatus& status = package_data[p].first;
PackageAction& action = package_data[p].second;
if (status != STATUS_NOT_INSTALLED)
action = ACTION_UNINSTALL;
else // status == STATUS_NOT_INSTALLED
action = p->app_version > file_version ? ACTION_NOTHING : ACTION_NEW_MSE;
break;
}
}
}
}
/// This deals with the complexities of a downgrade and its dependencies.
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.
continue;
FOR_EACH(p, update_version_data->packages) {
if (p->name == dep->package) { //We have a match.
if (p->version >= dep->version) { //Versions line up
if (p->app_version > file_version) //We can't install this
continue;
PackageStatus& status = package_data[p].first;
PackageAction& action = package_data[p].second;
if (status == STATUS_NOT_INSTALLED)
action = ACTION_INSTALL;
else if (status == STATUS_UPGRADEABLE)
action = ACTION_UPGRADE;
break;
}
}
}
// TODO: Decide what to do if a dependency can't be met.
// It shouldn't happen with a decently maintained updates list.
// But it could, and we need to decide what to do in this situation.
}
FOR_EACH(p, update_version_data->packages) {
// dependencies that can no longer be met.
FOR_EACH(dep, p->depends) {
if (pack->name == dep->package) {
if (old_pack->version > dep->version) {
PackageStatus& status = package_data[p].first;
PackageAction& action = package_data[p].second;
if (status != STATUS_NOT_INSTALLED)
action = ACTION_UNINSTALL;
else // status == STATUS_NOT_INSTALLED
action = p->app_version > file_version ? ACTION_NOTHING : ACTION_NEW_MSE;
break;
}
}
}
}
}
BEGIN_EVENT_TABLE(UpdatesWindow, Frame)
......
......@@ -10,6 +10,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/welcome_window.hpp>
// ----------------------------------------------------------------------------- : Update checking
......@@ -39,6 +40,7 @@ DECLARE_POINTER_TYPE(PackageVersionData);
class UpdatesWindow : public Frame {
public:
UpdatesWindow();
~UpdatesWindow() { (new WelcomeWindow)->Show(); }
void DrawTitles(wxPaintEvent&);
......@@ -52,7 +54,7 @@ class UpdatesWindow : public Frame {
ACTION_UNINSTALL,
ACTION_UPGRADE,
ACTION_NOTHING,
ACTION_NEW_MSE
ACTION_NEW_MSE // means that you need a new version of MSE to install/upgrade
};
typedef pair<PackageStatus, PackageAction> PackageData;
......
......@@ -10,6 +10,7 @@
#include <gui/util.hpp>
#include <gui/new_window.hpp>
#include <gui/set/window.hpp>
#include <gui/update_checker.hpp>
#include <util/window_id.hpp>
#include <data/settings.hpp>
#include <data/format/formats.hpp>
......@@ -32,9 +33,11 @@ WelcomeWindow::WelcomeWindow()
#ifdef USE_HOVERBUTTON
wxControl* new_set = new HoverButtonExt(this, ID_FILE_NEW, load_resource_image(_("welcome_new")), _BUTTON_("new set"), _HELP_("new set"));
wxControl* open_set = new HoverButtonExt(this, ID_FILE_OPEN, load_resource_image(_("welcome_open")), _BUTTON_("open set"), _HELP_("open set"));
wxControl* updates = new HoverButtonExt(this, ID_FILE_CHECK_UPDATES, wxImage(), _BUTTON_("check updates"), _HELP_("check updates"));
#else
wxControl* new_set = new wxButton(this, ID_FILE_NEW, _BUTTON_("new set"));
wxControl* open_set = new wxButton(this, ID_FILE_OPEN, _BUTTON_("open set"));
wxControl* updates = new wxButton(this, ID_FILE_CHECK_UPDATES, _BUTTON_("check updates"));
#endif
wxControl* open_last = nullptr;
if (!settings.recent_sets.empty()) {
......@@ -53,6 +56,7 @@ WelcomeWindow::WelcomeWindow()
s2->AddSpacer(100);
s2->Add(new_set, 0, wxALL, 2);
s2->Add(open_set, 0, wxALL, 2);
s2->Add(updates, 0, wxALL, 2);
if (open_last) s2->Add(open_last, 0, wxALL, 2);
s2->AddStretchSpacer();
s1->Add(s2);
......@@ -101,6 +105,11 @@ void WelcomeWindow::onOpenLast(wxCommandEvent&) {
close( open_package<Set>(settings.recent_sets.front()) );
}
void WelcomeWindow::onCheckUpdates(wxCommandEvent&) {
(new UpdatesWindow)->Show();
Close();
}
void WelcomeWindow::close(const SetP& set) {
if (!set) return;
(new SetWindow(nullptr, set))->Show();
......@@ -112,6 +121,7 @@ BEGIN_EVENT_TABLE(WelcomeWindow, wxFrame)
EVT_BUTTON (ID_FILE_NEW, WelcomeWindow::onNewSet)
EVT_BUTTON (ID_FILE_OPEN, WelcomeWindow::onOpenSet)
EVT_BUTTON (ID_FILE_RECENT, WelcomeWindow::onOpenLast)
EVT_BUTTON (ID_FILE_CHECK_UPDATES, WelcomeWindow::onCheckUpdates)
EVT_PAINT ( WelcomeWindow::onPaint)
// EVT_IDLE ( WelcomeWindow::onIdle)
END_EVENT_TABLE ()
......
......@@ -39,7 +39,8 @@ class WelcomeWindow : public Frame {
void onOpenSet (wxCommandEvent&);
void onNewSet (wxCommandEvent&);
void onOpenLast(wxCommandEvent&);
void onOpenLast (wxCommandEvent&);
void onCheckUpdates(wxCommandEvent&);
// void onIdle (wxIdleEvent& ev);
/// Close the welcome window, and show the given set
......
......@@ -42,6 +42,7 @@ button:
add item: 0
always: 0
browse: 0
check updates: 0
check now: 0
close: 0
defaults: 0
......
......@@ -65,7 +65,6 @@ const String& Package::absoluteFilename() const {
return filename;
}
void Package::open(const String& n) {
assert(!isOpened()); // not already opened
// get absolute path
......@@ -86,6 +85,17 @@ 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);
......@@ -304,6 +314,15 @@ Package::FileInfo::~FileInfo() {
delete zipEntry;
}
void Package::loadZipStream() {
while (true) {
wxZipEntry* entry = zipStream->GetNextEntry();
if (!entry) break;
String name = toStandardName(entry->GetName());
files[name].zipEntry = entry;
}
zipStream->CloseEntry();
}
void Package::openDirectory() {
openSubdir(wxEmptyString);
......@@ -341,16 +360,9 @@ void Package::openZipfile() {
zipStream = new wxZipInputStream(*fileStream);
if (!zipStream->IsOk()) throw PackageError(_ERROR_1_("package not found", filename));
// read zip entries
while (true) {
wxZipEntry* entry = zipStream->GetNextEntry();
if (!entry) break;
String name = toStandardName(entry->GetName());
files[name].zipEntry = entry;
}
zipStream->CloseEntry();
loadZipStream();
}
void Package::saveToDirectory(const String& saveAs, bool remove_unused) {
// write to a directory
FOR_EACH(f, files) {
......
......@@ -71,6 +71,9 @@ 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
......@@ -168,6 +171,7 @@ class Package : public IntrusivePtrVirtualBase {
/// Filestream for reading zip files
wxZipInputStream* zipStream;
void loadZipStream();
void openDirectory();
void openSubdir(const String&);
void openZipfile();
......
......@@ -128,12 +128,14 @@ bool PackageManager::checkDependency(const PackageDependency& dep, bool report_e
// try global package
name = global_data_directory + _("/") + dep.package;
if (!wxFileExists(name) && !wxDirExists(name)) {
if (report_errors)
handle_warning(_ERROR_1_("package not found", dep.package),false);
return false;
}
}
PackagedP package = openAny(dep.package, true);
if (package->version < dep.version) {
if (report_errors)
handle_warning(_ERROR_3_("package out of date", dep.package, package->version.toString(), dep.version.toString()),false);
return false;
}
......
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