Installing and removing packages from an installer now WORKS

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@908 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-05-31 16:42:15 +00:00
parent f3ff6f22ae
commit 7a38986171
10 changed files with 135 additions and 64 deletions
+23 -9
View File
@@ -56,18 +56,29 @@ class RecursiveDeleter : public wxDirTraverser {
public:
RecursiveDeleter(const String& start) {
to_delete.push_back(start);
ok = true;
}
~RecursiveDeleter() {
bool ok;
void remove() {
FOR_EACH_REVERSE(dir, to_delete) {
wxRmdir(dir);
if (!wxRmdir(dir)) {
ok = false;
handle_error(_("Cannot delete ") + dir + _("\n")
_("The remainder of the package has still been removed, if possible.\n")
_("Other packages may have been removed, including packages that this on is dependent on. Please remove manually."));
}
}
}
wxDirTraverseResult OnFile(const String& filename) {
if (!wxRemoveFile(filename))
handle_error(_("Cannot delete ") + filename + _(". ")
_("The remainder of the package has still been removed, if possible.")
if (!wxRemoveFile(filename)) {
ok = false;
handle_error(_("Cannot delete ") + filename + _("\n")
_("The remainder of the package has still been removed, if possible.\n")
_("Other packages may have been removed, including packages that this on is dependent on. Please remove manually."));
}
return wxDIR_CONTINUE;
}
wxDirTraverseResult OnDir(const String& dirname) {
@@ -82,12 +93,15 @@ bool remove_file_or_dir(const String& name) {
if (wxFileExists(name)) {
return wxRemoveFile(name);
} else if (wxDirExists(name)) {
wxDir dir(name);
RecursiveDeleter rd(name);
dir.Traverse(rd);
return true;
{
wxDir dir(name);
dir.Traverse(rd);
}
rd.remove();
return rd.ok;
} else {
return false;
return true;
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ bool create_parent_dirs(const String& file);
/// Remove the given file or directory
/** It is not an error if the file doesn't exist.
* Removes all files in a directory.
* Returns true if something was removed
* Returns true if the file is gone or was never there to begin with
*/
bool remove_file_or_dir(const String& file);
+1 -1
View File
@@ -199,7 +199,7 @@ InputStreamP Package::openIn(const String& file) {
} else if (wxFileExists(filename) && it->second.zipEntry) {
// a file in a zip archive
// somebody in wx thought seeking was no longer needed, it now only works with the 'compatability constructor'
stream = new_shared2<wxZipInputStream>(filename, it->second.zipEntry->GetName());
stream = new_shared2<wxZipInputStream>(filename, it->second.zipEntry->GetInternalName());
//stream = static_pointer_cast<wxZipInputStream>(
// new_shared2<ZipFileInputStream>(filename, it->second.zipEntry));
} else {
+11 -10
View File
@@ -160,9 +160,9 @@ void PackageManager::findAllInstalledPackages(vector<InstallablePackageP>& packa
sort(packages);
}
void PackageManager::install(const InstallablePackage& package) {
bool PackageManager::install(const InstallablePackage& package) {
bool install_local = package.action & PACKAGE_LOCAL;
(install_local ? local : global).install(package);
return (install_local ? local : global).install(package);
}
// ----------------------------------------------------------------------------- : PackageDirectory
@@ -292,14 +292,14 @@ String PackageDirectory::databaseFile() {
bool PackageDirectory::install(const InstallablePackage& package) {
String n = name(package.description->name);
if (package.action & PACKAGE_REMOVE) {
remove_file_or_dir(n);
if (!remove_file_or_dir(n)) return false;
} else if (package.action & PACKAGE_INSTALL) {
remove_file_or_dir(n + _(".new"));
if (!remove_file_or_dir(n + _(".new"))) return false;
bool ok = actual_install(package, n + _(".new"));
if (!ok) return false;
move_ignored_files(n, n + _(".new"));
remove_file_or_dir(n);
rename_file_or_dir(n + _(".new"), n);
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;
}
return true;
}
@@ -317,11 +317,11 @@ bool PackageDirectory::actual_install(const InstallablePackage& package, const S
String file = it->first;
if (!is_substr(file,0,name)) continue; // not the right package
// correct filename
file = install_dir + file.substr(name.length());
create_parent_dirs(file);
String local_file = install_dir + file.substr(name.length());
create_parent_dirs(local_file);
// copy file
InputStreamP is = installer.openIn(file);
wxFileOutputStream os (install_dir + _("/") + file);
wxFileOutputStream os (local_file);
if (!os.IsOk()) {
int act = wxMessageBox(_ERROR_1_("cannot create file", file), _TITLE_("cannot create file"), wxICON_ERROR | wxYES_NO);
if (act == wxNO) return false;
@@ -329,6 +329,7 @@ bool PackageDirectory::actual_install(const InstallablePackage& package, const S
os.Write(*is);
}
// update package database
// TODO: bless the package?
return true;
}
+2 -2
View File
@@ -151,8 +151,8 @@ class PackageManager {
/// Get all installed packages
void findAllInstalledPackages(vector<InstallablePackageP>& packages);
/// Install/uninstall a package
void install(const InstallablePackage& package);
/// Install/uninstall a package, returns success
bool install(const InstallablePackage& package);
// --------------------------------------------------- : Packages on a server
+1
View File
@@ -240,6 +240,7 @@ enum ControlID {
, ID_SHARPEN_AMOUNT
// Updates window
, ID_PACKAGE_LIST
, ID_KEEP
, ID_INSTALL
, ID_UPGRADE
, ID_REMOVE