Commit d2666705 authored by twanvl's avatar twanvl

PACKAGE_INSTALL now stands for both installation and upgrades

parent 9c2ef1cf
......@@ -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;
......
......@@ -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"));
}
......
......@@ -204,10 +204,7 @@ void PackageUpdateList::TreeItem::toItems(vector<TreeList::ItemP>& items) {
}
bool PackageUpdateList::TreeItem::highlight() const {
if (package && ((package->installed && !(package->action & PACKAGE_REMOVE))
|| package->action & (PACKAGE_INSTALL | PACKAGE_UPGRADE))) {
return true;
}
if (package && package->willBeInstalled()) return true;
FOR_EACH_CONST(c,children) if (c->highlight()) return true;
return false;
}
......@@ -281,11 +278,13 @@ void PackageUpdateList::drawItem(DC& dc, size_t index, size_t column, int x, int
// Action
int act = ti.package->action;
if (act & PACKAGE_INSTALL) {
dc.SetTextForeground(lerp(color,Color(0,255,0),0.5));
dc.DrawText(_LABEL_("install package"), x+1,y+2);
} else if (act & PACKAGE_UPGRADE) {
dc.SetTextForeground(lerp(color,Color(0,0,255),0.5));
dc.DrawText(_LABEL_("upgrade package"), x+1,y+2);
if (ti.package->status & PACKAGE_INSTALLED) {
dc.SetTextForeground(lerp(color,Color(0,0,255),0.5));
dc.DrawText(_LABEL_("upgrade package"), x+1,y+2);
} else {
dc.SetTextForeground(lerp(color,Color(0,255,0),0.5));
dc.DrawText(_LABEL_("install package"), x+1,y+2);
}
} else if (act & PACKAGE_REMOVE) {
dc.SetTextForeground(lerp(color,Color(255,0,0),0.5));
dc.DrawText(_LABEL_("remove package"), x+1,y+2);
......@@ -364,6 +363,7 @@ BEGIN_EVENT_TABLE(PackageInfoPanel, wxPanel)
EVT_PAINT(PackageInfoPanel::onPaint)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : PackagesWindow
PackagesWindow::PackagesWindow(Window* parent, bool download_package_list)
......@@ -377,7 +377,7 @@ PackagesWindow::PackagesWindow(Window* parent, bool download_package_list)
wxBusyCursor busy;
packages.installedPackages(installable_packages);
FOR_EACH(p, installable_packages) p->determineStatus();
checkInstallerList();
checkInstallerList(false);
// ui elements
SetIcon(wxIcon());
......@@ -420,13 +420,13 @@ void PackagesWindow::onPackageSelect(wxCommandEvent& ev) {
void PackagesWindow::onActionChange(wxCommandEvent& ev) {
if (package) {
PackageAction act = ev.GetId() == ID_INSTALL ? PACKAGE_INSTALL
: ev.GetId() == ID_UPGRADE ? PACKAGE_UPGRADE
: ev.GetId() == ID_UPGRADE ? PACKAGE_INSTALL
: ev.GetId() == ID_REMOVE ? PACKAGE_REMOVE
: PACKAGE_NOTHING;
act = (PackageAction)(act | where);
act = act | where;
// toggle action
if (package->has(act)) {
set_package_action(installable_packages, package, (PackageAction)(PACKAGE_NOTHING | where));
set_package_action(installable_packages, package, PACKAGE_NOTHING | where);
} else {
set_package_action(installable_packages, package, act);
}
......@@ -455,7 +455,7 @@ void PackagesWindow::onOk(wxCommandEvent& ev) {
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) {
if ((ip->action & PACKAGE_INSTALL) && ip->installer && !ip->installer->installer) {
// download installer
wxURL url(ip->installer->installer_url);
wxInputStream* is = url.GetInputStream();
......@@ -487,17 +487,17 @@ void PackagesWindow::onOk(wxCommandEvent& ev) {
void PackagesWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch (ev.GetId()) {
case ID_INSTALL:
ev.Check (package && package->has(PACKAGE_INSTALL | where) && !package->installed);
ev.Enable(package && package->can(PACKAGE_INSTALL | where) && !package->installed);
break;
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));
ev.Check (package && package->has(PACKAGE_INSTALL | where) && package->installed);
ev.Enable(package && package->can(PACKAGE_INSTALL | where) && package->installed);
break;
case ID_REMOVE:
ev.Check (package && package->has(PACKAGE_REMOVE | where));
ev.Enable(package && package->can(PACKAGE_REMOVE | where));
break;
}
}
}
......@@ -505,7 +505,7 @@ void PackagesWindow::onIdle(wxIdleEvent& ev) {
ev.RequestMore(!checkInstallerList());
}
bool PackagesWindow::checkInstallerList() {
bool PackagesWindow::checkInstallerList(bool refresh) {
if (!waiting_for_list) return true;
if (!downloadable_installers.done()) return false;
waiting_for_list = false;
......@@ -515,9 +515,11 @@ bool PackagesWindow::checkInstallerList() {
}
FOR_EACH(p, installable_packages) p->determineStatus();
// refresh
package_list->rebuild();
package_info->setPackage(package = package_list->getSelection());
UpdateWindowUI(wxUPDATE_UI_RECURSE);
if (refresh) {
package_list->rebuild();
package_info->setPackage(package = package_list->getSelection());
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
return true;
}
......
......@@ -11,21 +11,9 @@
#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
......@@ -54,26 +42,7 @@ class PackagesWindow : public wxDialog {
void onUpdateUI(wxUpdateUIEvent&);
void onIdle(wxIdleEvent&);
bool checkInstallerList();
/*
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();
*/
bool checkInstallerList(bool refresh = true);
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -541,7 +541,10 @@ void Packaged::saveAs(const String& package, bool remove_unused) {
void Packaged::validate(Version) {
// a default for the short name
if (short_name.empty()) short_name = name();
if (short_name.empty()) {
if (!full_name.empty()) short_name = full_name;
short_name = name();
}
// check dependencies
FOR_EACH(dep, dependencies) {
packages.checkDependency(*dep, true);
......
......@@ -293,7 +293,7 @@ bool PackageDirectory::install(const InstallablePackage& package) {
String n = name(package.description->name);
if (package.action & PACKAGE_REMOVE) {
remove_file_or_dir(n);
} else if ((package.action & PACKAGE_UPGRADE) || (package.action & PACKAGE_INSTALL)) {
} else if (package.action & PACKAGE_INSTALL) {
remove_file_or_dir(n + _(".new"));
bool ok = actual_install(package, n + _(".new"));
if (!ok) return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment