Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
archive.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/*
24 * interface for reading from and creating archives.
25 */
26
27#ifndef INCLUDED_ARCHIVE
28#define INCLUDED_ARCHIVE
29
30#include "lib/file/file_system.h" // FileInfo
33
34// rationale: this module doesn't build a directory tree of the entries
35// within an archive. that task is left to the VFS; here, we are only
36// concerned with enumerating all archive entries.
37
38namespace ERR
39{
42}
43
45{
46};
47
48typedef std::shared_ptr<IArchiveFile> PIArchiveFile;
49
51{
52 virtual ~IArchiveReader();
53
54 /**
55 * called for each archive entry.
56 * @param pathname full pathname of entry; only valid during the callback.
57 **/
58 typedef void (*ArchiveEntryCallback)(const VfsPath& pathname, const CFileInfo& fileInfo, PIArchiveFile archiveFile, uintptr_t cbData);
59 virtual Status ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData) = 0;
60};
61
62typedef std::shared_ptr<IArchiveReader> PIArchiveReader;
63
64// note: when creating an archive, any existing file with the given pathname
65// will be overwritten.
66
67// rationale: don't support partial adding, i.e. updating archive with
68// only one file. this would require overwriting parts of the Zip archive,
69// which is annoying and slow. also, archives are usually built in
70// seek-optimal order, which would break if we start inserting files.
71// while testing, loose files can be used, so there's no loss.
72
74{
75 /**
76 * write out the archive to disk; only hereafter is it valid.
77 **/
78 virtual ~IArchiveWriter();
79
80 /**
81 * add a file to the archive.
82 *
83 * rationale: passing in a filename instead of the compressed file
84 * contents makes for better encapsulation because callers don't need
85 * to know about the codec. one disadvantage is that loading the file
86 * contents can no longer take advantage of the VFS cache nor previously
87 * archived versions. however, the archive builder usually adds files
88 * precisely because they aren't in archives, and the cache would
89 * thrash anyway, so this is deemed acceptable.
90 *
91 * @param pathname the actual file to add
92 * @param pathnameInArchive the name to store in the archive
93 **/
94 virtual Status AddFile(const OsPath& pathname, const Path& pathnameInArchive) = 0;
95
96 /**
97 * add a file to the archive, when it is already in memory and not on disk.
98 *
99 * @param data the uncompressed file contents to add
100 * @param size the length of data
101 * @param mtime the last-modified-time to be stored in the archive
102 * @param pathnameInArchive the name to store in the archive
103 **/
104 virtual Status AddMemory(const u8* data, size_t size, time_t mtime, const OsPath& pathnameInArchive) = 0;
105};
106
107typedef std::shared_ptr<IArchiveWriter> PIArchiveWriter;
108
109#endif // #ifndef INCLUDED_ARCHIVE
std::shared_ptr< IArchiveWriter > PIArchiveWriter
Definition: archive.h:107
std::shared_ptr< IArchiveReader > PIArchiveReader
Definition: archive.h:62
std::shared_ptr< IArchiveFile > PIArchiveFile
Definition: archive.h:48
Definition: file_system.h:43
Definition: path.h:80
Definition: debug.h:395
const Status ARCHIVE_UNKNOWN_METHOD
Definition: archive.h:41
const Status ARCHIVE_UNKNOWN_FORMAT
Definition: archive.h:40
i64 Status
Error handling system.
Definition: status.h:173
Definition: archive.h:45
Definition: archive.h:51
void(* ArchiveEntryCallback)(const VfsPath &pathname, const CFileInfo &fileInfo, PIArchiveFile archiveFile, uintptr_t cbData)
called for each archive entry.
Definition: archive.h:58
virtual ~IArchiveReader()
Definition: archive.cpp:36
virtual Status ReadEntries(ArchiveEntryCallback cb, uintptr_t cbData)=0
Definition: archive.h:74
virtual ~IArchiveWriter()
write out the archive to disk; only hereafter is it valid.
Definition: archive.cpp:40
virtual Status AddFile(const OsPath &pathname, const Path &pathnameInArchive)=0
add a file to the archive.
virtual Status AddMemory(const u8 *data, size_t size, time_t mtime, const OsPath &pathnameInArchive)=0
add a file to the archive, when it is already in memory and not on disk.
Definition: file_loader.h:29
uint8_t u8
Definition: types.h:37