2012-09-28 06:59:31 -05:00
|
|
|
#include "Chunk.h"
|
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
|
|
|
|
int32 Chunk::FindSubChunkOffset(std::string name)
|
|
|
|
|
{
|
|
|
|
|
// Reverse the name
|
|
|
|
|
name = std::string(name.rbegin(), name.rend());
|
|
|
|
|
if (name.size() != 4)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
FILE* stream = GetStream();
|
|
|
|
|
uint32 matched = 0;
|
2012-10-03 21:09:05 -05:00
|
|
|
while (uint32(ftell(stream)) < Utils::Size(stream))
|
2012-09-28 06:59:31 -05:00
|
|
|
{
|
|
|
|
|
char b;
|
|
|
|
|
fread(&b, sizeof(char), 1, stream);
|
|
|
|
|
if (b == name[matched])
|
|
|
|
|
++matched;
|
|
|
|
|
else
|
|
|
|
|
matched = 0;
|
|
|
|
|
if (matched == 4)
|
|
|
|
|
return ftell(stream) - 4;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FILE* Chunk::GetStream()
|
|
|
|
|
{
|
|
|
|
|
fseek(Stream, Offset, SEEK_SET);
|
|
|
|
|
return Stream;
|
|
|
|
|
}
|