Started to merge @ZobyTwo cmake branch

This commit is contained in:
xawotihs
2015-09-26 21:52:07 +02:00
parent 9e77899535
commit 85f4a4c36a
3112 changed files with 4615 additions and 9 deletions

12
thirdparty/zipFS/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,12 @@
set(SOURCES
stdafx.cpp
zfs.cpp
zfsystem.cpp
zstream.cpp
ziphdr.cpp)
FindOrBuildZLIB()
include_directories(${CMAKE_SOURCE_DIR}/JGE/include ${EXTRA_INCLUDES} ${ZLIB_INCLUDE_DIR})
add_library(zipFS ${SOURCES})
target_link_libraries(zipFS ${ZLIB_LIBRARY})

25
thirdparty/zipFS/Makefile vendored Normal file
View File

@@ -0,0 +1,25 @@
MAIN=zfs
CC=g++
CFLAGS= -O2 -Wall -DNDEBUG -DUNIX
INCLUDES=
LFLAGS= -lz
SRCS = \
zfs.cpp \
zfsystem.cpp \
ziphdr.cpp \
zstream.cpp \
OBJS = $(SRCS:.cpp=.o)
$(MAIN): $(OBJS)
$(CC) -o $(MAIN) $(LFLAGS) $(OBJS)
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
clean:
rm -f *.o $(MAIN)

BIN
thirdparty/zipFS/base_data/!Pak0.cpk vendored Normal file

Binary file not shown.

BIN
thirdparty/zipFS/base_data/!Pak1.cpk vendored Normal file

Binary file not shown.

256
thirdparty/zipFS/fileio.h vendored Normal file
View File

