2007-11-10 20:39:26 +01:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : archive.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : interface for reading from and creating archives.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// license: GPL; see lib/license.txt
|
|
|
|
|
|
|
|
#ifndef INCLUDED_ARCHIVE
|
|
|
|
#define INCLUDED_ARCHIVE
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
#include "lib/file/path.h"
|
|
|
|
#include "lib/file/file_system.h" // FileInfo
|
|
|
|
#include "lib/file/common/file_loader.h"
|
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2007-12-01 19:32:43 +01:00
|
|
|
|
2007-11-20 19:51:07 +01:00
|
|
|
// rationale: this module doesn't build a directory tree of the entries
|
|
|
|
// within an archive. that task is left to the VFS; here, we are only
|
|
|
|
// concerned with enumerating all archive entries.
|
2007-11-10 20:39:26 +01:00
|
|
|
|
|
|
|
namespace ERR
|
|
|
|
{
|
2007-11-20 19:51:07 +01:00
|
|
|
const LibError ARCHIVE_UNKNOWN_FORMAT = -110400;
|
|
|
|
const LibError ARCHIVE_UNKNOWN_METHOD = -110401;
|
2007-11-10 20:39:26 +01:00
|
|
|
}
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
struct IArchiveFile : public IFileLoader
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef shared_ptr<IArchiveFile> PIArchiveFile;
|
2007-11-10 20:39:26 +01:00
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
struct IArchiveReader
|
2007-11-10 20:39:26 +01:00
|
|
|
{
|
2007-11-20 19:51:07 +01:00
|
|
|
virtual ~IArchiveReader();
|
2007-11-10 20:39:26 +01:00
|
|
|
|
|
|
|
/**
|
2007-11-20 19:51:07 +01:00
|
|
|
* called for each archive entry.
|
2007-12-20 21:14:21 +01:00
|
|
|
* @param pathname full pathname of entry; only valid during the callback.
|
2007-11-10 20:39:26 +01:00
|
|
|
**/
|
2007-12-20 21:14:21 +01:00
|
|
|
typedef void (*ArchiveEntryCallback)(const VfsPath& pathname, const FileInfo& fileInfo, PIArchiveFile archiveFile, uintptr_t cbData);
|
2007-11-20 19:51:07 +01:00
|
|
|
virtual LibError ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData) = 0;
|
2007-11-10 20:39:26 +01:00
|
|
|
};
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
typedef shared_ptr<IArchiveReader> PIArchiveReader;
|
2007-12-01 19:32:43 +01:00
|
|
|
|
2007-11-10 20:39:26 +01:00
|
|
|
// note: when creating an archive, any existing file with the given pathname
|
|
|
|
// will be overwritten.
|
2007-11-20 19:51:07 +01:00
|
|
|
|
|
|
|
// rationale: don't support partial adding, i.e. updating archive with
|
|
|
|
// only one file. this would require overwriting parts of the Zip archive,
|
|
|
|
// which is annoying and slow. also, archives are usually built in
|
|
|
|
// seek-optimal order, which would break if we start inserting files.
|
|
|
|
// while testing, loose files can be used, so there's no loss.
|
|
|
|
|
|
|
|
struct IArchiveWriter
|
2007-11-10 20:39:26 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* write out the archive to disk; only hereafter is it valid.
|
|
|
|
**/
|
2007-11-20 19:51:07 +01:00
|
|
|
virtual ~IArchiveWriter();
|
2007-11-10 20:39:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* add a file to the archive.
|
|
|
|
*
|
2007-11-20 19:51:07 +01:00
|
|
|
* rationale: passing in a filename instead of the compressed file
|
|
|
|
* contents makes for better encapsulation because callers don't need
|
|
|
|
* to know about the codec. one disadvantage is that loading the file
|
|
|
|
* contents can no longer take advantage of the VFS cache nor previously
|
|
|
|
* archived versions. however, the archive builder usually adds files
|
|
|
|
* precisely because they aren't in archives, and the cache would
|
|
|
|
* thrash anyway, so this is deemed acceptable.
|
2007-11-10 20:39:26 +01:00
|
|
|
**/
|
2007-12-20 21:14:21 +01:00
|
|
|
virtual LibError AddFile(const Path& pathname) = 0;
|
2007-11-20 19:51:07 +01:00
|
|
|
};
|
|
|
|
|
2007-12-20 21:14:21 +01:00
|
|
|
typedef shared_ptr<IArchiveWriter> PIArchiveWriter;
|
2007-11-10 20:39:26 +01:00
|
|
|
|
|
|
|
#endif // #ifndef INCLUDED_ARCHIVE
|