mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
PACKAGE_INSTALL now stands for both installation and upgrades
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@795 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+28
-26
@@ -38,6 +38,7 @@ IMPLEMENT_REFLECTION(Installer) {
|
||||
REFLECT(packages);
|
||||
}
|
||||
|
||||
/*
|
||||
// ----------------------------------------------------------------------------- : Installing
|
||||
|
||||
void Installer::installFrom(const String& filename, bool message_on_success, bool local) {
|
||||
@@ -134,12 +135,12 @@ void Installer::install(bool local, bool check_dependencies) {
|
||||
}
|
||||
os.Write(*is);
|
||||
}
|
||||
*/
|
||||
* /
|
||||
}
|
||||
|
||||
void Installer::install(const String& package) {
|
||||
// TODO
|
||||
}
|
||||
}*/
|
||||
|
||||
// ----------------------------------------------------------------------------- : Creating
|
||||
|
||||
@@ -191,10 +192,6 @@ PackageDescription::PackageDescription(const Packaged& package)
|
||||
, 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()) {
|
||||
@@ -238,17 +235,26 @@ DownloadableInstaller::~DownloadableInstaller() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Installable package
|
||||
|
||||
InstallablePackage::InstallablePackage() : action(PACKAGE_NOTHING) {}
|
||||
InstallablePackage::InstallablePackage(const PackageVersionP& installed, const PackageDescriptionP& description)
|
||||
: installed(installed)
|
||||
, description(description)
|
||||
, action(PACKAGE_NOTHING)
|
||||
, status(PACKAGE_INSTALLED)
|
||||
{}
|
||||
InstallablePackage::InstallablePackage(const PackageDescriptionP& description , const DownloadableInstallerP& installer)
|
||||
: description(description)
|
||||
, installer(installer)
|
||||
, action(PACKAGE_NOTHING)
|
||||
, status(PACKAGE_INSTALLABLE)
|
||||
{}
|
||||
|
||||
void InstallablePackage::determineStatus() {
|
||||
status = PACKAGE_NOT_INSTALLED;
|
||||
if (installer) {
|
||||
status = (PackageStatus)(status | PACKAGE_INSTALLABLE);
|
||||
status = (PackageStatus)(status | PACKAGE_INSTALLER);
|
||||
if (!installed || installed->version < description->version) {
|
||||
status = (PackageStatus)(status | PACKAGE_INSTALLABLE);
|
||||
}
|
||||
}
|
||||
if (installed) {
|
||||
status = (PackageStatus)(status | PACKAGE_INSTALLED);
|
||||
@@ -256,19 +262,19 @@ void InstallablePackage::determineStatus() {
|
||||
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::willBeInstalled() const {
|
||||
return (action & PACKAGE_INSTALL) ||
|
||||
((status & PACKAGE_INSTALLED) && !(action & PACKAGE_REMOVE));
|
||||
}
|
||||
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_INSTALL) return flag(status, PACKAGE_INSTALLABLE);
|
||||
if (act & PACKAGE_REMOVE) {
|
||||
bool ok = (status & PACKAGE_REMOVABLE) == PACKAGE_REMOVABLE;
|
||||
bool ok = flag(status, PACKAGE_REMOVABLE);
|
||||
if (!(act & PACKAGE_GLOBAL) && installed && PackageVersion::STATUS_GLOBAL) {
|
||||
// package installed globally can't be removed locally
|
||||
return false;
|
||||
@@ -322,17 +328,14 @@ void merge(InstallablePackages& list1, const InstallablePackages& list2) {
|
||||
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);
|
||||
ips.push_back(new_intrusive2<InstallablePackage>(p,installer));
|
||||
}
|
||||
sort(ips);
|
||||
merge(installed, ips);
|
||||
}
|
||||
|
||||
|
||||
bool add_package_dependency(InstallablePackages& packages, const PackageDependency& dep, int where, bool set) {
|
||||
bool add_package_dependency(InstallablePackages& packages, const PackageDependency& dep, PackageAction where, bool set) {
|
||||
FOR_EACH(p, packages) {
|
||||
if (p->description->name == dep.package) {
|
||||
// Some package depends on this package, so install it if needed
|
||||
@@ -340,7 +343,7 @@ bool add_package_dependency(InstallablePackages& packages, const PackageDependen
|
||||
// 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)) {
|
||||
if (p->action & PACKAGE_INSTALL) {
|
||||
// this package is already scheduled for installation
|
||||
if (p->automatic) {
|
||||
// we are already automatically depending on this package
|
||||
@@ -352,8 +355,7 @@ bool add_package_dependency(InstallablePackages& packages, const PackageDependen
|
||||
}
|
||||
}
|
||||
} else if (set) {
|
||||
p->action = (PackageAction)(where |
|
||||
(p->installed ? PACKAGE_UPGRADE : PACKAGE_INSTALL));
|
||||
p->action = where | PACKAGE_INSTALL;
|
||||
p->automatic = 1;
|
||||
change = true;
|
||||
}
|
||||
@@ -370,7 +372,7 @@ bool add_package_dependency(InstallablePackages& packages, const PackageDependen
|
||||
return false;
|
||||
}
|
||||
|
||||
void remove_package_dependency(InstallablePackages& packages, const PackageDescription& ver, int where, bool set) {
|
||||
void remove_package_dependency(InstallablePackages& packages, const PackageDescription& ver, PackageAction where, bool set) {
|
||||
FOR_EACH(p, packages) {
|
||||
FOR_EACH(dep, p->description->dependencies) {
|
||||
if (dep->package == ver.name) {
|
||||
@@ -385,7 +387,7 @@ void remove_package_dependency(InstallablePackages& packages, const PackageDescr
|
||||
}
|
||||
}
|
||||
} else if (set) {
|
||||
p->action = (PackageAction)(where | PACKAGE_REMOVE);
|
||||
p->action = where | PACKAGE_REMOVE;
|
||||
p->automatic = 1;
|
||||
remove_package_dependency(packages, *p->description, where, set);
|
||||
}
|
||||
@@ -396,8 +398,8 @@ void remove_package_dependency(InstallablePackages& packages, const PackageDescr
|
||||
}
|
||||
|
||||
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))) {
|
||||
PackageAction where = (PackageAction)(action & PACKAGE_WHERE);
|
||||
if ((action & PACKAGE_INSTALL) || ((action & PACKAGE_NOTHING) && (package->status & PACKAGE_INSTALLED))) {
|
||||
// need the package
|
||||
package->automatic = 0;
|
||||
package->action = action;
|
||||
|
||||
+15
-7
@@ -26,13 +26,15 @@ class Installer : public Packaged {
|
||||
String prefered_filename; ///< What filename should be used (by default)
|
||||
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);
|
||||
/// Install all the packages
|
||||
void install(bool local, bool check_dependencies = true);
|
||||
/// Install a specific package
|
||||
void install(const String& package);
|
||||
|
||||
*/
|
||||
|
||||
/// Add a package to the installer (if it is not already added).
|
||||
/** If the package is named *.mse-installer uses it as the filename instead */
|
||||
void addPackage(const String& package);
|
||||
@@ -99,7 +101,8 @@ enum PackageStatus
|
||||
{ PACKAGE_NOT_INSTALLED = 0x0000
|
||||
, PACKAGE_INSTALLED = 0x0001
|
||||
, PACKAGE_REMOVABLE = 0x0002
|
||||
, PACKAGE_INSTALLABLE = 0x0010
|
||||
, PACKAGE_INSTALLER = 0x0010 ///< Package can be installed (there is an installer)
|
||||
, PACKAGE_INSTALLABLE = 0x0110 ///< Package can be installed (it makes sense to do so)
|
||||
, PACKAGE_UPDATES = 0x0111 ///< Remote updates available
|
||||
, PACKAGE_MODIFIED = 0x1001 ///< Local changes made
|
||||
, PACKAGE_CONFLICTS = PACKAGE_UPDATES | PACKAGE_MODIFIED
|
||||
@@ -108,18 +111,21 @@ enum PackageStatus
|
||||
/// (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_INSTALL = 0x002 ///< Install or upgrade the package
|
||||
, PACKAGE_REMOVE = 0x004 ///< Remove the package (if it was installed)
|
||||
, PACKAGE_LOCAL = 0x010 ///< In the local package directory
|
||||
, PACKAGE_GLOBAL = 0x020 ///< In the global package directory
|
||||
, PACKAGE_WHERE = PACKAGE_LOCAL | PACKAGE_GLOBAL
|
||||
};
|
||||
// bit twidling
|
||||
inline PackageAction operator | (PackageAction a, PackageAction b) { return (PackageAction)((int)a | (int) b); }
|
||||
inline bool flag(int flags, int flag) { return (flags & flag) == flag; }
|
||||
|
||||
/// A package that can be installed, or is already installed
|
||||
class InstallablePackage : public IntrusivePtrVirtualBase {
|
||||
public:
|
||||
InstallablePackage();
|
||||
//InstallablePackage();
|
||||
InstallablePackage(const PackageDescriptionP&, const DownloadableInstallerP&);
|
||||
InstallablePackage(const PackageVersionP&, const PackageDescriptionP&);
|
||||
|
||||
PackageVersionP installed; ///< The information of the installed package (if installed)
|
||||
@@ -130,12 +136,14 @@ class InstallablePackage : public IntrusivePtrVirtualBase {
|
||||
|
||||
int automatic; ///< Install/upgrade/remove automaticly to satisfy this many packages
|
||||
|
||||
|
||||
PackageAction old_action;
|
||||
int old_automatic;
|
||||
|
||||
void determineStatus();
|
||||
|
||||
/// After the action, will the package be installed?
|
||||
bool willBeInstalled() const;
|
||||
|
||||
/// Is the action possible?
|
||||
bool can(PackageAction act) const;
|
||||
/// Is the action currently selected?
|
||||
|
||||
@@ -205,6 +205,7 @@ DECLARE_TYPEOF(map<String COMMA String>);
|
||||
DECLARE_TYPEOF(map<String COMMA KeyValidator>);
|
||||
|
||||
void Locale::validate(Version ver) {
|
||||
Packaged::validate(ver);
|
||||
// load locale validator
|
||||
LocaleValidator v;
|
||||
Reader r(load_resource_text(_("expected_locale_keys")), nullptr, _("expected_locale_keys"));
|
||||
|
||||
@@ -131,6 +131,7 @@ void fix_value_207(const ValueP& value) {
|
||||
}
|
||||
|
||||
void Set::validate(Version file_app_version) {
|
||||
Packaged::validate(file_app_version);
|
||||
// are the
|
||||
if (!game) {
|
||||
throw Error(_ERROR_("no game specified for the set"));
|
||||
|
||||
@@ -64,7 +64,8 @@ String StyleSheet::stylesheetName() const {
|
||||
String StyleSheet::typeNameStatic() { return _("style"); }
|
||||
String StyleSheet::typeName() const { return _("style"); }
|
||||
|
||||
void StyleSheet::validate(Version) {
|
||||
void StyleSheet::validate(Version ver) {
|
||||
Packaged::validate(ver);
|
||||
if (!game) {
|
||||
throw Error(_ERROR_("no game specified for stylesheet"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user