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