mirror of https://github.com/stella-emu/stella.git
Removed dependency of Console from the Settings class. It didn't make
sense for the Settings class to have to depend on Console, especially since I plan to use the Settings class in the Windows frontend. Removed the snapshot filename code from the individual SettingsXXX classes, since it was redundant. Instead, added a ::fileExists() method, which is the only thing that was really platform-specific about the code anyway. Linux and Windows ports have been updated. The Mac port will have to be updated to work with this. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@253 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
af928f7dad
commit
6f9618a4da
|
@ -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: Console.cxx,v 1.27 2004-04-27 00:50:51 stephena Exp $
|
||||
// $Id: Console.cxx,v 1.28 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -65,9 +65,6 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
|
|||
mySystem = 0;
|
||||
myEvent = 0;
|
||||
|
||||
// Inform the settings object about the console
|
||||
mySettings.setConsole(this);
|
||||
|
||||
// Create an event handler which will collect and dispatch events
|
||||
myEventHandler = new EventHandler(this);
|
||||
myEvent = myEventHandler->event();
|
||||
|
|
|
@ -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: EventHandler.cxx,v 1.24 2004-05-28 18:25:19 stephena Exp $
|
||||
// $Id: EventHandler.cxx,v 1.25 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -343,7 +343,7 @@ void EventHandler::saveState()
|
|||
|
||||
// Do a state save using the System
|
||||
string md5 = myConsole->properties().get("Cartridge.MD5");
|
||||
string filename = myConsole->settings().stateFilename(myCurrentState);
|
||||
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
||||
int result = myConsole->system().saveState(filename, md5);
|
||||
|
||||
// Print appropriate message
|
||||
|
@ -380,7 +380,7 @@ void EventHandler::loadState()
|
|||
|
||||
// Do a state save using the System
|
||||
string md5 = myConsole->properties().get("Cartridge.MD5");
|
||||
string filename = myConsole->settings().stateFilename(myCurrentState);
|
||||
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
||||
int result = myConsole->system().loadState(filename, md5);
|
||||
|
||||
if(result == 1)
|
||||
|
@ -397,8 +397,42 @@ void EventHandler::loadState()
|
|||
void EventHandler::takeSnapshot()
|
||||
{
|
||||
#ifdef SNAPSHOT_SUPPORT
|
||||
// Figure out the correct snapshot name
|
||||
string filename;
|
||||
string sspath = myConsole->settings().getString("ssdir");
|
||||
string ssname = myConsole->settings().getString("ssname");
|
||||
|
||||
if(ssname == "romname")
|
||||
sspath = sspath + BSPF_PATH_SEPARATOR + myConsole->properties().get("Cartridge.Name");
|
||||
else if(ssname == "md5sum")
|
||||
sspath = sspath + BSPF_PATH_SEPARATOR + myConsole->properties().get("Cartridge.MD5");
|
||||
|
||||
// Replace all spaces in name with underscores
|
||||
replace(sspath.begin(), sspath.end(), ' ', '_');
|
||||
|
||||
// Check whether we want multiple snapshots created
|
||||
if(!myConsole->settings().getBool("sssingle"))
|
||||
{
|
||||
// Determine if the file already exists, checking each successive filename
|
||||
// until one doesn't exist
|
||||
filename = sspath + ".png";
|
||||
if(myConsole->settings().fileExists(filename))
|
||||
{
|
||||
ostringstream buf;
|
||||
for(uInt32 i = 1; ;++i)
|
||||
{
|
||||
buf.str("");
|
||||
buf << sspath << "_" << i << ".png";
|
||||
if(!myConsole->settings().fileExists(buf.str()))
|
||||
break;
|
||||
}
|
||||
filename = buf.str();
|
||||
}
|
||||
}
|
||||
else
|
||||
filename = sspath + ".png";
|
||||
|
||||
// Now save the snapshot file
|
||||
string filename = myConsole->settings().snapshotFilename();
|
||||
uInt32 multiplier = myConsole->settings().getInt("zoom");
|
||||
|
||||
myConsole->snapshot().savePNG(filename, multiplier);
|
||||
|
|
|
@ -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.19 2004-04-27 00:50:51 stephena Exp $
|
||||
// $Id: Settings.cxx,v 1.20 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cassert>
|
||||
|
@ -21,8 +21,6 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "Console.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "Settings.hxx"
|
||||
|
||||
#ifdef DEVELOPER_SUPPORT
|
||||
|
@ -32,7 +30,6 @@
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Settings::Settings()
|
||||
: myConsole(0)
|
||||
{
|
||||
// First create the settings array
|
||||
myCapacity = 30;
|
||||
|
|
|
@ -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.12 2004-04-21 16:27:18 stephena Exp $
|
||||
// $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SETTINGS_HXX
|
||||
|
@ -25,14 +25,12 @@
|
|||
|
||||
#include "bspf.hxx"
|
||||
|
||||
class Console;
|
||||
|
||||
|
||||
/**
|
||||
This class provides an interface for accessing frontend specific settings.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: Settings.hxx,v 1.12 2004-04-21 16:27:18 stephena Exp $
|
||||
@version $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $
|
||||
*/
|
||||
class Settings
|
||||
{
|
||||
|
@ -145,16 +143,21 @@ class Settings
|
|||
This method should be called to get the filename of a state file
|
||||
given the state number.
|
||||
|
||||
@param md5 The md5sum to use as part of the filename.
|
||||
@param state The state to use as part of the filename.
|
||||
|
||||
@return String representing the full path of the state filename.
|
||||
*/
|
||||
virtual string stateFilename(uInt32 state) = 0;
|
||||
virtual string stateFilename(const string& md5, uInt32 state) = 0;
|
||||
|
||||
/**
|
||||
This method should be called to get the filename of a snapshot.
|
||||
This method should be called to test whether the given file exists.
|
||||
|
||||
@return String representing the full path of the snapshot filename.
|
||||
@param filename The filename to test for existence.
|
||||
|
||||
@return boolean representing whether or not the file exists
|
||||
*/
|
||||
virtual string snapshotFilename() = 0;
|
||||
virtual bool fileExists(const string& filename) = 0;
|
||||
|
||||
/**
|
||||
This method should be called to display usage information.
|
||||
|
@ -164,12 +167,6 @@ class Settings
|
|||
virtual void usage(string& message) = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
This method should be called when the emulation core sets
|
||||
the console object.
|
||||
*/
|
||||
void setConsole(Console* console) { myConsole = console; }
|
||||
|
||||
/**
|
||||
This method should be called to get the filename of the users'
|
||||
properties (stella.pro) file.
|
||||
|
@ -225,9 +222,6 @@ class Settings
|
|||
string myUserConfigFile;
|
||||
string mySystemConfigFile;
|
||||
|
||||
// The global Console object
|
||||
Console* myConsole;
|
||||
|
||||
// The full pathname of the settings file for input
|
||||
string mySettingsInputFilename;
|
||||
|
||||
|
|
|
@ -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: bspf.hxx,v 1.3 2002-04-10 04:07:39 bwmott Exp $
|
||||
// $Id: bspf.hxx,v 1.4 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef BSPF_HXX
|
||||
|
@ -24,7 +24,7 @@
|
|||
that need to be defined for different operating systems.
|
||||
|
||||
@author Bradford W. Mott
|
||||
@version $Id: bspf.hxx,v 1.3 2002-04-10 04:07:39 bwmott Exp $
|
||||
@version $Id: bspf.hxx,v 1.4 2004-05-28 22:07:57 stephena Exp $
|
||||
*/
|
||||
|
||||
// Types for 8-bit signed and unsigned integers
|
||||
|
@ -54,7 +54,7 @@ typedef unsigned int uInt32;
|
|||
|
||||
#ifdef BSPF_WIN32
|
||||
// pragma to avoid all of the int <-> bool conversion warnings
|
||||
#pragma warning(disable: 4800)
|
||||
// #pragma warning(disable: 4800)
|
||||
#endif
|
||||
|
||||
// Some old compilers do not support the bool type
|
||||
|
@ -66,12 +66,11 @@ typedef unsigned int uInt32;
|
|||
|
||||
// Defines to help with path handling
|
||||
#if defined BSPF_UNIX
|
||||
#define BSPF_PATH_SEPARATOR '/'
|
||||
#define BSPF_PATH_SEPARATOR "/"
|
||||
#elif (defined(BSPF_DOS) || defined(BSPF_WIN32) || defined(BSPF_OS2))
|
||||
#define BSPF_PATH_SEPARATOR '\\'
|
||||
#elif defined BSPF_MACOS
|
||||
#define BSPF_PATH_SEPARATOR ':'
|
||||
#define BSPF_PATH_SEPARATOR "\\"
|
||||
#elif defined BSPF_MAC_OSX
|
||||
#define BSPF_PATH_SEPARATOR ":"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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.1 2004-05-24 17:18:23 stephena Exp $
|
||||
// $Id: SettingsUNIX.cxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -25,10 +25,6 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "Console.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaEvent.hxx"
|
||||
|
||||
#include "Settings.hxx"
|
||||
#include "SettingsUNIX.hxx"
|
||||
|
||||
|
@ -39,11 +35,11 @@ SettingsUNIX::SettingsUNIX()
|
|||
myBaseDir = getenv("HOME");
|
||||
string stelladir = myBaseDir + "/.stella";
|
||||
|
||||
if(access(stelladir.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||
if(!fileExists(stelladir))
|
||||
mkdir(stelladir.c_str(), 0777);
|
||||
|
||||
myStateDir = stelladir + "/state/";
|
||||
if(access(myStateDir.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||
if(!fileExists(myStateDir))
|
||||
mkdir(myStateDir.c_str(), 0777);
|
||||
|
||||
myUserPropertiesFile = stelladir + "/stella.pro";
|
||||
|
@ -53,7 +49,7 @@ SettingsUNIX::SettingsUNIX()
|
|||
|
||||
// Set up the names of the input and output config files
|
||||
mySettingsOutputFilename = myUserConfigFile;
|
||||
if(access(myUserConfigFile.c_str(), R_OK) == 0)
|
||||
if(fileExists(myUserConfigFile))
|
||||
mySettingsInputFilename = myUserConfigFile;
|
||||
else
|
||||
mySettingsInputFilename = mySystemConfigFile;
|
||||
|
@ -124,59 +120,18 @@ void SettingsUNIX::usage(string& message)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string SettingsUNIX::stateFilename(uInt32 state)
|
||||
string SettingsUNIX::stateFilename(const string& md5, uInt32 state)
|
||||
{
|
||||
if(!myConsole)
|
||||
return "";
|
||||
|
||||
ostringstream buf;
|
||||
buf << myStateDir << myConsole->properties().get("Cartridge.MD5")
|
||||
<< ".st" << state;
|
||||
buf << myStateDir << md5 << ".st" << state;
|
||||
|
||||
myStateFile = buf.str();
|
||||
|
||||
return myStateFile;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string SettingsUNIX::snapshotFilename()
|
||||
bool SettingsUNIX::fileExists(const string& filename)
|
||||
{
|
||||
if(!myConsole)
|
||||
return "";
|
||||
|
||||
string filename;
|
||||
string path = getString("ssdir");
|
||||
string theSnapshotName = getString("ssname");
|
||||
|
||||
if(theSnapshotName == "romname")
|
||||
path = path + "/" + myConsole->properties().get("Cartridge.Name");
|
||||
else if(theSnapshotName == "md5sum")
|
||||
path = path + "/" + myConsole->properties().get("Cartridge.MD5");
|
||||
|
||||
// Replace all spaces in name with underscores
|
||||
replace(path.begin(), path.end(), ' ', '_');
|
||||
|
||||
// Check whether we want multiple snapshots created
|
||||
if(!getBool("sssingle"))
|
||||
{
|
||||
// Determine if the file already exists, checking each successive filename
|
||||
// until one doesn't exist
|
||||
filename = path + ".png";
|
||||
if(access(filename.c_str(), F_OK) == 0 )
|
||||
{
|
||||
ostringstream buf;
|
||||
for(uInt32 i = 1; ;++i)
|
||||
{
|
||||
buf.str("");
|
||||
buf << path << "_" << i << ".png";
|
||||
if(access(buf.str().c_str(), F_OK) == -1 )
|
||||
break;
|
||||
}
|
||||
filename = buf.str();
|
||||
}
|
||||
}
|
||||
else
|
||||
filename = path + ".png";
|
||||
|
||||
mySnapshotFile = filename;
|
||||
return mySnapshotFile;
|
||||
return (access(filename.c_str(), F_OK|W_OK) == 0);
|
||||
}
|
||||
|
|
|
@ -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.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $
|
||||
// $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SETTINGS_UNIX_HXX
|
||||
|
@ -21,14 +21,12 @@
|
|||
|
||||
#include "bspf.hxx"
|
||||
|
||||
class Console;
|
||||
|
||||
|
||||
/**
|
||||
This class defines UNIX-like OS's (Linux) system specific settings.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: SettingsUNIX.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $
|
||||
@version $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
*/
|
||||
class SettingsUNIX : public Settings
|
||||
{
|
||||
|
@ -48,16 +46,22 @@ class SettingsUNIX : public Settings
|
|||
This method should be called to get the filename of a state file
|
||||
given the state number.
|
||||
|
||||
@param md5 The md5sum to use as part of the filename.
|
||||
@param state The state to use as part of the filename.
|
||||
|
||||
@return String representing the full path of the state filename.
|
||||
*/
|
||||
virtual string stateFilename(uInt32 state);
|
||||
virtual string stateFilename(const string& md5, uInt32 state);
|
||||
|
||||
|
||||
/**
|
||||
This method should be called to get the filename of a snapshot.
|
||||
This method should be called to test whether the given file exists.
|
||||
|
||||
@return String representing the full path of the snapshot filename.
|
||||
@param filename The filename to test for existence.
|
||||
|
||||
@return boolean representing whether or not the file exists
|
||||
*/
|
||||
virtual string snapshotFilename();
|
||||
virtual bool fileExists(const string& filename);
|
||||
|
||||
/**
|
||||
Display the commandline settings for this UNIX version of Stella.
|
||||
|
|
|
@ -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: SettingsWin32.cxx,v 1.1 2004-05-24 17:18:23 stephena Exp $
|
||||
// $Id: SettingsWin32.cxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -25,10 +25,6 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "Console.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "StellaEvent.hxx"
|
||||
|
||||
#include "Settings.hxx"
|
||||
#include "SettingsWin32.hxx"
|
||||
|
||||
|
@ -130,59 +126,18 @@ void SettingsWin32::usage(string& message)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string SettingsWin32::stateFilename(uInt32 state)
|
||||
string SettingsWin32::stateFilename(const string& md5, uInt32 state)
|
||||
{
|
||||
if(!myConsole)
|
||||
return "";
|
||||
|
||||
ostringstream buf;
|
||||
buf << myStateDir << myConsole->properties().get("Cartridge.MD5")
|
||||
<< ".st" << state;
|
||||
buf << myStateDir << md5 << ".st" << state;
|
||||
|
||||
myStateFile = buf.str();
|
||||
|
||||
return myStateFile;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string SettingsWin32::snapshotFilename()
|
||||
bool SettingsWin32::fileExists(const string& filename)
|
||||
{
|
||||
if(!myConsole)
|
||||
return "";
|
||||
|
||||
string filename;
|
||||
string path = getString("ssdir");
|
||||
string theSnapshotName = getString("ssname");
|
||||
|
||||
if(theSnapshotName == "romname")
|
||||
path = path + "\\" + myConsole->properties().get("Cartridge.Name");
|
||||
else if(theSnapshotName == "md5sum")
|
||||
path = path + "\\" + myConsole->properties().get("Cartridge.MD5");
|
||||
|
||||
// Replace all spaces in name with underscores
|
||||
replace(path.begin(), path.end(), ' ', '_');
|
||||
|
||||
// Check whether we want multiple snapshots created
|
||||
if(!getBool("sssingle"))
|
||||
{
|
||||
// Determine if the file already exists, checking each successive filename
|
||||
// until one doesn't exist
|
||||
filename = path + ".png";
|
||||
if(access(filename.c_str(), F_OK) == 0 )
|
||||
{
|
||||
ostringstream buf;
|
||||
for(uInt32 i = 1; ;++i)
|
||||
{
|
||||
buf.str("");
|
||||
buf << path << "_" << i << ".png";
|
||||
if(access(buf.str().c_str(), F_OK) == -1 )
|
||||
break;
|
||||
}
|
||||
filename = buf.str();
|
||||
}
|
||||
}
|
||||
else
|
||||
filename = path + ".png";
|
||||
|
||||
mySnapshotFile = filename;
|
||||
return mySnapshotFile;
|
||||
return false;//FIXME(access(filename.c_str(), F_OK|W_OK) == 0);
|
||||
}
|
||||
|
|
|
@ -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: SettingsWin32.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $
|
||||
// $Id: SettingsWin32.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SETTINGS_WIN32_HXX
|
||||
|
@ -21,14 +21,12 @@
|
|||
|
||||
#include "bspf.hxx"
|
||||
|
||||
class Console;
|
||||
|
||||
|
||||
/**
|
||||
This class defines Windows system specific settings.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: SettingsWin32.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $
|
||||
@version $Id: SettingsWin32.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $
|
||||
*/
|
||||
class SettingsWin32 : public Settings
|
||||
{
|
||||
|
@ -48,16 +46,21 @@ class SettingsWin32 : public Settings
|
|||
This method should be called to get the filename of a state file
|
||||
given the state number.
|
||||
|
||||
@param md5 The md5sum to use as part of the filename.
|
||||
@param state The state to use as part of the filename.
|
||||
|
||||
@return String representing the full path of the state filename.
|
||||
*/
|
||||
virtual string stateFilename(uInt32 state);
|
||||
virtual string stateFilename(const string& md5, uInt32 state) = 0;
|
||||
|
||||
/**
|
||||
This method should be called to get the filename of a snapshot.
|
||||
This method should be called to test whether the given file exists.
|
||||
|
||||
@return String representing the full path of the snapshot filename.
|
||||
@param filename The filename to test for existence.
|
||||
|
||||
@return boolean representing whether or not the file exists
|
||||
*/
|
||||
virtual string snapshotFilename();
|
||||
virtual bool fileExists(const string& filename) = 0;
|
||||
|
||||
/**
|
||||
Display the commandline settings for this UNIX version of Stella.
|
||||
|
|
Loading…
Reference in New Issue