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