@@ -0,0 +1,256 @@
// 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<74>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 "<directory>/*.<ext>".
// 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 <io.h> // Windows I/O facilities (Directories)
#else
#include <dirent.h>
#include <string.h>
#endif
#include <limits.h>
namespace io_facilities {
// 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::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 <class T>
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<char *>(&TmpVar), 1);
Var |= TmpVar << (i * CHAR_BIT);
}
return File;
}
template <class T>
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<const char *>(&(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

16
thirdparty/zipFS/static_assert.h vendored Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
namespace mstatic_assert {
template <bool> class compile_time_error;
template <> class compile_time_error<true> { };
}
#define mstatic_assert(expr) { mstatic_assert::compile_time_error<((expr) != 0)> ERROR_STATIC_ASSERT; (void) ERROR_STATIC_ASSERT; }
#define mstatic_assert_msg(expr, msg) { mstatic_assert::compile_time_error<((expr) != 0)> ERROR_##msg; (void) ERROR_##msg; }

8
thirdparty/zipFS/stdafx.cpp vendored Normal file
View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// zfs.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

21
thirdparty/zipFS/stdafx.h vendored Normal file
View File

@@ -0,0 +1,21 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
// Standard headers
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
//#include "stdint.h"
#include <stdint.h>

77
thirdparty/zipFS/stdint_old.h vendored Normal file
View File

@@ -0,0 +1,77 @@
#ifndef _ZIPFS_STDINT_H_
#define _ZIPFS_STDINT_H_
#include "static_assert.h"
#if defined _MSC_VER
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef signed short int_least16_t;
typedef unsigned short uint_least16_t;
typedef signed int int_least32_t;
typedef unsigned int uint_least32_t;
typedef signed __int64 int_least64_t;
typedef unsigned __int64 uint_least64_t;
#elif defined UNIX
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef signed short int_least16_t;
typedef unsigned short uint_least16_t;
typedef signed int int_least32_t;
typedef unsigned int uint_least32_t;
typedef signed long long int_least64_t;
typedef unsigned long long uint_least64_t;
#endif
inline void __CheckSizedTypes()
{
// one byte must be exactly 8 bits
//static_assert(CHAR_BIT == 8);
mstatic_assert(sizeof(int8_t) == 1);
mstatic_assert(sizeof(uint8_t) == 1);
mstatic_assert(sizeof(int16_t) == 2);
mstatic_assert(sizeof(uint16_t) == 2);
mstatic_assert(sizeof(int32_t) == 4);
mstatic_assert(sizeof(uint32_t) == 4);
mstatic_assert(sizeof(int64_t) == 8);
mstatic_assert(sizeof(uint64_t) == 8);
mstatic_assert(sizeof(int_least8_t) >= 1);
mstatic_assert(sizeof(uint_least8_t) >= 1);
mstatic_assert(sizeof(int_least16_t) >= 2);
mstatic_assert(sizeof(uint_least16_t) >= 2);
mstatic_assert(sizeof(int_least32_t) >= 4);
mstatic_assert(sizeof(uint_least32_t) >= 4);
mstatic_assert(sizeof(int_least64_t) >= 8);
mstatic_assert(sizeof(uint_least64_t) >= 8);
}
#endif

44
thirdparty/zipFS/zfs.cpp vendored Normal file
View File

@@ -0,0 +1,44 @@
// ZFS.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// ZFS headers
#include "zfsystem.h"
void DoSomething(std::istream & File)
{
// Output the file via cout (note: rdbuf() method is a std C++ method, not zfs specific)
std::cout << File.rdbuf() << std::endl;
}
int main(int argc, char * argv[])
{
using namespace std;
using zip_file_system::filesystem;
using zip_file_system::izfstream;
// Create and initialize the Zip File System (basepath, file_extension, makedefault)
// and output the its status via cout
filesystem FileSystem("base_data", "cpk", true);
cout << FileSystem << endl;
// Try to open a zipped file (Careful! The openmode is always 'ios::in | ios::binary'.)
izfstream File("testfile.txt");
if (! File)
cout << "ERROR: Cannot open file!" << endl;
// Call some function expecting an istream object
DoSomething(File);
// The End.
cout << "\nPress ENTER to continue." << endl;
cin.get();
}

21
thirdparty/zipFS/zfs.sln vendored Normal file
View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zfs", "zfs.vcproj", "{54F414A2-0634-467B-95D4-35E8D171D2CA}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{54F414A2-0634-467B-95D4-35E8D171D2CA}.Debug.ActiveCfg = Debug|Win32
{54F414A2-0634-467B-95D4-35E8D171D2CA}.Debug.Build.0 = Debug|Win32
{54F414A2-0634-467B-95D4-35E8D171D2CA}.Release.ActiveCfg = Release|Win32
{54F414A2-0634-467B-95D4-35E8D171D2CA}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

175
thirdparty/zipFS/zfs.vcproj vendored Normal file
View File

@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="zfs"
ProjectGUID="{54F414A2-0634-467B-95D4-35E8D171D2CA}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/zfs.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/zfs.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/zfs.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<File
RelativePath=".\zfs.cpp">
</File>
<File
RelativePath=".\zfsystem.cpp">
</File>
<File
RelativePath=".\ziphdr.cpp">
</File>
<File
RelativePath=".\zstream.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\fileio.h">
</File>
<File
RelativePath=".\static_assert.h">
</File>
<File
RelativePath=".\stdafx.h">
</File>
<File
RelativePath=".\stdint.h">
</File>
<File
RelativePath=".\zfsystem.h">
</File>
<File
RelativePath=".\ziphdr.h">
</File>
<File
RelativePath=".\zstream.h">
</File>
<File
RelativePath=".\zstream_zlib.h">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

105
thirdparty/zipFS/zfs.vcxproj vendored Normal file
View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{54F414A2-0634-467B-95D4-35E8D171D2CA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.lib</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>..\JGE\Dependencies\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:MSVCPRTD %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<OutputFile>$(OutDir)zfs.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)zfs.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)zfs.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="zfs.cpp" />
<ClCompile Include="zfsystem.cpp" />
<ClCompile Include="ziphdr.cpp" />
<ClCompile Include="zstream.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="fileio.h" />
<ClInclude Include="static_assert.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="stdint.h" />
<ClInclude Include="zfsystem.h" />
<ClInclude Include="ziphdr.h" />
<ClInclude Include="zstream.h" />
<ClInclude Include="zstream_zlib.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

53
thirdparty/zipFS/zfs.vcxproj.filters vendored Normal file
View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="zfs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="zfsystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ziphdr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="zstream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="fileio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="static_assert.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="zfsystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ziphdr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="zstream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="zstream_zlib.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

793
thirdparty/zipFS/zfsystem.cpp vendored Normal file
View File

@@ -0,0 +1,793 @@
//Important: This file has been modified in order to be integrated in to JGE++
//
// zfsystem.cpp: implementation of the zip file system classes.
//
// Copyright (C) 2004 Tanguy Fautre
// For conditions of distribution and use,
// see copyright notice in zfsystem.h
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zfsystem.h"
// Debug
#include "JLogger.h"
#include "fileio.h" // I/O facilities
#if defined (WIN32)
#include <sys/types.h>
#endif
#include <sys/stat.h>
namespace zip_file_system {
using namespace std;
//////////////////////////////////////////////////////////////////////
// Static variables initialization
//////////////////////////////////////////////////////////////////////
filesystem * izfstream::pDefaultFS = NULL;
string filesystem::CurrentZipName = "";
ifstream filesystem::CurrentZipFile;
filesystem * filesystem::pCurrentFS = NULL;
std::vector<filesystem::pooledBuffer *> filesystem::m_Buffers;
static const int STORED = 0;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
filesystem::filesystem(const char * BasePath, const char * FileExt, bool DefaultFS)
: m_BasePath(BasePath), m_FileExt(FileExt)
{
using io_facilities::search_iterator;
// Init m_BasePath and be sure the base path finish with a '/' or a '\'
if (! m_BasePath.empty()) {
string::iterator c = m_BasePath.end();
c--;
if ((*c != '/') && (*c != '\\'))
m_BasePath += '/';
}
// Search all *.zip files (or whatever the ZipExt specify as the file extension)
// Search is case insensitive (see fileio.h for details)
// The case insensitive state is mostly because some of the filesystems we support such as FAT32 are case insensitive
// Being case sensitive would lead to weird bugs on these systems.
vector<string> ZipFiles;
for (search_iterator ZSrch = (m_BasePath + "*." + m_FileExt).c_str(); ZSrch != ZSrch.end(); ++ZSrch)
ZipFiles.push_back(ZSrch.Name());
// Open each zip files that have been found, in alphabetic order
sort(ZipFiles.begin(), ZipFiles.end());
for (vector<string>::const_iterator ZipIt = ZipFiles.begin(); ZipIt != ZipFiles.end(); ++ZipIt)
InsertZip(ZipIt->c_str(), ZipIt - ZipFiles.begin());
// Should we make this the default File System for ifile?
if (DefaultFS)
MakeDefault();
}
//////////////////////////////////////////////////////////////////////
// File System Member Functions
//////////////////////////////////////////////////////////////////////
zbuffer * filesystem::getValidBuffer(const std::string & filename, const std::string & externalFilename, std::streamoff Offset, std::streamoff Size )
{
//if exists filename in pool and is not in use, return that
for (size_t i = 0; i < m_Buffers.size(); ++i)
{
if (m_Buffers[i]->filename != filename)
continue;
zbuffer * buffer = m_Buffers[i]->buffer;
if (buffer && !buffer->is_used())
{
buffer->use(Offset, Size);
return buffer;
}
}
// if more than 3 objects in the pool, delete and close the first one that is unused
if (m_Buffers.size() > 3)
{
for (size_t i = 0; i < m_Buffers.size(); ++i)
{
zbuffer * buffer = m_Buffers[i]->buffer;
if (buffer && !buffer->is_used())
{
delete m_Buffers[i];
m_Buffers.erase(m_Buffers.begin() + i);
break;
}
}
}
//No possiblility to open more files for now
if (m_Buffers.size() > 3)
return NULL;
//create a new buffer object, add it to the pool, and return that
pooledBuffer * pb = new pooledBuffer(filename, externalFilename);
zbuffer * buffer = new zbuffer_stored();
buffer->open(filename.c_str(), Offset, Size);
pb->buffer = buffer;
m_Buffers.push_back(pb);
return pb->buffer;
}
void filesystem::closeBufferPool()
{
for (size_t i = 0; i < m_Buffers.size(); ++i)
{
if (m_Buffers[i])
{
if (m_Buffers[i]->buffer && m_Buffers[i]->buffer->is_used())
{
LOG("FATAL: File Buffer still in use but need to close");
}
delete m_Buffers[i];
}
}
m_Buffers.clear();
}
void filesystem::unuse(izfstream & File)
{
File.setstate(std::ios::badbit);
if (!File.Zipped())
{
delete(File.rdbuf(NULL));
}
else
{
zbuffer * buffer = static_cast<zbuffer *>(File.rdbuf());
if (buffer)
buffer->unuse();
}
}
void filesystem::Open(izfstream & File, const char * Filename)
{
// Close the file if it was opened;
File.close();
File.setFS(this);
// Generate the path and see if the file is zipped or not
string FullPath = m_BasePath + Filename;
// File is not zipped
if (FileNotZipped(FullPath.c_str())) {
// Link the izfile object with an opened filebuf
filebuf * FileBuf = new filebuf;
FileBuf->open(FullPath.c_str(), ios::binary | ios::in);
if (FileBuf->is_open()) {
#ifdef USE_ZBUFFER_POOL
File.rdbuf(FileBuf);
#else
delete File.rdbuf(FileBuf);
#endif
File.clear(ios::goodbit);
File.m_FilePath = Filename;
File.m_FullFilePath = FullPath;
File.m_Zipped = false;
}
// File is maybe zipped
} else {
file_info FileInfo;
string ZipPath;
// Check whether the file is zipped, whether the file is a directory and try to open.
if (FindFile(Filename, &FileInfo) && (! FileInfo.m_Directory) && (! ((ZipPath = FindZip(FileInfo.m_PackID)).empty()))) {
// Get the position of the compressed data
if (CurrentZipName.size())
{
if ((pCurrentFS!= this) || (CurrentZipName.compare(ZipPath) != 0))
{
CurrentZipFile.close();
CurrentZipName = "";
pCurrentFS = NULL;
}
}
if (!CurrentZipName.size())
{
CurrentZipName = ZipPath;
string zipName = m_BasePath + CurrentZipName;
CurrentZipFile.open(zipName.c_str(), ios::binary);
pCurrentFS = this;
}
if (!CurrentZipFile) {
CurrentZipName = "";
pCurrentFS = NULL;
return;
}
streamoff DataPos = SkipLFHdr(CurrentZipFile, streamoff(FileInfo.m_Offset));
if (DataPos != streamoff(-1)) {
string zipName = m_BasePath + CurrentZipName;
// Open the file at the right position
#ifdef USE_ZBUFFER_POOL
zbuffer * buffer = getValidBuffer(zipName, Filename, streamoff(DataPos), streamoff(FileInfo.m_CompSize));
if (!buffer)
{
File.setstate(ios::badbit);
}
else
{
File.rdbuf(buffer);
File._SetCompMethod(FileInfo.m_CompMethod);
#else
((izstream &) File).open(
zipName.c_str(),
streamoff(DataPos),
streamoff(FileInfo.m_CompSize),
FileInfo.m_CompMethod
);
if (File) {
#endif
File.m_FilePath = Filename;
File.m_FullFilePath = FullPath;
File.m_Zipped = true;
File.m_UncompSize = FileInfo.m_Size;
File.m_CompSize = FileInfo.m_CompSize;
File.m_Offset = FileInfo.m_Offset;
}
}
}
}
}
bool filesystem::DirExists(const std::string & folderName)
{
//Check in zip
file_info FileInfo;
// Check whether the file is zipped, whether the file is a directory and try to open.
if (FindFile(folderName.c_str(), &FileInfo) && (FileInfo.m_Directory))
return true;
//check real folder
string FullPath = m_BasePath + folderName;
#if defined (WIN32)
struct _stat statBuffer;
if ((_stat(FullPath.c_str(), &statBuffer) >= 0 && // make sure it exists
statBuffer.st_mode & S_IFDIR)) // and it's not a file
return true;
#else
struct stat st;
if (stat(FullPath.c_str(), &st) == 0)
return true;
#endif
//Neither in real folder nor in zip
return false;
}
bool filesystem::FileExists(const std::string & fileName)
{
if (fileName.length() < 1) return false;
//Check in zip
file_info FileInfo;
// Check whether the file is zipped, whether the file is a directory and try to open.
if (FindFile(fileName.c_str(), &FileInfo) && (!FileInfo.m_Directory))
return true;
//check real folder
string FullPath = m_BasePath + fileName;
#if defined (WIN32)
struct _stat statBuffer;
if (_stat(FullPath.c_str(), &statBuffer) >= 0) // make sure it exists
return true;
#else
struct stat st;
if (stat(FullPath.c_str(), &st) == 0)
return true;
#endif
//Neither in real folder nor in zip
return false;
}
// Note: this doesn't scan the folders outside of the zip...should we add that here ?
std::vector<std::string>& filesystem::scanfolder(const std::string& folderName, std::vector<std::string>& results)
{
filemap_const_iterator folderPos = m_Files.find(folderName);
if (folderPos == m_Files.end())
return results;
filemap_const_iterator It = folderPos;
string folderNameLC = folderName;
std::transform(folderNameLC.begin(), folderNameLC.end(), folderNameLC.begin(), ::tolower);
size_t length = folderNameLC.length();
while(++It != m_Files.end())
{
string currentFile = (* It).first;
string currentFileLC = currentFile;
std::transform(currentFileLC.begin(), currentFileLC.end(), currentFileLC.begin(), ::tolower);
if (currentFileLC.find(folderNameLC) == 0)
{
string relativePath = currentFile.substr(length);
size_t pos = relativePath.find_first_of("/\\");
//Only add direct children, no recursive browse
if (pos == string::npos || pos == (relativePath.length() - 1))
results.push_back(relativePath);
}
else
{
break;
//We know other files will not belong to that folder because of the order of the map
}
}
return results;
}
//////////////////////////////////////////////////////////////////////
// File System Protected Member Functions
//////////////////////////////////////////////////////////////////////
bool filesystem::FileNotZipped(const char * FilePath) const
{
//return io_facilities::search_iterator(FilePath);
// follow new search_iterator implementation
std::ifstream File(FilePath);
if (! File)
return false;
return true;
}
bool filesystem::FindFile(const char * Filename, file_info * FileInfo) const
{
filemap_const_iterator It = m_Files.find(Filename);
if (It == m_Files.end())
return false; // File not found
* FileInfo = (* It).second;
return true;
}
const string & filesystem::FindZip(size_t PackID) const
{
static const string EmptyString;
zipmap_const_iterator It = m_Zips.find(PackID);
if (It == m_Zips.end())
return EmptyString; // PackID not valid
return (* It).second.m_Filename;
}
void filesystem::InsertZip(const char * Filename, const size_t PackID)
{
zipfile_info ZipInfo;
// Get full path to the zip file and prepare ZipInfo
ZipInfo.m_Filename = Filename;
string ZipPath = m_BasePath + Filename;
// Open zip
LOG(("opening zip:" + ZipPath).c_str());
ifstream File(ZipPath.c_str(), ios::binary);
if (! File)
return;
// Find the start of the central directory
if (! File.seekg(CentralDir(File)))
{
File.close();
return;
}
LOG("open zip ok");
// Check every headers within the zip file
file_header FileHdr;
while ((NextHeader(File) == FILE) && (FileHdr.ReadHeader(File))) {
// Include files into Files map
const char * Name = &(* FileHdr.m_Filename.begin());
const unsigned short i = FileHdr.m_FilenameSize - 1;
if (FileHdr.m_FilenameSize != 0) {
m_Files[Name] = file_info(
PackID, // Package ID
FileHdr.m_RelOffset, // "Local File" header offset position
FileHdr.m_UncompSize, // File Size
FileHdr.m_CompSize, // Compressed File Size
FileHdr.m_CompMethod, // Compression Method;
((Name[i] == '/') || (Name[i] == '\\')) // Is a directory?
);
++(ZipInfo.m_NbEntries);
ZipInfo.m_FilesSize += FileHdr.m_UncompSize;
ZipInfo.m_FilesCompSize += FileHdr.m_CompSize;
}
}
File.close();
// Add zip file to Zips data base (only if not empty)
if (ZipInfo.m_NbEntries != 0)
m_Zips[PackID] = ZipInfo;
LOG("--zip file loading DONE");
}
bool filesystem::PreloadZip(const char * Filename, map<string, limited_file_info>& target)
{
zipfile_info ZipInfo;
// Open zip
izfstream File;
File.open(Filename, this);
if (! File)
return false;
// Find the start of the central directory
if (File.Zipped())
{
streamoff realBeginOfFile = SkipLFHdr(CurrentZipFile, File.getOffset());
if (! CurrentZipFile.seekg(CentralDirZipped(CurrentZipFile, realBeginOfFile, File.getCompSize())))
{
File.close();
return false;
}
// Check every headers within the zip file
file_header FileHdr;
while ((NextHeader(CurrentZipFile) == FILE) && (FileHdr.ReadHeader(CurrentZipFile))) {
// Include files into Files map
const char * Name = &(* FileHdr.m_Filename.begin());
if (FileHdr.m_FilenameSize != 0) {
// The zip in zip method only supports stored Zips because of JFileSystem limitations
if ((FileHdr.m_UncompSize != FileHdr.m_CompSize) || FileHdr.m_CompMethod != STORED)
continue;
target[Name] = limited_file_info(
realBeginOfFile + FileHdr.m_RelOffset, // "Local File" header offset position
FileHdr.m_UncompSize // File Size
);
}
}
File.close();
return (target.size() ? true : false);
}
else
{
if (! File.seekg(CentralDir(File)))
{
File.close();
return false;
}
// Check every headers within the zip file
file_header FileHdr;
while ((NextHeader(File) == FILE) && (FileHdr.ReadHeader(File))) {
// Include files into Files map
const char * Name = &(* FileHdr.m_Filename.begin());
if (FileHdr.m_FilenameSize != 0) {
// The zip in zip method only supports stored Zips because of JFileSystem limitations
if ((FileHdr.m_UncompSize != FileHdr.m_CompSize) || FileHdr.m_CompMethod != STORED)
continue;
target[Name] = limited_file_info(
FileHdr.m_RelOffset, // "Local File" header offset position
FileHdr.m_UncompSize // File Size
);
}
}
File.close();
return (target.size() ? true : false);
}
}
//////////////////////////////////////////////////////////////////////
// File System Friend Functions
//////////////////////////////////////////////////////////////////////
ostream & operator << (ostream & Out, const filesystem & FS)
{
size_t NbFiles = 0;
filesystem::zipfile_info AllZipsInfo;
for (filesystem::zipmap_const_iterator It = FS.m_Zips.begin(); It != FS.m_Zips.end(); ++It) {
const filesystem::zipfile_info & ZInfo = (* It).second;
// Print zip filename
Out << setiosflags(ios::left) << setw(32) << "-> \"" + ZInfo.m_Filename + "\"" << resetiosflags(ios::left);
// Print number of entries found in this zip file
Out << " " << setw(5) << ZInfo.m_NbEntries << " files";
// Print the uncompressed size of all included files
Out << " " << setw(7) << ZInfo.m_FilesSize / 1024 << " KB";
// Print the compressed size of all these files
Out << " " << setw(7) << ZInfo.m_FilesCompSize / 1024 << " KB packed" << endl;
++NbFiles;
AllZipsInfo.m_NbEntries += ZInfo.m_NbEntries;
AllZipsInfo.m_FilesSize += ZInfo.m_FilesSize;
AllZipsInfo.m_FilesCompSize += ZInfo.m_FilesCompSize;
}
// Print the general info
Out << "\nTotal: ";
Out << NbFiles << " packs ";
Out << AllZipsInfo.m_NbEntries << " files ";
Out << float(AllZipsInfo.m_FilesSize) / (1024 * 1024) << " MB ";
Out << float(AllZipsInfo.m_FilesCompSize) / (1024 * 1024) << " MB packed." << endl;
return Out;
}
//////////////////////////////////////////////////////////////////////
// "Less Than" Comparaison lt_path_str Member Functions
//////////////////////////////////////////////////////////////////////
bool filesystem::lt_path::operator () (const string & s1, const string & s2) const
{
const char * A = s1.c_str();
const char * B = s2.c_str();
for (size_t i = 0; ; ++i) {
if ((A[i] == '\0') && (B[i] == '\0'))
return false;
// '/' is the same as '\'
if (! (
(A[i] == B[i]) ||
((A[i] == '\\') && (B[i] == '/')) ||
((A[i] == '/') && (B[i] == '\\'))
)) {
// This line puts uppercases first
if ((A[i] == '\0') || (A[i] < B[i]))
return true;
else
return false;
}
}
}
//////////////////////////////////////////////////////////////////////
// Zip Header Classes Related Member Functions
//////////////////////////////////////////////////////////////////////
streamoff filesystem::CentralDirZipped(std::istream & File, std::streamoff begin, std::size_t size) const
{
using io_facilities::readvar;
std::streamoff eof = begin + size;
// Look for the "end of central dir" header. Start minimum 22 bytes before end.
if (! File.seekg(eof - 22, ios::beg))
return -1;
streamoff EndPos;
streamoff StartPos = File.tellg();
if (StartPos == streamoff(0))
return -1;
if (StartPos <= begin + streamoff(65536))
EndPos = 1;
else
EndPos = StartPos - streamoff(65536);
// Start the scan
do {
unsigned int RawSignature;
if (! readvar(File, RawSignature, 4))
return -1;
eofcd_header Header;
streampos Pos = File.tellg();
// Found a potential "eofcd" header?
if ((RawSignature == ENDOFDIR) && (File.seekg(-4, ios::cur)) && (Header.ReadHeader(File))) {
// Check invariant values (1 disk only)
if ((Header.m_NbDisks == 0) && (0 == Header.m_DirDisk) && (Header.m_LocalEntries == Header.m_TotalEntries)) {
// Check comment ends at eof
if (! File.seekg(eof - 1 , ios::beg))
return -1;
if ((File.tellg() + streamoff(1)) == (Pos + streamoff(Header.m_CommentSize + 22 - 4))) {
// Check the start offset leads to a correct directory/file header;
if (! File.seekg(begin + Header.m_Offset)) return -1;
if (! readvar(File, RawSignature, 4)) return -1;
if (RawSignature == FILE)
return begin + Header.m_Offset;
}
}
}
File.seekg(Pos);
} while ((File.seekg(-5, ios::cur)) && (File.tellg() > EndPos) && (File.tellg() > begin));
return -1;
}
streamoff filesystem::CentralDir(istream & File) const
{
using io_facilities::readvar;
// Look for the "end of central dir" header. Start minimum 22 bytes before end.
if (! File.seekg(-22, ios::end)) return -1;
streamoff EndPos;
streamoff StartPos = File.tellg();
if (StartPos == streamoff(0)) return -1;
if (StartPos <= streamoff(65536))
EndPos = 1;
else
EndPos = StartPos - streamoff(65536);
// Start the scan
do {
unsigned int RawSignature;
if (! readvar(File, RawSignature, 4)) return -1;
eofcd_header Header;
streampos Pos = File.tellg();
// Found a potential "eofcd" header?
if ((RawSignature == ENDOFDIR) && (File.seekg(-4, ios::cur)) && (Header.ReadHeader(File))) {
// Check invariant values (1 disk only)
if ((Header.m_NbDisks == 0) && (0 == Header.m_DirDisk) && (Header.m_LocalEntries == Header.m_TotalEntries)) {
// Check comment ends at eof
if (! File.seekg(-1, ios::end)) return -1;
if ((File.tellg() + streamoff(1)) == (Pos + streamoff(Header.m_CommentSize + 22 - 4))) {
// Check the start offset leads to a correct directory/file header;
if (! File.seekg(Header.m_Offset)) return -1;
if (! readvar(File, RawSignature, 4)) return -1;
if (RawSignature == FILE)
return Header.m_Offset;
}
}
}
File.seekg(Pos);
} while ((File.seekg(-5, ios::cur)) && (File.tellg() > EndPos));
return -1;
}
streamoff filesystem::SkipLFHdr(istream & File, streamoff LFHdrPos)
{
using io_facilities::readvar;
unsigned short NameSize;
unsigned short FieldSize;
unsigned int RawSignature;
// verify it's a local header
if (! File.seekg(LFHdrPos)) return -1;
if (! readvar(File, RawSignature, 4)) return -1;
if (RawSignature != LOCALFILE) return -1;
// Skip and go directly to comment/field size
if (! File.seekg(22, ios::cur)) return -1;
if (! readvar(File, NameSize, 2)) return -1;
if (! readvar(File, FieldSize, 2)) return -1;
// Skip comment and extra field
if (! File.seekg(NameSize + FieldSize, ios::cur)) return -1;
// Now we are at the compressed data position
return (File.tellg());
}
headerid filesystem::NextHeader(istream & File) const
{
using io_facilities::readvar;
unsigned int RawSignature;
if (! readvar(File, RawSignature, 4))
return READERROR;
if (! File.seekg(-4, ios::cur))
return READERROR;
headerid Signature = headerid(RawSignature);
switch (Signature) {
case FILE:
case LOCALFILE:
case ENDOFDIR:
return Signature;
default:
return UNKNOWN;
}
}
} // namespace zip_file_system

332
thirdparty/zipFS/zfsystem.h vendored Normal file
View File

@@ -0,0 +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 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<74>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<std::string, limited_file_info>& 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<std::string>& scanfolder(const std::string& folderName, std::vector<std::string>& 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<size_t, zipfile_info> zipmap;
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<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>::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<pooledBuffer *> 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<zbuffer *>(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

123
thirdparty/zipFS/ziphdr.cpp vendored Normal file
View File

@@ -0,0 +1,123 @@
// ziphdr.cpp: implementation of the zip header classes.
//
// Copyright (C) 2002 Tanguy Fautre
// For conditions of distribution and use,
// see copyright notice in ziphdr.h
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ziphdr.h"
#include "fileio.h" // I/O facilities
namespace zip_file_system {
//////////////////////////////////////////////////////////////////////
// Zip Header Classes Member Functions
//////////////////////////////////////////////////////////////////////
bool local_file_header::ReadHeader(std::istream & File)
{
using io_facilities::readvar;
// quick check about char size
//static_assert(CHAR_BIT == 8);
if (! readvar(File, m_Signature, 4)) return false;
if (! readvar(File, m_VersionExtract, 2)) return false;
if (! readvar(File, m_GeneralFlags, 2)) return false;
if (! readvar(File, m_CompMethod, 2)) return false;
if (! readvar(File, m_Time, 2)) return false;
if (! readvar(File, m_Date, 2)) return false;
if (! readvar(File, m_CRC32, 4)) return false;
if (! readvar(File, m_CompSize, 4)) return false;
if (! readvar(File, m_UncompSize, 4)) return false;
if (! readvar(File, m_FilenameSize, 2)) return false;
if (! readvar(File, m_FieldSize, 2)) return false;
m_Filename.resize(m_FilenameSize + 1);
m_ExtraField.resize(m_FieldSize + 1);
if (! File.read(&(m_Filename[0]), m_FilenameSize)) return false;
if (! File.read(&(m_ExtraField[0]), m_FieldSize)) return false;
m_Filename[m_FilenameSize] = '\0';
m_ExtraField[m_FieldSize] = '\0';
return true;
}
bool file_header::ReadHeader(std::istream & File)
{
using io_facilities::readvar;
if (! readvar(File, m_Signature, 4)) return false;
if (! readvar(File, m_VersionMade, 2)) return false;
if (! readvar(File, m_VersionExtract, 2)) return false;
if (! readvar(File, m_GeneralFlags, 2)) return false;
if (! readvar(File, m_CompMethod, 2)) return false;
if (! readvar(File, m_Time, 2)) return false;
if (! readvar(File, m_Date, 2)) return false;
if (! readvar(File, m_CRC32, 4)) return false;
if (! readvar(File, m_CompSize, 4)) return false;
if (! readvar(File, m_UncompSize, 4)) return false;
if (! readvar(File, m_FilenameSize, 2)) return false;
if (! readvar(File, m_FieldSize, 2)) return false;
if (! readvar(File, m_CommentSize, 2)) return false;
if (! readvar(File, m_DiskNb, 2)) return false;
if (! readvar(File, m_IntAttrib, 2)) return false;
if (! readvar(File, m_ExtAttrib, 4)) return false;
if (! readvar(File, m_RelOffset, 4)) return false;
m_Filename.resize(m_FilenameSize + 1);
m_ExtraField.resize(m_FieldSize + 1);
m_Comment.resize(m_CommentSize + 1);
if (! File.read(&(m_Filename[0]), m_FilenameSize)) return false;
if (! File.read(&(m_ExtraField[0]), m_FieldSize)) return false;
if (! File.read(&(m_Comment[0]), m_CommentSize)) return false;
m_Filename[m_FilenameSize] = '\0';
m_ExtraField[m_FieldSize] = '\0';
m_Comment[m_CommentSize] = '\0';
return true;
}
bool eofcd_header::ReadHeader(std::istream & File)
{
using io_facilities::readvar;
if (! readvar(File, m_Signature, 4)) return false;
if (! readvar(File, m_NbDisks, 2)) return false;
if (! readvar(File, m_DirDisk, 2)) return false;
if (! readvar(File, m_LocalEntries, 2)) return false;
if (! readvar(File, m_TotalEntries, 2)) return false;
if (! readvar(File, m_DirSize, 4)) return false;
if (! readvar(File, m_Offset, 4)) return false;
if (! readvar(File, m_CommentSize, 2)) return false;
m_Comment.resize(m_CommentSize + 1);
if (! File.read(&(m_Comment[0]), m_CommentSize)) return false;
m_Comment[m_CommentSize] = '\0';
return true;
}
} // namespace zip_file_system

143
thirdparty/zipFS/ziphdr.h vendored Normal file
View File

@@ -0,0 +1,143 @@
// 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<74>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<char> m_Filename;
std::vector<char> 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<char> m_Filename;
std::vector<char> m_ExtraField;
std::vector<char> 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<char> m_Comment;
};
} // namespace zip_file_system

453
thirdparty/zipFS/zstream.cpp vendored Normal file
View File

@@ -0,0 +1,453 @@
// zstream.cpp: implementation of the zstream class.
//
// Copyright (C) 2002 Tanguy Fautre
// For conditions of distribution and use,
// see copyright notice in zfsystem.h
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zstream.h"
namespace zip_file_system {
using namespace std;
//////////////////////////////////////////////////////////////////////
// zstream Member Functions
//////////////////////////////////////////////////////////////////////
void izstream::open(const char * Filename, streamoff Offset, streamoff Size, int CompMethod)
{
// Change the buffer if need
if (m_CompMethod == CompMethod) {
if (rdbuf() != NULL)
static_cast<zbuffer *>(rdbuf())->close();
} else
SetCompMethod(CompMethod);
// clear up the file status
clear(ios::goodbit);
// open the buffer
switch (m_CompMethod) {
case STORED:
case DEFLATED:
if (! (static_cast<zbuffer *>(rdbuf())->open(Filename, Offset, Size))) {
setstate(ios::badbit);
SetCompMethod(-1);
}
break;
default:
setstate(ios::badbit);
}
}
zbuffer * izstream::GetRightBuffer(int CompMethod) const
{
switch (CompMethod) {
// stored
case STORED:
return new zbuffer_stored;
// deflated
case DEFLATED:
return new zbuffer_deflated;
// else not supported
default:
return NULL;
}
}
bool zbuffer::use(std::streamoff Offset, std::streamoff Size)
{
if (! m_ZipFile)
return false;
//Don't use a buffer already used;
if (m_Used)
return false;
// adjust file position
if (! m_ZipFile.seekg(Offset, ios::beg))
return false;
setg( m_Buffer, // beginning of putback area
m_Buffer, // read position
m_Buffer); // end of buffer
m_Buffer[0] = 0;
m_Pos = -1;
m_Size = Size;
m_Used = true;
return true;
}
//////////////////////////////////////////////////////////////////////
// zbuffer_stored Member Functions
//////////////////////////////////////////////////////////////////////
zbuffer_stored * zbuffer_stored::open(const char * Filename, streamoff Offset, streamoff Size)
{
// open main compressed file
m_ZipFile.open(Filename, ios::binary);
if (! m_ZipFile)
return NULL;
// adjust file position
if (! use(Offset, Size))
return NULL;
m_Opened = true;
m_Filename = Filename;
return this;
}
zbuffer_stored * zbuffer_stored::close()
{
if (! m_Opened)
return NULL;
else {
m_Opened = false;
m_Used = false;
m_ZipFile.close();
}
return this;
}
int zbuffer_stored::overflow(int)
{
return EOF;
}
int zbuffer_stored::underflow()
{
// Buffer Valid?
if (! m_Opened)
return EOF;
// Do we really need to refill it?
if (gptr() < egptr())
return static_cast<unsigned char>(* gptr());
// Refill de buffer.
// Set the real position of the beginning of the buffer.
if (m_Pos == streamoff(-1))
m_Pos = 0;
streamoff ToRead = ((m_Size - m_Pos) < BUFFERSIZE) ? (m_Size - m_Pos) : BUFFERSIZE;
if ((ToRead == 0) || (! m_ZipFile.read(m_Buffer, ToRead)))
return EOF;
m_Pos += ToRead;
// Reset buffer pointers.
setg( m_Buffer, // beginning of putback area
m_Buffer, // read position
m_Buffer + ToRead); // end of buffer
return static_cast<unsigned char>(m_Buffer[0]);
}
streampos zbuffer_stored::seekoff(streamoff off, ios::seekdir dir, ios::openmode nMode)
{
streamoff WantedPos = 0;
// Find out the wanted position.
switch (dir) {
case ios_base::cur:
WantedPos = m_Pos + streamoff(gptr() - eback()) + off;
break;
case ios_base::beg:
WantedPos = off;
break;
case ios_base::end:
WantedPos = m_Size + off;
break;
default:
assert(false);
}
// Is the position valid?
if ((WantedPos < 0) || (WantedPos > m_Size))
return streambuf::seekoff(off, dir, nMode); // return invalid streamoff
// Is the position already within the buffer?
if ((WantedPos >= m_Pos) && (WantedPos - m_Pos < egptr() - eback())) {
setg(eback(), eback() + (WantedPos - m_Pos), egptr());
return WantedPos;
}
// Fill up the buffer at the right position.
if (! m_ZipFile.seekg(WantedPos, ios::beg))
return streambuf::seekoff(off, dir, nMode);
m_Pos = WantedPos;
streamoff ToRead = ((m_Size - m_Pos) < BUFFERSIZE) ? (m_Size - m_Pos) : BUFFERSIZE;
if (ToRead == 0)
return WantedPos;
if (! m_ZipFile.read(m_Buffer, ToRead))
return streambuf::seekoff(off, dir, nMode);
// Set the buffer at the right position
setg(m_Buffer, m_Buffer, m_Buffer + ToRead);
return WantedPos;
}
int zbuffer_stored::sync()
{
return 0;
}
streambuf * zbuffer_stored::setbuf(char *, int)
{
return NULL;
}
//////////////////////////////////////////////////////////////////////
// zbuffer_deflated Member Functions
//////////////////////////////////////////////////////////////////////
zbuffer_deflated * zbuffer_deflated::open(const char * Filename, streamoff Offset, streamoff Size)
{
// open main compressed file
m_ZipFile.open(Filename, ios::binary);
if (! m_ZipFile)
return NULL;
// adjust file position
if (! use(Offset, Size))
return NULL;
// z_stream (NULL) Initialization
m_ZStream.next_in = Z_NULL;
m_ZStream.avail_in = 0;
m_ZStream.total_in = 0;
m_ZStream.next_out = Z_NULL;
m_ZStream.avail_out = 0;
m_ZStream.total_out = 0;
m_ZStream.zalloc = Z_NULL;
m_ZStream.zfree = Z_NULL;
m_ZStream.opaque = Z_NULL;
// inflate routine Initialization: Window Size = -MAX_WBITS tells there are no header
if (inflateInit2(&m_ZStream, -MAX_WBITS) != Z_OK)
return NULL;
m_Opened = true;
m_StreamEnd = false;
m_Pos = 0;
m_CompPos = 0;
m_Filename = Filename;
return this;
}
zbuffer_deflated * zbuffer_deflated::close()
{
if (! m_Opened)
return NULL;
else {
m_Opened = false;
m_Used = false;
m_ZipFile.close();
// z_stream unitialization.
if (inflateEnd(&m_ZStream) != Z_OK)
return NULL;
}
return this;
}
int zbuffer_deflated::overflow(int)
{
return EOF;
}
int zbuffer_deflated::underflow()
{
// Buffer Valid?
if (! m_Opened)
return EOF;
// Do we really need to refill it?
if (gptr() < egptr())
return static_cast<unsigned char>(* gptr());
// Can we refill?
if (m_StreamEnd)
return EOF;
streamoff ToRead;
streamoff OldPos;
bool BufferRefill = false;
// Check input (compressed) buffer status
if ((m_ZStream.avail_in == 0) && (m_CompPos < m_Size )) {
ToRead = ((m_Size - m_CompPos) > BUFFERSIZE) ? BUFFERSIZE : (m_Size - m_CompPos);
m_CompPos += ToRead;
if (! m_ZipFile.read(m_CompBuffer, ToRead))
return EOF;
m_ZStream.next_in = reinterpret_cast<unsigned char *>(m_CompBuffer);
m_ZStream.avail_in = ToRead;
}
// Ajust start read position in output buffer at the "old" end of buffer
ToRead = m_ZStream.total_out % BUFFERSIZE;
OldPos = m_ZStream.total_out;
// Check output (decompressed) buffer status
if (m_ZStream.avail_out == 0) {
BufferRefill = true;
m_ZStream.next_out = reinterpret_cast<unsigned char *>(m_Buffer);
m_ZStream.avail_out = BUFFERSIZE;
}
// Decompress (Inflate)
int Result = inflate(&m_ZStream, Z_SYNC_FLUSH);
// Check decompression result
if (Result == Z_STREAM_END)
m_StreamEnd = true;
else if (Result != Z_OK)
return EOF;
// Set the real position of the beginning of the buffer.
if (m_Pos == streamoff(-1))
m_Pos = 0;
else
if (BufferRefill)
m_Pos += m_ZStream.total_out - OldPos;
// Reset buffer pointers.
setg( m_Buffer, // beginning of putback area
m_Buffer + ToRead, // read position
m_Buffer + ((m_ZStream.total_out - 1) % (BUFFERSIZE)) + 1); // end of buffer
return static_cast<unsigned char>(m_Buffer[ToRead]);
}
streampos zbuffer_deflated::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode nMode)
{
streamoff WantedPos = 0;
// Find out the wanted position.
switch (dir) {
case ios_base::cur:
WantedPos = m_Pos + streamoff(gptr() - eback()) + off;
break;
case ios_base::beg:
WantedPos = off;
break;
case ios_base::end:
WantedPos = m_Size + off;
break;
default:
assert(false);
}
// Is the position valid?
if ((WantedPos < 0) || (WantedPos > m_Size))
return streambuf::seekoff(off, dir, nMode); // return invalid streamoff
// Is the position already within the buffer?
if ((WantedPos >= m_Pos) && (WantedPos - m_Pos < egptr() - eback())) {
setg(eback(), eback() + (WantedPos - m_Pos), egptr());
return WantedPos;
}
// Found out whether we have to decompress further or if we have to reset the decompression.
if (WantedPos < m_Pos) {
// Reset the decompression.
if (inflateReset(&m_ZStream) != Z_OK)
return streambuf::seekoff(off, dir, nMode);
// z_stream Reset
m_ZStream.next_in = Z_NULL;
m_ZStream.avail_in = 0;
m_ZStream.total_in = 0;
m_ZStream.next_out = Z_NULL;
m_ZStream.avail_out = 0;
m_ZStream.total_out = 0;
}
// call underflow() untill the right position is within the buffer.
while (WantedPos - m_Pos >= egptr() - eback()) {
setg(eback(), egptr(), egptr());
if (underflow() == EOF)
return streambuf::seekoff(off, dir, nMode);
}
// now the position is within the buffer.
setg(eback(), eback() + (WantedPos - m_Pos), egptr());
return WantedPos;
}
int zbuffer_deflated::sync()
{
return 0;
}
streambuf * zbuffer_deflated::setbuf(char *, int)
{
return NULL;
}
} // namespace zip_file_system

191
thirdparty/zipFS/zstream.h vendored Normal file
View File

@@ -0,0 +1,191 @@
// 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<74>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();
using std::streambuf::setbuf;
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();
using std::streambuf::setbuf;
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;

27
thirdparty/zipFS/zstream_zlib.h vendored Normal file
View File

@@ -0,0 +1,27 @@
//////////////////////////////////////////////////////////////////////
//
// !!! IMPORTANT !!!
//
// You'll need to modify the following library and header paths to
// correctly link with ZLib.
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <zlib.h>
// Visual C++
/*
#if defined _MSC_VER
#if defined _DEBUG
#pragma comment(lib, "../JGE/Dependencies/lib/zlibd.lib")
#else
#pragma comment(lib, "../JGE/Dependencies/lib/zdll.lib")
#endif
#endif
*/