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
// 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>
@ -271,7 +271,7 @@ static KeyList keyList[] = {
*/
static void ShowInfo(const string& msg)
{
if(theShowInfoFlag)
if(theShowInfoFlag && msg != "")
cout << msg << endl;
}
@ -499,7 +499,7 @@ void HandleEvents()
case SDLK_s: // Ctrl-s saves properties to a file
// Attempt to merge with propertiesSet
if(theConsole->settings().getBool("mergeprops"))
theConsole->saveProperties(theSettings->userPropertiesFilename(), true);
theConsole->saveProperties(theSettings->propertiesOutputFilename(), true);
else // Save to file in home directory
{
string newPropertiesFile = theConsole->settings().baseDir() + "/" + \
@ -520,8 +520,8 @@ void HandleEvents()
case SDL_MOUSEMOTION:
{
uInt32 zoom = theDisplay->zoomLevel();
Int32 width = theDisplay->width() * zoom;
uInt32 zoom = theDisplay->zoomLevel();
Int32 width = theDisplay->width() * zoom;
// Grabmouse and hidecursor introduce some lag into the mouse movement,
// so we need to fudge the numbers a bit
@ -649,7 +649,7 @@ void HandleEvents()
button = event.jbutton.button;
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(type == JT_STELLADAPTOR_1)
@ -719,23 +719,29 @@ void HandleEvents()
void SetupProperties(PropertiesSet& set)
{
bool useMemList = false;
string theAlternateProFile = theSettings->getString("altpro");
string theUserProFile = theSettings->userPropertiesFilename();
string theSystemProFile = theSettings->systemPropertiesFilename();
string theAltPropertiesFile = theSettings->getString("altpro");
string thePropertiesFile = theSettings->propertiesInputFilename();
// When 'listrominfo' or 'mergeprops' is specified, we need to have the
// full list in memory
if(theSettings->getBool("listrominfo") || theSettings->getBool("mergeprops"))
useMemList = true;
if(theAlternateProFile != "")
set.load(theAlternateProFile, useMemList);
else if(theUserProFile != "")
set.load(theUserProFile, useMemList);
else if(theSystemProFile != "")
set.load(theSystemProFile, useMemList);
stringstream buf;
if(theAltPropertiesFile != "")
{
buf << "Reading game properties from \'" << theAltPropertiesFile << "\'\n";
set.load(theAltPropertiesFile, useMemList);
}
else if(thePropertiesFile != "")
{
buf << "Reading game properties from \'" << thePropertiesFile << "\'\n";
set.load(thePropertiesFile, useMemList);
}
else
set.load("", false);
ShowInfo(buf.str());
}
@ -796,6 +802,12 @@ int main(int argc, char* argv[])
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
PropertiesSet propertiesSet;
SetupProperties(propertiesSet);
@ -809,12 +821,6 @@ int main(int argc, char* argv[])
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
putenv("SDL_VIDEO_CENTERED=1");

View File

@ -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.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>
@ -73,7 +73,7 @@ void Settings::loadConfig()
string line, key, value;
uInt32 equalPos;
ifstream in(mySettingsInputFilename.c_str());
ifstream in(myConfigInputFile.c_str());
if(!in || !in.is_open())
{
cout << "Error: Couldn't load settings file\n";
@ -167,7 +167,7 @@ void Settings::usage()
{
#ifndef MAC_OSX
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
<< "Valid options are:" << endl
<< endl
@ -209,7 +209,7 @@ void Settings::usage()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::saveConfig()
{
ofstream out(mySettingsOutputFilename.c_str());
ofstream out(myConfigOutputFile.c_str());
if(!out || !out.is_open())
{
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
// 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
@ -26,7 +26,7 @@
This class provides an interface for accessing frontend specific settings.
@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
{
@ -164,36 +164,37 @@ class Settings
public:
/**
This method should be called to get the filename of the users'
properties (stella.pro) file.
This method should be called to get the filename of the
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
properties (stella.pro) file.
This method should be called to get the filename of the
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'
config (stellarc) file.
This method should be called to get the filename of the config 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
config (stellarc) file.
This method should be called to get the filename of the config 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.
@ -205,19 +206,12 @@ class Settings
string myBaseDir;
string myStateDir;
string myStateFile;
string mySnapshotFile;
string myUserPropertiesFile;
string mySystemPropertiesFile;
string myUserConfigFile;
string mySystemConfigFile;
// The full pathname of the settings file for input
string mySettingsInputFilename;
string myPropertiesInputFile;
string myPropertiesOutputFile;
string myConfigInputFile;
string myConfigOutputFile;
// The full pathname of the settings file for output
string mySettingsOutputFilename;
// Structure used for storing settings
struct Setting
{

View File

@ -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: 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>
@ -42,20 +42,28 @@ SettingsUNIX::SettingsUNIX()
if(!fileExists(myStateDir))
mkdir(myStateDir.c_str(), 0777);
myUserPropertiesFile = stelladir + "/stella.pro";
mySystemPropertiesFile = "/etc/stella.pro";
myUserConfigFile = stelladir + "/stellarc";
mySystemConfigFile = "/etc/stellarc";
string userPropertiesFile = stelladir + "/stella.pro";
string systemPropertiesFile = "/etc/stella.pro";
string userConfigFile = stelladir + "/stellarc";
string systemConfigFile = "/etc/stellarc";
// Set up the names of the input and output config files
mySettingsOutputFilename = myUserConfigFile;
if(fileExists(myUserConfigFile))
mySettingsInputFilename = myUserConfigFile;
myConfigOutputFile = userConfigFile;
if(fileExists(userConfigFile))
myConfigInputFile = userConfigFile;
else if(fileExists(systemConfigFile))
myConfigInputFile = systemConfigFile;
else
mySettingsInputFilename = mySystemConfigFile;
myConfigInputFile = "";
mySnapshotFile = "";
myStateFile = "";
// Set up the input and output properties files
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;
buf << myStateDir << md5 << ".st" << state;
myStateFile = buf.str();
return myStateFile;
return buf.str();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SettingsUNIX::fileExists(const string& filename)
{
return (access(filename.c_str(), F_OK|W_OK) == 0);
return (access(filename.c_str(), F_OK) == 0);
}