1462 */ |
1462 */ |
1463 SaveOrLoadResult SaveOrLoad(const char *filename, int mode) |
1463 SaveOrLoadResult SaveOrLoad(const char *filename, int mode) |
1464 { |
1464 { |
1465 uint32 hdr[2]; |
1465 uint32 hdr[2]; |
1466 const SaveLoadFormat *fmt; |
1466 const SaveLoadFormat *fmt; |
1467 uint version; |
|
1468 |
1467 |
1469 /* An instance of saving is already active, so don't go saving again */ |
1468 /* An instance of saving is already active, so don't go saving again */ |
1470 if (_ts.saveinprogress && mode == SL_SAVE) { |
1469 if (_ts.saveinprogress && mode == SL_SAVE) { |
1471 // if not an autosave, but a user action, show error message |
1470 // if not an autosave, but a user action, show error message |
1472 if (!_do_autosave) ShowErrorMessage(INVALID_STRING_ID, STR_SAVE_STILL_IN_PROGRESS, 0, 0); |
1471 if (!_do_autosave) ShowErrorMessage(INVALID_STRING_ID, STR_SAVE_STILL_IN_PROGRESS, 0, 0); |
1513 |
1512 |
1514 ShowInfoF("Save game failed: %s.", _sl.excpt_msg); |
1513 ShowInfoF("Save game failed: %s.", _sl.excpt_msg); |
1515 return SL_ERROR; |
1514 return SL_ERROR; |
1516 } |
1515 } |
1517 |
1516 |
1518 /* We first initialize here to avoid: "warning: variable `version' might |
|
1519 * be clobbered by `longjmp' or `vfork'" */ |
|
1520 version = 0; |
|
1521 |
|
1522 /* General tactic is to first save the game to memory, then use an available writer |
1517 /* General tactic is to first save the game to memory, then use an available writer |
1523 * to write it to file, either in threaded mode if possible, or single-threaded */ |
1518 * to write it to file, either in threaded mode if possible, or single-threaded */ |
1524 if (mode == SL_SAVE) { /* SAVE game */ |
1519 if (mode == SL_SAVE) { /* SAVE game */ |
1525 fmt = GetSavegameFormat("memory"); // write to memory |
1520 fmt = GetSavegameFormat("memory"); // write to memory |
1526 |
1521 |
1555 for (fmt = _saveload_formats; ; fmt++) { |
1550 for (fmt = _saveload_formats; ; fmt++) { |
1556 /* No loader found, treat as version 0 and use LZO format */ |
1551 /* No loader found, treat as version 0 and use LZO format */ |
1557 if (fmt == endof(_saveload_formats)) { |
1552 if (fmt == endof(_saveload_formats)) { |
1558 DEBUG(misc, 0) ("[Sl] Unknown savegame type, trying to load it as the buggy format."); |
1553 DEBUG(misc, 0) ("[Sl] Unknown savegame type, trying to load it as the buggy format."); |
1559 rewind(_sl.fh); |
1554 rewind(_sl.fh); |
1560 _sl_version = version = 0; |
1555 _sl_version = 0; |
1561 _sl_minor_version = 0; |
1556 _sl_minor_version = 0; |
1562 fmt = _saveload_formats + 1; // LZO |
1557 fmt = _saveload_formats + 1; // LZO |
1563 break; |
1558 break; |
1564 } |
1559 } |
1565 |
1560 |
1566 if (fmt->tag == hdr[0]) { |
1561 if (fmt->tag == hdr[0]) { |
1567 // check version number |
1562 // check version number |
1568 _sl_version = version = TO_BE32(hdr[1]) >> 16; |
1563 _sl_version = TO_BE32(hdr[1]) >> 16; |
1569 /* Minor is not used anymore from version 18.0, but it is still needed |
1564 /* Minor is not used anymore from version 18.0, but it is still needed |
1570 * in versions before that (4 cases) which can't be removed easy. |
1565 * in versions before that (4 cases) which can't be removed easy. |
1571 * Therefor it is loaded, but never saved (or, it saves a 0 in any scenario). |
1566 * Therefor it is loaded, but never saved (or, it saves a 0 in any scenario). |
1572 * So never EVER use this minor version again. -- TrueLight -- 22-11-2005 */ |
1567 * So never EVER use this minor version again. -- TrueLight -- 22-11-2005 */ |
1573 _sl_minor_version = (TO_BE32(hdr[1]) >> 8) & 0xFF; |
1568 _sl_minor_version = (TO_BE32(hdr[1]) >> 8) & 0xFF; |