allow reading images from the current directory in the CLI interface

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1475 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2010-08-03 18:25:35 +00:00
parent 0673eda5c9
commit 4defd52aa2
6 changed files with 40 additions and 28 deletions
+6 -11
View File
@@ -66,7 +66,7 @@ const String& Package::absoluteFilename() const {
return filename;
}
void Package::open(const String& n) {
void Package::open(const String& n, bool fast) {
assert(!isOpened()); // not already opened
// get absolute path
wxFileName fn(n);
@@ -78,7 +78,7 @@ void Package::open(const String& n) {
}
// type of package
if (wxDirExists(filename)) {
openDirectory();
openDirectory(fast);
} else if (wxFileExists(filename)) {
openZipfile();
} else {
@@ -207,16 +207,15 @@ InputStreamP Package::openIn(const String& file) {
if (filename.find(_(".mse-")) != String::npos) {
throw PackageError(_ERROR_2_("file not found package like", file, filename));
}
throw FileNotFoundError(file, filename);
}
InputStreamP stream;
if (it->second.wasWritten()) {
if (it != files.end() && it->second.wasWritten()) {
// written to this file, open the temp file
stream = shared(new BufferedFileInputStream(it->second.tempName));
} else if (wxFileExists(filename+_("/")+file)) {
// a file in directory package
stream = shared(new BufferedFileInputStream(filename+_("/")+file));
} else if (wxFileExists(filename) && it->second.zipEntry) {
} else if (wxFileExists(filename) && it != files.end() && 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 = shared(new wxZipInputStream(filename, it->second.zipEntry->GetInternalName()));
@@ -339,9 +338,8 @@ void Package::loadZipStream() {
zipStream->CloseEntry();
}
void Package::openDirectory() {
zipfile = false;
openSubdir(wxEmptyString);
void Package::openDirectory(bool fast) {
if (!fast) openSubdir(wxEmptyString);
}
void Package::openSubdir(const String& name) {
@@ -368,7 +366,6 @@ void Package::openSubdir(const String& name) {
}
void Package::openZipfile() {
zipfile = true;
// close old streams
delete fileStream; fileStream = nullptr;
delete zipStream; zipStream = nullptr;
@@ -382,7 +379,6 @@ void Package::openZipfile() {
}
void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_copy) {
zipfile = false;
// write to a directory
VCSP vcs = getVCS();
FOR_EACH(f, files) {
@@ -414,7 +410,6 @@ void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_
}
void Package::saveToZipfile(const String& saveAs, bool remove_unused, bool is_copy) {
zipfile = true;
// create a temporary zip file name
String tempFile = saveAs + _(".tmp");
wxRemoveFile(tempFile);
+19 -13
View File
@@ -69,15 +69,24 @@ class Package : public IntrusivePtrVirtualBase {
/// The time this package was last modified
inline wxDateTime lastModified() const { return modified; }
/// Open a package, should only be called when the package is constructed using the default constructor!
/// @pre open not called before [TODO]
void open(const String& package);
/// Open a package
/**
* Should only be called when the package is constructed using the default constructor!
*
* If 'fast' is set, then for directories a full directory listing is not performed.
* This means that the file_infos will not be fully initialized.
*
* @pre open not called before [TODO]
*/
void open(const String& package, bool fast = false);
/// Saves the package, by default saves as a zip file, unless
/// it was already a directory
/** If remove_unused=true all files that were in the file and
/// Saves the package
/**
* By default saves as a zip file, unless it was already a directory.
*
* If remove_unused=true all files that were in the file and
* are not touched with referenceFile will be deleted from the new archive!
* This is a form of garbage collection, to get rid of old picture files for example.
* This is a form of garbage collection, to get rid of old picture files for example.
*/
void save(bool remove_unused = true);
@@ -140,8 +149,8 @@ class Package : public IntrusivePtrVirtualBase {
// TODO: I dislike putting this here very much. There ought to be a better way.
virtual VCSP getVCS() { return intrusive(new VCS()); }
/// true if this is a zip file, false if a directory (updated on open/save)
bool isZipfile() { return zipfile; }
/// true if this is a zip file, false if a directory
bool isZipfile() const { return !wxDirExists(filename); }
// --------------------------------------------------- : Private stuff
private:
@@ -163,9 +172,6 @@ class Package : public IntrusivePtrVirtualBase {
/// Last modified time
DateTime modified;
/// Zipfile flag
bool zipfile;
public:
/// Information on files in the package
/** Note: must be public for DECLARE_TYPEOF to work */
@@ -182,7 +188,7 @@ class Package : public IntrusivePtrVirtualBase {
wxZipInputStream* zipStream;
void loadZipStream();
void openDirectory();
void openDirectory(bool fast = false);
void openSubdir(const String&);
void openZipfile();
void reopen();