0ad/source/ps/FilePacker.cpp
janwas e6be7e36d2 FILE_WRITE_TO_MOD is now FILE_WRITE_TO_TARGET
ERR_(FILE|PATH)_NOT_FOUND -> ERR_TNODE_NOT_FOUND, ERR_NOT_(FILE|DIR) ->
ERR_TNODE_WRONG TYPE
path_util:
- path_append: bugfix (no more extraneous /); add support for appending
slash
- path_replace: bugfix (no more warnings for expected error)
- add path_last_component, path_foreach_component
- move some defs to the header that belong there from vfs.h/path.h

file: add dir_create; move PosixFile definition here and provide
accessor for fileio
vfs: no longer automatically append slash; instead, make sure caller
does
vfs_mount:
- mount_realpath: bugfix (strip trailing /), interface improvement
- document write_target; clarify MULTIPLE_MOUNTINGS; add support for
creating real dirs
vfs_tree:
- refactor TDir::add into find, add, find_and_add
- fix TDir and TNode for dir-ends-with-slash requirement
- split up lookup into lookup_cb and path_foreach_component
- add support for inserting dirs with given mount point: tree_add_path
(needed when mounting)

wposix: get rid of weird PATH_MAX = 260 (Win32 weirdness)


TextureManager: remove no longer needed SupportedTextureFormats
GameSetup, Xeromyces: setup XMB location to data/cache/mods/official/xmb
Util: HardcodedErrorString now uses error_description_r
VFSUtil, i18n: fixes for dir slash issue

Closes #79, #80

This was SVN commit r3874.
2006-05-17 14:48:18 +00:00

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);
memcpy2(&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);
}