mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
**********************************************************
** Big Maps Projects code (incl. Multiplayer v1.5 ** ********************************************************** - Merged Big Maps Project code from BMP+MP trunk (Revision: 3340) o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - Before THIS merge, I made a branch of the existing 1.13 source o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src - Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago - I will add VS 2010 projects and solution file in the next few days git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
//#define VFS_BASIC_TYPES
|
||||
#include <cstring>
|
||||
|
||||
#include "../vfs_types.h"
|
||||
|
||||
#include "vfs_create_7z_library.h"
|
||||
@@ -22,21 +23,21 @@ extern "C"
|
||||
/******************************************************************************************/
|
||||
namespace szExt
|
||||
{
|
||||
inline vfs::UInt32 WRITEBYTE(std::ostream& out, sz::Byte const& value)
|
||||
inline ::size_t WRITEBYTE(std::ostream& out, sz::Byte const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(sz::Byte));
|
||||
return 1;
|
||||
}
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITEALL(std::ostream& out, T const& value)
|
||||
inline ::size_t WRITEALL(std::ostream& out, T const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(T));
|
||||
return sizeof(T);
|
||||
}
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITEBUFFER(std::ostream& out, T* value, size_t num_elements)
|
||||
inline ::size_t WRITEBUFFER(std::ostream& out, T* value, ::size_t num_elements)
|
||||
{
|
||||
out.write((char*)value,sizeof(T) * num_elements);
|
||||
out.write((char*)value, num_elements*sizeof(T));
|
||||
return num_elements*sizeof(T);
|
||||
}
|
||||
|
||||
@@ -46,16 +47,16 @@ namespace szExt
|
||||
* - if the number is smaller than 128, use the extra byte to store the value
|
||||
*/
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITE(std::ostream& out, T const& value)
|
||||
inline ::size_t WRITE(std::ostream& out, T const& value)
|
||||
{
|
||||
vfs::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
sz::Byte data[8];
|
||||
sz::Byte firstByte = 0;
|
||||
sz::Byte* b = (sz::Byte*)&value;
|
||||
size_t SIZE = sizeof(T);
|
||||
::size_t SIZE = sizeof(T);
|
||||
b+= SIZE-1;
|
||||
vfs::Int32 i;
|
||||
for(i=SIZE-1; i>=0; --i)
|
||||
for(i = (vfs::Int32)(SIZE-1); i>=0; --i)
|
||||
{
|
||||
if( (*b & 0xFF) != 0)
|
||||
{
|
||||
@@ -107,7 +108,7 @@ vfs::CCreateUncompressed7zLibrary::~CCreateUncompressed7zLibrary()
|
||||
m_mapDirInfo.clear();
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
bool vfs::CCreateUncompressed7zLibrary::addFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
@@ -121,13 +122,13 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not open File \"" << pFile->GetFullPath()() << L"\"";
|
||||
wss << L"Could not open File \"" << pFile->getPath()() << L"\"";
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
SFileInfo fi;
|
||||
vfs::Path filename = pFile->GetFullPath();
|
||||
fi.name = filename().c_wcs();
|
||||
fi.size = pFile->GetFileSize();
|
||||
vfs::Path filename = pFile->getPath();
|
||||
fi.name = filename.c_wcs();
|
||||
fi.size = pFile->getSize();
|
||||
if(m_lFileInfo.empty())
|
||||
{
|
||||
fi.offset = 0;
|
||||
@@ -138,23 +139,23 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
fi.offset = fic.offset + fic.size;
|
||||
}
|
||||
|
||||
std::vector<vfs::Byte> data(fi.size);
|
||||
UInt32 ui_read;
|
||||
pFile->Read(&data[0], fi.size, ui_read);
|
||||
fi.CRC = sz::CrcCalc(&data[0],fi.size);
|
||||
m_ssFileStream.write(&data[0],fi.size);
|
||||
typedef std::vector<vfs::Byte> tByteVector;
|
||||
tByteVector data( (tByteVector::size_type)fi.size );
|
||||
THROWIFFALSE(fi.size == pFile->read(&data[0], (vfs::size_t)fi.size), L"");
|
||||
fi.CRC = sz::CrcCalc(&data[0],(::size_t)fi.size);
|
||||
m_ssFileStream.write(&data[0],(std::streamsize)fi.size);
|
||||
|
||||
m_lFileInfo.push_back(fi);
|
||||
|
||||
vfs::Path path,dummy;
|
||||
filename.SplitLast(path,dummy);
|
||||
filename.splitLast(path,dummy);
|
||||
if(!path.empty())
|
||||
{
|
||||
tDirInfo::iterator it_find = m_mapDirInfo.find(path().c_wcs());
|
||||
tDirInfo::iterator it_find = m_mapDirInfo.find(path.c_wcs());
|
||||
if(it_find == m_mapDirInfo.end())
|
||||
{
|
||||
SFileInfo dir;
|
||||
dir.name = path().c_wcs();
|
||||
dir.name = path.c_wcs();
|
||||
dir.offset = 0;
|
||||
dir.size = 0;
|
||||
dir.time_creation = 0;
|
||||
@@ -166,12 +167,12 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::Path const& sLibName)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::Path const& sLibName)
|
||||
{
|
||||
vfs::COpenWriteFile outfile(sLibName,true);
|
||||
return WriteLibrary(&outfile.file());
|
||||
return writeLibrary(&outfile.file());
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::tWriteableFile* pFile)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::tWritableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
@@ -182,32 +183,30 @@ bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::tWriteableFile* pFile)
|
||||
return false;
|
||||
}
|
||||
m_pLibFile = pFile;
|
||||
if(!m_pLibFile->IsOpenWrite() && !m_pLibFile->OpenWrite(true,true))
|
||||
if(!m_pLibFile->isOpenWrite() && !m_pLibFile->openWrite(true,true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//
|
||||
WriteNextHeader(m_ssInfoStream);
|
||||
writeNextHeader(m_ssInfoStream);
|
||||
//
|
||||
std::stringstream ssSigHeader;
|
||||
WriteSignatureHeader(ssSigHeader);
|
||||
writeSignatureHeader(ssSigHeader);
|
||||
//
|
||||
UInt32 written;
|
||||
m_pLibFile->write(ssSigHeader.str().c_str() , (vfs::size_t)ssSigHeader.str().length());
|
||||
//
|
||||
m_pLibFile->Write(ssSigHeader.str().c_str(),ssSigHeader.str().length(), written);
|
||||
m_pLibFile->write(m_ssFileStream.str().c_str() , (vfs::size_t)m_ssFileStream.str().length());
|
||||
//
|
||||
m_pLibFile->Write(m_ssFileStream.str().c_str(),m_ssFileStream.str().length(), written);
|
||||
//
|
||||
m_pLibFile->Write(m_ssInfoStream.str().c_str(),m_ssInfoStream.str().length(), written);
|
||||
m_pLibFile->write(m_ssInfoStream.str().c_str() , (vfs::size_t)m_ssInfoStream.str().length());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSignatureHeader(std::ostream& out)
|
||||
{
|
||||
vfs::UInt32 count=0;
|
||||
::size_t count=0;
|
||||
|
||||
// #define k7zSignatureSize -> not in namespace sz
|
||||
count += szExt::WRITEBUFFER(out, sz::k7zSignature, k7zSignatureSize);
|
||||
@@ -221,7 +220,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
SFileInfo const& fi = m_lFileInfo.back();
|
||||
sz::UInt64 NextHeaderOffset = fi.offset + fi.size;
|
||||
sz::UInt64 NextHeaderSize = m_ssInfoStream.str().length()*sizeof(char);
|
||||
NextHeaderCRC = sz::CrcCalc(m_ssInfoStream.str().c_str(),(size_t)NextHeaderSize);
|
||||
NextHeaderCRC = sz::CrcCalc(m_ssInfoStream.str().c_str(),(::size_t)NextHeaderSize);
|
||||
|
||||
std::stringstream sstemp;
|
||||
count += szExt::WRITEALL(sstemp, (sz::UInt64)NextHeaderOffset );
|
||||
@@ -234,7 +233,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteNextHeader(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeNextHeader(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdHeader);
|
||||
|
||||
@@ -243,25 +242,25 @@ bool vfs::CCreateUncompressed7zLibrary::WriteNextHeader(std::ostream& out)
|
||||
// this->WriteAdditionalStreamsInfo(out)
|
||||
|
||||
//
|
||||
this->WriteMainStreamsInfo(out);
|
||||
this->writeMainStreamsInfo(out);
|
||||
|
||||
//
|
||||
this->WriteFilesInfo(out);
|
||||
this->writeFilesInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteMainStreamsInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeMainStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdMainStreamsInfo );
|
||||
|
||||
this->WritePackInfo(out);
|
||||
this->writePackInfo(out);
|
||||
|
||||
this->WriteUnPackInfo(out);
|
||||
this->writeUnPackInfo(out);
|
||||
|
||||
this->WriteSubStreamsInfo(out);
|
||||
this->writeSubStreamsInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
@@ -269,7 +268,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteMainStreamsInfo(std::ostream& out)
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WritePackInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writePackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdPackInfo );
|
||||
szExt::WRITE(out, (sz::UInt64)0 ); // data offset
|
||||
@@ -285,7 +284,7 @@ bool vfs::CCreateUncompressed7zLibrary::WritePackInfo(std::ostream& out)
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeUnPackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdUnpackInfo );
|
||||
|
||||
@@ -296,7 +295,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
this->WriteFolder(out);
|
||||
this->writeFolder(out);
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCodersUnpackSize );
|
||||
@@ -310,7 +309,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteSubStreamsInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSubStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdSubStreamsInfo );
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCRC );
|
||||
@@ -326,7 +325,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSubStreamsInfo(std::ostream& out)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteFolder(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFolder(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::UInt32)1 ); // NumCoders
|
||||
|
||||
@@ -336,7 +335,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFolder(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFilesInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdFilesInfo );
|
||||
|
||||
@@ -346,34 +345,34 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
// empty stream -> pack info in bit-vector
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEmptyStream );
|
||||
sz::UInt64 num_empty64 = num_files/8 + (num_files%8 == 0 ? 0 : 1);
|
||||
size_t num_empty = (size_t)num_empty64;
|
||||
::size_t num_empty = (::size_t)num_empty64;
|
||||
THROWIFFALSE(num_empty == num_empty64, L"WTF");
|
||||
|
||||
sz::Byte *empty_vector = new sz::Byte[num_empty];
|
||||
memset(empty_vector,0,num_empty);
|
||||
for(vfs::UInt32 e=m_lFileInfo.size(); e < num_files; ++e)
|
||||
memset(empty_vector,0,(::size_t)num_empty);
|
||||
for(::size_t e=m_lFileInfo.size(); e < num_files; ++e)
|
||||
{
|
||||
size_t index = e / 8;
|
||||
::size_t index = e / 8;
|
||||
empty_vector[index] |= 1 << (7 - e%8);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)num_empty ); // size
|
||||
szExt::WRITEBUFFER(out, empty_vector, num_empty);
|
||||
szExt::WRITEBUFFER(out, empty_vector, (::size_t)num_empty);
|
||||
delete[] empty_vector;
|
||||
|
||||
// names
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdName );
|
||||
sz::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
std::stringstream name_stream;
|
||||
count += szExt::WRITE(name_stream, (sz::Byte)0 ); // switch
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
count += this->WriteFileName(name_stream, fit->name);
|
||||
count += (::size_t)this->writeFileName(name_stream, fit->name);
|
||||
}
|
||||
std::map<utf8string::str_t,SFileInfo>::iterator dit = m_mapDirInfo.begin();
|
||||
for(;dit != m_mapDirInfo.end(); ++dit)
|
||||
{
|
||||
count += this->WriteFileName(name_stream, dit->second.name);
|
||||
count += (::size_t)this->writeFileName(name_stream, dit->second.name);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)count ); // size
|
||||
szExt::WRITEBUFFER(out, name_stream.str().c_str(), name_stream.str().length() );
|
||||
@@ -390,13 +389,13 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CCreateUncompressed7zLibrary::WriteFileName(std::ostream& out, utf8string const& filename)
|
||||
vfs::size_t vfs::CCreateUncompressed7zLibrary::writeFileName(std::ostream& out, utf8string const& filename)
|
||||
{
|
||||
vfs::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
THROWIFFALSE(filename.length(), L"zero length name");
|
||||
count += szExt::WRITEBUFFER(out, &filename.c_wcs().at(0), filename.length());
|
||||
count += szExt::WRITEBUFFER(out, filename.c_str(), filename.length());
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
return count;
|
||||
return (vfs::size_t)count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user