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.
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
/**
|
|
* =========================================================================
|
|
* File : FileUnpacker.h
|
|
* Project : 0 A.D.
|
|
* Description : Buffer and 'stream' for reading binary files
|
|
* =========================================================================
|
|
*/
|
|
|
|
#ifndef INCLUDED_FILEUNPACKER
|
|
#define INCLUDED_FILEUNPACKER
|
|
|
|
#include <vector>
|
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
class CStr8;
|
|
|
|
#include "ps/Errors.h"
|
|
#ifndef ERROR_GROUP_FILE_DEFINED
|
|
#define ERROR_GROUP_FILE_DEFINED
|
|
// FilePacker.h defines these too
|
|
ERROR_GROUP(File);
|
|
ERROR_TYPE(File, OpenFailed);
|
|
#endif
|
|
ERROR_TYPE(File, InvalidType);
|
|
ERROR_TYPE(File, InvalidVersion);
|
|
ERROR_TYPE(File, ReadFailed);
|
|
ERROR_TYPE(File, UnexpectedEOF);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// CFileUnpacker: class to assist in reading of binary files
|
|
class CFileUnpacker
|
|
{
|
|
public:
|
|
// constructor
|
|
CFileUnpacker();
|
|
|
|
~CFileUnpacker();
|
|
|
|
// Read: open and read in given file, check magic bits against those given; throw
|
|
// variety of exceptions for missing files etc
|
|
void Read(const VfsPath& filename, const char magicstr[4]);
|
|
|
|
// GetVersion: return stored file version
|
|
u32 GetVersion() const { return m_Version; }
|
|
|
|
// UnpackRaw: unpack given number of bytes from the input stream into the given array
|
|
// - throws PSERROR_File_UnexpectedEOF if the end of the data stream is reached before
|
|
// the given number of bytes have been read
|
|
void UnpackRaw(void* rawdata, size_t rawdatalen);
|
|
// UnpackString: unpack a string from the raw data stream
|
|
void UnpackString(CStr8& result);
|
|
|
|
private:
|
|
// the data read from file and used during unpack operations
|
|
shared_ptr<u8> m_Buf;
|
|
size_t m_Size;
|
|
// current unpack position in stream
|
|
size_t m_UnpackPos;
|
|
// version of the file currently being read
|
|
u32 m_Version;
|
|
};
|
|
|
|
#endif
|