From 7418c47b48925b095f7ff9daae9962f92f297cc7 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Tue, 28 Oct 2003 13:46:28 +0000 Subject: If we fail to read the game settings, use sensible defaults. svn-id: r10990 --- sword2/controls.cpp | 30 ++++++++++-------------------- sword2/controls.h | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 9ece464b72..c51861cd5f 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -717,7 +717,7 @@ private: Button *_okButton; Button *_cancelButton; - int32 writeOptionSettings(void); + void writeOptionSettings(void); public: OptionsDialog() { @@ -886,7 +886,7 @@ public: } }; -int32 OptionsDialog::writeOptionSettings(void) { +void OptionsDialog::writeOptionSettings(void) { uint8 buff[10]; char filename[256]; SaveFile *fp; @@ -905,18 +905,13 @@ int32 OptionsDialog::writeOptionSettings(void) { buff[8] = gui._pointerTextSelected; buff[9] = gui._stereoReversed; - if (!(fp = mgr->open_savefile(filename, g_sword2->getSavePath(), true))) - return 1; + fp = mgr->open_savefile(filename, g_sword2->getSavePath(), true); - if (fp->write(buff, 10) != 10) { - delete fp; - delete mgr; - return 2; - } + if (fp) + fp->write(buff, 10); delete fp; delete mgr; - return 0; } enum { @@ -1464,7 +1459,7 @@ void Gui::restartControl(void) { this_screen.new_palette = 99; } -int32 Gui::readOptionSettings(void) { +void Gui::readOptionSettings(void) { // settings file is 9 bytes long: // 1 music volume // 2 speech volume @@ -1477,20 +1472,16 @@ int32 Gui::readOptionSettings(void) { // 9 object labels uint8 buff[10]; + uint8 default_settings[10] = { 14, 12, 12, 0, 0, 0, 2, 1, 1 }; char filename[256]; SaveFile *fp; SaveFileManager *mgr = g_system->get_savefile_manager(); sprintf(filename, "%s-settings.dat", g_sword2->_targetName); - if (!(fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false))) - return 1; - - if (fp->read(buff, 10) != 10) { - delete fp; - delete mgr; - return 2; - } + fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false); + if (!fp || fp->read(buff, 10) != 10) + memcpy(buff, default_settings, sizeof(buff)); delete fp; delete mgr; @@ -1512,7 +1503,6 @@ int32 Gui::readOptionSettings(void) { g_sound->reverseStereo(); gui._stereoReversed = buff[9]; - return 0; } void Gui::optionControl(void) { diff --git a/sword2/controls.h b/sword2/controls.h index 49e06f0274..ea5ff2fd8e 100644 --- a/sword2/controls.h +++ b/sword2/controls.h @@ -40,7 +40,7 @@ public: void quitControl(void); void restartControl(void); void optionControl(void); - int32 readOptionSettings(void); + void readOptionSettings(void); void updateGraphicsLevel(uint8 newLevel); }; -- cgit v1.2.3