Skip to content

Commit

Permalink
SCUMM: Add support for append mode to o72_openFile()
Browse files Browse the repository at this point in the history
The baseball2001 hall of fame data saves properly now
  • Loading branch information
Matthew Hoops committed Apr 2, 2011
1 parent 211842c commit dfc8723
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions engines/scumm/he/script_v72he.cpp
Expand Up @@ -1408,24 +1408,49 @@ void ScummEngine_v72he::o72_openFile() {

if (slot != -1) {
switch (mode) {
case 1:
case 1: // Read mode
if (!_saveFileMan->listSavefiles(filename).empty()) {
_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
} else {
_hInFileTable[slot] = SearchMan.createReadStreamForMember(filename);
}
break;
case 2:
case 2: // Write mode
if (!strchr(filename, '/')) {
_hOutFileTable[slot] = _saveFileMan->openForSaving(filename);
}
break;
case 6:
// FIXME: Appending to saved game file is not supported right now
// This is used in several Backyard Sports games. The stub is required for
// baseball2001 to continue after trying to save Hall of Fame data.
slot = -1;
break;
case 6: { // Append mode
if (strchr(filename, '/'))
break;

// First check if the file already exists
Common::InSaveFile *initialState = 0;
if (!_saveFileMan->listSavefiles(filename).empty())
initialState = _saveFileMan->openForLoading(filename);
else
initialState = SearchMan.createReadStreamForMember(filename);

// Read in the data from the initial file
uint32 initialSize = 0;
byte *initialData = 0;
if (initialState) {
initialSize = initialState->size();
initialData = new byte[initialSize];
initialState->read(initialData, initialSize);
delete initialState;
}

// Attempt to open a save file
_hOutFileTable[slot] = _saveFileMan->openForSaving(filename);

// Begin us off with the data from the previous file
if (_hOutFileTable[slot] && initialData) {
_hOutFileTable[slot]->write(initialData, initialSize);
delete[] initialData;
}

} break;
default:
error("o72_openFile(): wrong open file mode %d", mode);
}
Expand Down

0 comments on commit dfc8723

Please sign in to comment.