Added an option to create an installer package.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@512 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-07-06 20:19:02 +00:00
parent fdb725963c
commit 6e17e7d31f
7 changed files with 163 additions and 24 deletions
+66
View File
@@ -7,7 +7,11 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/installer.hpp>
#include <util/io/package_manager.hpp>
#include <script/to_value.hpp>
#include <wx/filename.h>
DECLARE_TYPEOF_COLLECTION(String);
// ----------------------------------------------------------------------------- : Installer
@@ -17,3 +21,65 @@ IMPLEMENT_REFLECTION(Installer) {
REFLECT_BASE(Packaged);
REFLECT(packages);
}
// ----------------------------------------------------------------------------- : Installing
void Installer::installFrom(const String& filename, bool message_on_success) {
Installer i;
i.open(filename);
i.install();
if (message_on_success) {
wxMessageBox(String::Format(_("'%s' successfully installed %d package%s."), i.name(), i.packages.size(), i.packages.size() == 1 ? _("") : _("s")),
_("Magic Set Editor"), wxOK | wxICON_INFORMATION);
}
}
void Installer::install() {
// Walk over all files in this installer
const FileInfos& file_infos = getFileInfos();
for (FileInfos::const_iterator it = file_infos.begin() ; it != file_infos.end() ; ++it) {
// const String& filename = it->first;
//
}
// REMOVE?
FOR_EACH(p, packages) {
install(p);
}
}
void Installer::install(const String& package) {
// 1. Make sure the package is not loaded
// TODO
}
// ----------------------------------------------------------------------------- : Creating
void Installer::addPackage(const String& package) {
wxFileName fn(package);
if (fn.GetExt() == _(".mse-installer")) {
prefered_filename = package;
} else {
PackagedP p = ::packages.openAny(package);
addPackage(*p);
}
}
void Installer::addPackage(Packaged& package) {
// Add to list of packages
String name = package.relativeFilename();
if (find(packages.begin(), packages.end(), package.name()) != packages.end()) {
return; // already added
}
if (prefered_filename.empty()) {
prefered_filename = package.name() + _(".mse-installer");
}
packages.push_back(name);
// Copy all files from that package to this one
const FileInfos& file_infos = package.getFileInfos();
for (FileInfos::const_iterator it = file_infos.begin() ; it != file_infos.end() ; ++it) {
String file = it->first;
InputStreamP is = package.openIn(file);
OutputStreamP os = openOut(name + _("/") + file);
os->Write(*is);
}
}
+8 -1
View File
@@ -20,13 +20,20 @@ class Installer : public Packaged {
String prefered_filename; ///< What filename should be used (by default)
vector<String> packages; ///< Packages to install
/// Load an installer from a file, and run it
static void installFrom(const String& filename, bool message_on_success);
/// Install all the packages
void install();
/// 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);
/// Add a package to the installer (if it is not already added).
/** The first package gives the name of the installer.
*/
void addPackage(const Packaged& package);
void addPackage(Packaged& package);
protected:
String typeName() const;