2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2007 by Christian Schoenebeck * |
* Copyright (C) 2003-2019 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
36 |
# define DEBUG 0 |
# define DEBUG 0 |
37 |
#endif |
#endif |
38 |
|
|
39 |
|
#ifndef OVERRIDE |
40 |
|
# if defined(__cplusplus) && __cplusplus >= 201103L |
41 |
|
# define OVERRIDE override |
42 |
|
# else |
43 |
|
# define OVERRIDE |
44 |
|
# endif |
45 |
|
#endif |
46 |
|
|
47 |
#include <string> |
#include <string> |
48 |
#include <list> |
#include <list> |
|
#include <set> |
|
49 |
#include <map> |
#include <map> |
50 |
|
#include <set> |
51 |
|
#include <vector> |
52 |
#include <iostream> |
#include <iostream> |
53 |
|
#include <stdarg.h> |
54 |
|
|
55 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
56 |
# include <config.h> |
# include <config.h> |
63 |
# include <unistd.h> |
# include <unistd.h> |
64 |
#endif // POSIX |
#endif // POSIX |
65 |
|
|
66 |
|
#if defined _MSC_VER && _MSC_VER < 1600 |
67 |
|
// Visual C++ 2008 doesn't have stdint.h |
68 |
|
typedef __int8 int8_t; |
69 |
|
typedef __int16 int16_t; |
70 |
|
typedef __int32 int32_t; |
71 |
|
typedef __int64 int64_t; |
72 |
|
typedef unsigned __int8 uint8_t; |
73 |
|
typedef unsigned __int16 uint16_t; |
74 |
|
typedef unsigned __int32 uint32_t; |
75 |
|
typedef unsigned __int64 uint64_t; |
76 |
|
#else |
77 |
#include <stdint.h> |
#include <stdint.h> |
78 |
|
#endif |
79 |
|
|
80 |
#ifdef WIN32 |
#ifdef WIN32 |
81 |
|
# if (_WIN32 && !_WIN64) || (__GNUC__ && !(__x86_64__ || __ppc64__)) /* if 32 bit windows compilation */ |
82 |
|
# if _WIN32_WINNT < 0x0501 |
83 |
|
# undef _WIN32_WINNT |
84 |
|
# define _WIN32_WINNT 0x0501 /* Win XP (no service pack): required for 32 bit compilation for GetFileSizeEx() to be declared by windows.h */ |
85 |
|
# endif |
86 |
|
# endif |
87 |
# include <windows.h> |
# include <windows.h> |
88 |
typedef unsigned int uint; |
typedef unsigned int uint; |
89 |
#endif // WIN32 |
#endif // WIN32 |
94 |
# define CHUNK_ID_RIFF 0x52494646 |
# define CHUNK_ID_RIFF 0x52494646 |
95 |
# define CHUNK_ID_RIFX 0x52494658 |
# define CHUNK_ID_RIFX 0x52494658 |
96 |
# define CHUNK_ID_LIST 0x4C495354 |
# define CHUNK_ID_LIST 0x4C495354 |
97 |
|
|
98 |
|
# define LIST_TYPE_INFO 0x494E464F |
99 |
|
# define CHUNK_ID_ICMT 0x49434D54 |
100 |
|
# define CHUNK_ID_ICOP 0x49434F50 |
101 |
|
# define CHUNK_ID_ICRD 0x49435244 |
102 |
|
# define CHUNK_ID_IENG 0x49454E47 |
103 |
|
# define CHUNK_ID_INAM 0x494E414D |
104 |
|
# define CHUNK_ID_IPRD 0x49505244 |
105 |
|
# define CHUNK_ID_ISFT 0x49534654 |
106 |
|
|
107 |
|
# define CHUNK_ID_SMPL 0x736D706C |
108 |
|
|
109 |
#else // little endian |
#else // little endian |
110 |
# define CHUNK_ID_RIFF 0x46464952 |
# define CHUNK_ID_RIFF 0x46464952 |
111 |
# define CHUNK_ID_RIFX 0x58464952 |
# define CHUNK_ID_RIFX 0x58464952 |
112 |
# define CHUNK_ID_LIST 0x5453494C |
# define CHUNK_ID_LIST 0x5453494C |
|
#endif // WORDS_BIGENDIAN |
|
113 |
|
|
114 |
#define CHUNK_HEADER_SIZE 8 |
# define LIST_TYPE_INFO 0x4F464E49 |
115 |
#define LIST_HEADER_SIZE 12 |
# define CHUNK_ID_ICMT 0x544D4349 |
116 |
#define RIFF_HEADER_SIZE 12 |
# define CHUNK_ID_ICOP 0x504F4349 |
117 |
|
# define CHUNK_ID_ICRD 0x44524349 |
118 |
|
# define CHUNK_ID_IENG 0x474E4549 |
119 |
|
# define CHUNK_ID_INAM 0x4D414E49 |
120 |
|
# define CHUNK_ID_IPRD 0x44525049 |
121 |
|
# define CHUNK_ID_ISFT 0x54465349 |
122 |
|
|
123 |
|
# define CHUNK_ID_SMPL 0x6C706D73 |
124 |
|
|
125 |
|
#endif // WORDS_BIGENDIAN |
126 |
|
|
127 |
|
#define CHUNK_HEADER_SIZE(fileOffsetSize) (4 + fileOffsetSize) |
128 |
|
#define LIST_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) |
129 |
|
#define RIFF_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) |
130 |
|
|
131 |
/** |
/** |
132 |
* @brief RIFF specific classes and definitions |
* @brief RIFF specific classes and definitions |
156 |
|
|
157 |
typedef std::string String; |
typedef std::string String; |
158 |
|
|
159 |
|
/** Type used by libgig for handling file positioning during file I/O tasks. */ |
160 |
|
typedef uint64_t file_offset_t; |
161 |
|
|
162 |
/** Whether file stream is open in read or in read/write mode. */ |
/** Whether file stream is open in read or in read/write mode. */ |
163 |
typedef enum { |
enum stream_mode_t { |
164 |
stream_mode_read = 0, |
stream_mode_read = 0, |
165 |
stream_mode_read_write = 1, |
stream_mode_read_write = 1, |
166 |
stream_mode_closed = 2 |
stream_mode_closed = 2 |
167 |
} stream_mode_t; |
}; |
168 |
|
|
169 |
/** Current state of the file stream. */ |
/** Current state of the file stream. */ |
170 |
typedef enum { |
enum stream_state_t { |
171 |
stream_ready = 0, |
stream_ready = 0, |
172 |
stream_end_reached = 1, |
stream_end_reached = 1, |
173 |
stream_closed = 2 |
stream_closed = 2 |
174 |
} stream_state_t; |
}; |
175 |
|
|
176 |
/** File stream position dependent to these relations. */ |
/** File stream position dependent to these relations. */ |
177 |
typedef enum { |
enum stream_whence_t { |
178 |
stream_start = 0, |
stream_start = 0, |
179 |
stream_curpos = 1, |
stream_curpos = 1, |
180 |
stream_backward = 2, |
stream_backward = 2, |
181 |
stream_end = 3 |
stream_end = 3 |
182 |
} stream_whence_t; |
}; |
183 |
|
|
184 |
/** Alignment of data bytes in memory (system dependant). */ |
/** Alignment of data bytes in memory (system dependant). */ |
185 |
typedef enum { |
enum endian_t { |
186 |
endian_little = 0, |
endian_little = 0, |
187 |
endian_big = 1, |
endian_big = 1, |
188 |
endian_native = 2 |
endian_native = 2 |
189 |
} endian_t; |
}; |
190 |
|
|
191 |
|
/** General RIFF chunk structure of a RIFF file. */ |
192 |
|
enum layout_t { |
193 |
|
layout_standard = 0, ///< Standard RIFF file layout: First chunk in file is a List chunk which contains all other chunks and there are no chunks outside the scope of that very first (List) chunk. |
194 |
|
layout_flat = 1 ///< Not a "real" RIFF file: First chunk in file is an ordinary data chunk, not a List chunk, and there might be other chunks after that first chunk. |
195 |
|
}; |
196 |
|
|
197 |
|
/** Size of RIFF file offsets used in all RIFF chunks' headers. @see File::GetFileOffsetSize() */ |
198 |
|
enum offset_size_t { |
199 |
|
offset_size_auto = 0, ///< Use 32 bit offsets for files smaller than 4 GB, use 64 bit offsets for files equal or larger than 4 GB. |
200 |
|
offset_size_32bit = 4, ///< Always use 32 bit offsets (even for files larger than 4 GB). |
201 |
|
offset_size_64bit = 8 ///< Always use 64 bit offsets (even for files smaller than 4 GB). |
202 |
|
}; |
203 |
|
|
204 |
|
/** |
205 |
|
* @brief Used for indicating the progress of a certain task. |
206 |
|
* |
207 |
|
* The function pointer argument has to be supplied with a valid |
208 |
|
* function of the given signature which will then be called on |
209 |
|
* progress changes. An equivalent progress_t structure will be passed |
210 |
|
* back as argument to the callback function on each progress change. |
211 |
|
* The factor field of the supplied progress_t structure will then |
212 |
|
* reflect the current progress as value between 0.0 and 1.0. You might |
213 |
|
* want to use the custom field for data needed in your callback |
214 |
|
* function. |
215 |
|
*/ |
216 |
|
struct progress_t { |
217 |
|
void (*callback)(progress_t*); ///< Callback function pointer which has to be assigned to a function for progress notification. |
218 |
|
float factor; ///< Reflects current progress as value between 0.0 and 1.0. |
219 |
|
void* custom; ///< This pointer can be used for arbitrary data. |
220 |
|
float __range_min; ///< Only for internal usage, do not modify! |
221 |
|
float __range_max; ///< Only for internal usage, do not modify! |
222 |
|
progress_t(); |
223 |
|
std::vector<progress_t> subdivide(int iSubtasks); |
224 |
|
}; |
225 |
|
|
226 |
/** @brief Ordinary RIFF Chunk |
/** @brief Ordinary RIFF Chunk |
227 |
* |
* |
230 |
*/ |
*/ |
231 |
class Chunk { |
class Chunk { |
232 |
public: |
public: |
233 |
Chunk(File* pFile, unsigned long StartPos, List* Parent); |
Chunk(File* pFile, file_offset_t StartPos, List* Parent); |
234 |
String GetChunkIDString(); |
String GetChunkIDString() const; |
235 |
uint32_t GetChunkID() { return ChunkID; }; ///< Chunk ID in unsigned integer representation. |
uint32_t GetChunkID() const { return ChunkID; } ///< Chunk ID in unsigned integer representation. |
236 |
List* GetParent() { return pParent; }; ///< Returns pointer to the chunk's parent list chunk. |
File* GetFile() const { return pFile; } ///< Returns pointer to the chunk's File object. |
237 |
unsigned long GetSize() { return CurrentChunkSize; }; ///< Chunk size in bytes (without header, thus the chunk data body) |
List* GetParent() const { return pParent; } ///< Returns pointer to the chunk's parent list chunk. |
238 |
unsigned long GetNewSize() { return NewChunkSize; }; ///< New chunk size if it was modified with Resize(). |
file_offset_t GetSize() const { return ullCurrentChunkSize; } ///< Chunk size in bytes (without header, thus the chunk data body) |
239 |
unsigned long GetPos() { return ulPos; }; ///< Position within the chunk data body |
file_offset_t GetNewSize() const { return ullNewChunkSize; } ///< New chunk size if it was modified with Resize(), otherwise value returned will be equal to GetSize(). |
240 |
unsigned long GetFilePos() { return ulStartPos + ulPos; }; ///< Current, actual offset in file. |
file_offset_t GetPos() const { return ullPos; } ///< Position within the chunk data body (starting with 0). |
241 |
unsigned long SetPos(unsigned long Where, stream_whence_t Whence = stream_start); |
file_offset_t GetFilePos() const { return ullStartPos + ullPos; } ///< Current, actual offset of chunk data body start in file. |
242 |
unsigned long RemainingBytes(); |
file_offset_t SetPos(file_offset_t Where, stream_whence_t Whence = stream_start); |
243 |
stream_state_t GetState(); |
file_offset_t RemainingBytes() const; |
244 |
unsigned long Read(void* pData, unsigned long WordCount, unsigned long WordSize); |
stream_state_t GetState() const; |
245 |
unsigned long ReadInt8(int8_t* pData, unsigned long WordCount = 1); |
file_offset_t Read(void* pData, file_offset_t WordCount, file_offset_t WordSize); |
246 |
unsigned long ReadUint8(uint8_t* pData, unsigned long WordCount = 1); |
file_offset_t ReadInt8(int8_t* pData, file_offset_t WordCount = 1); |
247 |
unsigned long ReadInt16(int16_t* pData, unsigned long WordCount = 1); |
file_offset_t ReadUint8(uint8_t* pData, file_offset_t WordCount = 1); |
248 |
unsigned long ReadUint16(uint16_t* pData, unsigned long WordCount = 1); |
file_offset_t ReadInt16(int16_t* pData, file_offset_t WordCount = 1); |
249 |
unsigned long ReadInt32(int32_t* pData, unsigned long WordCount = 1); |
file_offset_t ReadUint16(uint16_t* pData, file_offset_t WordCount = 1); |
250 |
unsigned long ReadUint32(uint32_t* pData, unsigned long WordCount = 1); |
file_offset_t ReadInt32(int32_t* pData, file_offset_t WordCount = 1); |
251 |
|
file_offset_t ReadUint32(uint32_t* pData, file_offset_t WordCount = 1); |
252 |
int8_t ReadInt8(); |
int8_t ReadInt8(); |
253 |
uint8_t ReadUint8(); |
uint8_t ReadUint8(); |
254 |
int16_t ReadInt16(); |
int16_t ReadInt16(); |
255 |
uint16_t ReadUint16(); |
uint16_t ReadUint16(); |
256 |
int32_t ReadInt32(); |
int32_t ReadInt32(); |
257 |
uint32_t ReadUint32(); |
uint32_t ReadUint32(); |
258 |
unsigned long Write(void* pData, unsigned long WordCount, unsigned long WordSize); |
void ReadString(String& s, int size); |
259 |
unsigned long WriteInt8(int8_t* pData, unsigned long WordCount = 1); |
file_offset_t Write(void* pData, file_offset_t WordCount, file_offset_t WordSize); |
260 |
unsigned long WriteUint8(uint8_t* pData, unsigned long WordCount = 1); |
file_offset_t WriteInt8(int8_t* pData, file_offset_t WordCount = 1); |
261 |
unsigned long WriteInt16(int16_t* pData, unsigned long WordCount = 1); |
file_offset_t WriteUint8(uint8_t* pData, file_offset_t WordCount = 1); |
262 |
unsigned long WriteUint16(uint16_t* pData, unsigned long WordCount = 1); |
file_offset_t WriteInt16(int16_t* pData, file_offset_t WordCount = 1); |
263 |
unsigned long WriteInt32(int32_t* pData, unsigned long WordCount = 1); |
file_offset_t WriteUint16(uint16_t* pData, file_offset_t WordCount = 1); |
264 |
unsigned long WriteUint32(uint32_t* pData, unsigned long WordCount = 1); |
file_offset_t WriteInt32(int32_t* pData, file_offset_t WordCount = 1); |
265 |
|
file_offset_t WriteUint32(uint32_t* pData, file_offset_t WordCount = 1); |
266 |
void* LoadChunkData(); |
void* LoadChunkData(); |
267 |
void ReleaseChunkData(); |
void ReleaseChunkData(); |
268 |
void Resize(int iNewSize); |
void Resize(file_offset_t NewSize); |
269 |
virtual ~Chunk(); |
virtual ~Chunk(); |
270 |
protected: |
protected: |
271 |
uint32_t ChunkID; |
uint32_t ChunkID; |
272 |
uint32_t CurrentChunkSize; /* in bytes */ |
file_offset_t ullCurrentChunkSize; /* in bytes */ |
273 |
uint32_t NewChunkSize; /* in bytes (if chunk was scheduled to be resized) */ |
file_offset_t ullNewChunkSize; /* in bytes (if chunk was scheduled to be resized) */ |
274 |
List* pParent; |
List* pParent; |
275 |
File* pFile; |
File* pFile; |
276 |
unsigned long ulStartPos; /* actual position in file where chunk (without header) starts */ |
file_offset_t ullStartPos; /* actual position in file where chunk data (without header) starts */ |
277 |
unsigned long ulPos; /* # of bytes from ulStartPos */ |
file_offset_t ullPos; /* # of bytes from ulStartPos */ |
278 |
uint8_t* pChunkData; |
uint8_t* pChunkData; |
279 |
unsigned long ulChunkDataSize; |
file_offset_t ullChunkDataSize; |
280 |
|
|
281 |
Chunk(File* pFile); |
Chunk(File* pFile); |
282 |
Chunk(File* pFile, List* pParent, uint32_t uiChunkID, uint uiBodySize); |
Chunk(File* pFile, List* pParent, uint32_t uiChunkID, file_offset_t ullBodySize); |
283 |
void ReadHeader(unsigned long fPos); |
void ReadHeader(file_offset_t filePos); |
284 |
void WriteHeader(unsigned long fPos); |
void WriteHeader(file_offset_t filePos); |
285 |
unsigned long ReadSceptical(void* pData, unsigned long WordCount, unsigned long WordSize); |
file_offset_t ReadSceptical(void* pData, file_offset_t WordCount, file_offset_t WordSize); |
286 |
inline void swapBytes_16(void* Word) { |
inline static String convertToString(uint32_t word) { |
|
uint8_t byteCache = *((uint8_t*) Word); |
|
|
*((uint8_t*) Word) = *((uint8_t*) Word + 1); |
|
|
*((uint8_t*) Word + 1) = byteCache; |
|
|
} |
|
|
inline void swapBytes_32(void* Word) { |
|
|
uint8_t byteCache = *((uint8_t*) Word); |
|
|
*((uint8_t*) Word) = *((uint8_t*) Word + 3); |
|
|
*((uint8_t*) Word + 3) = byteCache; |
|
|
byteCache = *((uint8_t*) Word + 1); |
|
|
*((uint8_t*) Word + 1) = *((uint8_t*) Word + 2); |
|
|
*((uint8_t*) Word + 2) = byteCache; |
|
|
} |
|
|
inline void swapBytes(void* Word, unsigned long WordSize) { |
|
|
uint8_t byteCache; |
|
|
unsigned long lo = 0, hi = WordSize - 1; |
|
|
for (; lo < hi; hi--, lo++) { |
|
|
byteCache = *((uint8_t*) Word + lo); |
|
|
*((uint8_t*) Word + lo) = *((uint8_t*) Word + hi); |
|
|
*((uint8_t*) Word + hi) = byteCache; |
|
|
} |
|
|
} |
|
|
inline String convertToString(uint32_t word) { |
|
287 |
String result; |
String result; |
288 |
for (int i = 0; i < 4; i++) { |
for (int i = 0; i < 4; i++) { |
289 |
uint8_t byte = *((uint8_t*)(&word) + i); |
uint8_t byte = *((uint8_t*)(&word) + i); |
292 |
} |
} |
293 |
return result; |
return result; |
294 |
} |
} |
295 |
virtual unsigned long WriteChunk(unsigned long ulWritePos, unsigned long ulCurrentDataOffset); |
virtual file_offset_t RequiredPhysicalSize(int fileOffsetSize); |
296 |
|
virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset, progress_t* pProgress = NULL); |
297 |
virtual void __resetPos(); ///< Sets Chunk's read/write position to zero. |
virtual void __resetPos(); ///< Sets Chunk's read/write position to zero. |
298 |
|
|
299 |
friend class List; |
friend class List; |
306 |
*/ |
*/ |
307 |
class List : public Chunk { |
class List : public Chunk { |
308 |
public: |
public: |
309 |
List(File* pFile, unsigned long StartPos, List* Parent); |
List(File* pFile, file_offset_t StartPos, List* Parent); |
310 |
String GetListTypeString(); |
String GetListTypeString() const; |
311 |
uint32_t GetListType() { return ListType; } ///< Returns unsigned integer representation of the list's ID |
uint32_t GetListType() const { return ListType; } ///< Returns unsigned integer representation of the list's ID |
312 |
Chunk* GetSubChunk(uint32_t ChunkID); |
Chunk* GetSubChunk(uint32_t ChunkID); |
313 |
List* GetSubList(uint32_t ListType); |
List* GetSubList(uint32_t ListType); |
314 |
Chunk* GetFirstSubChunk(); |
Chunk* GetFirstSubChunk(); |
315 |
Chunk* GetNextSubChunk(); |
Chunk* GetNextSubChunk(); |
316 |
List* GetFirstSubList(); |
List* GetFirstSubList(); |
317 |
List* GetNextSubList(); |
List* GetNextSubList(); |
318 |
unsigned int CountSubChunks(); |
size_t CountSubChunks(); |
319 |
unsigned int CountSubChunks(uint32_t ChunkID); |
size_t CountSubChunks(uint32_t ChunkID); |
320 |
unsigned int CountSubLists(); |
size_t CountSubLists(); |
321 |
unsigned int CountSubLists(uint32_t ListType); |
size_t CountSubLists(uint32_t ListType); |
322 |
Chunk* AddSubChunk(uint32_t uiChunkID, uint uiBodySize); |
Chunk* AddSubChunk(uint32_t uiChunkID, file_offset_t ullBodySize); |
323 |
List* AddSubList(uint32_t uiListType); |
List* AddSubList(uint32_t uiListType); |
324 |
void DeleteSubChunk(Chunk* pSubChunk); |
void DeleteSubChunk(Chunk* pSubChunk); |
325 |
void MoveSubChunk(Chunk* pSrc, Chunk* pDst); |
void MoveSubChunk(Chunk* pSrc, Chunk* pDst); // read API doc comments !!! |
326 |
|
void MoveSubChunk(Chunk* pSrc, List* pNewParent); |
327 |
virtual ~List(); |
virtual ~List(); |
328 |
protected: |
protected: |
329 |
typedef std::map<uint32_t, RIFF::Chunk*> ChunkMap; |
typedef std::map<uint32_t, RIFF::Chunk*> ChunkMap; |
330 |
typedef std::list<Chunk*> ChunkList; |
typedef std::list<Chunk*> ChunkList; |
331 |
|
typedef std::set<Chunk*> ChunkSet; |
332 |
|
|
333 |
uint32_t ListType; |
uint32_t ListType; |
334 |
ChunkList* pSubChunks; |
ChunkList* pSubChunks; |
338 |
|
|
339 |
List(File* pFile); |
List(File* pFile); |
340 |
List(File* pFile, List* pParent, uint32_t uiListID); |
List(File* pFile, List* pParent, uint32_t uiListID); |
341 |
void ReadHeader(unsigned long fPos); |
void ReadHeader(file_offset_t filePos); |
342 |
void WriteHeader(unsigned long fPos); |
void WriteHeader(file_offset_t filePos); |
343 |
void LoadSubChunks(); |
void LoadSubChunks(progress_t* pProgress = NULL); |
344 |
void LoadSubChunksRecursively(); |
void LoadSubChunksRecursively(progress_t* pProgress = NULL); |
345 |
virtual unsigned long WriteChunk(unsigned long ulWritePos, unsigned long ulCurrentDataOffset); |
virtual file_offset_t RequiredPhysicalSize(int fileOffsetSize); |
346 |
|
virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset, progress_t* pProgress = NULL); |
347 |
virtual void __resetPos(); ///< Sets List Chunk's read/write position to zero and causes all sub chunks to do the same. |
virtual void __resetPos(); ///< Sets List Chunk's read/write position to zero and causes all sub chunks to do the same. |
348 |
|
void DeleteChunkList(); |
349 |
}; |
}; |
350 |
|
|
351 |
/** @brief RIFF File |
/** @brief RIFF File |
358 |
public: |
public: |
359 |
File(uint32_t FileType); |
File(uint32_t FileType); |
360 |
File(const String& path); |
File(const String& path); |
361 |
stream_mode_t GetMode(); |
File(const String& path, uint32_t FileType, endian_t Endian, layout_t layout, offset_size_t fileOffsetSize = offset_size_auto); |
362 |
|
stream_mode_t GetMode() const; |
363 |
bool SetMode(stream_mode_t NewMode); |
bool SetMode(stream_mode_t NewMode); |
364 |
void SetByteOrder(endian_t Endian); |
void SetByteOrder(endian_t Endian); |
365 |
String GetFileName(); |
String GetFileName() const; |
366 |
virtual void Save(); |
void SetFileName(const String& path); |
367 |
virtual void Save(const String& path); |
bool IsNew() const; |
368 |
|
layout_t GetLayout() const; |
369 |
|
file_offset_t GetCurrentFileSize() const; |
370 |
|
file_offset_t GetRequiredFileSize(); |
371 |
|
file_offset_t GetRequiredFileSize(offset_size_t fileOffsetSize); |
372 |
|
int GetFileOffsetSize() const; |
373 |
|
int GetRequiredFileOffsetSize(); |
374 |
|
|
375 |
|
virtual void Save(progress_t* pProgress = NULL); |
376 |
|
virtual void Save(const String& path, progress_t* pProgress = NULL); |
377 |
virtual ~File(); |
virtual ~File(); |
378 |
protected: |
protected: |
379 |
#if POSIX |
#if POSIX |
388 |
#endif // POSIX |
#endif // POSIX |
389 |
String Filename; |
String Filename; |
390 |
bool bEndianNative; |
bool bEndianNative; |
391 |
|
bool bIsNewFile; |
392 |
|
layout_t Layout; ///< An ordinary RIFF file is always set to layout_standard. |
393 |
|
offset_size_t FileOffsetPreference; |
394 |
|
int FileOffsetSize; ///< Size of file offsets (in bytes) when this file was opened (or saved the last time). |
395 |
|
|
|
void LogAsResized(Chunk* pResizedChunk); |
|
|
void UnlogResized(Chunk* pResizedChunk); |
|
396 |
friend class Chunk; |
friend class Chunk; |
397 |
friend class List; |
friend class List; |
398 |
private: |
private: |
399 |
stream_mode_t Mode; |
stream_mode_t Mode; |
|
std::set<Chunk*> ResizedChunks; ///< All chunks which have been resized (enlarged / shortened). |
|
400 |
|
|
401 |
unsigned long GetFileSize(); |
void __openExistingFile(const String& path, uint32_t* FileType = NULL); |
402 |
void ResizeFile(unsigned long ulNewSize); |
void ResizeFile(file_offset_t ullNewSize); |
403 |
#if POSIX |
#if POSIX |
404 |
unsigned long __GetFileSize(int hFile); |
file_offset_t __GetFileSize(int hFile) const; |
405 |
#elif defined(WIN32) |
#elif defined(WIN32) |
406 |
unsigned long __GetFileSize(HANDLE hFile); |
file_offset_t __GetFileSize(HANDLE hFile) const; |
407 |
#else |
#else |
408 |
unsigned long __GetFileSize(FILE* hFile); |
file_offset_t __GetFileSize(FILE* hFile) const; |
409 |
#endif |
#endif |
410 |
|
int FileOffsetSizeFor(file_offset_t fileSize) const; |
411 |
|
void Cleanup(); |
412 |
}; |
}; |
413 |
|
|
414 |
/** |
/** |
418 |
public: |
public: |
419 |
String Message; |
String Message; |
420 |
|
|
421 |
Exception(String Message) { Exception::Message = Message; }; |
Exception(String format, ...); |
422 |
|
Exception(String format, va_list arg); |
423 |
void PrintMessage(); |
void PrintMessage(); |
424 |
virtual ~Exception() {}; |
virtual ~Exception() {} |
425 |
|
|
426 |
|
protected: |
427 |
|
Exception(); |
428 |
|
static String assemble(String format, va_list arg); |
429 |
}; |
}; |
430 |
|
|
431 |
String libraryName(); |
String libraryName(); |