1268 |
if (!pSubChunks) { |
if (!pSubChunks) { |
1269 |
pSubChunks = new ChunkList(); |
pSubChunks = new ChunkList(); |
1270 |
pSubChunksMap = new ChunkMap(); |
pSubChunksMap = new ChunkMap(); |
1271 |
|
#if defined(WIN32) |
1272 |
|
if (pFile->hFileRead == INVALID_HANDLE_VALUE) return; |
1273 |
|
#else |
1274 |
if (!pFile->hFileRead) return; |
if (!pFile->hFileRead) return; |
1275 |
|
#endif |
1276 |
unsigned long uiOriginalPos = GetPos(); |
unsigned long uiOriginalPos = GetPos(); |
1277 |
SetPos(0); // jump to beginning of list chunk body |
SetPos(0); // jump to beginning of list chunk body |
1278 |
while (RemainingBytes() >= CHUNK_HEADER_SIZE) { |
while (RemainingBytes() >= CHUNK_HEADER_SIZE) { |
1367 |
* Use this constructor if you want to create a new RIFF file completely |
* Use this constructor if you want to create a new RIFF file completely |
1368 |
* "from scratch". Note: there must be no empty chunks or empty list |
* "from scratch". Note: there must be no empty chunks or empty list |
1369 |
* chunks when trying to make the new RIFF file persistent with Save()! |
* chunks when trying to make the new RIFF file persistent with Save()! |
1370 |
* Note that this constructor will create a RIFX file on |
* |
1371 |
* big-endian machines. |
* Note: by default, the RIFF file will be saved in native endian |
1372 |
|
* format; that is, as a RIFF file on little-endian machines and |
1373 |
|
* as a RIFX file on big-endian. To change this behaviour, call |
1374 |
|
* SetByteOrder() before calling Save(). |
1375 |
* |
* |
1376 |
* @param FileType - four-byte identifier of the RIFF file type |
* @param FileType - four-byte identifier of the RIFF file type |
1377 |
* @see AddSubChunk(), AddSubList() |
* @see AddSubChunk(), AddSubList(), SetByteOrder() |
1378 |
*/ |
*/ |
1379 |
File::File(uint32_t FileType) : List(this) { |
File::File(uint32_t FileType) : List(this) { |
1380 |
#if defined(WIN32) |
#if defined(WIN32) |
1388 |
ListType = FileType; |
ListType = FileType; |
1389 |
} |
} |
1390 |
|
|
|
|
|
|
/** @brief Create new RIFF file. |
|
|
* |
|
|
* Use this constructor if you want to create a new RIFF file |
|
|
* completely "from scratch" and also want to specify |
|
|
* endianess. Note: there must be no empty chunks or empty list |
|
|
* chunks when trying to make the new RIFF file persistent with |
|
|
* Save()! |
|
|
* |
|
|
* @param FileType - four-byte identifier of the RIFF file type |
|
|
* @param Endian - endianess used in the new file. A value of |
|
|
* endian_little will create a RIFF file, |
|
|
* endian_big a RIFX file, endian_native will |
|
|
* create a RIFF file on little-endian machines |
|
|
* and RIFX on big-endian. |
|
|
* @see AddSubChunk(), AddSubList() |
|
|
*/ |
|
|
File::File(uint32_t FileType, endian_t Endian) : List(this) { |
|
|
#if defined(WIN32) |
|
|
hFileRead = hFileWrite = INVALID_HANDLE_VALUE; |
|
|
#else |
|
|
hFileRead = hFileWrite = 0; |
|
|
#endif |
|
|
Mode = stream_mode_closed; |
|
|
#if WORDS_BIGENDIAN |
|
|
bEndianNative = Endian != endian_little; |
|
|
#else |
|
|
bEndianNative = Endian != endian_big; |
|
|
#endif |
|
|
ulStartPos = RIFF_HEADER_SIZE; |
|
|
ListType = FileType; |
|
|
} |
|
|
|
|
1391 |
/** @brief Load existing RIFF file. |
/** @brief Load existing RIFF file. |
1392 |
* |
* |
1393 |
* Loads an existing RIFF file with all its chunks. |
* Loads an existing RIFF file with all its chunks. |
1502 |
NULL, OPEN_EXISTING, |
NULL, OPEN_EXISTING, |
1503 |
FILE_ATTRIBUTE_NORMAL, NULL |
FILE_ATTRIBUTE_NORMAL, NULL |
1504 |
); |
); |
1505 |
throw Exception("Could not (re)open file \"" + Filename + "\" in read mode"); |
throw Exception("Could not (re)open file \"" + Filename + "\" in read+write mode"); |
1506 |
} |
} |
1507 |
#else |
#else |
1508 |
if (hFileRead) fclose(hFileRead); |
if (hFileRead) fclose(hFileRead); |
1536 |
return false; |
return false; |
1537 |
} |
} |
1538 |
|
|
1539 |
|
/** @brief Set the byte order to be used when saving. |
1540 |
|
* |
1541 |
|
* Set the byte order to be used in the file. A value of |
1542 |
|
* endian_little will create a RIFF file, endian_big a RIFX file |
1543 |
|
* and endian_native will create a RIFF file on little-endian |
1544 |
|
* machines and RIFX on big-endian machines. |
1545 |
|
* |
1546 |
|
* @param Endian - endianess to use when file is saved. |
1547 |
|
*/ |
1548 |
|
void File::SetByteOrder(endian_t Endian) { |
1549 |
|
#if WORDS_BIGENDIAN |
1550 |
|
bEndianNative = Endian != endian_little; |
1551 |
|
#else |
1552 |
|
bEndianNative = Endian != endian_big; |
1553 |
|
#endif |
1554 |
|
} |
1555 |
|
|
1556 |
/** @brief Save changes to same file. |
/** @brief Save changes to same file. |
1557 |
* |
* |
1558 |
* Make all changes of all chunks persistent by writing them to the |
* Make all changes of all chunks persistent by writing them to the |
1694 |
// forget all resized chunks |
// forget all resized chunks |
1695 |
ResizedChunks.clear(); |
ResizedChunks.clear(); |
1696 |
|
|
1697 |
if (Filename.length() > 0) { |
#if POSIX |
1698 |
#if POSIX |
if (hFileWrite) close(hFileWrite); |
1699 |
close(hFileWrite); |
#elif defined(WIN32) |
1700 |
#elif defined(WIN32) |
if (hFileWrite != INVALID_HANDLE_VALUE) CloseHandle(hFileWrite); |
1701 |
CloseHandle(hFileWrite); |
#else |
1702 |
#else |
if (hFileWrite) fclose(hFileWrite); |
1703 |
fclose(hFileWrite); |
#endif |
1704 |
#endif |
hFileWrite = hFileRead; |
|
hFileWrite = hFileRead; |
|
|
} |
|
1705 |
|
|
1706 |
// associate new file with this File object from now on |
// associate new file with this File object from now on |
1707 |
Filename = path; |
Filename = path; |