- made Filedescriptors pool a compile-time option. This should fix some issues found in previous revision
This commit is contained in:
@@ -159,9 +159,7 @@ void filesystem::unuse(izfstream & File)
|
||||
|
||||
if (!File.Zipped())
|
||||
{
|
||||
std::streambuf * buffer = File.rdbuf(NULL);
|
||||
if (buffer)
|
||||
delete(buffer);
|
||||
delete(File.rdbuf(NULL));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -188,7 +186,11 @@ void filesystem::Open(izfstream & File, const char * Filename)
|
||||
FileBuf->open(FullPath.c_str(), ios::binary | ios::in);
|
||||
|
||||
if (FileBuf->is_open()) {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
File.rdbuf(FileBuf);
|
||||
#else
|
||||
delete File.rdbuf(FileBuf);
|
||||
#endif
|
||||
File.clear(ios::goodbit);
|
||||
File.m_FilePath = Filename;
|
||||
File.m_FullFilePath = FullPath;
|
||||
@@ -233,12 +235,27 @@ void filesystem::Open(izfstream & File, const char * Filename)
|
||||
if (DataPos != streamoff(-1)) {
|
||||
string zipName = m_BasePath + CurrentZipName;
|
||||
// Open the file at the right position
|
||||
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
zbuffer * buffer = getValidBuffer(zipName, Filename, streamoff(DataPos), streamoff(FileInfo.m_CompSize));
|
||||
|
||||
if (buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
File.setstate(ios::badbit);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.rdbuf(buffer);
|
||||
File.SetCompMethod(FileInfo.m_CompMethod);
|
||||
|
||||
File._SetCompMethod(FileInfo.m_CompMethod);
|
||||
#else
|
||||
((izstream &) File).open(
|
||||
zipName.c_str(),
|
||||
streamoff(DataPos),
|
||||
streamoff(FileInfo.m_CompSize),
|
||||
FileInfo.m_CompMethod
|
||||
);
|
||||
if (File) {
|
||||
#endif
|
||||
File.m_FilePath = Filename;
|
||||
File.m_FullFilePath = FullPath;
|
||||
File.m_Zipped = true;
|
||||
@@ -246,10 +263,6 @@ void filesystem::Open(izfstream & File, const char * Filename)
|
||||
File.m_CompSize = FileInfo.m_CompSize;
|
||||
File.m_Offset = FileInfo.m_Offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
File.setstate(ios::badbit);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -263,8 +263,12 @@ inline void izfstream::open(const char * FilePath, filesystem * pFS) {
|
||||
}
|
||||
|
||||
inline void izfstream::close() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
if (m_pFS)
|
||||
m_pFS->unuse( * this);
|
||||
#else
|
||||
izstream::close();
|
||||
#endif
|
||||
m_FilePath = m_FullFilePath = "";
|
||||
m_UncompSize = 0;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace std;
|
||||
// zstream Member Functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
|
||||
void izstream::open(const char * Filename, streamoff Offset, streamoff Size, int CompMethod)
|
||||
{
|
||||
// Change the buffer if need
|
||||
@@ -68,7 +68,7 @@ zbuffer * izstream::GetRightBuffer(int CompMethod) const
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
bool zbuffer::use(std::streamoff Offset, std::streamoff Size)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,9 @@
|
||||
|
||||
#include "zstream_zlib.h" // Zlib dependencies
|
||||
|
||||
|
||||
#ifdef PSP
|
||||
#define USE_ZBUFFER_POOL
|
||||
#endif
|
||||
|
||||
// Zip File System Namespace
|
||||
namespace zip_file_system {
|
||||
@@ -151,25 +153,31 @@ class izstream : public std::istream
|
||||
public:
|
||||
|
||||
izstream() : std::istream(NULL), m_CompMethod(-1) { setstate(std::ios::badbit); }
|
||||
virtual ~izstream() { rdbuf(NULL); } //This doesn't delete the buffer, deletion is handled by zfsystem;
|
||||
virtual ~izstream() {
|
||||
#ifdef USE_ZBUFFER_POOL
|
||||
rdbuf(NULL); //This doesn't delete the buffer, deletion is handled by zfsystem;
|
||||
#else
|
||||
delete(rdbuf());
|
||||
#endif
|
||||
}
|
||||
|
||||
//void open(const char * Filename, std::streamoff Offset, std::streamoff Size, int CompMethod);
|
||||
//void close() { SetCompMethod(-1); }
|
||||
void open(const char * Filename, std::streamoff Offset, std::streamoff Size, int CompMethod);
|
||||
void close() { SetCompMethod(-1); }
|
||||
|
||||
void SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; };
|
||||
void _SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; };
|
||||
|
||||
protected:
|
||||
static const int STORED = 0;
|
||||
static const int DEFLATED = 8;
|
||||
|
||||
//zbuffer * GetRightBuffer(int CompMethod) const;
|
||||
zbuffer * GetRightBuffer(int CompMethod) const;
|
||||
|
||||
/*void SetCompMethod(int CompMethod) {
|
||||
void SetCompMethod(int CompMethod) {
|
||||
delete rdbuf(GetRightBuffer(m_CompMethod = CompMethod));
|
||||
|
||||
if (rdbuf() == NULL)
|
||||
setstate(std::ios::badbit);
|
||||
}*/
|
||||
}
|
||||
|
||||
int m_CompMethod;
|
||||
};
|
||||
|
||||
@@ -117,7 +117,6 @@ u32 ramAvailable(void);
|
||||
|
||||
bool fileExists(const char * filename);
|
||||
bool FileExists(const string & filename);
|
||||
|
||||
std::string buildFilePath(const vector<string> & folders, const string & filename);
|
||||
std::string ensureFolder(const string & folderName);
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user