janwas
623e649acb
all cpu-related stuff is now defined in cpu.h (with cpu_ prefix and fully encapsulated). fix quite brittle core/HT unit/package detection. implement mkdir on VC8, where it is deprecated add strdup on MacOSX move ia32 code into separate subdir. functions implemented in asm are called ia32_asm_*. add some unix versions of sysdep functions (cannot test them) timer: fix for amd64 linux This was SVN commit r4995.
62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Name: FilePacker.cpp
|
|
// Author: Rich Cross
|
|
// Contact: rich@wildfiregames.com
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "precompiled.h"
|
|
|
|
#include "FilePacker.h"
|
|
|
|
#include <string.h>
|
|
#include "lib/res/file/vfs.h"
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// CFilePacker constructor
|
|
// rationale for passing in version + signature here: see header
|
|
CFilePacker::CFilePacker(u32 version, const char magicstr[4])
|
|
{
|
|
// put header in our data array.
|
|
// (size will be updated on every Pack*() call)
|
|
m_Data.resize(12);
|
|
u8* header = (u8*)&m_Data[0];
|
|
strncpy((char*)(header+0), magicstr, 4); // not 0-terminated => no _s
|
|
*(u32*)(header+4) = version;
|
|
*(u32*)(header+8) = 0; // datasize
|
|
// FIXME m_Version: Byte order? -- Simon
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// Write: write out to file all packed data added so far
|
|
void CFilePacker::Write(const char* filename)
|
|
{
|
|
// write out all data (including header)
|
|
if(vfs_store(filename, &m_Data[0], m_Data.size(), FILE_NO_AIO|FILE_WRITE_TO_TARGET) < 0)
|
|
throw PSERROR_File_WriteFailed();
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// PackRaw: pack given number of bytes onto the end of the data stream
|
|
void CFilePacker::PackRaw(const void* rawdata,u32 rawdatalen)
|
|
{
|
|
u32 start=(u32)m_Data.size();
|
|
m_Data.resize(m_Data.size()+rawdatalen);
|
|
cpu_memcpy(&m_Data[start],rawdata,rawdatalen);
|
|
|
|
*(u32*)&m_Data[8] += rawdatalen; // FIXME byte order?
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// PackString: pack a string onto the end of the data stream
|
|
void CFilePacker::PackString(const CStr& str)
|
|
{
|
|
u32 len=(u32)str.length();
|
|
PackRaw(&len,sizeof(len));
|
|
PackRaw((const char*) str,len);
|
|
}
|
|
|