Commit 1f618486 authored by twanvl's avatar twanvl

Installed packages will be blessed.

For now, everything is considered blessed, because we are not yet using installers everywhere.
parent 0f0b9c94
......@@ -29,6 +29,9 @@ DECLARE_TYPEOF_COLLECTION(InstallablePackageP);
DECLARE_POINTER_TYPE(wxFileInputStream);
DECLARE_POINTER_TYPE(wxZipInputStream);
// Don't do this check for now, because we can't bless packages
#define USE_MODIFIED_CHECK 0
// ----------------------------------------------------------------------------- : Installer
String Installer::typeName() const { return _("installer"); }
......@@ -287,9 +290,11 @@ void InstallablePackage::determineStatus() {
status = (PackageStatus)(status | PACKAGE_REMOVABLE);
}
}
#if USE_MODIFIED_CHECK
if (installed && (installed->status & PackageVersion::STATUS_MODIFIED)) {
status = (PackageStatus)(status | PACKAGE_MODIFIED);
}
#endif
}
bool InstallablePackage::willBeInstalled() const {
......
......@@ -176,9 +176,9 @@ PackagesWindow::PackagesWindow(Window* parent, const InstallerP& installer)
// add installer
merge(installable_packages, new_intrusive1<DownloadableInstaller>(installer));
// mark all packages in the installer for installation
FOR_EACH(p, installable_packages) {
if (p->installer) {
set_package_action(installable_packages, p, PACKAGE_INSTALL | where);
FOR_EACH(ip, installable_packages) {
if (ip->can(PACKAGE_INSTALL)) {
set_package_action(installable_packages, ip, PACKAGE_INSTALL | where);
}
}
// update window
......@@ -271,7 +271,7 @@ void PackagesWindow::onOk(wxCommandEvent& ev) {
if ((ip->action & PACKAGE_INSTALL) && ip->installer && !ip->installer->installer) ++to_download;
if (ip->action & PACKAGE_REMOVE) {
to_remove++;
if (ip->status & PACKAGE_MODIFIED) with_modifications++;
if ((ip->status & PACKAGE_MODIFIED) == PACKAGE_MODIFIED) with_modifications++;
}
}
// Warn about removing
......
......@@ -112,10 +112,7 @@ int MSE::OnRun() {
InstallerP installer = open_package<Installer>(argv[1]);
PackagesWindow wnd(nullptr, installer);
wnd.ShowModal();
//return wxApp::OnRun();
return EXIT_SUCCESS;
//%%% Installer::installFrom(argv[1], true, isInstallLocal(type));
//%%% return EXIT_SUCCESS;
} else if (arg == _("--symbol-editor")) {
Window* wnd = new SymbolWindow(nullptr);
wnd->Show();
......
......@@ -20,6 +20,7 @@
#include <wx/wfstream.h>
DECLARE_TYPEOF_COLLECTION(InstallablePackageP);
DECLARE_TYPEOF_COLLECTION(PackageVersionP);
DECLARE_TYPEOF_COLLECTION(PackageVersion::FileInfo);
// ----------------------------------------------------------------------------- : PackageManager : in memory
......@@ -262,6 +263,35 @@ void PackageDirectory::installedPackages(vector<InstallablePackageP>& packages_o
}
}
void PackageDirectory::bless(const String& package_name) {
PackagedP pack = package_manager.openAny(package_name, true);
// already have this package?
FOR_EACH(ver, packages) {
if (ver->name == package_name) {
ver->check_status(*pack);
ver->bless();
return;
}
}
// a new package
PackageVersionP ver(new PackageVersion(
is_local ? PackageVersion::STATUS_LOCAL : PackageVersion::STATUS_GLOBAL));
ver->check_status(*pack);
ver->bless();
packages.push_back(ver);
sort(packages.begin(), packages.end(), compare_name);
}
void PackageDirectory::removeFromDatabase(const String& package_name) {
size_t i = 0, j = 0;
for ( ; i < packages.size() ; ++i) {
if (packages[i]->name != package_name) {
packages[j++] = packages[i];
}
}
packages.resize(j);
}
IMPLEMENT_REFLECTION(PackageDirectory) {
REFLECT(packages);
}
......@@ -293,6 +323,7 @@ bool PackageDirectory::install(const InstallablePackage& package) {
String n = name(package.description->name);
if (package.action & PACKAGE_REMOVE) {
if (!remove_file_or_dir(n)) return false;
removeFromDatabase(package.description->name);
} else if (package.action & PACKAGE_INSTALL) {
if (!remove_file_or_dir(n + _(".new"))) return false;
bool ok = actual_install(package, n + _(".new"));
......@@ -300,7 +331,9 @@ bool PackageDirectory::install(const InstallablePackage& package) {
move_ignored_files(n, n + _(".new")); // copy over files from the old installed version to the new one
if (!remove_file_or_dir(n)) return false;
if (!rename_file_or_dir(n + _(".new"), n)) return false;
bless(package.description->name);
}
saveDatabase();
return true;
}
......
......@@ -77,6 +77,11 @@ class PackageDirectory {
/// Install/uninstall a package
bool install(const InstallablePackage& package);
/// Bless a package
void bless(const String& package_name);
/// Remove a package from the database
void removeFromDatabase(const String& package_name);
void loadDatabase();
void saveDatabase();
private:
......
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