6 * Tennix Archive File Format
7 * Copyright (C) 2009-2010 Thomas Perl <thp@thpinfo.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
33 #define TENNIX_ARCHIVE_HEADER "thpinfo.com/2009/tennix/afmt "
34 #define TENNIX_ARCHIVE_HEADER_LEN 30
36 #define TENNIX_ARCHIVE_VERSIONMAJOR 1
37 #define TENNIX_ARCHIVE_VERSIONMINOR 0
39 #define TENNIX_ARCHIVE_ITEM_MAXNAME 86
42 /* architecture-independent (in-file) structs */
44 struct _TennixArchiveItem
{
45 char filename
[TENNIX_ARCHIVE_ITEM_MAXNAME
];
46 uint32_t offset
; /* network byte order */
47 uint32_t length
; /* network byte order */
51 typedef struct _TennixArchiveItem TennixArchiveItem
;
54 operator<<(std::ostream
& out
, TennixArchiveItem
& item
);
56 struct _TennixArchiveHeader
{
57 char header
[TENNIX_ARCHIVE_HEADER_LEN
];
58 uint8_t versionmajor
; /* major file version */
59 uint8_t versionminor
; /* minor file version */
61 uint8_t items
; /* maximum 255 files per archive */
64 typedef struct _TennixArchiveHeader TennixArchiveHeader
;
67 operator<<(std::ostream
& out
, TennixArchiveHeader
& header
);
72 TennixArchiveHeader header
;
73 TennixArchiveItem
* items
;
79 static void xormem(char* mem
, uint32_t length
, char key
);
83 strcpy(header
.header
, TENNIX_ARCHIVE_HEADER
);
89 TennixArchive(const char* filename
, const char* fallback
=NULL
);
98 int setItemFilename(const char* filename
);
100 const char* getItemFilename() {
101 return items
[current_item
].filename
;
104 char* getItemBytes();
106 size_t getItemSize() {
107 return items
[current_item
].length
;
111 return current_item
>= header
.items
;
118 /* only for building/utility mode: */
119 void appendItem(char* filename
, char* data
, uint32_t length
);
120 void buildFile(char* filename
);
122 friend std::ostream
& operator<<(std::ostream
& out
, TennixArchive
& archive
);
125 /* Used for dumping the contents of a TennixArchive */
127 operator<<(std::ostream
& out
, TennixArchive
& archive
);