diff options
author | Matthew Hoops | 2011-04-02 00:59:29 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-04-02 00:59:29 -0400 |
commit | dfc87237264a76e820015bd9f7ebc8c1e5583d2c (patch) | |
tree | 00845aab8db6198f10f692f081c3f62e56258533 /engines | |
parent | 211842c2fbb79d53ed62b8f88e44fd2290512bd5 (diff) | |
download | scummvm-rg350-dfc87237264a76e820015bd9f7ebc8c1e5583d2c.tar.gz scummvm-rg350-dfc87237264a76e820015bd9f7ebc8c1e5583d2c.tar.bz2 scummvm-rg350-dfc87237264a76e820015bd9f7ebc8c1e5583d2c.zip |
SCUMM: Add support for append mode to o72_openFile()
The baseball2001 hall of fame data saves properly now
Diffstat (limited to 'engines')
-rw-r--r-- | engines/scumm/he/script_v72he.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp index 25f5f3dc3f..8aaf16e81b 100644 --- a/engines/scumm/he/script_v72he.cpp +++ b/engines/scumm/he/script_v72he.cpp @@ -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); } |