Finally got precompiled headers to work.

Now all C++ files need to #include <util/prec.hpp>
 That is why all .cpp files are touched by this commit

Many changes to installers and update checking:
     - the window is now called PackagesWindow, in a new source file
     - update checking is now independent from the PackagesWindow. For update checking only a list of package versions are needed (vector<PackageDependency>). This is much less information to download at each startup.
     - the list of available packages is now a list of available Installers, since an installer can contain multiple packages.
     - moved the logic of dependency checking etc. to data/installer
     - moved the actual installation to util/io/package_manager
     - moved directory iteration/creation logic to util/file_utils
     - added PackageDirectory: the local and global package directory now have their own object (was part of PackageManager)
     - added PackageVersion: for detecting if a package has been modified after it was installed.
     - added PackageDescription: description/header of a package. Basicly the same as what Packaged provides.
     - added DownloadableInstaller: where to find an insaller, what does it contain?
     - added InstallablePackage: brining it all together: installer, package, status, action.

Current status: the insaller is currently broken in a few places, more on that soon.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@792 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-29 18:30:41 +00:00
parent 361488b4fe
commit d2196eea09
182 changed files with 2508 additions and 809 deletions
+46 -11
View File
@@ -1,6 +1,8 @@
mse version: 0.3.5
mse version: 0.3.6
installer group: locales
full name: English
version: 2007-09-23
icon: usgb.png
############################################################## Menu items
menu:
@@ -93,13 +95,6 @@ menu:
symmetry: S&ymmetry F9
paint: P&aint F10
# Updates window
apply changes: Apply changes
cancel changes: Cancel changes
install package: Install package
upgrade package: Upgrade package
remove package: Remove package
############################################################## Menu help texts
help:
welcome: Welcome to Magic Set Editor
@@ -459,6 +454,23 @@ label:
# Symbol editor
sides: sides
# Packages window
package name: Package
package installed version: Installed version
package remote version: Latest version
package status: Status
package action: Action
package conflicts: conflicting modifications
package modified: local modifications
package updates: updates available
package installed: installed
package installable: not installed
install package: install
upgrade package: upgrade
remove package: remove
############################################################## Buttons/checkboxes/choices in the GUI
button:
# Editor
@@ -516,6 +528,15 @@ button:
enabled: Enabled
whole word: Match whole word only
# Packages window
install package: &Install
upgrade package: &Upgrade
remove package: &Remove
install group: &Install All
upgrade group: &Upgrade All
remove group: &Remove All
############################################################## Titles in the GUI
title:
magic set editor: Magic Set Editor
@@ -639,9 +660,7 @@ error:
dependency not given:
The package '%s' uses files from the package '%s', but it does not list a dependency.
To resolve this, add:
depends on:
package: %s
version: %s
depends on: %s %s
# Script stuff
has no member: %s has no member '%s'
@@ -687,6 +706,22 @@ error:
# Package update window
no packages: Found no package updates.
checking updates: Checking for updates.
can't download installer:
Unable to download installer for package %s from %s.
Nothing has been installed.
downloading updates: Downloading updates (%d of %d)
installing updates: Updating packages (%d of %d)
remove packages:
This will remove %s packages, do you want to continue?
remove packages modified:
This will remove %s packages, %s of those have been modified after installing.
Removing them can not be undone.
Do you want to continue?
cannot create file: Can not create file '%s', continue installation?
############################################################## Types used in scripts / shape names
Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/action/keyword.hpp>
#include <data/keyword.hpp>
#include <data/set.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/action/set.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/action/symbol.hpp>
#include <data/action/symbol_part.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/action/symbol_part.hpp>
#include <gfx/bezier.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/action/value.hpp>
#include <data/field.hpp>
#include <data/field/text.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/card.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/export_template.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field.hpp>
#include <data/field/text.hpp>
#include <data/field/choice.hpp>
+3 -2
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/boolean.hpp>
// ----------------------------------------------------------------------------- : BooleanField
@@ -31,8 +32,8 @@ BooleanStyle::BooleanStyle(const ChoiceFieldP& field)
: ChoiceStyle(field)
{
render_style = RENDER_BOTH;
//%%choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//%%choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
//choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
choice_images[_("yes")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_yes")));
choice_images[_("no")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_no")));
}
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/choice.hpp>
#include <util/io/package.hpp>
#include <wx/imaglist.h>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/color.hpp>
#include <script/script.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/image.hpp>
// ----------------------------------------------------------------------------- : ImageField
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/information.hpp>
#include <script/script.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/multiple_choice.hpp>
// ----------------------------------------------------------------------------- : MultipleChoiceField
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/package_choice.hpp>
#include <util/io/package_manager.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/symbol.hpp>
#include <render/symbol/filter.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field/text.hpp>
#include <util/tagged_string.hpp>
#include <script/script.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/font.hpp>
// ----------------------------------------------------------------------------- : Font
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/settings.hpp>
#include <data/set.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/clipboard.hpp>
#include <data/format/formats.hpp>
#include <data/card.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
// ----------------------------------------------------------------------------- :
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
#include <data/stylesheet.hpp>
+1
View File
@@ -13,6 +13,7 @@
#pragma warning(disable:4996)
#endif
#include <util/prec.hpp>
#include <data/format/image_to_symbol.hpp>
#include <gfx/bezier.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
#include <data/settings.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/format/formats.hpp>
#include <data/game.hpp>
#include <data/set.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
#include <data/field/choice.hpp>
+289 -4
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/installer.hpp>
#include <data/locale.hpp>
#include <data/game.hpp>
@@ -23,6 +24,8 @@
DECLARE_TYPEOF_COLLECTION(String);
DECLARE_TYPEOF_COLLECTION(PackagedP);
DECLARE_TYPEOF_COLLECTION(PackageDependencyP);
DECLARE_TYPEOF_COLLECTION(PackageDescriptionP);
DECLARE_TYPEOF_COLLECTION(InstallablePackageP);
DECLARE_POINTER_TYPE(wxFileInputStream);
DECLARE_POINTER_TYPE(wxZipInputStream);
@@ -64,11 +67,12 @@ struct dependency_check : public unary_function<bool, PackagedP> {
void Installer::install(bool local, bool check_dependencies) {
// Destination directory
String install_dir = local ? ::packages.getLocalDataDir() : ::packages.getGlobalDataDir();
// String install_dir = local ? ::packages.getLocalDataDir() : ::packages.getGlobalDataDir();
String install_dir = _("TODO");
if (!wxDirExists(install_dir)) {
wxMkdir(install_dir, 0755);
}
/*
// All the packages we're installing.
vector<PackagedP> new_packages;
@@ -130,6 +134,7 @@ void Installer::install(bool local, bool check_dependencies) {
}
os.Write(*is);
}
*/
}
void Installer::install(const String& package) {
@@ -151,13 +156,16 @@ void Installer::addPackage(const String& package) {
void Installer::addPackage(Packaged& package) {
// Add to list of packages
String name = package.relativeFilename();
if (find(packages.begin(), packages.end(), package.name()) != packages.end()) {
FOR_EACH(p, packages) {
if (p->name == name) {
return; // already added
}
}
packages.push_back(new_intrusive1<PackageDescription>(package));
// use this as a filename?
if (prefered_filename.empty()) {
prefered_filename = package.name() + _(".mse-installer");
}
packages.push_back(name);
// Copy all files from that package to this one
const FileInfos& file_infos = package.getFileInfos();
for (FileInfos::const_iterator it = file_infos.begin() ; it != file_infos.end() ; ++it) {
@@ -167,3 +175,280 @@ void Installer::addPackage(Packaged& package) {
os->Write(*is);
}
}
// ----------------------------------------------------------------------------- : Installer descriptions
PackageDescription::PackageDescription() : position_hint(0) {}
PackageDescription::PackageDescription(const Packaged& package)
: name(package.relativeFilename())
, version(package.version)
, short_name(package.short_name)
, full_name(package.full_name)
, icon_url(_(""))
, installer_group(package.installer_group)
, position_hint(package.position_hint)
//, description(package.description)
, dependencies(package.dependencies)
{
// name
if (short_name.empty()) {
if (!full_name.empty()) short_name = full_name;
else short_name = package.name();
}
if (full_name.empty()) full_name = short_name;
// installer group
if (installer_group.empty()) {
// "game-style.mse-something" -> "game/style" -> "game"
installer_group = replace_all(package.name(),_("-"),_("/"));
size_t pos = installer_group.find_last_of(_('/'));
if (pos != String::npos) installer_group.resize(pos);
}
// icon
InputStreamP file = const_cast<Packaged&>(package).openIconFile();
if (file) icon.LoadFile(*file);
}
IMPLEMENT_REFLECTION_NO_SCRIPT(PackageDescription) {
REFLECT(name);
REFLECT(version);
REFLECT(short_name);
REFLECT(full_name);
REFLECT(icon_url);
REFLECT(installer_group);
REFLECT(position_hint);
REFLECT(description);
REFLECT_N("depends ons", dependencies);
}
IMPLEMENT_REFLECTION_NO_SCRIPT(InstallerDescription) {
REFLECT(packages);
}
IMPLEMENT_REFLECTION_NO_SCRIPT(DownloadableInstaller) {
REFLECT_N("url", installer_url);
REFLECT(downloadable);
REFLECT(packages);
}
DownloadableInstaller::~DownloadableInstaller() {
if (!installer_file.empty()) {
wxRemoveFile(installer_file);
}
}
// ----------------------------------------------------------------------------- : Installable package
InstallablePackage::InstallablePackage() : action(PACKAGE_NOTHING) {}
InstallablePackage::InstallablePackage(const PackageVersionP& installed, const PackageDescriptionP& description)
: installed(installed)
, description(description)
, action(PACKAGE_NOTHING)
{}
void InstallablePackage::determineStatus() {
status = PACKAGE_NOT_INSTALLED;
if (installer) {
status = (PackageStatus)(status | PACKAGE_INSTALLABLE);
}
if (installed) {
status = (PackageStatus)(status | PACKAGE_INSTALLED);
if (!(installed->status & PackageVersion::STATUS_FIXED)) {
status = (PackageStatus)(status | PACKAGE_REMOVABLE);
}
}
if (installed && installed->version < description->version) {
status = (PackageStatus)(status | PACKAGE_UPDATES);
}
if (installed && (installed->status & PackageVersion::STATUS_MODIFIED)) {
status = (PackageStatus)(status | PACKAGE_MODIFIED);
}
}
bool InstallablePackage::can(PackageAction act) const {
if (act & PACKAGE_INSTALL) return (status & PACKAGE_INSTALLABLE) == PACKAGE_INSTALLABLE;
if (act & PACKAGE_UPGRADE) return (status & PACKAGE_UPDATES) == PACKAGE_UPDATES;
if (act & PACKAGE_REMOVE) {
bool ok = (status & PACKAGE_REMOVABLE) == PACKAGE_REMOVABLE;
if (!(act & PACKAGE_GLOBAL) && installed && PackageVersion::STATUS_GLOBAL) {
// package installed globally can't be removed locally
return false;
}
return ok;
}
else return false;
}
bool InstallablePackage::has(PackageAction act) const {
return (action & act) == act;
}
void InstallablePackage::merge(const InstallablePackage& p) {
if (!installed) installed = p.installed;
if (!installer) {
description = p.description; // installer has new description
installer = p.installer;
}
}
bool before(const InstallablePackageP& a, const InstallablePackageP& b) {
assert(a->description && b->description);
return a->description->name < b->description->name;
}
void sort(InstallablePackages& packages) {
sort(packages.begin(), packages.end(), before);
}
void merge(InstallablePackages& list1, const InstallablePackages& list2) {
InstallablePackages::iterator it1 = list1.begin();
InstallablePackages::const_iterator it2 = list2.begin();
InstallablePackages add;
while (it1 != list1.end() || it2 != list2.end()) {
if (it1 != list1.end() && (it2 == list2.end() || before(*it1,*it2))) {
++it1;
} else if (it1 == list1.end() || before(*it2,*it1)) {
add.push_back(*it2);
++it2;
} else {
(*it1)->merge(**it2);
++it1,++it2;
}
}
if (!add.empty()) {
list1.insert(list1.end(), add.begin(), add.end());
sort(list1);
}
}
void merge(InstallablePackages& installed, const DownloadableInstallerP& installer) {
InstallablePackages ips;
FOR_EACH(p, installer->packages) {
InstallablePackageP ip(new InstallablePackage);
ip->description = p;
ip->installer = installer;
ips.push_back(ip);
}
merge(installed, ips);
}
bool add_package_dependency(InstallablePackages& packages, const PackageDependency& dep, int where, bool set) {
FOR_EACH(p, packages) {
if (p->description->name == dep.package) {
// Some package depends on this package, so install it if needed
// Mark the installation as "automatically needed for X packages"
// if !set then instead the dependency is no longer needed because we are not installing the package
if (!p->installed || p->installed->version < dep.version) {
bool change = false;
if (p->action & (PACKAGE_INSTALL | PACKAGE_UPGRADE)) {
// this package is already scheduled for installation
if (p->automatic) {
// we are already automatically depending on this package
p->automatic += set ? +1 : -1;
if (p->automatic == 0) {
// no one needs this package anymore
p->action = PACKAGE_NOTHING;
change = true;
}
}
} else if (set) {
p->action = (PackageAction)(where |
(p->installed ? PACKAGE_UPGRADE : PACKAGE_INSTALL));
p->automatic = 1;
change = true;
}
// recursively add/remove dependencies
FOR_EACH(dep, p->description->dependencies) {
if (!add_package_dependency(packages, *dep, where, set)) {
return false; // failed
}
}
}
return true;
}
}
return false;
}
void remove_package_dependency(InstallablePackages& packages, const PackageDescription& ver, int where, bool set) {
FOR_EACH(p, packages) {
FOR_EACH(dep, p->description->dependencies) {
if (dep->package == ver.name) {
// we can no longer use package p
if (p->action & PACKAGE_REMOVE) {
if (p->automatic) {
p->automatic += set ? +1 : -1;
if (p->automatic == 0) {
// no one needs this package anymore
p->action = PACKAGE_NOTHING;
remove_package_dependency(packages, *p->description, where, set);
}
}
} else if (set) {
p->action = (PackageAction)(where | PACKAGE_REMOVE);
p->automatic = 1;
remove_package_dependency(packages, *p->description, where, set);
}
break;
}
}
}
}
bool set_package_action_unsafe(InstallablePackages& packages, const InstallablePackageP& package, PackageAction action) {
int where = action & PACKAGE_WHERE;
if ((action & PACKAGE_INSTALL) || (action & PACKAGE_UPGRADE) || ((action & PACKAGE_NOTHING) && (package->status & PACKAGE_INSTALLED))) {
// need the package
package->automatic = 0;
package->action = action;
// check dependencies
FOR_EACH(dep, package->description->dependencies) {
if (!add_package_dependency(packages, *dep, where, !(action & PACKAGE_NOTHING))) return false;
}
return true;
} else if ((action & PACKAGE_REMOVE) || ((action & PACKAGE_NOTHING) && !(package->status & PACKAGE_INSTALLED))) {
package->automatic = 0;
package->action = action;
// check dependencies
remove_package_dependency(packages, *package->description, where, !(action & PACKAGE_NOTHING));
return true;
}
return false;
}
bool set_package_action(InstallablePackages& packages, const InstallablePackageP& package, PackageAction action) {
if (package->has(action)) return false;
// backup
FOR_EACH(p,packages) {
p->old_action = p->action;
p->old_automatic = p->automatic;
}
// set
if (set_package_action_unsafe(packages, package, action)) return true;
// undo
FOR_EACH(p,packages) {
p->action = p->old_action;
p->automatic = p->old_automatic;
}
return false;
}
// ----------------------------------------------------------------------------- : MSE package
String mse_package = _("magicseteditor.exe");
InstallablePackageP mse_installable_package() {
PackageVersionP mse_version(new PackageVersion(
PackageVersion::STATUS_GLOBAL |
PackageVersion::STATUS_BLESSED |
PackageVersion::STATUS_FIXED));
mse_version->name = mse_package;
mse_version->version = app_version;
PackageDescriptionP mse_description(new PackageDescription);
mse_description->name = mse_package;
mse_description->short_name = mse_description->full_name = _TITLE_("magic set editor");
mse_description->position_hint = -100;
//mse_description->icon = load_resource_image(_("mse_icon"));
//mse_description->description = _LABEL_("magic set editor package");
return new_intrusive2<InstallablePackage>(mse_version,mse_description);
}
+134 -14
View File
@@ -9,22 +9,14 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/settings.hpp>
#include <util/prec.hpp>
#include <util/io/package.hpp>
// ----------------------------------------------------------------------------- : InstallType
// Platform default install directory.
#ifdef __WXMSW__
#define DEFAULT_INSTALL_LOCAL false
#else
#define DEFAULT_INSTALL_LOCAL true
#endif
inline bool isInstallLocal(const InstallType& type)
{
return type == INSTALL_DEFAULT ? DEFAULT_INSTALL_LOCAL : type == INSTALL_LOCAL;
}
DECLARE_POINTER_TYPE(Installer);
DECLARE_POINTER_TYPE(PackageVersion);
DECLARE_POINTER_TYPE(PackageDescription);
DECLARE_POINTER_TYPE(DownloadableInstaller);
DECLARE_POINTER_TYPE(InstallablePackage);
// ----------------------------------------------------------------------------- : Installer
@@ -32,7 +24,7 @@ inline bool isInstallLocal(const InstallType& type)
class Installer : public Packaged {
public:
String prefered_filename; ///< What filename should be used (by default)
vector<String> packages; ///< Packages to install
vector<PackageDescriptionP> packages; ///< Packages to install
/// Load an installer from a file, and run it
static void installFrom(const String& filename, bool message_on_success, bool local);
@@ -54,5 +46,133 @@ class Installer : public Packaged {
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : Installer descriptions
/// A description of a package in an installer
class PackageDescription : public IntrusivePtrBase<PackageDescription> {
public:
PackageDescription();
PackageDescription(const Packaged& package);
String name; ///< Filename of the package
Version version; ///< Version number of this package
String short_name; ///< Short name of this package
String full_name; ///< Name of this package, for menus etc.
String icon_url; ///< Filename or URL of icon to use in package lists
Image icon; ///< Icon for the package
String installer_group; ///< Where to put this package in the installer
int position_hint; ///< A hint for the package list
String description; ///< Changelog/description
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
DECLARE_REFLECTION();
};
/// A description of the contents of an installer
class InstallerDescription : public IntrusivePtrBase<InstallerDescription> {
public:
vector<PackageDescriptionP> packages;
DECLARE_REFLECTION();
};
/// Information on an installer that can be downloaded
class DownloadableInstaller : public IntrusivePtrBase<DownloadableInstaller> {
public:
DownloadableInstaller() : downloadable(true) {}
DownloadableInstaller(const InstallerP& installer);
~DownloadableInstaller();
InstallerP installer; ///< The installer, if it is loaded
String installer_url; ///< The URL where the installer can be found
String installer_file; ///< The temp file where the installer can be found (after downloading)
bool downloadable; ///< Is the installer downloadable (in)directly from that url?
vector<PackageDescriptionP> packages; ///< Packages provided by this installer
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : Installable package
/// Installation status of a package
enum PackageStatus
{ PACKAGE_NOT_INSTALLED = 0x0000
, PACKAGE_INSTALLED = 0x0001
, PACKAGE_REMOVABLE = 0x0002
, PACKAGE_INSTALLABLE = 0x0010
, PACKAGE_UPDATES = 0x0111 ///< Remote updates available
, PACKAGE_MODIFIED = 0x1001 ///< Local changes made
, PACKAGE_CONFLICTS = PACKAGE_UPDATES | PACKAGE_MODIFIED
};
/// (un)install a package?
enum PackageAction
{ PACKAGE_NOTHING = 0x001 ///< Don't change anything
, PACKAGE_INSTALL = 0x002 ///< Install the package
, PACKAGE_UPGRADE = 0x004 ///< Upgrade the package
, PACKAGE_REMOVE = 0x008 ///< Remove the package
, PACKAGE_LOCAL = 0x010 ///< In the local package directory
, PACKAGE_GLOBAL = 0x020 ///< In the global package directory
, PACKAGE_WHERE = PACKAGE_LOCAL | PACKAGE_GLOBAL
};
/// A package that can be installed, or is already installed
class InstallablePackage : public IntrusivePtrVirtualBase {
public:
InstallablePackage();
InstallablePackage(const PackageVersionP&, const PackageDescriptionP&);
PackageVersionP installed; ///< The information of the installed package (if installed)
PackageDescriptionP description; ///< The details of the package. Either from the installed package or from an installer
DownloadableInstallerP installer; ///< The installer to install from (if updates are available)
PackageStatus status; ///< Status of installation
PackageAction action; ///< What to do with this package?
int automatic; ///< Install/upgrade/remove automaticly to satisfy this many packages
PackageAction old_action;
int old_automatic;
void determineStatus();
/// Is the action possible?
bool can(PackageAction act) const;
/// Is the action currently selected?
bool has(PackageAction act) const;
/// Merge two descriptions of installable packages
void merge(const InstallablePackage& p2);
};
typedef vector<InstallablePackageP> InstallablePackages;
/// Sort a list of InstallablePackages by package name
void sort(InstallablePackages& packages);
/// Merge two lists of InstallablePackages.
/** The first list contains installed packages, the second list contains packages in an installer
* @pre both lists are sorted by package name
* @post the output will be sorted
*/
void merge(InstallablePackages& installed, const InstallablePackages& from_installer);
/// Merge the packages from a DownloadableInstaller into a list of InstallablePackages.
void merge(InstallablePackages& installed, const DownloadableInstallerP& installer);
/// Set the action to perform on a given package, makes sure the dependencies are also set correctly
/** Returns true on success
* action may be PACKAGE_NOTHING to clear the action
*/
bool set_package_action(InstallablePackages& packages, const InstallablePackageP& package, PackageAction action);
// ----------------------------------------------------------------------------- : Program package
/// The "magicseteditor.exe" package is special, it refers to the program
extern String mse_package;
InstallablePackageP mse_installable_package();
// ----------------------------------------------------------------------------- : EOF
#endif
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/keyword.hpp>
#include <util/tagged_string.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/locale.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/pack.hpp>
// ----------------------------------------------------------------------------- : PackType
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
+17 -2
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/settings.hpp>
#include <data/installer.hpp>
#include <data/game.hpp>
@@ -38,6 +39,15 @@ IMPLEMENT_REFLECTION_ENUM(InstallType) {
VALUE_N("global", INSTALL_GLOBAL);
}
bool is_install_local(InstallType type) {
#ifdef __WXMSW__
#define DEFAULT_INSTALL_LOCAL false
#else
#define DEFAULT_INSTALL_LOCAL true
#endif
return type == INSTALL_DEFAULT ? DEFAULT_INSTALL_LOCAL : type == INSTALL_LOCAL;
}
IMPLEMENT_REFLECTION_ENUM(FilenameConflicts) {
VALUE_N("keep old", CONFLICT_KEEP_OLD);
VALUE_N("overwrite", CONFLICT_OVERWRITE);
@@ -143,8 +153,10 @@ Settings::Settings()
, symbol_grid_size (30)
, symbol_grid (true)
, symbol_grid_snap (false)
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
, package_versions_url (_("http://magicseteditor.sourceforge.net/packages"))
, installer_list_url (_("http://magicseteditor.sourceforge.net/installers"))
, check_updates (CHECK_IF_CONNECTED)
, check_updates_all (true)
, install_type (INSTALL_DEFAULT)
, website_url (_("http://magicseteditor.sourceforge.net/"))
{}
@@ -221,8 +233,11 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
REFLECT(symbol_grid_snap);
REFLECT(default_game);
REFLECT(apprentice_location);
REFLECT(updates_url);
REFLECT_IGNORE(306,"updates url");
REFLECT(package_versions_url);
REFLECT(installer_list_url);
REFLECT(check_updates);
REFLECT(check_updates_all);
REFLECT(install_type);
REFLECT(website_url);
REFLECT(game_settings);
+4 -2
View File
@@ -41,6 +41,7 @@ enum InstallType
};
bool parse_enum(const String&, InstallType&);
bool is_install_local(InstallType type);
/// How to handle filename conflicts
enum FilenameConflicts
@@ -164,11 +165,12 @@ class Settings {
// --------------------------------------------------- : Special game stuff
String apprentice_location;
String mws_location;
// --------------------------------------------------- : Update checking
String updates_url;
String package_versions_url; ///< latest package versions
String installer_list_url; ///< available installers
CheckUpdates check_updates;
bool check_updates_all; ///< Check updates of all packages, not just the program
String website_url;
// --------------------------------------------------- : Installation settings
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/statistics.hpp>
#include <data/field.hpp>
#include <data/field/choice.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/stylesheet.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/symbol.hpp>
#include <script/to_value.hpp>
#include <gfx/bezier.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/symbol_font.hpp>
#include <data/stylesheet.hpp>
#include <util/dynamic_arg.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/word_list.hpp>
// ----------------------------------------------------------------------------- : WordList
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/bezier.hpp>
#include <gfx/polynomial.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
// ----------------------------------------------------------------------------- : Color utility functions
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/reflect.hpp>
#include <algorithm>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/generated_image.hpp>
#include <util/io/package.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/polynomial.hpp>
#include <complex>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/error.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
#include <util/error.hpp>
#include <gui/util.hpp> // clearDC_black
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gfx/gfx.hpp>
// ----------------------------------------------------------------------------- : Implementation
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/about_window.hpp>
#include <gui/util.hpp>
#include <util/version.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/auto_replace_window.hpp>
#include <gui/control/item_list.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/card_select_window.hpp>
#include <gui/control/select_card_list.hpp>
#include <util/window_id.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/card_editor.hpp>
#include <gui/value/editor.hpp>
#include <gui/icon_menu.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/card_list.hpp>
#include <gui/control/card_list_column_select.hpp>
#include <gui/icon_menu.hpp>
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/card_list_column_select.hpp>
#include <data/game.hpp>
#include <data/field.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/card_viewer.hpp>
#include <data/stylesheet.hpp>
#include <data/settings.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/filtered_card_list.hpp>
DECLARE_TYPEOF_COLLECTION(CardP);
+1 -1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/gallery_list.hpp>
#include <gfx/gfx.hpp>
#include <wx/dcbuffer.h>
@@ -91,7 +92,6 @@ void GalleryList::scrollTo(int top, bool update_scrollbar) {
top = max(0, top);
// scroll
if (top == visible_start) return;
//%int old_top = visible_start;
visible_start = top;
if (update_scrollbar) {
// scroll bar
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/graph.hpp>
#include <util/alignment.hpp>
#include <gfx/gfx.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/image_card_list.hpp>
#include <gui/thumbnail_thread.hpp>
#include <data/field/image.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/item_list.hpp>
#include <gui/util.hpp>
#include <wx/imaglist.h>
-2
View File
@@ -12,8 +12,6 @@
#include <util/prec.hpp>
#include <wx/listctrl.h>
typedef intrusive_ptr<IntrusivePtrVirtualBase> VoidP;
// ----------------------------------------------------------------------------- : ItemList
/// A generic list of items
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/keyword_list.hpp>
#include <gui/icon_menu.hpp>
#include <data/set.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/native_look_editor.hpp>
#include <gui/value/editor.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/package_list.hpp>
#include <util/io/package_manager.hpp>
#include <util/alignment.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/select_card_list.hpp>
#include <gui/util.hpp>
#include <data/card.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/text_ctrl.hpp>
#include <gui/value/editor.hpp>
#include <gui/util.hpp>
+48 -37
View File
@@ -6,12 +6,13 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/control/tree_list.hpp>
#include <gfx/gfx.hpp>
#include <wx/renderer.h>
#include <wx/dcbuffer.h>
DECLARE_TYPEOF_COLLECTION(TreeList::Item);
DECLARE_TYPEOF_COLLECTION(TreeList::ItemP);
// ----------------------------------------------------------------------------- : TreeList : item managment
@@ -23,21 +24,28 @@ void TreeList::rebuild(bool full) {
}
bool TreeList::hasChildren(size_t item) const {
return item < items.size() && items[item].level < items[item+1].level;
return item + 1 < items.size() && items[item]->level < items[item+1]->level;
}
void TreeList::expand(size_t item, bool expand) {
if (hasChildren(item) && items[item].expanded != expand) {
items[item].expanded = expand;
if (hasChildren(item) && items[item]->expanded != expand) {
items[item]->expanded = expand;
rebuild(false);
}
}
void TreeList::select(size_t item) {
void TreeList::select(size_t item, bool event) {
if (item >= items.size() || selection == item) return;
size_t oldpos = selection < items.size() ? items[selection].position : 0;
// select
size_t oldpos = selection < items.size() ? items[selection]->position : 0;
selection = item;
size_t pos = items[selection].position;
size_t pos = items[selection]->position;
// event
if (event) {
wxCommandEvent ev(wxEVT_COMMAND_LISTBOX_SELECTED, GetId());
ProcessEvent(ev);
}
// redraw
if (pos < first_line) {
ScrollToLine(pos);
} else if (pos >= first_line + visible_lines_t) {
@@ -53,28 +61,28 @@ void TreeList::calcItemCount() {
total_lines = 0;
int visible_level = 0;
FOR_EACH(i,items) {
if (i.level <= visible_level) {
i.position = total_lines;
if (i->level <= visible_level) {
i->position = total_lines;
++total_lines;
if (i.expanded) visible_level = i.level + 1;
else visible_level = i.level;
if (i->expanded) visible_level = i->level + 1;
else visible_level = i->level;
} else {
i.position = NOTHING;
i->position = NOTHING;
}
}
// update lines
UInt lines = 0;
FOR_EACH_REVERSE(i,items) {
if (i.visible()) {
i.lines = lines;
lines &= (1 << i.level) - 1;
lines |= 1 << i.level;
if (i->visible()) {
i->lines = lines;
lines &= (1 << i->level) - 1;
lines |= 1 << i->level;
}
}
// selection hidden? move to first visible item before it
if (selection < items.size()) {
for ( ; selection + 1 > 0 ; --selection) {
if (items[selection].visible()) break; // visible
if (items[selection]->visible()) break; // visible
}
if (selection >= items.size()) selection = 0;
}
@@ -86,20 +94,20 @@ size_t TreeList::findItemByPos(int y) const {
}
size_t TreeList::findItem(size_t line, size_t start) const {
for (size_t i = start ; i < items.size() ; ++i) {
if (items[i].visible() && items[i].position >= line) return i;
if (items[i]->visible() && items[i]->position >= line) return i;
}
return items.size();
}
size_t TreeList::findLastItem(size_t start) const {
for (size_t i = min(items.size(), start) - 1 ; i + 1 > 0 ; --i) {
if (items[i].visible()) return i;
if (items[i]->visible()) return i;
}
return items.size();
}
size_t TreeList::findParent(size_t start) const {
int level = items[start].level;
int level = items[start]->level;
for (size_t i = start - 1 ; i + 1 > 0 ; --i) {
if (items[i].visible() && items[i].level < level) return i;
if (items[i]->visible() && items[i]->level < level) return i;
}
return items.size();
}
@@ -147,9 +155,13 @@ void TreeList::onPaint(wxPaintEvent& ev) {
size_t start = findItem(first_line);
size_t end = findItem(first_line + visible_lines);
for (size_t i = start ; i < end ; ++i) {
const Item& item = items[i];
const Item& item = *items[i];
if (!item.visible()) continue; // invisible
x = level_width * (item.level + 1);
// line below
dc.SetPen(lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),0.2));
dc.DrawLine(x,y+item_height-1,cs.x,y+item_height-1);
// draw lines
dc.SetPen(lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),0.4));
@@ -171,15 +183,12 @@ void TreeList::onPaint(wxPaintEvent& ev) {
if (selection == i) {
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
dc.DrawRectangle(x, y, cs.x-x, item_height);
dc.DrawRectangle(x, y, cs.x-x, item_height-1);
}
// draw text(s)
for (size_t j = 0 ; j < cols ; ++j) {
int w = columnWidth(j);
if (selection != i)
dc.SetTextForeground(itemColor(i,j));
dc.DrawText(itemText(i,j),x+1,y+1);
drawItem(dc, i, j, x+1, y, selection == i);
if (j == 0) x = 0;
x += w;
}
@@ -197,7 +206,7 @@ void TreeList::onChar(wxKeyEvent& ev) {
break;
} case WXK_LEFT: {
if (selection < items.size()) {
if (hasChildren(selection) && items[selection].expanded) {
if (hasChildren(selection) && items[selection]->expanded) {
expand(selection, false);
} else {
// select parent
@@ -207,7 +216,7 @@ void TreeList::onChar(wxKeyEvent& ev) {
break;
} case WXK_RIGHT: {
if (selection < items.size() && hasChildren(selection)) {
if (items[selection].expanded) {
if (items[selection]->expanded) {
// select first child
select(selection+1);
Refresh(false);
@@ -216,10 +225,10 @@ void TreeList::onChar(wxKeyEvent& ev) {
}
}
break;
} case WXK_PAGEUP: {
} case WXK_PAGEUP: case WXK_PRIOR: {
ScrollToLine(first_line > visible_lines_t ? first_line - visible_lines_t : 0);
break;
} case WXK_PAGEDOWN: {
} case WXK_PAGEDOWN: case WXK_NEXT: {
ScrollToLine(first_line + visible_lines_t);
break;
} case WXK_HOME: {
@@ -242,9 +251,9 @@ void TreeList::onChar(wxKeyEvent& ev) {
void TreeList::onLeftDown(wxMouseEvent& ev) {
size_t i = findItemByPos(ev.GetY());
if (i >= items.size()) return;
int left = items[i].level * level_width;
int left = items[i]->level * level_width;
if (hasChildren(i) && ev.GetX() >= left && ev.GetX() < left + level_width) {
expand(i, !items[i].expanded);
expand(i, !items[i]->expanded);
} else {
select(i);
}
@@ -255,7 +264,7 @@ void TreeList::onLeftDClick(wxMouseEvent& ev) {
size_t i = findItemByPos(ev.GetY());
if (i >= items.size()) return;
if (hasChildren(i)) {
expand(i, !items[i].expanded);
expand(i, !items[i]->expanded);
}
ev.Skip();
}
@@ -264,7 +273,8 @@ void TreeList::onLeftDClick(wxMouseEvent& ev) {
void TreeList::ScrollToLine(size_t line) {
// determine the real first line to scroll to: we shouldn't scroll beyond the end
line = (size_t)min((int)line, (int)(total_lines - visible_lines_t));
line = (size_t)max((int)line, 0);
line = (size_t)min((int)line, max(0, (int)(total_lines - visible_lines_t)));
// nothing to do?
if (line == first_line) return;
first_line = line;
@@ -314,12 +324,13 @@ void TreeList::onScroll(wxScrollWinEvent& ev) {
void TreeList::onSize(wxSizeEvent& ev) {
UpdateScrollbar();
Refresh(false);
ev.Skip();
}
void TreeList::onMouseWheel(wxMouseEvent& ev) {
ScrollLines(-ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta());
Refresh(false);
int delta = -ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta();
ScrollToLine(first_line + delta);
}
+14 -16
View File
@@ -12,8 +12,6 @@
#include <util/prec.hpp>
#include <wx/vscroll.h>
typedef intrusive_ptr<IntrusivePtrVirtualBase> VoidP;
// ----------------------------------------------------------------------------- : TreeList
/// A combination of a TreeCtrl and a ListCtrl. A tree with multiple columns.
@@ -24,7 +22,7 @@ class TreeList : public wxPanel {
/// Expand/collapse an item
void expand(size_t item, bool expand = true);
/// Select an item
void select(size_t item);
void select(size_t item, bool event = true);
/// (re)build the list
void rebuild(bool full = true);
@@ -32,24 +30,26 @@ class TreeList : public wxPanel {
public:
/// An item in the tree list
struct Item {
Item() {}
Item(int level, bool expanded = false, VoidP data = VoidP())
: level(level), expanded(expanded), data(data)
{}
class Item : public IntrusivePtrBase<Item> {
public:
Item() : level(0), expanded(false) {}
virtual ~Item() {}
int level;
bool expanded;
VoidP data;
inline bool visible() const { return position != NOTHING; }
private:
friend class TreeList;
size_t position; // NOTHING if invisible, otherwise the line the item is on
UInt lines; // lines in front of this item (bit set)
inline bool visible() const { return position != NOTHING; }
};
typedef intrusive_ptr<Item> ItemP;
protected:
/// The items in the tree list
vector<Item> items;
vector<ItemP> items;
static const size_t NOTHING = (size_t)-1;
size_t selection;
@@ -57,10 +57,8 @@ class TreeList : public wxPanel {
/// Initialize the items
virtual void initItems() = 0;
/// Get the text of an item
virtual String itemText(size_t item, size_t column) const = 0;
/// Get the color of an item
virtual Color itemColor(size_t item, size_t column) const = 0;
/// Draw the text of an item
virtual void drawItem(DC& dc, size_t index, size_t column, int x, int y, bool selected) const = 0;
/// The number of columns
virtual size_t columnCount() const = 0;
@@ -69,11 +67,11 @@ class TreeList : public wxPanel {
/// The width of a column in pixels
virtual int columnWidth(size_t column) const = 0;
private:
int item_height;
static const int header_height = 17;
static const int level_width = 17;
private:
size_t total_lines; // number of shown items
size_t first_line; // first visible line
size_t visible_lines; // number of (partially) visible lines
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/drop_down_list.hpp>
#include <gui/util.hpp>
#include <render/value/viewer.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/html_export_window.hpp>
#include <gui/control/package_list.hpp>
#include <gui/control/native_look_editor.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/image_slice_window.hpp>
#include <gui/util.hpp>
#include <util/window_id.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/images_export_window.hpp>
#include <gui/control/select_card_list.hpp>
#include <data/settings.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/new_window.hpp>
#include <gui/control/gallery_list.hpp>
#include <gui/control/package_list.hpp>
+884
View File
@@ -0,0 +1,884 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/packages_window.hpp>
#include <gui/control/tree_list.hpp>
//%#include <gui/update_checker.hpp>
#include <gui/util.hpp>
#include <util/io/package_repository.hpp>
#include <util/io/package_manager.hpp>
#include <util/window_id.hpp>
#include <data/installer.hpp>
#include <data/settings.hpp>
#include <gfx/gfx.hpp>
//%#include <list>
//%#include <set>
#include <wx/wfstream.h>
#include <wx/html/htmlwin.h>
#include <wx/dialup.h>
#include <wx/url.h>
#include <wx/dcbuffer.h>
#include <wx/progdlg.h>
//%DECLARE_POINTER_TYPE(VersionData); //%% TODO
DECLARE_POINTER_TYPE(Installer);
//%DECLARE_POINTER_TYPE(PackageVersionData);
DECLARE_TYPEOF_COLLECTION(PackageVersionDataP);
DECLARE_TYPEOF_COLLECTION(PackageDependencyP);
DECLARE_TYPEOF_COLLECTION(InstallablePackageP);
DECLARE_TYPEOF_COLLECTION(TreeList::ItemP);
//%DECLARE_TYPEOF(list<PackageVersionDataP>);
//%DECLARE_TYPEOF(set<String>);
// ----------------------------------------------------------------------------- : TODO: MOVE
/*
/// Information on available packages
class PackageVersionData : public IntrusivePtrVirtualBase {
public:
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
Version app_version; ///< The minimium version of MSE required
vector<PackageDependencyP> depends; ///< Packages this depends on
DECLARE_REFLECTION();
};
/// Information on the latest available version
class VersionData : public IntrusivePtrBase<VersionData> {
public:
Version version; ///< Latest version number of MSE
String description; ///< html description of the latest MSE release
String new_updates_url; ///< updates url has moved?
vector<PackageVersionDataP> packages; ///< Available packages
DECLARE_REFLECTION();
};
extern VersionDataP update_version_data;
// A HTML control that opens all pages in an actual browser
struct HtmlWindowToBrowser : public wxHtmlWindow {
HtmlWindowToBrowser(Window* parent, int id, const wxPoint& pos, const wxSize& size, long flags)
: wxHtmlWindow(parent, id, pos, size, flags)
{}
virtual void OnLinkClicked(const wxHtmlLinkInfo& info) {
wxLaunchDefaultBrowser( info.GetHref() );
}
};
// ----------------------------------------------------------------------------- : PackageUpdateList
/*
class PackageUpdateList : public wxVListBox {
public:
PackageUpdateList(UpdatesWindow* parent)
: wxVListBox (parent, ID_PACKAGE_LIST, wxDefaultPosition, wxSize(540,210), wxNO_BORDER | wxVSCROLL)
, parent(parent)
{
if (!checking_updates && !update_version_data) {
check_updates_now(true);
}
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
static wxBrush greyBrush(Color(224,224,224));
if (checking_updates) {
String text = _ERROR_("checking updates");
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
dc.DrawRectangle(rect);
int w, h;
dc.GetTextExtent(text, &w, &h);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
} else if (!update_version_data || update_version_data->packages.empty()) {
String text = _ERROR_("no packages");
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(greyBrush);
dc.DrawRectangle(rect);
int w, h;
dc.GetTextExtent(text, &w, &h);
dc.DrawText(text, rect.GetLeft() + (rect.GetWidth() - w) / 2, rect.GetTop() + (rect.GetHeight() - h) / 2);
} else {
static wxBrush darkBrush(Color(192,224,255));
static wxBrush selectBrush(Color(96,96,192));
PackageVersionDataP pack = update_version_data->packages[n];
UpdatesWindow::PackageStatus status = parent->package_data[pack].first;
UpdatesWindow::PackageAction action = parent->package_data[pack].second;
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(IsSelected(n) ? selectBrush : (n % 2 ? *wxWHITE_BRUSH : darkBrush));
dc.DrawRectangle(rect);
// These two arrays correspond to PackageStatus and PackageAction, respectively
static Color status_colors [] = {
Color(32,160,32)
,Color(32,32,255)
,Color(192,32,32)
};
static Color action_colors [] = {
Color(32,160,32)
,Color(192,32,32)
,Color(192,192,32)
,Color(32,32,255)
,Color(32,32,32)
};
// Ditto here (these are the locale names)
static String status_texts [] = {
_TYPE_("installed")
,_TYPE_("uninstalled")
,_TYPE_("upgradeable")
};
static String action_texts [] = {
_TYPE_("install")
,_TYPE_("uninstall")
,_TYPE_("upgrade")
,_TYPE_("do nothing")
,_TYPE_("new mse")
};
static Color packageFront(64,64,64);
#define SELECT_WHITE(color) (IsSelected(n) ? *wxWHITE : color)
dc.SetClippingRegion(wxRect(rect.x, rect.y, 180, rect.height));
dc.SetTextForeground(SELECT_WHITE(packageFront));
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() + 300, rect.GetTop());
dc.SetTextForeground(SELECT_WHITE(action_colors[action]));
dc.DrawText(action_texts[action], rect.GetLeft() + 420, rect.GetTop());
#undef SELECT_WHITE
}
}
virtual wxCoord OnMeasureItem(size_t) const {
return (update_version_data && !update_version_data->packages.empty()) ? 15 : 210;
}
void onUpdateCheckingFinished(wxEvent& event) {
SetItemCount(update_version_data ? update_version_data->packages.size() : 1);
}
virtual wxCoord EstimateTotalHeight() const {
return (update_version_data && !update_version_data->packages.empty())
? 15 * (int)update_version_data->packages.size()
: 210;
}
private:
DECLARE_EVENT_TABLE()
UpdatesWindow* parent;
};
BEGIN_EVENT_TABLE(PackageUpdateList, wxVListBox)
EVT_CUSTOM(UPDATE_CHECK_FINISHED_EVT, wxID_ANY, PackageUpdateList::onUpdateCheckingFinished)
END_EVENT_TABLE()
*/
// ----------------------------------------------------------------------------- : PackageUpdateList
/// A list of installed and downloadable packages
class PackageUpdateList : public TreeList {
public:
PackageUpdateList(PackagesWindow* parent, int id = wxID_ANY)
: TreeList(parent, id)
, parent(parent)
, images(16,16)
{
item_height = max(item_height,17);
rebuild();
}
InstallablePackageP getSelection() const {
return selection == NOTHING ? InstallablePackageP() : get(selection);
}
InstallablePackageP get(size_t item) const {
return static_pointer_cast<TreeItem>(items[item])->package;
}
protected:
virtual void initItems();
virtual void drawItem(DC& dc, size_t index, size_t column, int x, int y, bool selected) const;
virtual size_t columnCount() const { return 3; }
virtual String columnText(size_t column) const;
virtual int columnWidth(size_t column) const;
private:
PackagesWindow* parent;
mutable wxImageList images;
class TreeItem;
public:
typedef intrusive_ptr<TreeItem> TreeItemP;
private:
class TreeItem : public Item {
public:
String label;
vector<TreeItemP> children;
InstallablePackageP package;
void add(const InstallablePackageP& package, const String& path, int level = -1);
void toItems(vector<TreeList::ItemP>& items);
};
};
DECLARE_TYPEOF_COLLECTION(PackageUpdateList::TreeItemP);
void PackageUpdateList::TreeItem::add(const InstallablePackageP& package, const String& path, int level) {
size_t pos = path.find_first_of(_('/'));
String name = path.substr(0,pos);
String rest = pos == String::npos ? _("") : path.substr(pos+1);
// find/add child
FOR_EACH(ti, children) {
if (ti->label == name) {
// already have this child
if (pos == String::npos) {
if (ti->package) {
// two packages with the same path
TreeItemP ti2(new TreeItem);
ti2->level = level + 1;
ti2->label = name;
ti2->package = package;
children.insert(ti_IT.first, ti2);
} else {
ti->package = package;
}
} else {
ti->add(package, rest, level + 1);
}
return;
}
}
// don't have this child
TreeItemP ti(new TreeItem);
children.push_back(ti);
ti->level = level + 1;
ti->label = name;
if (pos == String::npos) {
ti->package = package;
} else {
ti->add(package, rest, level + 1);
}
}
bool compare_pos_hint(const PackageUpdateList::TreeItemP& a, const PackageUpdateList::TreeItemP& b) {
int pa = a->package ? a->package->description->position_hint : 0;
int pb = b->package ? b->package->description->position_hint : 0;
if (pa < pb) return true;
if (pa > pb) return false;
return a->label < b->label;
}
void PackageUpdateList::TreeItem::toItems(vector<TreeList::ItemP>& items) {
sort(children.begin(), children.end(), compare_pos_hint);
FOR_EACH(c, children) {
items.push_back(c);
c->toItems(items);
}
}
void PackageUpdateList::initItems() {
// packages to tree
TreeItem root;
FOR_EACH(ip, parent->installable_packages) {
String group = ip->description->installer_group;
//% if (group.empty()) group = _("Custom");
//% group += _("/");
if (!group.empty()) group += _("/");
group += ip->description->short_name;
root.add(ip, group);
}
// tree to treelist items
items.clear();
root.toItems(items);
// init image list
images.RemoveAll();
Image resampled(16,16,false);
FOR_EACH(i,items) {
const TreeItem& ti = static_cast<const TreeItem&>(*i);
const InstallablePackageP& p = ti.package;
if (p && p->description->icon.Ok()) {
resample_preserve_aspect(p->description->icon, resampled);
images.Add(resampled);
} else if (p) {
images.Add(load_resource_image(_("installer_package")));
} else if (ti.label == _("locales")) {
images.Add(load_resource_image(_("installer_locales")));
} else {
images.Add(load_resource_image(_("installer_group")));
}
}
}
void PackageUpdateList::drawItem(DC& dc, size_t index, size_t column, int x, int y, bool selected) const {
const TreeItem& ti = static_cast<const TreeItem&>(*items[index]);
Color color = wxSystemSettings::GetColour(selected ? wxSYS_COLOUR_HIGHLIGHTTEXT : wxSYS_COLOUR_WINDOWTEXT);
if (column == 0) {
// Name
images.Draw((int)index, dc, x, y);
dc.SetTextForeground(color);
dc.DrawText(ti.label, x+18, y+2);
} else if (column == 1 && ti.package) {
// Status
int stat = ti.package->status;
if ((stat & PACKAGE_CONFLICTS) == PACKAGE_CONFLICTS) {
dc.DrawText(_LABEL_("package conflicts"), x+1,y+2);
} else if ((stat & PACKAGE_MODIFIED) == PACKAGE_MODIFIED) {
dc.DrawText(_LABEL_("package modified"), x+1,y+2);
} else if ((stat & PACKAGE_UPDATES) == PACKAGE_UPDATES) {
dc.DrawText(_LABEL_("package updates"), x+1,y+2);
} else if ((stat & PACKAGE_INSTALLED) == PACKAGE_INSTALLED) {
dc.DrawText(_LABEL_("package installed"), x+1,y+2);
} else if ((stat & PACKAGE_INSTALLABLE) == PACKAGE_INSTALLABLE) {
dc.DrawText(_LABEL_("package installable"), x+1,y+2);
}
} else if (column == 2 && ti.package) {
// Action
int act = ti.package->action;
if (act & PACKAGE_INSTALL) {
dc.DrawText(_LABEL_("install package"), x+1,y+2);
} else if (act & PACKAGE_UPGRADE) {
dc.DrawText(_LABEL_("upgrade package"), x+1,y+2);
} else if (act & PACKAGE_REMOVE) {
dc.DrawText(_LABEL_("remove package"), x+1,y+2);
}
}
}
String PackageUpdateList::columnText(size_t column) const {
if (column == 0) return _LABEL_("package name");
else if (column == 1) return _LABEL_("package status");
else if (column == 2) return _LABEL_("package action");
else throw InternalError(_("Unknown column"));
}
int PackageUpdateList::columnWidth(size_t column) const {
if (column == 0) {
wxSize cs = GetClientSize();
return cs.x - 300;
} else {
return 150;
}
}
// ----------------------------------------------------------------------------- : PackageInfoPanel
class PackageInfoPanel : public wxPanel {
public:
PackageInfoPanel(Window* parent);
void setPackage(const InstallablePackageP& package);
virtual wxSize DoGetBestSize() const;
private:
InstallablePackageP package;
DECLARE_EVENT_TABLE();
void onPaint(wxPaintEvent&);
};
PackageInfoPanel::PackageInfoPanel(Window* parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
{}
void PackageInfoPanel::setPackage(const InstallablePackageP& package) {
this->package = package;
Refresh(false);
}
void PackageInfoPanel::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this);
wxSize cs = GetClientSize();
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
dc.DrawRectangle(0,0,cs.x,cs.y);
// draw package info
if (!package) return;
PackageDescription& d = *package->description;
int x = 5;
if (d.icon.Ok()) {
int h = d.icon.GetHeight();
int y = max(0,20-h)/2 + 5;
dc.DrawBitmap(d.icon, x,y);
x += d.icon.GetWidth();
}
dc.SetFont(wxFont(16, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _("Arial")));
dc.DrawText(d.full_name, x + 5, 3);
}
wxSize PackageInfoPanel::DoGetBestSize() const {
return wxSize(200, 120);
}
BEGIN_EVENT_TABLE(PackageInfoPanel, wxPanel)
EVT_PAINT(PackageInfoPanel::onPaint)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : PackagesWindow
PackagesWindow::PackagesWindow(Window* parent, bool download_package_list)
: wxDialog(parent, wxID_ANY, _TITLE_("package list"), wxDefaultPosition, wxSize(640,480), wxDEFAULT_DIALOG_STYLE | wxCLIP_CHILDREN | wxRESIZE_BORDER)
, where(is_install_local(settings.install_type) ? PACKAGE_LOCAL : PACKAGE_GLOBAL)
{
// get packages
wxBusyCursor busy;
packages.installedPackages(installable_packages);
FOR_EACH(p, installable_packages) p->determineStatus();
// ui elements
SetIcon(wxIcon());
package_list = new PackageUpdateList(this, ID_PACKAGE_LIST);
package_info = new PackageInfoPanel(this);
//wxToolbar* buttons = new wxToolbar
wxButton* install_button = new wxButton(this, ID_INSTALL, _BUTTON_("install package"));
wxButton* upgrade_button = new wxButton(this, ID_UPGRADE, _BUTTON_("upgrade package"));
wxButton* remove_button = new wxButton(this, ID_REMOVE, _BUTTON_("remove package"));
/*
description_window = new HtmlWindowToBrowser(this, wxID_ANY, wxDefaultPosition, wxSize(540,100), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
setDefaultPackageStatus();
(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"));
// Init sizer
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();
*/
/* wxBoxSizer *h2 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *h3 = new wxBoxSizer(wxHORIZONTAL);
h3->AddStretchSpacer();
h3->Add(apply_button);
h3->AddStretchSpacer();
// v->Add(h2);
// v->Add(h3);*/
wxBoxSizer* v = new wxBoxSizer(wxVERTICAL);
v->Add(package_list, 1, wxEXPAND | wxALL & ~wxBOTTOM, 8);
v->AddSpacer(4);
wxBoxSizer* h = new wxBoxSizer(wxHORIZONTAL);
h->Add(package_info, 1, wxRIGHT, 4);
wxBoxSizer* v2 = new wxBoxSizer(wxVERTICAL);
v2->Add(install_button, 0, wxEXPAND | wxBOTTOM, 4);
v2->Add(upgrade_button, 0, wxEXPAND | wxBOTTOM, 4);
v2->Add(remove_button, 0, wxEXPAND | wxBOTTOM, 4);
v2->AddStretchSpacer();
h->Add(v2);
v->Add(h, 0, wxEXPAND | wxALL & ~wxTOP, 8);
v->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxALL & ~wxTOP, 8);
SetSizer(v);
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
PackagesWindow::~PackagesWindow() {
//(new WelcomeWindow)->Show();
}
/*
void PackagesWindow::onUpdateCheckFinished(wxCommandEvent&) {
setDefaultPackageStatus();
}*/
void PackagesWindow::onPackageSelect(wxCommandEvent& ev) {
// updateButtons(package_list->getSelection());
package_info->setPackage(package = package_list->getSelection());
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
void PackagesWindow::onActionChange(wxCommandEvent& ev) {
if (package) {
PackageAction act = ev.GetId() == ID_INSTALL ? PACKAGE_INSTALL
: ev.GetId() == ID_UPGRADE ? PACKAGE_UPGRADE
: ev.GetId() == ID_REMOVE ? PACKAGE_REMOVE
: PACKAGE_NOTHING;
act = (PackageAction)(act | where);
// toggle action
if (package->has(act)) {
set_package_action(installable_packages, package, (PackageAction)(PACKAGE_NOTHING | where));
} else {
set_package_action(installable_packages, package, act);
}
package_list->Refresh(false);
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
}
void PackagesWindow::onOk(wxCommandEvent& ev) {
// Do we need a new version of MSE first?
// progress dialog
int total = (int)installable_packages.size();
wxProgressDialog progress(
_TITLE_("installing updates"),
String::Format(_ERROR_("downloading updates"), 0, 2*total),
total,
this,
wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_SMOOTH
);
// Clear package list
packages.reset();
// Download installers
int n = 0;
FOR_EACH(ip, installable_packages) {
++n;
if (!progress.Update(n, String::Format(_ERROR_("downloading updates"), n, total))) {
return; // aborted
}
if ((ip->action & (PACKAGE_INSTALL | PACKAGE_UPGRADE)) && ip->installer && !ip->installer->installer) {
// download installer
wxURL url(ip->installer->installer_url);
wxInputStream* is = url.GetInputStream();
if (!is) {
throw Error(_ERROR_2_("can't download installer", ip->description->name, ip->installer->installer_url));
}
ip->installer->installer_file = wxFileName::CreateTempFileName(_("mse-installer"));
wxFileOutputStream os(ip->installer->installer_file);
os.Write(*is);
os.Close();
// open installer
ip->installer->installer = new_intrusive<Installer>();
ip->installer->installer->open(ip->installer->installer_file);
}
}
// Install stuff
int n2 = 0 ;
FOR_EACH(ip, installable_packages) {
++n; ++n2;
if (!progress.Update(n, String::Format(_ERROR_("installing updates"), n2, total))) {
// don't allow abort.
}
packages.install(*ip);
}
// Done
wxDialog::OnOK(ev);
}
void PackagesWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch (ev.GetId()) {
case ID_INSTALL:
case ID_UPGRADE:
case ID_REMOVE: {
PackageAction act = ev.GetId() == ID_INSTALL ? PACKAGE_INSTALL
: ev.GetId() == ID_UPGRADE ? PACKAGE_UPGRADE
: ev.GetId() == ID_REMOVE ? PACKAGE_REMOVE
: PACKAGE_NOTHING;
act = (PackageAction)(act | where);
ev.Check (package && package->has(act));
ev.Enable(package && package->can(act));
break;
}
}
}
/*
void PackagesWindow::onActionChange(wxCommandEvent& ev) {
PackageVersionDataP pack = package_list->getSelection();
if (!pack) return;
PackageAction& action = package_data[pack].second;
switch (ev.GetId()) {
case ID_INSTALL:
action = ACTION_INSTALL;
SelectPackageDependencies(pack);
break;
case ID_REMOVE:
action = ACTION_UNINSTALL;
RemovePackageDependencies(pack);
break;
case ID_UPGRADE:
action = ACTION_UPGRADE;
SelectPackageDependencies(pack);
break;
case ID_CANCEL:
switch (package_data[pack].first) {
case STATUS_INSTALLED:
SelectPackageDependencies(pack);
break;
case STATUS_NOT_INSTALLED:
RemovePackageDependencies(pack);
break;
case STATUS_UPGRADEABLE:
if (action == ACTION_UPGRADE)
DowngradePackageDependencies(pack);
else
SelectPackageDependencies(pack);
break;
}
action = (pack->app_version > file_version) ? ACTION_NEW_MSE : ACTION_NOTHING;
break;
}
updateButtons(package_list->getSelection());
package_list->Refresh();
}
void PackagesWindow::onApplyChanges(wxCommandEvent& ev) {
list<PackageVersionDataP> to_install, to_remove;
FOR_EACH(pack, update_version_data->packages) {
switch (package_data[pack].second) {
case ACTION_INSTALL:
to_install.push_back(pack);
break;
case ACTION_UPGRADE:
to_install.push_back(pack);
case ACTION_UNINSTALL:
to_remove.push_back(pack);
default:;
}
}
FOR_EACH(pack, to_remove) {
String filename = packages.openAny(pack->name, true)->absoluteFilename();
if (!remove_file_or_dir(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."));
}
}
FOR_EACH(pack, to_install) {
wxURL url(pack->url);
wxInputStream* is = url.GetInputStream();
if (!is) {
handle_error(_("Cannot fetch file ") + pack->url + _(" to install package ") + pack->name + _(". ")
_("Other packages may have been installed, including packages that depend on this one. ")
_("Please remove those packages manually or install this one manually."));
}
wxString filename = wxFileName::CreateTempFileName(_(""));
wxFileOutputStream os (filename);
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();
}
void PackagesWindow::updateButtons(const PackageVersionDataP& pack) {
description_window->SetPage(pack->description);
PackageStatus status = package_data[pack].first;
PackageAction action = package_data[pack].second;
if (action == ACTION_NEW_MSE) {
install_button->Disable();
remove_button->Enable(status != STATUS_NOT_INSTALLED);
upgrade_button->Disable();
cancel_button->Disable();
} else if (status == STATUS_INSTALLED) {
install_button->Disable();
remove_button->Enable(action != ACTION_UNINSTALL);
upgrade_button->Disable();
cancel_button->Enable(action == ACTION_UNINSTALL);
} else if (status == STATUS_NOT_INSTALLED) {
install_button->Enable(action != ACTION_INSTALL);
remove_button->Disable();
upgrade_button->Disable();
cancel_button->Enable(action == ACTION_INSTALL);
} else /* status == STATUS_UPGRADEABLE * / {
install_button->Disable();
remove_button->Enable(action != ACTION_UNINSTALL);
upgrade_button->Enable(action != ACTION_UPGRADE);
cancel_button->Enable(action != ACTION_NOTHING);
}
}
void PackagesWindow::setDefaultPackageStatus() {
if (!update_version_data) return;
FOR_EACH(p, update_version_data->packages) {
PackagedP pack;
try { pack = packages.openAny(p->name, true); }
catch (PackageNotFoundError&) { } // We couldn't open a package... no cause for alarm
if (!pack || !(wxFileExists(pack->absoluteFilename()) || wxDirExists(pack->absoluteFilename()))) {
// not installed
if (p->app_version > file_version) {
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NEW_MSE);
} else {
package_data[p] = PackageData(STATUS_NOT_INSTALLED, ACTION_NOTHING);
}
} else if (pack->version < p->version) {
// newer version
if (p->app_version > file_version) {
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_NEW_MSE);
} else {
package_data[p] = PackageData(STATUS_UPGRADEABLE, ACTION_UPGRADE);
}
} else {
package_data[p] = PackageData(STATUS_INSTALLED, ACTION_NOTHING);
}
}
}
/// 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 PackagesWindow::SelectPackageDependencies (PackageVersionDataP pack) {
FOR_EACH(dep, pack->depends) {
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.
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 PackagesWindow::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_NEW_MSE : ACTION_NOTHING;
break;
}
}
}
}
/// This deals with the complexities of a downgrade and its dependencies.
void PackagesWindow::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, false)) //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.
// Ideally, some sort of error should occur, such that we don't have packages
// with unmet dependencies.
}
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_NEW_MSE : ACTION_NOTHING;
break;
}
}
}
}
}
*/
BEGIN_EVENT_TABLE(PackagesWindow, wxDialog)
// EVT_COMMAND(wxID_ANY, UPDATE_CHECK_FINISHED_EVT, PackagesWindow::onUpdateCheckFinished)
EVT_LISTBOX(ID_PACKAGE_LIST, PackagesWindow::onPackageSelect)
EVT_BUTTON(ID_INSTALL, PackagesWindow::onActionChange)
EVT_BUTTON(ID_REMOVE, PackagesWindow::onActionChange)
EVT_BUTTON(ID_UPGRADE, PackagesWindow::onActionChange)
EVT_BUTTON(wxID_OK, PackagesWindow::onOk)
EVT_UPDATE_UI(wxID_ANY, PackagesWindow::onUpdateUI)
END_EVENT_TABLE()
+76
View File
@@ -0,0 +1,76 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_PACKAGES_WINDOW
#define HEADER_GUI_PACKAGES_WINDOW
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/installer.hpp>
// #include <gui/welcome_window.hpp> //???
class PackageUpdateList;
class PackageInfoPanel;
//class wxHtmlWindow;
//DECLARE_POINTER_TYPE(PackageVersionData);
//DECLARE_POINTER_TYPE(PackageVersion);
//DECLARE_POINTER_TYPE(PackageDescription);
//DECLARE_POINTER_TYPE(InstallableInstaller);
DECLARE_POINTER_TYPE(InstallablePackage);
// ----------------------------------------------------------------------------- : Available Packages
// ----------------------------------------------------------------------------- : Packages window
/// A window that displays the installed packages and updates to them
class PackagesWindow : public wxDialog {
public:
PackagesWindow(Window* parent, bool download_package_list = true);
~PackagesWindow();
InstallablePackages installable_packages;
private:
PackageUpdateList* package_list; ///< List of available packages
PackageInfoPanel* package_info; ///< Description of the selected package
InstallablePackageP package; ///< Selected package
PackageAction where; ///< Where to install? (PACKAGE_LOCAL or PACKAGE_GLOBAL)
DECLARE_EVENT_TABLE();
void onOk(wxCommandEvent&);
void onActionChange(wxCommandEvent&);
void onPackageSelect(wxCommandEvent&);
void onUpdateUI(wxUpdateUIEvent&);
/*
wxHtmlWindow* description_window;
wxButton *install_button, *upgrade_button, *remove_button, *cancel_button, *apply_button;
void onUpdateCheckFinished(wxCommandEvent&);
void onPackageSelect(wxCommandEvent&);
void onActionChange(wxCommandEvent&);
void onApplyChanges(wxCommandEvent&);
void SelectPackageDependencies (PackageVersionDataP);
void RemovePackageDependencies (PackageVersionDataP);
void DowngradePackageDependencies(PackageVersionDataP);
/// Update the buttons to indicate that this is selected.
void updateButtons(const PackageVersionDataP& pack);
void setDefaultPackageStatus();
*/
};
// ----------------------------------------------------------------------------- : EOF
#endif
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/preferences_window.hpp>
#include <gui/update_checker.hpp>
#include <data/settings.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/print_window.hpp>
#include <gui/card_select_window.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/cards_panel.hpp>
#include <gui/control/image_card_list.hpp>
#include <gui/control/card_editor.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/keywords_panel.hpp>
#include <gui/control/keyword_list.hpp>
#include <gui/control/text_ctrl.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
#include <data/card.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/set_info_panel.hpp>
#include <gui/control/native_look_editor.hpp>
#include <gui/icon_menu.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/stats_panel.hpp>
#include <gui/control/graph.hpp>
#include <gui/control/gallery_list.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/style_panel.hpp>
#include <gui/control/package_list.hpp>
#include <gui/control/card_viewer.hpp>
+5 -3
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/window.hpp>
#include <gui/set/panel.hpp>
#include <gui/set/cards_panel.hpp>
@@ -18,6 +19,7 @@
#include <gui/control/gallery_list.hpp>
#include <gui/about_window.hpp>
#include <gui/update_checker.hpp>
#include <gui/packages_window.hpp>
#include <gui/new_window.hpp>
#include <gui/preferences_window.hpp>
#include <gui/print_window.hpp>
@@ -538,8 +540,8 @@ void SetWindow::onFileExportMWS(wxCommandEvent&) {
void SetWindow::onFileCheckUpdates(wxCommandEvent&) {
if (!askSaveAndContinue()) return;
(new UpdatesWindow)->Show();
Destroy();
(new PackagesWindow(this))->Show();
//Destroy();
}
void SetWindow::onFilePrint(wxCommandEvent&) {
@@ -562,7 +564,7 @@ void SetWindow::onFileReload(wxCommandEvent&) {
vector<CardP>::const_iterator card_it = find(set->cards.begin(), set->cards.end(), current_panel->selectedCard());
if (card_it != set->cards.end()) card_pos = card_it - set->cards.begin();
}
packages.destroy(); // unload all packages
packages.reset(); // unload all packages
settings.read(); // reload settings
setSet(import_set(filename));
// reselect card
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/basic_shape_editor.hpp>
#include <gui/util.hpp>
#include <util/window_id.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/control.hpp>
#include <gui/symbol/window.hpp>
#include <gui/symbol/editor.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/editor.hpp>
#include <gui/symbol/window.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/part_list.hpp>
#include <gui/symbol/selection.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/point_editor.hpp>
#include <gui/symbol/window.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/select_editor.hpp>
#include <gui/symbol/window.hpp>
#include <gui/util.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/selection.hpp>
#include <data/symbol.hpp>
#include <gfx/bezier.hpp>
+1
View File
@@ -6,6 +6,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/symbol/symmetry_editor.hpp>
#include <gui/util.hpp>
#include <util/window_id.hpp>

Some files were not shown because too many files have changed in this diff Show More