forked from mirrors/0ad
a859562ea7
- properly differentiate between buffer/offset alignment and length alignment (relevant since block size has been increased to 256k) - use VfsPath for most game paths instead of CStr - clean up timer interface and implementation - self-tests no longer crash - file_cache.cpp: fix for the case where allocation fails (prevent deleter from seeing a null pointer) - allocators: move all shared_ptr-related stuff to its own component; add DummySharedPtr - codec: disable checksums (important for performance at work) - File: made into an interface class to avoid export problems. not entirely sure about this.. - vfs_path.h, path.h, os_path.h: proper fix for using fs::change_extension and similar utility functions with derivatives of basic_path - lib_api: automatically link against import lib if building lib/ as a DLL - path_util: remove unused functions (this component is deprecated) - compiler.h: add INLINE - Xeromyces.cpp: pass PIVFS so that GetXMBPath works in self-test (should do this mostly everywhere rather than have one singleton g_VFS) This was SVN commit r5537.
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
/**
|
|
* =========================================================================
|
|
* File : FilePacker.h
|
|
* Project : 0 A.D.
|
|
* Description : Resizable buffer, for writing binary files
|
|
* =========================================================================
|
|
*/
|
|
|
|
#ifndef INCLUDED_FILEPACKER
|
|
#define INCLUDED_FILEPACKER
|
|
|
|
#include <vector>
|
|
#include "CStr.h"
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
|
|
#include "ps/Errors.h"
|
|
#include "ps/Filesystem.h" // WriteBuffer
|
|
|
|
#ifndef ERROR_GROUP_FILE_DEFINED
|
|
#define ERROR_GROUP_FILE_DEFINED
|
|
// FileUnpacker.h defines these too
|
|
ERROR_GROUP(File);
|
|
ERROR_TYPE(File, OpenFailed);
|
|
#endif
|
|
ERROR_TYPE(File, WriteFailed);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// CFilePacker: class to assist in writing of binary files.
|
|
// basically a resizeable buffer that allows adding raw data and strings;
|
|
// upon calling Write(), everything is written out to disk.
|
|
class CFilePacker
|
|
{
|
|
public:
|
|
// constructor
|
|
// adds version and signature (i.e. the header) to the buffer.
|
|
// this means Write() can write the entire buffer to file in one go,
|
|
// which is simpler and more efficient than writing in pieces.
|
|
CFilePacker(u32 version, const char magicstr[4]);
|
|
|
|
// Write: write out to file all packed data added so far
|
|
void Write(const VfsPath& filename);
|
|
|
|
// PackRaw: pack given number of bytes onto the end of the data stream
|
|
void PackRaw(const void* rawdata, size_t rawdatalen);
|
|
// PackString: pack a string onto the end of the data stream
|
|
void PackString(const CStr& str);
|
|
|
|
private:
|
|
// the output data stream built during pack operations.
|
|
// contains the header, so we can write this out in one go.
|
|
WriteBuffer m_writeBuffer;
|
|
};
|
|
|
|
#endif
|