29 |
|
|
30 |
namespace RIFF { |
namespace RIFF { |
31 |
|
|
32 |
|
// *************** Internal functions ************** |
33 |
|
// * |
34 |
|
|
35 |
|
/// Returns a human readable path of the given chunk. |
36 |
|
String __resolveChunkPath(Chunk* pCk) { |
37 |
|
String sPath; |
38 |
|
for (Chunk* pChunk = pCk; pChunk; pChunk = pChunk->GetParent()) { |
39 |
|
if (pChunk->GetChunkID() == CHUNK_ID_LIST) { |
40 |
|
List* pList = (List*) pChunk; |
41 |
|
sPath = "->'" + pList->GetListTypeString() + "'" + sPath; |
42 |
|
} else { |
43 |
|
sPath = "->'" + pChunk->GetChunkIDString() + "'" + sPath; |
44 |
|
} |
45 |
|
} |
46 |
|
return sPath; |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
// *************** Chunk ************** |
// *************** Chunk ************** |
52 |
// * |
// * |
53 |
|
|
794 |
* @see File::Save() |
* @see File::Save() |
795 |
*/ |
*/ |
796 |
void Chunk::Resize(int iNewSize) { |
void Chunk::Resize(int iNewSize) { |
797 |
if (iNewSize <= 0) throw Exception("Chunk size must be at least one byte"); |
if (iNewSize <= 0) |
798 |
|
throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(this)); |
799 |
if (NewChunkSize == iNewSize) return; |
if (NewChunkSize == iNewSize) return; |
800 |
NewChunkSize = iNewSize; |
NewChunkSize = iNewSize; |
801 |
pFile->LogAsResized(this); |
pFile->LogAsResized(this); |
1555 |
unsigned long ulPositiveSizeDiff = 0; |
unsigned long ulPositiveSizeDiff = 0; |
1556 |
for (ChunkList::iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) { |
for (ChunkList::iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) { |
1557 |
if ((*iter)->GetNewSize() == 0) { |
if ((*iter)->GetNewSize() == 0) { |
1558 |
// just to make the exception message a bit more verbose: resolve the chunk's path |
throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(*iter)); |
|
String sChunkPath; |
|
|
for (Chunk* pChunk = *iter; pChunk; pChunk = pChunk->GetParent()) { |
|
|
if (pChunk->GetChunkID() == CHUNK_ID_LIST) { |
|
|
List* pList = (List*) pChunk; |
|
|
sChunkPath = "->'" + pList->GetListTypeString() + "'" + sChunkPath; |
|
|
} else { |
|
|
sChunkPath = "->'" + pChunk->GetChunkIDString() + "'" + sChunkPath; |
|
|
} |
|
|
} |
|
|
throw Exception("There is at least one empty chunk (zero size): " + sChunkPath); |
|
1559 |
} |
} |
1560 |
if ((*iter)->GetNewSize() + 1L > (*iter)->GetSize()) { |
if ((*iter)->GetNewSize() + 1L > (*iter)->GetSize()) { |
1561 |
unsigned long ulDiff = (*iter)->GetNewSize() - (*iter)->GetSize() + 1L; // +1 in case we have to add a pad byte |
unsigned long ulDiff = (*iter)->GetNewSize() - (*iter)->GetSize() + 1L; // +1 in case we have to add a pad byte |