Fixed a bug reported by D. Baron whereby the /etc/stella.pro file wasn't

used even when it should have been.  OSX and Windows users would never
see this, since those ports don't (yet) have any concept of user vs.
system files.  The OSX and Windows ports will have to be updated though,
because of changes in the Settings class.

Changed the code in SettingsUNIX::fileExists() to only check for the
existence of a file, not whether you can write to it.  This is what
the name implies.

Bumped the version number to 1.4.2_cvs.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@343 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2004-08-17 01:17:08 +00:00
parent 0430cd0f22
commit 97aabd229a
4 changed files with 75 additions and 69 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: mainSDL.cxx,v 1.15 2004-08-06 01:51:15 stephena Exp $ // $Id: mainSDL.cxx,v 1.16 2004-08-17 01:17:08 stephena Exp $
//============================================================================ //============================================================================
#include <fstream> #include <fstream>
@ -271,7 +271,7 @@ static KeyList keyList[] = {
*/ */
static void ShowInfo(const string& msg) static void ShowInfo(const string& msg)
{ {
if(theShowInfoFlag) if(theShowInfoFlag && msg != "")
cout << msg << endl; cout << msg << endl;
} }
@ -499,7 +499,7 @@ void HandleEvents()
case SDLK_s: // Ctrl-s saves properties to a file case SDLK_s: // Ctrl-s saves properties to a file
// Attempt to merge with propertiesSet // Attempt to merge with propertiesSet
if(theConsole->settings().getBool("mergeprops")) if(theConsole->settings().getBool("mergeprops"))
theConsole->saveProperties(theSettings->userPropertiesFilename(), true); theConsole->saveProperties(theSettings->propertiesOutputFilename(), true);
else // Save to file in home directory else // Save to file in home directory
{ {
string newPropertiesFile = theConsole->settings().baseDir() + "/" + \ string newPropertiesFile = theConsole->settings().baseDir() + "/" + \
@ -520,8 +520,8 @@ void HandleEvents()
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
{ {
uInt32 zoom = theDisplay->zoomLevel(); uInt32 zoom = theDisplay->zoomLevel();
Int32 width = theDisplay->width() * zoom; Int32 width = theDisplay->width() * zoom;
// Grabmouse and hidecursor introduce some lag into the mouse movement, // Grabmouse and hidecursor introduce some lag into the mouse movement,
// so we need to fudge the numbers a bit // so we need to fudge the numbers a bit
@ -649,7 +649,7 @@ void HandleEvents()
button = event.jbutton.button; button = event.jbutton.button;
state = event.jbutton.state == SDL_PRESSED ? 1 : 0; state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
// Send button events for the joysticks/paddles // Send button events for the joysticks/paddles/driving controllers
if(button == 0) if(button == 0)
{ {
if(type == JT_STELLADAPTOR_1) if(type == JT_STELLADAPTOR_1)
@ -719,23 +719,29 @@ void HandleEvents()
void SetupProperties(PropertiesSet& set) void SetupProperties(PropertiesSet& set)
{ {
bool useMemList = false; bool useMemList = false;
string theAlternateProFile = theSettings->getString("altpro"); string theAltPropertiesFile = theSettings->getString("altpro");
string theUserProFile = theSettings->userPropertiesFilename(); string thePropertiesFile = theSettings->propertiesInputFilename();
string theSystemProFile = theSettings->systemPropertiesFilename();
// When 'listrominfo' or 'mergeprops' is specified, we need to have the // When 'listrominfo' or 'mergeprops' is specified, we need to have the
// full list in memory // full list in memory
if(theSettings->getBool("listrominfo") || theSettings->getBool("mergeprops")) if(theSettings->getBool("listrominfo") || theSettings->getBool("mergeprops"))
useMemList = true; useMemList = true;
if(theAlternateProFile != "") stringstream buf;
set.load(theAlternateProFile, useMemList); if(theAltPropertiesFile != "")
else if(theUserProFile != "") {
set.load(theUserProFile, useMemList); buf << "Reading game properties from \'" << theAltPropertiesFile << "\'\n";
else if(theSystemProFile != "") set.load(theAltPropertiesFile, useMemList);
set.load(theSystemProFile, useMemList); }
else if(thePropertiesFile != "")
{
buf << "Reading game properties from \'" << thePropertiesFile << "\'\n";
set.load(thePropertiesFile, useMemList);
}
else else
set.load("", false); set.load("", false);
ShowInfo(buf.str());
} }
@ -796,6 +802,12 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
// Cache some settings so they don't have to be repeatedly searched for
thePaddleMode = theSettings->getInt("paddle");
theShowInfoFlag = theSettings->getBool("showinfo");
theGrabMouseIndicator = theSettings->getBool("grabmouse");
theHideCursorIndicator = theSettings->getBool("hidecursor");
// Create a properties set for us to use and set it up // Create a properties set for us to use and set it up
PropertiesSet propertiesSet; PropertiesSet propertiesSet;
SetupProperties(propertiesSet); SetupProperties(propertiesSet);
@ -809,12 +821,6 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
// Cache some settings so they don't have to be repeatedly searched for
thePaddleMode = theSettings->getInt("paddle");
theShowInfoFlag = theSettings->getBool("showinfo");
theGrabMouseIndicator = theSettings->getBool("grabmouse");
theHideCursorIndicator = theSettings->getBool("hidecursor");
// Request that the SDL window be centered, if possible // Request that the SDL window be centered, if possible
putenv("SDL_VIDEO_CENTERED=1"); putenv("SDL_VIDEO_CENTERED=1");

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Settings.cxx,v 1.28 2004-08-12 23:36:15 stephena Exp $ // $Id: Settings.cxx,v 1.29 2004-08-17 01:17:08 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -73,7 +73,7 @@ void Settings::loadConfig()
string line, key, value; string line, key, value;
uInt32 equalPos; uInt32 equalPos;
ifstream in(mySettingsInputFilename.c_str()); ifstream in(myConfigInputFile.c_str());
if(!in || !in.is_open()) if(!in || !in.is_open())
{ {
cout << "Error: Couldn't load settings file\n"; cout << "Error: Couldn't load settings file\n";
@ -167,7 +167,7 @@ void Settings::usage()
{ {
#ifndef MAC_OSX #ifndef MAC_OSX
cout << endl cout << endl
<< "Stella version 1.4.1\n\nUsage: stella [options ...] romfile" << endl << "Stella version 1.4.2_cvs\n\nUsage: stella [options ...] romfile" << endl
<< endl << endl
<< "Valid options are:" << endl << "Valid options are:" << endl
<< endl << endl
@ -209,7 +209,7 @@ void Settings::usage()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::saveConfig() void Settings::saveConfig()
{ {
ofstream out(mySettingsOutputFilename.c_str()); ofstream out(myConfigOutputFile.c_str());
if(!out || !out.is_open()) if(!out || !out.is_open())
{ {
cout << "Error: Couldn't save settings file\n"; cout << "Error: Couldn't save settings file\n";

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Settings.hxx,v 1.17 2004-07-28 23:54:39 stephena Exp $ // $Id: Settings.hxx,v 1.18 2004-08-17 01:17:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef SETTINGS_HXX #ifndef SETTINGS_HXX
@ -26,7 +26,7 @@
This class provides an interface for accessing frontend specific settings. This class provides an interface for accessing frontend specific settings.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Settings.hxx,v 1.17 2004-07-28 23:54:39 stephena Exp $ @version $Id: Settings.hxx,v 1.18 2004-08-17 01:17:08 stephena Exp $
*/ */
class Settings class Settings
{ {
@ -164,36 +164,37 @@ class Settings
public: public:
/** /**
This method should be called to get the filename of the users' This method should be called to get the filename of the
properties (stella.pro) file. properties (stella.pro) file for the purpose of loading.
@return String representing the full path of the user properties filename. @return String representing the full path of the properties filename.
*/ */
string userPropertiesFilename() { return myUserPropertiesFile; } string propertiesInputFilename() { return myPropertiesInputFile; }
/** /**
This method should be called to get the filename of the system This method should be called to get the filename of the
properties (stella.pro) file. properties (stella.pro) file for the purpose of saving.
@return String representing the full path of the system properties filename. @return String representing the full path of the properties filename.
*/ */
string systemPropertiesFilename() { return mySystemPropertiesFile; } string propertiesOutputFilename() { return myPropertiesOutputFile; }
/** /**
This method should be called to get the filename of the users' This method should be called to get the filename of the config file
config (stellarc) file. for the purpose of loading.
@return String representing the full path of the user config filename. @return String representing the full path of the config filename.
*/ */
string userConfigFilename() { return myUserConfigFile; } string configInputFilename() { return myConfigInputFile; }
/** /**
This method should be called to get the filename of the system This method should be called to get the filename of the config file
config (stellarc) file. for the purpose of saving.
@return String representing the full path of the system config filename. @return String representing the full path of the config filename.
*/ */
string systemConfigFilename() { return mySystemConfigFile; } string configOutputFilename() { return myConfigOutputFile; }
/** /**
Return the default directory for storing data. Return the default directory for storing data.
@ -205,19 +206,12 @@ class Settings
string myBaseDir; string myBaseDir;
string myStateDir; string myStateDir;
string myStateFile;
string mySnapshotFile;
string myUserPropertiesFile;
string mySystemPropertiesFile;
string myUserConfigFile;
string mySystemConfigFile;
// The full pathname of the settings file for input string myPropertiesInputFile;
string mySettingsInputFilename; string myPropertiesOutputFile;
string myConfigInputFile;
string myConfigOutputFile;
// The full pathname of the settings file for output
string mySettingsOutputFilename;
// Structure used for storing settings // Structure used for storing settings
struct Setting struct Setting
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: SettingsUNIX.cxx,v 1.6 2004-07-05 00:53:48 stephena Exp $ // $Id: SettingsUNIX.cxx,v 1.7 2004-08-17 01:17:08 stephena Exp $
//============================================================================ //============================================================================
#include <cstdlib> #include <cstdlib>
@ -42,20 +42,28 @@ SettingsUNIX::SettingsUNIX()
if(!fileExists(myStateDir)) if(!fileExists(myStateDir))
mkdir(myStateDir.c_str(), 0777); mkdir(myStateDir.c_str(), 0777);
myUserPropertiesFile = stelladir + "/stella.pro"; string userPropertiesFile = stelladir + "/stella.pro";
mySystemPropertiesFile = "/etc/stella.pro"; string systemPropertiesFile = "/etc/stella.pro";
myUserConfigFile = stelladir + "/stellarc"; string userConfigFile = stelladir + "/stellarc";
mySystemConfigFile = "/etc/stellarc"; string systemConfigFile = "/etc/stellarc";
// Set up the names of the input and output config files // Set up the names of the input and output config files
mySettingsOutputFilename = myUserConfigFile; myConfigOutputFile = userConfigFile;
if(fileExists(myUserConfigFile)) if(fileExists(userConfigFile))
mySettingsInputFilename = myUserConfigFile; myConfigInputFile = userConfigFile;
else if(fileExists(systemConfigFile))
myConfigInputFile = systemConfigFile;
else else
mySettingsInputFilename = mySystemConfigFile; myConfigInputFile = "";
mySnapshotFile = ""; // Set up the input and output properties files
myStateFile = ""; myPropertiesOutputFile = userPropertiesFile;
if(fileExists(userPropertiesFile))
myPropertiesInputFile = userPropertiesFile;
else if(fileExists(systemPropertiesFile))
myPropertiesInputFile = systemPropertiesFile;
else
myPropertiesInputFile = "";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -69,13 +77,11 @@ string SettingsUNIX::stateFilename(const string& md5, uInt32 state)
ostringstream buf; ostringstream buf;
buf << myStateDir << md5 << ".st" << state; buf << myStateDir << md5 << ".st" << state;
myStateFile = buf.str(); return buf.str();
return myStateFile;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SettingsUNIX::fileExists(const string& filename) bool SettingsUNIX::fileExists(const string& filename)
{ {
return (access(filename.c_str(), F_OK|W_OK) == 0); return (access(filename.c_str(), F_OK) == 0);
} }