From 7583e61510b8ae7361cdd4b1ce07682b232dbdb6 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 26 Aug 2012 06:07:48 +0000 Subject: [PATCH] remove non ascii characters from ZipFS --- JGE/src/zipFS/fileio.h | 512 ++++++++++++++-------------- JGE/src/zipFS/zfsystem.cpp | 2 +- JGE/src/zipFS/zfsystem.h | 664 ++++++++++++++++++------------------- JGE/src/zipFS/ziphdr.cpp | 2 +- JGE/src/zipFS/ziphdr.h | 286 ++++++++-------- JGE/src/zipFS/zstream.cpp | 2 +- JGE/src/zipFS/zstream.h | 378 ++++++++++----------- 7 files changed, 923 insertions(+), 923 deletions(-) diff --git a/JGE/src/zipFS/fileio.h b/JGE/src/zipFS/fileio.h index 61edfd953..1594c9317 100644 --- a/JGE/src/zipFS/fileio.h +++ b/JGE/src/zipFS/fileio.h @@ -1,256 +1,256 @@ -// bfileio.h: interface for the binary file i/o. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2004 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@telenet.be -// -////////////////////////////////////////////////////////////////////// -// -// File I/O Facilities. -// ******************** -// -// Current version: 1.00 BETA 4 (16/07/2004) -// -// Comment: readvar() and writevar() read a little endian ordered -// value on a file and put it in a variable. -// search_iterator only accepts "/*.". -// Uses ANSI C "assert()". Define NDEBUG to turn it off. -// (note: Visual C++ define NDEBUG in Release mode) -// -// History: - 1.00 BETA 4 (16/07/2004) - Fixed small bug in UNIX search_iterator -// - 1.00 BETA 3 (27/06/2004) - Added UNIX compatibility -// - 1.00 BETA 2 (21/02/2003) - Now endianess independent -// - 1.00 BETA 1 (06/09/2002) - First public release -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - - -#if defined WIN32 -#include // Windows I/O facilities (Directories) -#else -#include -#include -#endif - -#include - -namespace io_facilities { - - - - -// Global function for reading binary variables -template std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes); -template std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes); - - - -// Class for searching files and directories -// (!!! not compliant with C++ std::iterator and is thus meant for specific use !!!) -class search_iterator -{ -public: - search_iterator(); - search_iterator(const char * FileSpec); - ~search_iterator(); - - operator bool () const; - search_iterator & operator ++ (); - search_iterator & begin(const char * FileSpec); - search_iterator & next(); - bool end() const; - std::string Name() const; - -protected: - bool m_Valid; - -#if defined WIN32 - intptr_t m_hFiles; - _finddata_t m_FindData; -#else - DIR * m_Directory; - std::string m_Extension; - struct dirent * m_DirectoryEntry; -#endif -}; - - - - -////////////////////////////////////////////////////////////////////// -// io_facilities:: Inline Functions -////////////////////////////////////////////////////////////////////// - -template -inline std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes) -{ - // Debug test to ensure type size is big enough - assert(sizeof(T) >= size_t(NbBytes)); - - // Var = 0 ensure type size won't matter - T TmpVar = Var = 0; - - for (std::streamsize i = 0; i < NbBytes; ++i) { - File.read(reinterpret_cast(&TmpVar), 1); - Var |= TmpVar << (i * CHAR_BIT); - } - - return File; -} - - - -template -inline std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes) -{ - // Debug test to ensure type size is big enough - assert(sizeof(T) >= size_t(NbBytes)); - - T TmpVar = Var; - - for (std::streamsize i = 0; i < NbBytes; ++i) - File.write(reinterpret_cast(&(TmpVar >>= (CHAR_BIT * i))), 1); - - return File; -} - - - -////////////////////////////////////////////////////////////////////// -// io_facilities::search_iterator Inline Member Functions -////////////////////////////////////////////////////////////////////// - -inline search_iterator::search_iterator() - : m_Valid(false), -#if defined WIN32 - m_hFiles(-1) -#else - m_Directory(NULL) -#endif - { } - -inline search_iterator::search_iterator(const char * FileSpec) - : m_Valid(false), -#if defined WIN32 - m_hFiles(-1) -#else - m_Directory(NULL) -#endif -{ - begin(FileSpec); -} - -inline search_iterator::~search_iterator() { -#if defined WIN32 - if (m_hFiles != -1) _findclose(m_hFiles); -#else - if (m_Directory != NULL) closedir(m_Directory); -#endif -} - -inline search_iterator::operator bool () const { - return m_Valid; -} - -inline search_iterator & search_iterator::operator ++ () { - return next(); -} - -inline search_iterator & search_iterator::begin(const char * FileSpec) { -#if defined WIN32 - if (m_hFiles != -1) _findclose(m_hFiles); - m_Valid = ((m_hFiles = _findfirst(FileSpec, &m_FindData)) != -1); -#else - std::string DirectoryName; - - if (m_Directory != NULL) closedir(m_Directory); - - int i; - for (i = strlen(FileSpec); i >= 0; --i) - if (FileSpec[i] == '/') break; - - if (i < 0) - DirectoryName = "."; - else - DirectoryName.assign(FileSpec + 0, FileSpec + i++); - - m_Extension = FileSpec + i + 1; - std::transform(m_Extension.begin(), m_Extension.end(), m_Extension.begin(), ::tolower); - m_Valid = ((m_Directory = opendir(DirectoryName.c_str())) != NULL); - - if (! m_Valid) - return (* this); - - next(); -#endif - - return (* this); -} - -inline bool search_iterator::end() const { - return false; -} - -inline search_iterator & search_iterator::next() { -#if defined WIN32 - m_Valid = (_findnext(m_hFiles, &m_FindData) != -1); -#else - bool Found = false; - while (! Found) { - m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL); - if (m_Valid) { - std::string FileName = m_DirectoryEntry->d_name; - if (FileName[0] == '.') - Found = false; - else if (FileName.size() <= m_Extension.size()) - Found = false; - else { - std::transform(FileName.begin(), FileName.end(), FileName.begin(), ::tolower); - if (std::equal(m_Extension.rbegin(), m_Extension.rend(), FileName.rbegin())) - Found = true; - } - } - else - break; - } -#endif - - return (* this); -} - -inline std::string search_iterator::Name() const { -#if defined WIN32 - return (m_FindData.name); -#else - return (m_DirectoryEntry->d_name); -#endif -} - - - - -} // namespace io_facilities - - +// bfileio.h: interface for the binary file i/o. +// +////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2004 Tanguy Fautre +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +// +// Tanguy FautrE +// softdev@telenet.be +// +////////////////////////////////////////////////////////////////////// +// +// File I/O Facilities. +// ******************** +// +// Current version: 1.00 BETA 4 (16/07/2004) +// +// Comment: readvar() and writevar() read a little endian ordered +// value on a file and put it in a variable. +// search_iterator only accepts "/*.". +// Uses ANSI C "assert()". Define NDEBUG to turn it off. +// (note: Visual C++ define NDEBUG in Release mode) +// +// History: - 1.00 BETA 4 (16/07/2004) - Fixed small bug in UNIX search_iterator +// - 1.00 BETA 3 (27/06/2004) - Added UNIX compatibility +// - 1.00 BETA 2 (21/02/2003) - Now endianess independent +// - 1.00 BETA 1 (06/09/2002) - First public release +// +////////////////////////////////////////////////////////////////////// + +#pragma once + + + +#if defined WIN32 +#include // Windows I/O facilities (Directories) +#else +#include +#include +#endif + +#include + +namespace io_facilities { + + + + +// Global function for reading binary variables +template std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes); +template std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes); + + + +// Class for searching files and directories +// (!!! not compliant with C++ std::iterator and is thus meant for specific use !!!) +class search_iterator +{ +public: + search_iterator(); + search_iterator(const char * FileSpec); + ~search_iterator(); + + operator bool () const; + search_iterator & operator ++ (); + search_iterator & begin(const char * FileSpec); + search_iterator & next(); + bool end() const; + std::string Name() const; + +protected: + bool m_Valid; + +#if defined WIN32 + intptr_t m_hFiles; + _finddata_t m_FindData; +#else + DIR * m_Directory; + std::string m_Extension; + struct dirent * m_DirectoryEntry; +#endif +}; + + + + +////////////////////////////////////////////////////////////////////// +// io_facilities:: Inline Functions +////////////////////////////////////////////////////////////////////// + +template +inline std::istream & readvar(std::istream & File, T & Var, const std::streamsize NbBytes) +{ + // Debug test to ensure type size is big enough + assert(sizeof(T) >= size_t(NbBytes)); + + // Var = 0 ensure type size won't matter + T TmpVar = Var = 0; + + for (std::streamsize i = 0; i < NbBytes; ++i) { + File.read(reinterpret_cast(&TmpVar), 1); + Var |= TmpVar << (i * CHAR_BIT); + } + + return File; +} + + + +template +inline std::ostream & writevar(std::ostream & File, const T & Var, const std::streamsize NbBytes) +{ + // Debug test to ensure type size is big enough + assert(sizeof(T) >= size_t(NbBytes)); + + T TmpVar = Var; + + for (std::streamsize i = 0; i < NbBytes; ++i) + File.write(reinterpret_cast(&(TmpVar >>= (CHAR_BIT * i))), 1); + + return File; +} + + + +////////////////////////////////////////////////////////////////////// +// io_facilities::search_iterator Inline Member Functions +////////////////////////////////////////////////////////////////////// + +inline search_iterator::search_iterator() + : m_Valid(false), +#if defined WIN32 + m_hFiles(-1) +#else + m_Directory(NULL) +#endif + { } + +inline search_iterator::search_iterator(const char * FileSpec) + : m_Valid(false), +#if defined WIN32 + m_hFiles(-1) +#else + m_Directory(NULL) +#endif +{ + begin(FileSpec); +} + +inline search_iterator::~search_iterator() { +#if defined WIN32 + if (m_hFiles != -1) _findclose(m_hFiles); +#else + if (m_Directory != NULL) closedir(m_Directory); +#endif +} + +inline search_iterator::operator bool () const { + return m_Valid; +} + +inline search_iterator & search_iterator::operator ++ () { + return next(); +} + +inline search_iterator & search_iterator::begin(const char * FileSpec) { +#if defined WIN32 + if (m_hFiles != -1) _findclose(m_hFiles); + m_Valid = ((m_hFiles = _findfirst(FileSpec, &m_FindData)) != -1); +#else + std::string DirectoryName; + + if (m_Directory != NULL) closedir(m_Directory); + + int i; + for (i = strlen(FileSpec); i >= 0; --i) + if (FileSpec[i] == '/') break; + + if (i < 0) + DirectoryName = "."; + else + DirectoryName.assign(FileSpec + 0, FileSpec + i++); + + m_Extension = FileSpec + i + 1; + std::transform(m_Extension.begin(), m_Extension.end(), m_Extension.begin(), ::tolower); + m_Valid = ((m_Directory = opendir(DirectoryName.c_str())) != NULL); + + if (! m_Valid) + return (* this); + + next(); +#endif + + return (* this); +} + +inline bool search_iterator::end() const { + return false; +} + +inline search_iterator & search_iterator::next() { +#if defined WIN32 + m_Valid = (_findnext(m_hFiles, &m_FindData) != -1); +#else + bool Found = false; + while (! Found) { + m_Valid = ((m_DirectoryEntry = readdir(m_Directory)) != NULL); + if (m_Valid) { + std::string FileName = m_DirectoryEntry->d_name; + if (FileName[0] == '.') + Found = false; + else if (FileName.size() <= m_Extension.size()) + Found = false; + else { + std::transform(FileName.begin(), FileName.end(), FileName.begin(), ::tolower); + if (std::equal(m_Extension.rbegin(), m_Extension.rend(), FileName.rbegin())) + Found = true; + } + } + else + break; + } +#endif + + return (* this); +} + +inline std::string search_iterator::Name() const { +#if defined WIN32 + return (m_FindData.name); +#else + return (m_DirectoryEntry->d_name); +#endif +} + + + + +} // namespace io_facilities + + diff --git a/JGE/src/zipFS/zfsystem.cpp b/JGE/src/zipFS/zfsystem.cpp index b8ef786d9..34699d080 100644 --- a/JGE/src/zipFS/zfsystem.cpp +++ b/JGE/src/zipFS/zfsystem.cpp @@ -3,7 +3,7 @@ // zfsystem.cpp: implementation of the zip file system classes. // -// Copyright (C) 2004 Tanguy Fautré. +// Copyright (C) 2004 Tanguy Fautre // For conditions of distribution and use, // see copyright notice in zfsystem.h // diff --git a/JGE/src/zipFS/zfsystem.h b/JGE/src/zipFS/zfsystem.h index 66a8193f2..8fca5bc2a 100644 --- a/JGE/src/zipFS/zfsystem.h +++ b/JGE/src/zipFS/zfsystem.h @@ -1,332 +1,332 @@ -//Important: This file has been modified in order to be integrated in to JGE++ -// - -// zfsystem.h: interface for the zip file system classes. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2004 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@telenet.be -// -////////////////////////////////////////////////////////////////////// -// -// Zip File System. -// **************** -// -// Current version: 1.00 BETA 2 (16/07/2004) -// -// Comment: - -// -// History: - 1.00 BETA 2 (16/07/2004) - Updated to follow latest version -// of fileio.h -// - 1.00 BETA 1 (21/07/2002) - First public release -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - -#include "stdafx.h" -#include "ziphdr.h" // Zip file header -#include "zstream.h" // Zip Stream - - - -// Zip File System Namespace -namespace zip_file_system { - - - - -class filesystem; - - - -// Input Zip File class -class izfstream : public izstream -{ -public: - izfstream(filesystem * pFS = pDefaultFS); - izfstream(const char * FilePath, filesystem * pFS = pDefaultFS); - - void open(const char * FilePath, filesystem * pFS = pDefaultFS); - void close(); - - bool is_open() const; - - void setFS(filesystem * pFS = pDefaultFS); - - bool Zipped() const; - bool isBeingUsed() const; - const std::string & FilePath() const; - const std::string & FullFilePath() const; - size_t getUncompSize(); - size_t getOffset(); - size_t getCompSize(); - -protected: - friend class filesystem; - - // Default File System Pointer (default = NULL) - static filesystem * pDefaultFS; - - std::string m_FilePath; - std::string m_FullFilePath; - filesystem * m_pFS; - bool m_Zipped; - size_t m_UncompSize; - size_t m_Offset; - size_t m_CompSize; - bool m_Used; - -}; - - - - -// Zip File System central class -class filesystem -{ -public: - // "local" file info class - class file_info - { - public: - file_info() : m_PackID(0), m_Offset(0), m_Size(0), m_CompSize(0), m_CompMethod(0), m_Directory(true) { } - file_info(size_t PackID, size_t Offset, size_t Size, size_t CompSize, short CompMethod, bool Directory) : - m_PackID(PackID), m_Offset(Offset), m_Size(Size), m_CompSize(CompSize), m_CompMethod(CompMethod), m_Directory(Directory) { } - - size_t m_PackID; - size_t m_Offset; - size_t m_Size; - size_t m_CompSize; - short m_CompMethod; - bool m_Directory; - }; - - class limited_file_info - { - public: - limited_file_info() : m_Offset(0), m_Size(0) { } - limited_file_info(size_t Offset, size_t Size) : - m_Offset(Offset), m_Size(Size) { } - - size_t m_Offset; - size_t m_Size; - }; - - class pooledBuffer - { - public: - pooledBuffer(std::string filename, std::string externalFilename ) : filename(filename), externalFilename(externalFilename), buffer(NULL) {} - ~pooledBuffer() { if (buffer) { delete buffer; } } - std::string filename; - std::string externalFilename; - zbuffer * buffer; - }; - - - filesystem(const char * BasePath = "", const char * FileExt = "zip", bool DefaultFS = true); - ~filesystem(); - - void MakeDefault(); - void Open(izfstream & File, const char * Filename); - bool DirExists(const std::string & folderName); - bool FileExists(const std::string & fileName); - bool PreloadZip(const char * Filename, std::map& target); - static std::string getCurrentZipName(); - static filesystem * getCurrentFS(); - static std::streamoff SkipLFHdr(std::istream & File, std::streamoff LFHdrPos); - void unuse(izfstream & File); - - //Fills the vector results with a list of children of the given folder - std::vector& scanfolder(const std::string& folderName, std::vector& results); - - friend std::ostream & operator << (std::ostream & Out, const filesystem & FS); - static void closeTempFiles(); - -protected: - - - - // Zip file info class - class zipfile_info - { - public: - zipfile_info() : m_NbEntries(0), m_FilesSize(0), m_FilesCompSize(0) { } - - std::string m_Filename; - size_t m_NbEntries; - size_t m_FilesSize; - size_t m_FilesCompSize; - }; - - // Class for file path string comparaison - struct lt_path - { - bool operator() (const std::string & s1, const std::string & s2) const; - }; - - - // Protected member functions - // Zip file format related functions - std::streamoff CentralDir(std::istream & File) const; - std::streamoff CentralDirZipped(std::istream & File, std::streamoff begin, std::size_t size) const; - headerid NextHeader(std::istream & File) const; - - // File/Zip map related functions - bool FileNotZipped(const char * FilePath) const; - bool FindFile(const char * Filename, file_info * FileInfo) const; - const std::string & FindZip(size_t PackID) const; - void InsertZip(const char * Filename, const size_t PackID); - - static zbuffer * getValidBuffer(const std::string & filename, const std::string & externalFilename, std::streamoff Offset = 0, std::streamoff Size = 0); - static void closeBufferPool(); - - // New type definitions - typedef std::map zipmap; - typedef std::map::iterator zipmap_iterator; - typedef std::map::const_iterator zipmap_const_iterator; - typedef std::map filemap; - typedef std::map::iterator filemap_iterator; - typedef std::map::const_iterator filemap_const_iterator; - - // Mighty protected member variables - std::string m_BasePath; - std::string m_FileExt; - zipmap m_Zips; - filemap m_Files; - static std::vector m_Buffers; - static std::ifstream CurrentZipFile; - static std::string CurrentZipName; - static filesystem * pCurrentFS; -}; - - - - -////////////////////////////////////////////////////////////////////// -// zip_file_system::izfile Inline Functions -////////////////////////////////////////////////////////////////////// - -inline izfstream::izfstream(filesystem * pFS) : m_pFS(pFS) { } - -inline izfstream::izfstream(const char * FilePath, filesystem * pFS) : m_pFS(pFS) { - open(FilePath); -} - -inline void izfstream::setFS(filesystem * pFS) { - m_pFS = pFS; -} - -inline size_t izfstream::getUncompSize() -{ - return m_UncompSize; -} - -inline size_t izfstream::getOffset() -{ - return m_Offset; -} - -inline size_t izfstream::getCompSize() -{ - return m_CompSize; -} - - - -inline void izfstream::open(const char * FilePath, filesystem * pFS) { - if (pFS) - m_pFS = pFS; - - if (m_pFS != NULL) - m_pFS->Open(* this, FilePath); -} - -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; -} - -inline bool izfstream::is_open() const { - return static_cast(rdbuf())->is_open(); -} - -inline bool izfstream::Zipped() const { - return m_Zipped; -} - -inline bool izfstream::isBeingUsed() const { - return m_Used; -} - -inline const std::string & izfstream::FilePath() const { - return m_FilePath; -} - -inline const std::string & izfstream::FullFilePath() const { - return m_FullFilePath; -} - - - -////////////////////////////////////////////////////////////////////// -// zip_file_system::filesystem Inline Functions -////////////////////////////////////////////////////////////////////// - -inline filesystem::~filesystem() { - // Security mesure with izfile::pDefaultFS - if (izfstream::pDefaultFS == this) - izfstream::pDefaultFS = NULL; -} - -inline void filesystem::closeTempFiles() { - if (CurrentZipName.size()) - { - CurrentZipFile.close(); - CurrentZipName = ""; - } - closeBufferPool(); -} -inline void filesystem::MakeDefault() { - izfstream::pDefaultFS = this; -} - - -inline std::string filesystem::getCurrentZipName() -{ - return CurrentZipName; -} - -inline filesystem * filesystem::getCurrentFS() -{ - return pCurrentFS; -} - -} // namespace zip_file_system - +//Important: This file has been modified in order to be integrated in to JGE++ +// + +// zfsystem.h: interface for the zip file system classes. +// +////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2004 Tanguy Fautre +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +// +// Tanguy FautrE +// softdev@telenet.be +// +////////////////////////////////////////////////////////////////////// +// +// Zip File System. +// **************** +// +// Current version: 1.00 BETA 2 (16/07/2004) +// +// Comment: - +// +// History: - 1.00 BETA 2 (16/07/2004) - Updated to follow latest version +// of fileio.h +// - 1.00 BETA 1 (21/07/2002) - First public release +// +////////////////////////////////////////////////////////////////////// + +#pragma once + + +#include "stdafx.h" +#include "ziphdr.h" // Zip file header +#include "zstream.h" // Zip Stream + + + +// Zip File System Namespace +namespace zip_file_system { + + + + +class filesystem; + + + +// Input Zip File class +class izfstream : public izstream +{ +public: + izfstream(filesystem * pFS = pDefaultFS); + izfstream(const char * FilePath, filesystem * pFS = pDefaultFS); + + void open(const char * FilePath, filesystem * pFS = pDefaultFS); + void close(); + + bool is_open() const; + + void setFS(filesystem * pFS = pDefaultFS); + + bool Zipped() const; + bool isBeingUsed() const; + const std::string & FilePath() const; + const std::string & FullFilePath() const; + size_t getUncompSize(); + size_t getOffset(); + size_t getCompSize(); + +protected: + friend class filesystem; + + // Default File System Pointer (default = NULL) + static filesystem * pDefaultFS; + + std::string m_FilePath; + std::string m_FullFilePath; + filesystem * m_pFS; + bool m_Zipped; + size_t m_UncompSize; + size_t m_Offset; + size_t m_CompSize; + bool m_Used; + +}; + + + + +// Zip File System central class +class filesystem +{ +public: + // "local" file info class + class file_info + { + public: + file_info() : m_PackID(0), m_Offset(0), m_Size(0), m_CompSize(0), m_CompMethod(0), m_Directory(true) { } + file_info(size_t PackID, size_t Offset, size_t Size, size_t CompSize, short CompMethod, bool Directory) : + m_PackID(PackID), m_Offset(Offset), m_Size(Size), m_CompSize(CompSize), m_CompMethod(CompMethod), m_Directory(Directory) { } + + size_t m_PackID; + size_t m_Offset; + size_t m_Size; + size_t m_CompSize; + short m_CompMethod; + bool m_Directory; + }; + + class limited_file_info + { + public: + limited_file_info() : m_Offset(0), m_Size(0) { } + limited_file_info(size_t Offset, size_t Size) : + m_Offset(Offset), m_Size(Size) { } + + size_t m_Offset; + size_t m_Size; + }; + + class pooledBuffer + { + public: + pooledBuffer(std::string filename, std::string externalFilename ) : filename(filename), externalFilename(externalFilename), buffer(NULL) {} + ~pooledBuffer() { if (buffer) { delete buffer; } } + std::string filename; + std::string externalFilename; + zbuffer * buffer; + }; + + + filesystem(const char * BasePath = "", const char * FileExt = "zip", bool DefaultFS = true); + ~filesystem(); + + void MakeDefault(); + void Open(izfstream & File, const char * Filename); + bool DirExists(const std::string & folderName); + bool FileExists(const std::string & fileName); + bool PreloadZip(const char * Filename, std::map& target); + static std::string getCurrentZipName(); + static filesystem * getCurrentFS(); + static std::streamoff SkipLFHdr(std::istream & File, std::streamoff LFHdrPos); + void unuse(izfstream & File); + + //Fills the vector results with a list of children of the given folder + std::vector& scanfolder(const std::string& folderName, std::vector& results); + + friend std::ostream & operator << (std::ostream & Out, const filesystem & FS); + static void closeTempFiles(); + +protected: + + + + // Zip file info class + class zipfile_info + { + public: + zipfile_info() : m_NbEntries(0), m_FilesSize(0), m_FilesCompSize(0) { } + + std::string m_Filename; + size_t m_NbEntries; + size_t m_FilesSize; + size_t m_FilesCompSize; + }; + + // Class for file path string comparaison + struct lt_path + { + bool operator() (const std::string & s1, const std::string & s2) const; + }; + + + // Protected member functions + // Zip file format related functions + std::streamoff CentralDir(std::istream & File) const; + std::streamoff CentralDirZipped(std::istream & File, std::streamoff begin, std::size_t size) const; + headerid NextHeader(std::istream & File) const; + + // File/Zip map related functions + bool FileNotZipped(const char * FilePath) const; + bool FindFile(const char * Filename, file_info * FileInfo) const; + const std::string & FindZip(size_t PackID) const; + void InsertZip(const char * Filename, const size_t PackID); + + static zbuffer * getValidBuffer(const std::string & filename, const std::string & externalFilename, std::streamoff Offset = 0, std::streamoff Size = 0); + static void closeBufferPool(); + + // New type definitions + typedef std::map zipmap; + typedef std::map::iterator zipmap_iterator; + typedef std::map::const_iterator zipmap_const_iterator; + typedef std::map filemap; + typedef std::map::iterator filemap_iterator; + typedef std::map::const_iterator filemap_const_iterator; + + // Mighty protected member variables + std::string m_BasePath; + std::string m_FileExt; + zipmap m_Zips; + filemap m_Files; + static std::vector m_Buffers; + static std::ifstream CurrentZipFile; + static std::string CurrentZipName; + static filesystem * pCurrentFS; +}; + + + + +////////////////////////////////////////////////////////////////////// +// zip_file_system::izfile Inline Functions +////////////////////////////////////////////////////////////////////// + +inline izfstream::izfstream(filesystem * pFS) : m_pFS(pFS) { } + +inline izfstream::izfstream(const char * FilePath, filesystem * pFS) : m_pFS(pFS) { + open(FilePath); +} + +inline void izfstream::setFS(filesystem * pFS) { + m_pFS = pFS; +} + +inline size_t izfstream::getUncompSize() +{ + return m_UncompSize; +} + +inline size_t izfstream::getOffset() +{ + return m_Offset; +} + +inline size_t izfstream::getCompSize() +{ + return m_CompSize; +} + + + +inline void izfstream::open(const char * FilePath, filesystem * pFS) { + if (pFS) + m_pFS = pFS; + + if (m_pFS != NULL) + m_pFS->Open(* this, FilePath); +} + +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; +} + +inline bool izfstream::is_open() const { + return static_cast(rdbuf())->is_open(); +} + +inline bool izfstream::Zipped() const { + return m_Zipped; +} + +inline bool izfstream::isBeingUsed() const { + return m_Used; +} + +inline const std::string & izfstream::FilePath() const { + return m_FilePath; +} + +inline const std::string & izfstream::FullFilePath() const { + return m_FullFilePath; +} + + + +////////////////////////////////////////////////////////////////////// +// zip_file_system::filesystem Inline Functions +////////////////////////////////////////////////////////////////////// + +inline filesystem::~filesystem() { + // Security mesure with izfile::pDefaultFS + if (izfstream::pDefaultFS == this) + izfstream::pDefaultFS = NULL; +} + +inline void filesystem::closeTempFiles() { + if (CurrentZipName.size()) + { + CurrentZipFile.close(); + CurrentZipName = ""; + } + closeBufferPool(); +} +inline void filesystem::MakeDefault() { + izfstream::pDefaultFS = this; +} + + +inline std::string filesystem::getCurrentZipName() +{ + return CurrentZipName; +} + +inline filesystem * filesystem::getCurrentFS() +{ + return pCurrentFS; +} + +} // namespace zip_file_system + diff --git a/JGE/src/zipFS/ziphdr.cpp b/JGE/src/zipFS/ziphdr.cpp index ff85c51d9..dd8c23978 100644 --- a/JGE/src/zipFS/ziphdr.cpp +++ b/JGE/src/zipFS/ziphdr.cpp @@ -1,6 +1,6 @@ // ziphdr.cpp: implementation of the zip header classes. // -// Copyright (C) 2002 Tanguy Fautré. +// Copyright (C) 2002 Tanguy Fautre // For conditions of distribution and use, // see copyright notice in ziphdr.h // diff --git a/JGE/src/zipFS/ziphdr.h b/JGE/src/zipFS/ziphdr.h index 530d83c98..b8e47dcc9 100644 --- a/JGE/src/zipFS/ziphdr.h +++ b/JGE/src/zipFS/ziphdr.h @@ -1,143 +1,143 @@ -// zfsystem.h: interface for the zip header classes. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2002 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@telenet.be -// -////////////////////////////////////////////////////////////////////// -// -// Zip File Format Headers. -// *********************** -// -// Current version: 1.00 BETA 2 (01/09/2003) -// -// Comment: Based on the ZIP file format specification from Appnote.txt -// from the PKZip Website on July 13, 1998. -// New implementations of the ZIP file format might not work -// correctly (ZIP64 ?). -// -// History: - 1.00 BETA 2 (01/09/2003) - Use stdint.h sized types -// - 1.00 BETA 1 (12/06/2002) - First public release -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - - -// Zip File System Namespace -namespace zip_file_system { - - - - -// Zip file headers -enum headerid { LOCALFILE = 0x04034b50, - FILE = 0x02014b50, - ENDOFDIR = 0x06054b50, - UNKNOWN, - READERROR -}; - - - -// Zip file "local file" header class -struct local_file_header -{ - bool ReadHeader(std::istream & File); - - static const uint_least32_t m_ConstSign= LOCALFILE; - - uint_least32_t m_Signature; - uint_least16_t m_VersionExtract; - uint_least16_t m_GeneralFlags; - uint_least16_t m_CompMethod; - uint_least16_t m_Time; - uint_least16_t m_Date; - uint_least32_t m_CRC32; - uint_least32_t m_CompSize; - uint_least32_t m_UncompSize; - uint_least16_t m_FilenameSize; - uint_least16_t m_FieldSize; - - std::vector m_Filename; - std::vector m_ExtraField; -}; - - - -// Zip file "file header" header class -struct file_header -{ - bool ReadHeader(std::istream & File); - - static const headerid m_ConstSign = FILE; - - uint_least32_t m_Signature; - uint_least16_t m_VersionMade; - uint_least16_t m_VersionExtract; - uint_least16_t m_GeneralFlags; - uint_least16_t m_CompMethod; - uint_least16_t m_Time; - uint_least16_t m_Date; - uint_least32_t m_CRC32; - uint_least32_t m_CompSize; - uint_least32_t m_UncompSize; - uint_least16_t m_FilenameSize; - uint_least16_t m_FieldSize; - uint_least16_t m_CommentSize; - uint_least16_t m_DiskNb; - uint_least16_t m_IntAttrib; - uint_least32_t m_ExtAttrib; - uint_least32_t m_RelOffset; - - std::vector m_Filename; - std::vector m_ExtraField; - std::vector m_Comment; -}; - - - -// Zip file "end of central dir" header class -struct eofcd_header -{ - bool ReadHeader(std::istream & File); - - static const headerid m_ConstSign = ENDOFDIR; - - uint_least32_t m_Signature; - uint_least16_t m_NbDisks; - uint_least16_t m_DirDisk; - uint_least16_t m_LocalEntries; - uint_least16_t m_TotalEntries; - uint_least32_t m_DirSize; - uint_least32_t m_Offset; - uint_least16_t m_CommentSize; - - std::vector m_Comment; -}; - - - - -} // namespace zip_file_system - +// zfsystem.h: interface for the zip header classes. +// +////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2002 Tanguy Fautre +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +// +// Tanguy FautrE +// softdev@telenet.be +// +////////////////////////////////////////////////////////////////////// +// +// Zip File Format Headers. +// *********************** +// +// Current version: 1.00 BETA 2 (01/09/2003) +// +// Comment: Based on the ZIP file format specification from Appnote.txt +// from the PKZip Website on July 13, 1998. +// New implementations of the ZIP file format might not work +// correctly (ZIP64 ?). +// +// History: - 1.00 BETA 2 (01/09/2003) - Use stdint.h sized types +// - 1.00 BETA 1 (12/06/2002) - First public release +// +////////////////////////////////////////////////////////////////////// + +#pragma once + + + +// Zip File System Namespace +namespace zip_file_system { + + + + +// Zip file headers +enum headerid { LOCALFILE = 0x04034b50, + FILE = 0x02014b50, + ENDOFDIR = 0x06054b50, + UNKNOWN, + READERROR +}; + + + +// Zip file "local file" header class +struct local_file_header +{ + bool ReadHeader(std::istream & File); + + static const uint_least32_t m_ConstSign= LOCALFILE; + + uint_least32_t m_Signature; + uint_least16_t m_VersionExtract; + uint_least16_t m_GeneralFlags; + uint_least16_t m_CompMethod; + uint_least16_t m_Time; + uint_least16_t m_Date; + uint_least32_t m_CRC32; + uint_least32_t m_CompSize; + uint_least32_t m_UncompSize; + uint_least16_t m_FilenameSize; + uint_least16_t m_FieldSize; + + std::vector m_Filename; + std::vector m_ExtraField; +}; + + + +// Zip file "file header" header class +struct file_header +{ + bool ReadHeader(std::istream & File); + + static const headerid m_ConstSign = FILE; + + uint_least32_t m_Signature; + uint_least16_t m_VersionMade; + uint_least16_t m_VersionExtract; + uint_least16_t m_GeneralFlags; + uint_least16_t m_CompMethod; + uint_least16_t m_Time; + uint_least16_t m_Date; + uint_least32_t m_CRC32; + uint_least32_t m_CompSize; + uint_least32_t m_UncompSize; + uint_least16_t m_FilenameSize; + uint_least16_t m_FieldSize; + uint_least16_t m_CommentSize; + uint_least16_t m_DiskNb; + uint_least16_t m_IntAttrib; + uint_least32_t m_ExtAttrib; + uint_least32_t m_RelOffset; + + std::vector m_Filename; + std::vector m_ExtraField; + std::vector m_Comment; +}; + + + +// Zip file "end of central dir" header class +struct eofcd_header +{ + bool ReadHeader(std::istream & File); + + static const headerid m_ConstSign = ENDOFDIR; + + uint_least32_t m_Signature; + uint_least16_t m_NbDisks; + uint_least16_t m_DirDisk; + uint_least16_t m_LocalEntries; + uint_least16_t m_TotalEntries; + uint_least32_t m_DirSize; + uint_least32_t m_Offset; + uint_least16_t m_CommentSize; + + std::vector m_Comment; +}; + + + + +} // namespace zip_file_system + diff --git a/JGE/src/zipFS/zstream.cpp b/JGE/src/zipFS/zstream.cpp index 7118f228e..5fe924730 100644 --- a/JGE/src/zipFS/zstream.cpp +++ b/JGE/src/zipFS/zstream.cpp @@ -1,6 +1,6 @@ // zstream.cpp: implementation of the zstream class. // -// Copyright (C) 2002 Tanguy Fautré. +// Copyright (C) 2002 Tanguy Fautre // For conditions of distribution and use, // see copyright notice in zfsystem.h // diff --git a/JGE/src/zipFS/zstream.h b/JGE/src/zipFS/zstream.h index 55ed81499..2f5d9b9f9 100644 --- a/JGE/src/zipFS/zstream.h +++ b/JGE/src/zipFS/zstream.h @@ -1,189 +1,189 @@ -// zstream.h: interface for the zstream classes. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2002 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@telenet.be -// -////////////////////////////////////////////////////////////////////// -// -// Zip (Input) Stream. -// ******************* -// -// Current version: 1.00 BETA 4 (02/09/2003) -// -// Comment: izstream currently only supports "stored" and "deflated" -// compression methods. -// -// !!!IMPORTANT!!! -// Modify "zstream_zlib.h" for headers and lib dependencies -// on Zlib (http://www.zlib.org) -// -// History: - 1.00 BETA 4 (02/09/2003) - Made zbuffer constructor protected -// - 1.00 BETA 3 (21/02/2003) - Fixed bugs with seekoff() -// - 1.00 BETA 2 (23/12/2002) - Fixed a bug with izstream -// (Added m_ComMethod(-1) in constructor) -// - 1.00 BETA 1 (29/05/2002) - First public release -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - - -#include "zstream_zlib.h" // Zlib dependencies - -#ifdef PSP -#define USE_ZBUFFER_POOL -#endif - -// Zip File System Namespace -namespace zip_file_system { - - - - -// Base buffer class -class zbuffer : public std::streambuf -{ -public: - virtual ~zbuffer() { } - - virtual zbuffer * open(const char * Filename, std::streamoff Offset, std::streamoff Size) = 0; - virtual zbuffer * close() = 0; - - bool is_open() const { return m_Opened; } - bool is_used() const {return m_Used;} - void unuse() { m_Used = false;} - bool use(std::streamoff Offset, std::streamoff Size); - std::string getFilename() { return m_Filename; } - -protected: - zbuffer() : m_Size(0), m_Opened(false), m_Used(false) { } - - static const int BUFFERSIZE = 4092; - - std::string m_Filename; - - - std::ifstream m_ZipFile; - std::streamoff m_Pos; - std::streamoff m_Size; - char m_Buffer[BUFFERSIZE]; - bool m_Opened; - bool m_Used; -}; - - - -// Buffer class for stored compression method. -class zbuffer_stored : public zbuffer -{ -public: - virtual ~zbuffer_stored() { close(); } - - virtual zbuffer_stored * open(const char * Filename, std::streamoff Offset, std::streamoff Size); - virtual zbuffer_stored * close(); - - virtual int overflow(int c = EOF); - virtual int underflow(); - virtual int sync(); - virtual std::streambuf * setbuf(char * pr, int nLength); - virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode); - - // Default Implementation is enough - // virtual streampos seekpos(streampos, int); -}; - - - - -// Buffer class for deflated compression method. -class zbuffer_deflated : public zbuffer -{ -public: - - virtual ~zbuffer_deflated() { - close(); - } - - virtual zbuffer_deflated * open(const char * Filename, std::streamoff Offset, std::streamoff Size); - virtual zbuffer_deflated * close(); - - virtual int overflow(int c = EOF); - virtual int underflow(); - virtual int sync(); - virtual std::streambuf * setbuf(char * pr, int nLength); - virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode); - - // Default Implementation is enough - // virtual streampos seekpos(streampos, int); - -protected: - z_stream m_ZStream; - std::streamoff m_CompPos; - char m_CompBuffer[BUFFERSIZE]; - bool m_StreamEnd; -}; - - - - -// main istream class for reading zipped files -class izstream : public std::istream -{ -public: - - izstream() : std::istream(NULL), m_CompMethod(-1) { setstate(std::ios::badbit); } - 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 _SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; }; - -protected: - static const int STORED = 0; - static const int DEFLATED = 8; - - zbuffer * GetRightBuffer(int CompMethod) const; - - void SetCompMethod(int CompMethod) { - delete rdbuf(GetRightBuffer(m_CompMethod = CompMethod)); - - if (rdbuf() == NULL) - setstate(std::ios::badbit); - } - - int m_CompMethod; -}; - - - - -} // namespace zip_file_system; - +// zstream.h: interface for the zstream classes. +// +////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2002 Tanguy Fautre +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +// +// Tanguy FautrE +// softdev@telenet.be +// +////////////////////////////////////////////////////////////////////// +// +// Zip (Input) Stream. +// ******************* +// +// Current version: 1.00 BETA 4 (02/09/2003) +// +// Comment: izstream currently only supports "stored" and "deflated" +// compression methods. +// +// !!!IMPORTANT!!! +// Modify "zstream_zlib.h" for headers and lib dependencies +// on Zlib (http://www.zlib.org) +// +// History: - 1.00 BETA 4 (02/09/2003) - Made zbuffer constructor protected +// - 1.00 BETA 3 (21/02/2003) - Fixed bugs with seekoff() +// - 1.00 BETA 2 (23/12/2002) - Fixed a bug with izstream +// (Added m_ComMethod(-1) in constructor) +// - 1.00 BETA 1 (29/05/2002) - First public release +// +////////////////////////////////////////////////////////////////////// + +#pragma once + + + +#include "zstream_zlib.h" // Zlib dependencies + +#ifdef PSP +#define USE_ZBUFFER_POOL +#endif + +// Zip File System Namespace +namespace zip_file_system { + + + + +// Base buffer class +class zbuffer : public std::streambuf +{ +public: + virtual ~zbuffer() { } + + virtual zbuffer * open(const char * Filename, std::streamoff Offset, std::streamoff Size) = 0; + virtual zbuffer * close() = 0; + + bool is_open() const { return m_Opened; } + bool is_used() const {return m_Used;} + void unuse() { m_Used = false;} + bool use(std::streamoff Offset, std::streamoff Size); + std::string getFilename() { return m_Filename; } + +protected: + zbuffer() : m_Size(0), m_Opened(false), m_Used(false) { } + + static const int BUFFERSIZE = 4092; + + std::string m_Filename; + + + std::ifstream m_ZipFile; + std::streamoff m_Pos; + std::streamoff m_Size; + char m_Buffer[BUFFERSIZE]; + bool m_Opened; + bool m_Used; +}; + + + +// Buffer class for stored compression method. +class zbuffer_stored : public zbuffer +{ +public: + virtual ~zbuffer_stored() { close(); } + + virtual zbuffer_stored * open(const char * Filename, std::streamoff Offset, std::streamoff Size); + virtual zbuffer_stored * close(); + + virtual int overflow(int c = EOF); + virtual int underflow(); + virtual int sync(); + virtual std::streambuf * setbuf(char * pr, int nLength); + virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode); + + // Default Implementation is enough + // virtual streampos seekpos(streampos, int); +}; + + + + +// Buffer class for deflated compression method. +class zbuffer_deflated : public zbuffer +{ +public: + + virtual ~zbuffer_deflated() { + close(); + } + + virtual zbuffer_deflated * open(const char * Filename, std::streamoff Offset, std::streamoff Size); + virtual zbuffer_deflated * close(); + + virtual int overflow(int c = EOF); + virtual int underflow(); + virtual int sync(); + virtual std::streambuf * setbuf(char * pr, int nLength); + virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, std::ios::openmode); + + // Default Implementation is enough + // virtual streampos seekpos(streampos, int); + +protected: + z_stream m_ZStream; + std::streamoff m_CompPos; + char m_CompBuffer[BUFFERSIZE]; + bool m_StreamEnd; +}; + + + + +// main istream class for reading zipped files +class izstream : public std::istream +{ +public: + + izstream() : std::istream(NULL), m_CompMethod(-1) { setstate(std::ios::badbit); } + 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 _SetCompMethod(int CompMethod) { m_CompMethod = CompMethod; }; + +protected: + static const int STORED = 0; + static const int DEFLATED = 8; + + zbuffer * GetRightBuffer(int CompMethod) const; + + void SetCompMethod(int CompMethod) { + delete rdbuf(GetRightBuffer(m_CompMethod = CompMethod)); + + if (rdbuf() == NULL) + setstate(std::ios::badbit); + } + + int m_CompMethod; +}; + + + + +} // namespace zip_file_system; +