Some more cleanup of movie.cpp LoadFM2

This commit is contained in:
SuuperW 2018-08-31 21:29:37 -05:00
parent a5d843e361
commit 10dc63abca
1 changed files with 24 additions and 28 deletions

View File

@ -391,53 +391,49 @@ bool LoadFM2(MovieData &movieData, EMUFILE &fp, int size, bool stopAfterHeader)
else else
endOfMovie = fp.ftell() + size; endOfMovie = fp.ftell() + size;
//TODO - start with something different. like 'desmume movie version 1"
int curr = fp.ftell();
//movie must start with "version 1" //movie must start with "version 1"
//TODO - start with something different. like 'desmume movie version 1"
char buf[9]; char buf[9];
curr = fp.ftell(); fp.fread(buf, 9);
fp.fread(buf,9); fp.fseek(-9, SEEK_CUR);
fp.fseek(curr, SEEK_SET);
// if(fp->fail()) return false; // if(fp->fail()) return false;
if (memcmp(buf,"version 1",9)) if (memcmp(buf, "version 1", 9))
return false; return false;
std::string key,value;
enum {
NEWLINE, KEY, SEPARATOR, VALUE, RECORD
} state = NEWLINE;
while (fp.ftell() < endOfMovie) while (fp.ftell() < endOfMovie)
{ {
readUntilNotWhitespace(fp); readUntilNotWhitespace(fp);
int c = fp.fgetc(); int c = fp.fgetc();
if (c == -1) // This will be the case if there is a newline at the end of the file.
break; if (c == -1) break;
else if (c == '|')
bool isRecord = c == '|';
if(isRecord && movieData.binaryFlag && !stopAfterHeader)
{ {
LoadFM2_binarychunk(movieData, fp, endOfMovie - fp.ftell()); if (stopAfterHeader) break;
return true; else if (movieData.binaryFlag)
} {
LoadFM2_binarychunk(movieData, fp, endOfMovie - fp.ftell());
if (isRecord) break;
{ }
if (stopAfterHeader) return true; else
int currcount = movieData.records.size(); {
movieData.records.resize(currcount + 1); int currcount = movieData.records.size();
movieData.records[currcount].parse(fp); movieData.records.resize(currcount + 1);
movieData.records[currcount].parse(fp);
}
} }
else // key value else // key value
{ {
fp.unget(); fp.unget();
key = readUntilWhitespace(fp); std::string key = readUntilWhitespace(fp);
readUntilNotWhitespace(fp); readUntilNotWhitespace(fp);
value = readUntilNewline(fp); std::string value = readUntilNewline(fp);
movieData.installValue(key, value); movieData.installValue(key, value);
} }
} }
// just in case readUntilNotWhitespace read past the limit set by size parameter
fp.fseek(endOfMovie, SEEK_SET);
return true; return true;
} }