mirror of
https://github.com/id-Software/GtkRadiant.git
synced 2026-03-19 16:39:26 +01:00
The GtkRadiant sources as originally released under the GPL license.
This commit is contained in:
353
plugins/archivezip/archive.cpp
Normal file
353
plugins/archivezip/archive.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "idatastream.h"
|
||||
#include "cmdlib.h"
|
||||
#include "bytestreamutils.h"
|
||||
|
||||
#include "modulesystem.h"
|
||||
#include "iarchive.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "stream/filestream.h"
|
||||
#include "container/array.h"
|
||||
#include "archivelib.h"
|
||||
#include "zlibstream.h"
|
||||
|
||||
class DeflatedArchiveFile : public ArchiveFile
|
||||
{
|
||||
CopiedString m_name;
|
||||
FileInputStream m_istream;
|
||||
SubFileInputStream m_substream;
|
||||
DeflatedInputStream m_zipstream;
|
||||
FileInputStream::size_type m_size;
|
||||
public:
|
||||
typedef FileInputStream::size_type size_type;
|
||||
typedef FileInputStream::position_type position_type;
|
||||
|
||||
DeflatedArchiveFile(const char* name, const char* archiveName, position_type position, size_type stream_size, size_type file_size)
|
||||
: m_name(name), m_istream(archiveName), m_substream(m_istream, position, stream_size), m_zipstream(m_substream), m_size(file_size)
|
||||
{
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
size_type size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
const char* getName() const
|
||||
{
|
||||
return m_name.c_str();
|
||||
}
|
||||
InputStream& getInputStream()
|
||||
{
|
||||
return m_zipstream;
|
||||
}
|
||||
};
|
||||
|
||||
class DeflatedArchiveTextFile : public ArchiveTextFile
|
||||
{
|
||||
CopiedString m_name;
|
||||
FileInputStream m_istream;
|
||||
SubFileInputStream m_substream;
|
||||
DeflatedInputStream m_zipstream;
|
||||
BinaryToTextInputStream<DeflatedInputStream> m_textStream;
|
||||
public:
|
||||
typedef FileInputStream::size_type size_type;
|
||||
typedef FileInputStream::position_type position_type;
|
||||
|
||||
DeflatedArchiveTextFile(const char* name, const char* archiveName, position_type position, size_type stream_size)
|
||||
: m_name(name), m_istream(archiveName), m_substream(m_istream, position, stream_size), m_zipstream(m_substream), m_textStream(m_zipstream)
|
||||
{
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
TextInputStream& getInputStream()
|
||||
{
|
||||
return m_textStream;
|
||||
}
|
||||
};
|
||||
|
||||
#include "pkzip.h"
|
||||
|
||||
#include <map>
|
||||
#include "string/string.h"
|
||||
#include "fs_filesystem.h"
|
||||
|
||||
|
||||
class ZipArchive : public Archive
|
||||
{
|
||||
class ZipRecord
|
||||
{
|
||||
public:
|
||||
enum ECompressionMode
|
||||
{
|
||||
eStored,
|
||||
eDeflated,
|
||||
};
|
||||
ZipRecord(unsigned int position, unsigned int compressed_size, unsigned int uncompressed_size, ECompressionMode mode)
|
||||
: m_position(position), m_stream_size(compressed_size), m_file_size(uncompressed_size), m_mode(mode)
|
||||
{
|
||||
}
|
||||
unsigned int m_position;
|
||||
unsigned int m_stream_size;
|
||||
unsigned int m_file_size;
|
||||
ECompressionMode m_mode;
|
||||
};
|
||||
|
||||
typedef GenericFileSystem<ZipRecord> ZipFileSystem;
|
||||
ZipFileSystem m_filesystem;
|
||||
CopiedString m_name;
|
||||
FileInputStream m_istream;
|
||||
|
||||
bool read_record()
|
||||
{
|
||||
zip_magic magic;
|
||||
istream_read_zip_magic(m_istream, magic);
|
||||
if(!(magic == zip_root_dirent_magic))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
zip_version version_encoder;
|
||||
istream_read_zip_version(m_istream, version_encoder);
|
||||
zip_version version_extract;
|
||||
istream_read_zip_version(m_istream, version_extract);
|
||||
//unsigned short flags =
|
||||
istream_read_int16_le(m_istream);
|
||||
unsigned short compression_mode = istream_read_int16_le(m_istream);
|
||||
if(compression_mode != Z_DEFLATED && compression_mode != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
zip_dostime dostime;
|
||||
istream_read_zip_dostime(m_istream, dostime);
|
||||
//unsigned int crc32 =
|
||||
istream_read_int32_le(m_istream);
|
||||
unsigned int compressed_size = istream_read_uint32_le(m_istream);
|
||||
unsigned int uncompressed_size = istream_read_uint32_le(m_istream);
|
||||
unsigned int namelength = istream_read_uint16_le(m_istream);
|
||||
unsigned short extras = istream_read_uint16_le(m_istream);
|
||||
unsigned short comment = istream_read_uint16_le(m_istream);
|
||||
//unsigned short diskstart =
|
||||
istream_read_int16_le(m_istream);
|
||||
//unsigned short filetype =
|
||||
istream_read_int16_le(m_istream);
|
||||
//unsigned int filemode =
|
||||
istream_read_int32_le(m_istream);
|
||||
unsigned int position = istream_read_int32_le(m_istream);
|
||||
|
||||
Array<char> filename(namelength+1);
|
||||
m_istream.read(reinterpret_cast<FileInputStream::byte_type*>(filename.data()), namelength);
|
||||
filename[namelength] = '\0';
|
||||
|
||||
m_istream.seek(extras + comment, FileInputStream::cur);
|
||||
|
||||
if(path_is_directory(filename.data()))
|
||||
{
|
||||
m_filesystem[filename.data()] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ZipFileSystem::entry_type& file = m_filesystem[filename.data()];
|
||||
if(!file.is_directory())
|
||||
{
|
||||
globalOutputStream() << "Warning: zip archive " << makeQuoted(m_name.c_str()) << " contains duplicated file: " << makeQuoted(filename.data()) << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
file = new ZipRecord(position, compressed_size, uncompressed_size, (compression_mode == Z_DEFLATED) ? ZipRecord::eDeflated : ZipRecord::eStored);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_pkzip()
|
||||
{
|
||||
SeekableStream::position_type pos = pkzip_find_disk_trailer(m_istream);
|
||||
if(pos != 0)
|
||||
{
|
||||
zip_disk_trailer disk_trailer;
|
||||
m_istream.seek(pos);
|
||||
istream_read_zip_disk_trailer(m_istream, disk_trailer);
|
||||
if(!(disk_trailer.z_magic == zip_disk_trailer_magic))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_istream.seek(disk_trailer.z_rootseek);
|
||||
for(unsigned int i = 0; i < disk_trailer.z_entries; ++i)
|
||||
{
|
||||
if(!read_record())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public:
|
||||
ZipArchive(const char* name)
|
||||
: m_name(name), m_istream(name)
|
||||
{
|
||||
if(!m_istream.failed())
|
||||
{
|
||||
if(!read_pkzip())
|
||||
{
|
||||
globalErrorStream() << "ERROR: invalid zip-file " << makeQuoted(name) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
~ZipArchive()
|
||||
{
|
||||
for(ZipFileSystem::iterator i = m_filesystem.begin(); i != m_filesystem.end(); ++i)
|
||||
{
|
||||
delete i->second.file();
|
||||
}
|
||||
}
|
||||
|
||||
bool failed()
|
||||
{
|
||||
return m_istream.failed();
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
ArchiveFile* openFile(const char* name)
|
||||
{
|
||||
ZipFileSystem::iterator i = m_filesystem.find(name);
|
||||
if(i != m_filesystem.end() && !i->second.is_directory())
|
||||
{
|
||||
ZipRecord* file = i->second.file();
|
||||
|
||||
m_istream.seek(file->m_position);
|
||||
zip_file_header file_header;
|
||||
istream_read_zip_file_header(m_istream, file_header);
|
||||
if(file_header.z_magic != zip_file_header_magic)
|
||||
{
|
||||
globalErrorStream() << "error reading zip file " << makeQuoted(m_name.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(file->m_mode)
|
||||
{
|
||||
case ZipRecord::eStored:
|
||||
return StoredArchiveFile::create(name, m_name.c_str(), m_istream.tell(), file->m_stream_size, file->m_file_size);
|
||||
case ZipRecord::eDeflated:
|
||||
return new DeflatedArchiveFile(name, m_name.c_str(), m_istream.tell(), file->m_stream_size, file->m_file_size);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
ArchiveTextFile* openTextFile(const char* name)
|
||||
{
|
||||
ZipFileSystem::iterator i = m_filesystem.find(name);
|
||||
if(i != m_filesystem.end() && !i->second.is_directory())
|
||||
{
|
||||
ZipRecord* file = i->second.file();
|
||||
|
||||
m_istream.seek(file->m_position);
|
||||
zip_file_header file_header;
|
||||
istream_read_zip_file_header(m_istream, file_header);
|
||||
if(file_header.z_magic != zip_file_header_magic)
|
||||
{
|
||||
globalErrorStream() << "error reading zip file " << makeQuoted(m_name.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(file->m_mode)
|
||||
{
|
||||
case ZipRecord::eStored:
|
||||
return StoredArchiveTextFile::create(name, m_name.c_str(), m_istream.tell(), file->m_stream_size);
|
||||
case ZipRecord::eDeflated:
|
||||
return new DeflatedArchiveTextFile(name, m_name.c_str(), m_istream.tell(), file->m_stream_size);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool containsFile(const char* name)
|
||||
{
|
||||
ZipFileSystem::iterator i = m_filesystem.find(name);
|
||||
return i != m_filesystem.end() && !i->second.is_directory();
|
||||
}
|
||||
void forEachFile(VisitorFunc visitor, const char* root)
|
||||
{
|
||||
m_filesystem.traverse(visitor, root);
|
||||
}
|
||||
};
|
||||
|
||||
Archive* OpenArchive(const char* name)
|
||||
{
|
||||
return new ZipArchive(name);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
class TestZip
|
||||
{
|
||||
class TestVisitor : public Archive::IVisitor
|
||||
{
|
||||
public:
|
||||
void visit(const char* name)
|
||||
{
|
||||
int bleh = 0;
|
||||
}
|
||||
};
|
||||
public:
|
||||
TestZip()
|
||||
{
|
||||
testzip("c:/quake3/baseq3/mapmedia.pk3", "textures/radiant/notex.tga");
|
||||
}
|
||||
|
||||
void testzip(const char* name, const char* filename)
|
||||
{
|
||||
Archive* archive = OpenArchive(name);
|
||||
ArchiveFile* file = archive->openFile(filename);
|
||||
if(file != 0)
|
||||
{
|
||||
unsigned char buffer[4096];
|
||||
std::size_t count = file->getInputStream().read((InputStream::byte_type*)buffer, 4096);
|
||||
file->release();
|
||||
}
|
||||
TestVisitor visitor;
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), "");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), "");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFiles, 1), "");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eDirectories, 1), "");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), "textures");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), "textures/");
|
||||
archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 2), "");
|
||||
archive->release();
|
||||
}
|
||||
};
|
||||
|
||||
TestZip g_TestZip;
|
||||
|
||||
#endif
|
||||
22
plugins/archivezip/archive.h
Normal file
22
plugins/archivezip/archive.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
Archive* OpenArchive(const char* name);
|
||||
7
plugins/archivezip/archivezip.def
Normal file
7
plugins/archivezip/archivezip.def
Normal file
@@ -0,0 +1,7 @@
|
||||
; archivezip.def : Declares the module parameters for the DLL.
|
||||
|
||||
LIBRARY "ARCHIVEZIP"
|
||||
|
||||
EXPORTS
|
||||
; Explicit exports can go here
|
||||
Radiant_RegisterModules @1
|
||||
154
plugins/archivezip/archivezip.dsp
Normal file
154
plugins/archivezip/archivezip.dsp
Normal file
@@ -0,0 +1,154 @@
|
||||
# Microsoft Developer Studio Project File - Name="archivezip" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=archivezip - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "archivezip.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "archivezip.mak" CFG="archivezip - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "archivezip - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "archivezip - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName "archivezip"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "archivezip - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE F90 /compile_only /include:"Release/" /libs:dll /nologo /warn:nofileopt /dll
|
||||
# ADD F90 /compile_only /include:"Release/" /libs:dll /nologo /warn:nofileopt /dll
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ARCHIVEZIP_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /O2 /I "..\..\include" /I "..\..\..\gtk2-win32\include\glib-2.0" /I "..\..\..\gtk2-win32\lib\glib-2.0\include" /I "..\common" /I "..\..\libs" /I "..\..\..\STLPort\stlport" /I "..\..\..\libxml2\include" /I "..\..\..\zlib" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ARCHIVEZIP_EXPORTS" /D "ZLIB_DLL" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 cmdlib.lib glib-2.0.lib zlib.lib /nologo /dll /machine:I386 /def:".\archivezip.def" /libpath:"..\..\libs\cmdlib\release" /libpath:"..\..\..\gtk2-win32\lib" /libpath:"..\..\..\libpng\projects\msvc\zlib___Win32_Release"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Copy to dir...
|
||||
PostBuild_Cmds=copy Release\archivezip.dll "../../install/modules"
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "archivezip - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE F90 /check:bounds /compile_only /debug:full /include:"Debug/" /libs:dll /nologo /warn:argument_checking /warn:nofileopt /dll
|
||||
# ADD F90 /check:bounds /compile_only /debug:full /include:"Debug/" /libs:dll /nologo /warn:argument_checking /warn:nofileopt /dll
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ARCHIVEZIP_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\..\gtk2-win32\include\glib-2.0" /I "..\..\..\gtk2-win32\lib\glib-2.0\include" /I "..\common" /I "..\..\libs" /I "..\..\..\STLPort\stlport" /I "..\..\..\libxml2\include" /I "..\..\..\zlib" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ARCHIVEZIP_EXPORTS" /D "ZLIB_DLL" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 cmdlib.lib glib-2.0.lib zlibd.lib /nologo /dll /debug /machine:I386 /def:".\archivezip.def" /pdbtype:sept /libpath:"..\..\libs\cmdlib\debug" /libpath:"..\..\..\gtk2-win32\lib" /libpath:"..\..\..\libpng\projects\msvc\zlib___Win32_Debug"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Copy to dir...
|
||||
PostBuild_Cmds=copy Debug\archivezip.dll "../../install/modules"
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "archivezip - Win32 Release"
|
||||
# Name "archivezip - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;f90;for;f;fpp"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\archive.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\archivezip.def
|
||||
# PROP Exclude_From_Build 1
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\plugin.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\archive.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pkzip.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\plugin.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\zlibstream.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Conscript
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
218
plugins/archivezip/archivezip.vcproj
Normal file
218
plugins/archivezip/archivezip.vcproj
Normal file
@@ -0,0 +1,218 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="archivezip"
|
||||
ProjectGUID="{A7E0FE03-E9BB-4478-9752-250BBD406C2D}"
|
||||
RootNamespace="archivezip"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include;../../libs;"../../../STLPort-4.6/stlport";../../../zlib1-1.2/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;ARCHIVEZIP_EXPORTS"
|
||||
StringPooling="TRUE"
|
||||
MinimalRebuild="TRUE"
|
||||
ExceptionHandling="FALSE"
|
||||
BasicRuntimeChecks="0"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="FALSE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
BrowseInformation="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="zdll.lib"
|
||||
OutputFile="$(OutDir)/archivezip.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../zlib1-1.2/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtd.lib"
|
||||
ModuleDefinitionFile="$(ProjectName).def"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/archivezip.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/archivezip.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\modules"
|
||||
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)install\modules""/>
|
||||
<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="2"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OptimizeForWindowsApplication="FALSE"
|
||||
AdditionalIncludeDirectories="../../include;../../libs;"../../../STLPort-4.6/stlport";../../../zlib1-1.2/include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;ARCHIVEZIP_EXPORTS"
|
||||
StringPooling="TRUE"
|
||||
ExceptionHandling="FALSE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="zdll.lib"
|
||||
OutputFile="$(OutDir)/archivezip.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="../../../zlib1-1.2/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprt.lib"
|
||||
ModuleDefinitionFile="$(ProjectName).def"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/archivezip.lib"
|
||||
TargetMachine="1"
|
||||
FixedBaseAddress="0"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\modules"
|
||||
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)install\modules""/>
|
||||
<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="src"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\archive.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\archive.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pkzip.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pkzip.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\plugin.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\plugin.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\zlibstream.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\zlibstream.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\..\debug.py">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)debug.py""
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetName).pdb""
|
||||
Outputs=""$(TargetDir)$(TargetName).pdb""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)debug.py""
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetName).pdb""
|
||||
Outputs=""$(TargetDir)$(TargetName).pdb""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\archivezip.def">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetFileName)""
|
||||
Outputs=""$(TargetPath)""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetFileName)""
|
||||
Outputs=""$(TargetPath)""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
23
plugins/archivezip/pkzip.cpp
Normal file
23
plugins/archivezip/pkzip.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "pkzip.h"
|
||||
|
||||
266
plugins/archivezip/pkzip.h
Normal file
266
plugins/archivezip/pkzip.h
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(INCLUDED_PKZIP_H)
|
||||
#define INCLUDED_PKZIP_H
|
||||
|
||||
#include "bytestreamutils.h"
|
||||
#include "idatastream.h"
|
||||
#include <algorithm>
|
||||
|
||||
class zip_magic
|
||||
{
|
||||
public:
|
||||
bool operator==(const zip_magic& other) const
|
||||
{
|
||||
return m_value[0] == other.m_value[0]
|
||||
&& m_value[1] == other.m_value[1]
|
||||
&& m_value[2] == other.m_value[2]
|
||||
&& m_value[3] == other.m_value[3];
|
||||
}
|
||||
bool operator!=(const zip_magic& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
char m_value[4];
|
||||
};
|
||||
|
||||
inline void istream_read_zip_magic(InputStream& istream, zip_magic& magic)
|
||||
{
|
||||
istream.read(reinterpret_cast<InputStream::byte_type*>(magic.m_value), 4);
|
||||
}
|
||||
|
||||
struct zip_version
|
||||
{
|
||||
char version;
|
||||
char ostype;
|
||||
};
|
||||
|
||||
inline void istream_read_zip_version(InputStream& istream, zip_version& version)
|
||||
{
|
||||
version.version = istream_read_byte(istream);
|
||||
version.ostype = istream_read_byte(istream);
|
||||
}
|
||||
|
||||
struct zip_dostime
|
||||
{
|
||||
unsigned short time;
|
||||
unsigned short date;
|
||||
};
|
||||
|
||||
inline void istream_read_zip_dostime(InputStream& istream, zip_dostime& dostime)
|
||||
{
|
||||
dostime.time = istream_read_int16_le(istream);
|
||||
dostime.date = istream_read_int16_le(istream);
|
||||
}
|
||||
|
||||
const zip_magic zip_file_header_magic = { 'P', 'K', 0x03, 0x04, };
|
||||
|
||||
/* A. Local file header */
|
||||
struct zip_file_header
|
||||
{
|
||||
zip_magic z_magic; /* local file header signature (0x04034b50) */
|
||||
zip_version z_extract; /* version needed to extract */
|
||||
unsigned short z_flags; /* general purpose bit flag */
|
||||
unsigned short z_compr; /* compression method */
|
||||
zip_dostime z_dostime; /* last mod file time (dos format) */
|
||||
unsigned int z_crc32; /* crc-32 */
|
||||
unsigned int z_csize; /* compressed size */
|
||||
unsigned int z_usize; /* uncompressed size */
|
||||
unsigned short z_namlen; /* filename length (null if stdin) */
|
||||
unsigned short z_extras; /* extra field length */
|
||||
/* followed by filename (of variable size) */
|
||||
/* followed by extra field (of variable size) */
|
||||
};
|
||||
|
||||
inline void istream_read_zip_file_header(SeekableInputStream& istream, zip_file_header& file_header)
|
||||
{
|
||||
istream_read_zip_magic(istream, file_header.z_magic);
|
||||
istream_read_zip_version(istream, file_header.z_extract);
|
||||
file_header.z_flags = istream_read_uint16_le(istream);
|
||||
file_header.z_compr = istream_read_uint16_le(istream);
|
||||
istream_read_zip_dostime(istream, file_header.z_dostime);
|
||||
file_header.z_crc32 = istream_read_uint32_le(istream);
|
||||
file_header.z_csize = istream_read_uint32_le(istream);
|
||||
file_header.z_usize = istream_read_uint32_le(istream);
|
||||
file_header.z_namlen = istream_read_uint16_le(istream);
|
||||
file_header.z_extras = istream_read_uint16_le(istream);
|
||||
istream.seek(file_header.z_namlen + file_header.z_extras, SeekableInputStream::cur);
|
||||
};
|
||||
|
||||
/* B. data descriptor
|
||||
* the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
|
||||
* and immediately follows the last byte of compressed data. It is only used if
|
||||
* the output media of the compressor was not seekable, eg. standard output.
|
||||
*/
|
||||
const zip_magic zip_file_trailer_magic = { 'P', 'K', 0x07, 0x08, };
|
||||
|
||||
struct zip_file_trailer
|
||||
{
|
||||
zip_magic z_magic;
|
||||
unsigned int z_crc32; /* crc-32 */
|
||||
unsigned int z_csize; /* compressed size */
|
||||
unsigned int z_usize; /* uncompressed size */
|
||||
};
|
||||
|
||||
inline void istream_read_zip_file_trailer(InputStream& istream, zip_file_trailer& file_trailer)
|
||||
{
|
||||
istream_read_zip_magic(istream, file_trailer.z_magic);
|
||||
file_trailer.z_crc32 = istream_read_uint32_le(istream);
|
||||
file_trailer.z_csize = istream_read_uint32_le(istream);
|
||||
file_trailer.z_usize = istream_read_uint32_le(istream);
|
||||
};
|
||||
|
||||
|
||||
/* C. central directory structure:
|
||||
[file header] . . . end of central dir record
|
||||
*/
|
||||
|
||||
/* directory file header
|
||||
* - a single entry including filename, extras and comment may not exceed 64k.
|
||||
*/
|
||||
|
||||
const zip_magic zip_root_dirent_magic = { 'P', 'K', 0x01, 0x02, };
|
||||
|
||||
struct zip_root_dirent
|
||||
{
|
||||
zip_magic z_magic;
|
||||
zip_version z_encoder; /* version made by */
|
||||
zip_version z_extract; /* version need to extract */
|
||||
unsigned short z_flags; /* general purpose bit flag */
|
||||
unsigned short z_compr; /* compression method */
|
||||
zip_dostime z_dostime; /* last mod file time&date (dos format) */
|
||||
unsigned int z_crc32; /* crc-32 */
|
||||
unsigned int z_csize; /* compressed size */
|
||||
unsigned int z_usize; /* uncompressed size */
|
||||
unsigned short z_namlen; /* filename length (null if stdin) */
|
||||
unsigned short z_extras; /* extra field length */
|
||||
unsigned short z_comment; /* file comment length */
|
||||
unsigned short z_diskstart; /* disk number of start (if spanning zip over multiple disks) */
|
||||
unsigned short z_filetype; /* internal file attributes, bit0 = ascii */
|
||||
unsigned int z_filemode; /* extrnal file attributes, eg. msdos attrib byte */
|
||||
unsigned int z_off; /* relative offset of local file header, seekval if singledisk */
|
||||
/* followed by filename (of variable size) */
|
||||
/* followed by extra field (of variable size) */
|
||||
/* followed by file comment (of variable size) */
|
||||
};
|
||||
|
||||
inline void istream_read_zip_root_dirent(SeekableInputStream& istream, zip_root_dirent& root_dirent)
|
||||
{
|
||||
istream_read_zip_magic(istream, root_dirent.z_magic);
|
||||
istream_read_zip_version(istream, root_dirent.z_encoder);
|
||||
istream_read_zip_version(istream, root_dirent.z_extract);
|
||||
root_dirent.z_flags = istream_read_uint16_le(istream);
|
||||
root_dirent.z_compr = istream_read_uint16_le(istream);
|
||||
istream_read_zip_dostime(istream, root_dirent.z_dostime);
|
||||
root_dirent.z_crc32 = istream_read_uint32_le(istream);
|
||||
root_dirent.z_csize = istream_read_uint32_le(istream);
|
||||
root_dirent.z_usize = istream_read_uint32_le(istream);
|
||||
root_dirent.z_namlen = istream_read_uint16_le(istream);
|
||||
root_dirent.z_extras = istream_read_uint16_le(istream);
|
||||
root_dirent.z_comment = istream_read_uint16_le(istream);
|
||||
root_dirent.z_diskstart = istream_read_uint16_le(istream);
|
||||
root_dirent.z_filetype = istream_read_uint16_le(istream);
|
||||
root_dirent.z_filemode = istream_read_uint32_le(istream);
|
||||
root_dirent.z_off = istream_read_uint32_le(istream);
|
||||
istream.seek(root_dirent.z_namlen + root_dirent.z_extras + root_dirent.z_comment, SeekableInputStream::cur);
|
||||
}
|
||||
|
||||
/* end of central dir record */
|
||||
const zip_magic zip_disk_trailer_magic = { 'P', 'K', 0x05, 0x06, };
|
||||
const unsigned int disk_trailer_length = 22;
|
||||
struct zip_disk_trailer
|
||||
{
|
||||
zip_magic z_magic;
|
||||
unsigned short z_disk; /* number of this disk */
|
||||
unsigned short z_finaldisk; /* number of the disk with the start of the central dir */
|
||||
unsigned short z_entries; /* total number of entries in the central dir on this disk */
|
||||
unsigned short z_finalentries; /* total number of entries in the central dir */
|
||||
unsigned int z_rootsize; /* size of the central directory */
|
||||
unsigned int z_rootseek; /* offset of start of central directory with respect to *
|
||||
* the starting disk number */
|
||||
unsigned short z_comment; /* zipfile comment length */
|
||||
/* followed by zipfile comment (of variable size) */
|
||||
};
|
||||
|
||||
inline void istream_read_zip_disk_trailer(SeekableInputStream& istream, zip_disk_trailer& disk_trailer)
|
||||
{
|
||||
istream_read_zip_magic(istream, disk_trailer.z_magic);
|
||||
disk_trailer.z_disk = istream_read_uint16_le(istream);
|
||||
disk_trailer.z_finaldisk = istream_read_uint16_le(istream);
|
||||
disk_trailer.z_entries = istream_read_uint16_le(istream);
|
||||
disk_trailer.z_finalentries = istream_read_uint16_le(istream);
|
||||
disk_trailer.z_rootsize = istream_read_uint32_le(istream);
|
||||
disk_trailer.z_rootseek = istream_read_uint32_le(istream);
|
||||
disk_trailer.z_comment = istream_read_uint16_le(istream);
|
||||
istream.seek(disk_trailer.z_comment, SeekableInputStream::cur);
|
||||
}
|
||||
|
||||
inline SeekableStream::position_type pkzip_find_disk_trailer(SeekableInputStream& istream)
|
||||
{
|
||||
istream.seek(0, SeekableInputStream::end);
|
||||
SeekableStream::position_type start_position = istream.tell();
|
||||
if(start_position < disk_trailer_length)
|
||||
return 0;
|
||||
start_position -= disk_trailer_length;
|
||||
|
||||
zip_magic magic;
|
||||
istream.seek(start_position);
|
||||
istream_read_zip_magic(istream, magic);
|
||||
|
||||
if(magic == zip_disk_trailer_magic)
|
||||
return start_position;
|
||||
else
|
||||
{
|
||||
const SeekableStream::position_type max_comment = 0x10000;
|
||||
const SeekableStream::position_type bufshift = 6;
|
||||
const SeekableStream::position_type bufsize = max_comment >> bufshift;
|
||||
unsigned char buffer[bufsize];
|
||||
|
||||
SeekableStream::position_type search_end = (max_comment < start_position) ? start_position - max_comment : 0;
|
||||
SeekableStream::position_type position = start_position;
|
||||
while(position != search_end)
|
||||
{
|
||||
StreamBase::size_type to_read = std::min(bufsize, position - search_end);
|
||||
position -= to_read;
|
||||
|
||||
istream.seek(position);
|
||||
StreamBase::size_type size = istream.read(buffer, to_read);
|
||||
|
||||
unsigned char* p = buffer + size;
|
||||
while(p != buffer)
|
||||
{
|
||||
--p;
|
||||
magic.m_value[3] = magic.m_value[2];
|
||||
magic.m_value[2] = magic.m_value[1];
|
||||
magic.m_value[1] = magic.m_value[0];
|
||||
magic.m_value[0] = *p;
|
||||
if(magic == zip_disk_trailer_magic)
|
||||
{
|
||||
return position + (p - buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
85
plugins/archivezip/plugin.cpp
Normal file
85
plugins/archivezip/plugin.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
#include "iarchive.h"
|
||||
|
||||
#include "debugging/debugging.h"
|
||||
#include "modulesystem/singletonmodule.h"
|
||||
|
||||
#include "archive.h"
|
||||
|
||||
|
||||
class ArchiveZipAPI
|
||||
{
|
||||
_QERArchiveTable m_archivezip;
|
||||
public:
|
||||
typedef _QERArchiveTable Type;
|
||||
STRING_CONSTANT(Name, "pk3");
|
||||
|
||||
ArchiveZipAPI()
|
||||
{
|
||||
m_archivezip.m_pfnOpenArchive = &OpenArchive;
|
||||
}
|
||||
_QERArchiveTable* getTable()
|
||||
{
|
||||
return &m_archivezip;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ArchiveZipAPI> ArchiveZipModule;
|
||||
|
||||
ArchiveZipModule g_ArchiveZipModule;
|
||||
|
||||
|
||||
class ArchivePK4API
|
||||
{
|
||||
_QERArchiveTable m_archivepk4;
|
||||
public:
|
||||
typedef _QERArchiveTable Type;
|
||||
STRING_CONSTANT(Name, "pk4");
|
||||
|
||||
ArchivePK4API()
|
||||
{
|
||||
m_archivepk4.m_pfnOpenArchive = &OpenArchive;
|
||||
}
|
||||
_QERArchiveTable* getTable()
|
||||
{
|
||||
return &m_archivepk4;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ArchivePK4API> ArchivePK4Module;
|
||||
|
||||
ArchivePK4Module g_ArchivePK4Module;
|
||||
|
||||
|
||||
extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
|
||||
{
|
||||
GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
|
||||
GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
|
||||
GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
|
||||
GlobalModuleServer::instance().set(server);
|
||||
|
||||
g_ArchiveZipModule.selfRegister();
|
||||
g_ArchivePK4Module.selfRegister();
|
||||
}
|
||||
25
plugins/archivezip/plugin.h
Normal file
25
plugins/archivezip/plugin.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(INCLUDED_PLUGIN_H)
|
||||
#define INCLUDED_PLUGIN_H
|
||||
|
||||
#endif
|
||||
23
plugins/archivezip/zlibstream.cpp
Normal file
23
plugins/archivezip/zlibstream.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "zlibstream.h"
|
||||
|
||||
75
plugins/archivezip/zlibstream.h
Normal file
75
plugins/archivezip/zlibstream.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(INCLUDED_ZLIBSTREAM_H)
|
||||
#define INCLUDED_ZLIBSTREAM_H
|
||||
|
||||
#include "zlib.h"
|
||||
#include "idatastream.h"
|
||||
|
||||
/// \brief A wrapper around an InputStream of data compressed with the zlib deflate algorithm.
|
||||
///
|
||||
/// - Uses z_stream to decompress the data stream on the fly.
|
||||
/// - Uses a buffer to reduce the number of times the wrapped stream must be read.
|
||||
class DeflatedInputStream : public InputStream
|
||||
{
|
||||
InputStream& m_istream;
|
||||
z_stream m_zipstream;
|
||||
static const int m_bufsize = 1024;
|
||||
unsigned char m_buffer[m_bufsize];
|
||||
|
||||
public:
|
||||
DeflatedInputStream(InputStream& istream)
|
||||
: m_istream(istream)
|
||||
{
|
||||
m_zipstream.zalloc = 0;
|
||||
m_zipstream.zfree = 0;
|
||||
m_zipstream.opaque = 0;
|
||||
m_zipstream.avail_in = 0;
|
||||
inflateInit2(&m_zipstream, -MAX_WBITS);
|
||||
}
|
||||
~DeflatedInputStream()
|
||||
{
|
||||
inflateEnd(&m_zipstream);
|
||||
}
|
||||
size_type read(byte_type* buffer, size_type length)
|
||||
{
|
||||
m_zipstream.next_out = buffer;
|
||||
m_zipstream.avail_out = static_cast<uInt>(length);
|
||||
while(m_zipstream.avail_out != 0)
|
||||
{
|
||||
if(m_zipstream.avail_in == 0)
|
||||
{
|
||||
m_zipstream.next_in = m_buffer;
|
||||
m_zipstream.avail_in = static_cast<uInt>(m_istream.read(m_buffer, m_bufsize));
|
||||
}
|
||||
if(inflate(&m_zipstream, Z_SYNC_FLUSH) != Z_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return length - m_zipstream.avail_out;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user