[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-devel] Possible way to remove file_zip.cc
From: |
Tacvek |
Subject: |
[Enigma-devel] Possible way to remove file_zip.cc |
Date: |
Sun, 16 Apr 2006 22:43:59 -0400 |
Bellow is an example of a way to elimate file_zip.cc
Baically the header conflicts are resolved by including
zipios-config.h.in
I moved findInZip into the GameFS namespace.
I also made the method static and moved the static variables into its scope.
This
was easier than having to add the zipios header to file.hh which causes
other problems,
and also easier than having to deal with the 'const'ness of the method that
call findInZip.
I provide this as one possible way. It may be that the inclusion of the
'zipios-config.h.in'
is a worse kluge than the use of a seperate file.
The diff below is for refernce purposes. If a formal diff is desired I can
provide one.
Index: file.hh
===================================================================
--- file.hh (revision 122)
+++ file.hh (working copy)
@@ -162,6 +162,10 @@
*/
bool findImageFile (const FileName &f, std::string &dst_path);
+ // banned code to file_zip.cc due to macro clashes
+ static bool findInZip(std::string zipPath, std::string
zippedFilename1,
+ std::string zippedFilename2, string &dest,
+ std::auto_ptr<std::istream> &isresult);
private:
// Variables
std::vector<FSEntry> entries;
@@ -172,10 +176,7 @@
/*! Load a complete file/input stream `is' into `dst'. */
std::istream &Readfile (std::istream &is, ByteVec &dst, int
blocksize=512);
- // banned code to file_zip.cc due to macro clashes
- bool findInZip(std::string zipPath, std::string zippedFilename1,
- std::string zippedFilename2, string &dest,
- std::auto_ptr<std::istream> &isresult);
+
} // namespace enigma
#endif
Index: file.cc
===================================================================
--- file.cc (revision 122)
+++ file.cc (working copy)
@@ -23,6 +23,8 @@
#include "ecl_system.hh"
+#include "zipios++/zipfile.h"
+#include "zipios++/zipios-config.h.in"
#include "config.h"
#include <sys/types.h>
@@ -33,6 +35,7 @@
#include <ios>
#include <iostream>
#include <fstream>
+#include <istream>
using namespace enigma;
using namespace ecl;
@@ -327,6 +330,34 @@
return true;
}
+bool GameFS::findInZip(std::string zipPath, std::string zippedFilename1,
+ std::string zippedFilename2, string &dest,
+ std::auto_ptr<std::istream> &isresult) {
+
+ static std::auto_ptr<zipios::ZipFile> zip;
+ static std::string lastZipPath;
+
+ // reuse last opened zip if possible
+ if (lastZipPath != zipPath) {
+ zip.reset (new zipios::ZipFile (zipPath));
+ lastZipPath = zipPath;
+ }
+ std::auto_ptr<istream> isptr (zip->getInputStream
(zippedFilename2));
+ if(isptr.get() != 0) {
+ isresult = isptr;
+ dest = zippedFilename2;
+ return true;
+ }
+ isptr.reset(zip->getInputStream (zippedFilename1));
+ if(isptr.get() != 0) {
+ isresult = isptr;
+ dest = zippedFilename1;
+ return true;
+ }
+ return false;
+}
+
+
/* -------------------- Helper functions -------------------- */
std::istream &
Index: Makefile.am
===================================================================
--- Makefile.am (revision 122)
+++ Makefile.am (working copy)
@@ -45,7 +45,6 @@
enigma.hh \
file.cc \
file.hh \
- file_zip.cc \
floors.cc \
floors.hh \
fwd.hh \
- [Enigma-devel] Possible way to remove file_zip.cc,
Tacvek <=
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Ronald Lamprecht, 2006/04/17
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Erich Schubert, 2006/04/17
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Ronald Lamprecht, 2006/04/17
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Erich Schubert, 2006/04/17
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Daniel Heck, 2006/04/18
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Erich Schubert, 2006/04/19
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Ronald Lamprecht, 2006/04/27
- Re: [Enigma-devel] Possible way to remove file_zip.cc, Tacvek, 2006/04/17