mirror of https://github.com/stella-emu/stella.git
Added error checking to the Settings class. Now, only settings
specified in the program will be saved to the rcfile. Previously, *any* text in the rcfile was saved on exit, even bogus settings. Also, any settings given from the commandline which are not meant to be ever saved in the rcfile are now actually not saved. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@187 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
4651f21bcd
commit
ab62868912
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Settings.cxx,v 1.7 2003-09-23 00:58:31 stephena Exp $
|
||||
// $Id: Settings.cxx,v 1.8 2003-09-23 17:27:11 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -108,7 +108,11 @@ void Settings::loadConfig()
|
|||
if((key.length() == 0) || (value.length() == 0))
|
||||
continue;
|
||||
|
||||
// Only settings which have been previously set are valid
|
||||
if(contains(key))
|
||||
set(key, value);
|
||||
else
|
||||
cerr << "Invalid setting: " << key << endl;
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
@ -128,7 +132,9 @@ bool Settings::loadCommandLine(Int32 argc, char** argv)
|
|||
key = key.substr(1, key.length());
|
||||
string value = argv[++i];
|
||||
|
||||
set(key, value);
|
||||
// Settings read from the commandline must not be saved to
|
||||
// the rc-file, unless they were previously set
|
||||
set(key, value, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -164,20 +170,25 @@ void Settings::saveConfig()
|
|||
|
||||
// Write out each of the key and value pairs
|
||||
for(uInt32 i = 0; i < mySize; ++i)
|
||||
if(mySettings[i].save)
|
||||
out << mySettings[i].key << " = " << mySettings[i].value << endl;
|
||||
|
||||
out.close();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Settings::set(const string& key, const string& value)
|
||||
void Settings::set(const string& key, const string& value, bool save)
|
||||
{
|
||||
// See if the setting already exists
|
||||
for(uInt32 i = 0; i < mySize; ++i)
|
||||
{
|
||||
// If a key is already present in the array, then we assume
|
||||
// that it was set by the emulation core and must be saved
|
||||
// to the rc-file.
|
||||
if(key == mySettings[i].key)
|
||||
{
|
||||
mySettings[i].value = value;
|
||||
mySettings[i].save = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +213,7 @@ void Settings::set(const string& key, const string& value)
|
|||
// Add new property to the array
|
||||
mySettings[mySize].key = key;
|
||||
mySettings[mySize].value = value;
|
||||
mySettings[mySize].save = save;
|
||||
|
||||
++mySize;
|
||||
}
|
||||
|
@ -211,12 +223,8 @@ Int32 Settings::getInt(const string& key) const
|
|||
{
|
||||
// Try to find the named setting and answer its value
|
||||
for(uInt32 i = 0; i < mySize; ++i)
|
||||
{
|
||||
if(key == mySettings[i].key)
|
||||
{
|
||||
return atoi(mySettings[i].value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -246,16 +254,23 @@ string Settings::getString(const string& key) const
|
|||
{
|
||||
// Try to find the named setting and answer its value
|
||||
for(uInt32 i = 0; i < mySize; ++i)
|
||||
{
|
||||
if(key == mySettings[i].key)
|
||||
{
|
||||
return mySettings[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool Settings::contains(const string& key)
|
||||
{
|
||||
// Try to find the named setting
|
||||
for(uInt32 i = 0; i < mySize; ++i)
|
||||
if(key == mySettings[i].key)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Settings::Settings(const Settings&)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: Settings.hxx,v 1.6 2003-09-23 00:58:31 stephena Exp $
|
||||
// $Id: Settings.hxx,v 1.7 2003-09-23 17:27:11 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SETTINGS_HXX
|
||||
|
@ -32,7 +32,7 @@ class Console;
|
|||
This class provides an interface for accessing frontend specific settings.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: Settings.hxx,v 1.6 2003-09-23 00:58:31 stephena Exp $
|
||||
@version $Id: Settings.hxx,v 1.7 2003-09-23 17:27:11 stephena Exp $
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
|
@ -95,8 +95,9 @@ class Settings
|
|||
|
||||
@param key The key of the setting
|
||||
@param value The value to assign to the setting
|
||||
@param save Whether this setting should be saved to the rc-file.
|
||||
*/
|
||||
void set(const string& key, const string& value);
|
||||
void set(const string& key, const string& value, bool save = true);
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -231,11 +232,15 @@ class Settings
|
|||
// Assignment operator isn't supported by this class so make it private
|
||||
Settings& operator = (const Settings&);
|
||||
|
||||
// Structure used for storing properties
|
||||
// Test whether the given setting is present in the array
|
||||
bool contains(const string& key);
|
||||
|
||||
// Structure used for storing settings
|
||||
struct Setting
|
||||
{
|
||||
string key;
|
||||
string value;
|
||||
bool save;
|
||||
};
|
||||
|
||||
// Pointer to a dynamically allocated array of settings
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: mainSDL.cxx,v 1.52 2003-09-23 00:58:31 stephena Exp $
|
||||
// $Id: mainSDL.cxx,v 1.53 2003-09-23 17:27:11 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <fstream>
|
||||
|
@ -1187,9 +1187,9 @@ void cleanup()
|
|||
if(SDL_WasInit(SDL_INIT_EVERYTHING))
|
||||
{
|
||||
#ifdef HAVE_JOYSTICK
|
||||
if(SDL_JoystickOpened(0))
|
||||
if(SDL_JoystickOpened(theLeftJoystickNumber))
|
||||
SDL_JoystickClose(theLeftJoystick);
|
||||
if(SDL_JoystickOpened(1))
|
||||
if(SDL_JoystickOpened(theRightJoystickNumber))
|
||||
SDL_JoystickClose(theRightJoystick);
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue