Finally got precompiled headers to work.

Now all C++ files need to #include <util/prec.hpp>
 That is why all .cpp files are touched by this commit

Many changes to installers and update checking:
     - the window is now called PackagesWindow, in a new source file
     - update checking is now independent from the PackagesWindow. For update checking only a list of package versions are needed (vector<PackageDependency>). This is much less information to download at each startup.
     - the list of available packages is now a list of available Installers, since an installer can contain multiple packages.
     - moved the logic of dependency checking etc. to data/installer
     - moved the actual installation to util/io/package_manager
     - moved directory iteration/creation logic to util/file_utils
     - added PackageDirectory: the local and global package directory now have their own object (was part of PackageManager)
     - added PackageVersion: for detecting if a package has been modified after it was installed.
     - added PackageDescription: description/header of a package. Basicly the same as what Packaged provides.
     - added DownloadableInstaller: where to find an insaller, what does it contain?
     - added InstallablePackage: brining it all together: installer, package, status, action.

Current status: the insaller is currently broken in a few places, more on that soon.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@792 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-29 18:30:41 +00:00
parent 361488b4fe
commit d2196eea09
182 changed files with 2508 additions and 809 deletions
+134
View File
@@ -0,0 +1,134 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/file_utils.hpp>
#include <wx/filename.h>
#include <wx/dir.h>
DECLARE_TYPEOF_COLLECTION(String);
// ----------------------------------------------------------------------------- : File names
String normalize_filename(const String& name) {
wxFileName fn(name);
fn.Normalize();
return fn.GetFullPath();
}
String normalize_internal_filename(const String& name) {
String ret;
FOR_EACH_CONST(c, name) {
if (c==_('\\')) ret += _('/');
else ret += toLower(c);
}
return ret;
}
bool ignore_file(const String& name) {
// Files that are never part of a package,
// i.e. random stuff the OS file manager dumps without being asked
return name == _("Thumbs.db"); // winXP explorer thumbnails
}
// ----------------------------------------------------------------------------- : Directories
bool create_parent_dirs(const String& file) {
for (size_t pos = file.find_first_of(_("\\/")) ;
pos != String::npos ;
pos = file.find_first_of(_("\\/"),pos+1)) {
String part = file.substr(0,pos);
if (!wxDirExists(part)) {
if (!wxMkdir(part)) return false;
}
}
return true;
}
// ----------------------------------------------------------------------------- : Removing
class RecursiveDeleter : public wxDirTraverser {
public:
RecursiveDeleter(const String& start) {
to_delete.push_back(start);
}
~RecursiveDeleter() {
FOR_EACH_REVERSE(dir, to_delete) {
wxRmdir(dir);
}
}
wxDirTraverseResult OnFile(const String& filename) {
if (!wxRemoveFile(filename))
handle_error(_("Cannot delete ") + filename + _(". ")
_("The remainder of the package has still been removed, if possible.")
_("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) {
to_delete.push_back(dirname);
return wxDIR_CONTINUE;
}
private:
vector<String> to_delete;
};
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;
} else {
return false;
}
}
// ----------------------------------------------------------------------------- : Renaming
bool rename_file_or_dir(const String& from, const String& to) {
create_parent_dirs(to);
return wxRenameFile(from, to);
}
// ----------------------------------------------------------------------------- : Moving
class IgnoredMover : public wxDirTraverser {
public:
IgnoredMover(const String& from, const String& to)
: from(from), to(to)
{}
wxDirTraverseResult OnFile(const String& filename) {
tryMove(filename);
return wxDIR_CONTINUE;
}
wxDirTraverseResult OnDir(const String& dirname) {
return tryMove(dirname) ? wxDIR_IGNORE : wxDIR_CONTINUE;
}
private:
String from, to;
bool tryMove(const String& from_path) {
if (is_substr(from_path,0,from)) {
String to_path = to + from_path.substr(from.size());
return rename_file_or_dir(from_path, to_path);
} else {
// This shouldn't happen
return false;
}
}
};
void move_ignored_files(const String& from_dir, const String& to_dir) {
if (wxDirExists(from_dir) && wxDirExists(to_dir)) {
wxDir dir(from_dir);
IgnoredMover im(from_dir, to_dir);
dir.Traverse(im);
}
}