Installed packages will be blessed.

For now, everything is considered blessed, because we are not yet using installers everywhere.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@912 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-05-31 18:33:23 +00:00
parent 282ac72502
commit 50fe805657
5 changed files with 47 additions and 7 deletions
+33
View File
@@ -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;
}