More code upheaval on the quest for better ZIP handling (although

it's still partially broken).

Converted many methods to take FSNode objects instead of raw string
filenames.  This is necessary since file reading will eventually
be abstracted into the FSNode class directly.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2605 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2013-02-12 21:57:14 +00:00
parent 3aa7bfd8e3
commit 17df4efe9e
9 changed files with 74 additions and 63 deletions

View File

@ -133,7 +133,7 @@ int main(int argc, char* argv[])
theOSystem->logMessage("Showing output from 'rominfo' ...", 2); theOSystem->logMessage("Showing output from 'rominfo' ...", 2);
FilesystemNode romnode(romfile); FilesystemNode romnode(romfile);
if(argc > 1 && romnode.exists() && romnode.isFile()) if(argc > 1 && romnode.exists() && romnode.isFile())
theOSystem->logMessage(theOSystem->getROMInfo(romfile), 0); theOSystem->logMessage(theOSystem->getROMInfo(romnode), 0);
else else
theOSystem->logMessage("ERROR: ROM doesn't exist", 0); theOSystem->logMessage("ERROR: ROM doesn't exist", 0);
@ -175,7 +175,7 @@ int main(int argc, char* argv[])
return Cleanup(); return Cleanup();
} }
} }
else if(theOSystem->createConsole(romnode.getPath())) else if(theOSystem->createConsole(romnode))
{ {
if(theOSystem->settings().getBool("takesnapshot")) if(theOSystem->settings().getBool("takesnapshot"))
{ {

View File

@ -593,8 +593,7 @@ void EventHandler::poll(uInt64 time)
break; break;
case KBDK_r: // Ctrl-r reloads the currently loaded ROM case KBDK_r: // Ctrl-r reloads the currently loaded ROM
myOSystem->deleteConsole(); myOSystem->reloadConsole();
myOSystem->createConsole();
break; break;
case KBDK_PAGEUP: // Ctrl-PageUp increases Height case KBDK_PAGEUP: // Ctrl-PageUp increases Height

View File

@ -503,7 +503,7 @@ void OSystem::createSound()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::createConsole(const string& romfile, const string& md5sum) bool OSystem::createConsole(const FilesystemNode& rom, const string& md5sum)
{ {
ostringstream buf; ostringstream buf;
@ -512,19 +512,14 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
bool showmessage = false; bool showmessage = false;
// If a blank ROM has been given, we reload the current one (assuming one exists) // If same ROM has been given, we reload the current one (assuming one exists)
if(romfile == "") if(rom == myRomFile)
{ {
showmessage = true; // we show a message if a ROM is being reloaded showmessage = true; // we show a message if a ROM is being reloaded
if(myRomFile == "")
{
logMessage("ERROR: Rom file not specified ...", 0);
return false;
}
} }
else else
{ {
myRomFile = romfile; myRomFile = rom;
myRomMD5 = md5sum; myRomMD5 = md5sum;
// Each time a new console is loaded, we simulate a cart removal // Each time a new console is loaded, we simulate a cart removal
@ -568,7 +563,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
myFrameBuffer->showMessage("Multicart " + type + ", loading ROM" + id); myFrameBuffer->showMessage("Multicart " + type + ", loading ROM" + id);
} }
buf << "Game console created:" << endl buf << "Game console created:" << endl
<< " ROM file: " << FilesystemNode(myRomFile).getShortPath() << endl << endl << " ROM file: " << myRomFile.getShortPath() << endl << endl
<< getROMInfo(myConsole) << endl; << getROMInfo(myConsole) << endl;
logMessage(buf.str(), 1); logMessage(buf.str(), 1);
@ -590,7 +585,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
} }
else else
{ {
buf << "ERROR: Couldn't create console for " << myRomFile << endl; buf << "ERROR: Couldn't create console for " << myRomFile.getShortPath() << endl;
logMessage(buf.str(), 0); logMessage(buf.str(), 0);
return false; return false;
} }
@ -620,6 +615,13 @@ void OSystem::deleteConsole()
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::reloadConsole()
{
deleteConsole();
return createConsole(myRomFile);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::createLauncher(const string& startdir) bool OSystem::createLauncher(const string& startdir)
{ {
@ -645,7 +647,7 @@ bool OSystem::createLauncher(const string& startdir)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string OSystem::getROMInfo(const string& romfile) string OSystem::getROMInfo(const FilesystemNode& romfile)
{ {
string md5, type, id, result = ""; string md5, type, id, result = "";
Console* console = openConsole(romfile, md5, type, id); Console* console = openConsole(romfile, md5, type, id);
@ -655,19 +657,19 @@ string OSystem::getROMInfo(const string& romfile)
delete console; delete console;
} }
else else
result = "ERROR: Couldn't get ROM info for " + romfile + " ..."; result = "ERROR: Couldn't get ROM info for " + romfile.getShortPath() + " ...";
return result; return result;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string OSystem::MD5FromFile(const string& filename) string OSystem::MD5FromFile(const FilesystemNode& file)
{ {
string md5 = ""; string md5 = "";
uInt8* image = 0; uInt8* image = 0;
uInt32 size = 0; uInt32 size = 0;
if((image = openROM(filename, md5, size)) != 0) if((image = openROM(file, md5, size)) != 0)
if(image != 0 && size > 0) if(image != 0 && size > 0)
delete[] image; delete[] image;
@ -691,7 +693,7 @@ void OSystem::logMessage(const string& message, uInt8 level)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console* OSystem::openConsole(const string& romfile, string& md5, Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5,
string& type, string& id) string& type, string& id)
{ {
#define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \ #define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \
@ -757,7 +759,7 @@ Console* OSystem::openConsole(const string& romfile, string& md5,
else else
{ {
ostringstream buf; ostringstream buf;
buf << "ERROR: Couldn't open \'" << romfile << "\'" << endl; buf << "ERROR: Couldn't open \'" << romfile.getShortPath() << "\'" << endl;
logMessage(buf.str(), 0); logMessage(buf.str(), 0);
} }
@ -769,7 +771,7 @@ Console* OSystem::openConsole(const string& romfile, string& md5,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8* OSystem::openROM(string file, string& md5, uInt32& size) uInt8* OSystem::openROM(const FilesystemNode& romfile, string& md5, uInt32& size)
{ {
// This method has a documented side-effect: // This method has a documented side-effect:
// It not only loads a ROM and creates an array with its contents, // It not only loads a ROM and creates an array with its contents,
@ -778,6 +780,8 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size)
uInt8* image = 0; uInt8* image = 0;
// FIXME - this entire code to be replaced by romfile.read(...)
#if 0
// First try to load as ZIP archive // First try to load as ZIP archive
if(loadFromZIP(file, &image, size)) if(loadFromZIP(file, &image, size))
{ {
@ -787,9 +791,10 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size)
return image; return image;
} }
else else
#endif
{ {
// Assume the file is either gzip'ed or not compressed at all // Assume the file is either gzip'ed or not compressed at all
gzFile f = gzopen(file.c_str(), "rb"); gzFile f = gzopen(romfile.getPath().c_str(), "rb");
if(!f) if(!f)
return image; return image;
@ -817,12 +822,8 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size)
Properties props; Properties props;
if(!myPropSet->getMD5(md5, props)) if(!myPropSet->getMD5(md5, props))
{ {
// Get the filename from the rom pathname
FilesystemNode node(file);
file = node.getName();
props.set(Cartridge_MD5, md5); props.set(Cartridge_MD5, md5);
props.set(Cartridge_Name, file); props.set(Cartridge_Name, romfile.getName());
myPropSet->insert(props, false); myPropSet->insert(props, false);
} }

View File

@ -40,6 +40,7 @@ namespace GUI {
} }
#include "Array.hxx" #include "Array.hxx"
#include "FSNode.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "PNGLibrary.hxx" #include "PNGLibrary.hxx"
#include "ZipHandler.hxx" #include "ZipHandler.hxx"
@ -363,18 +364,18 @@ class OSystem
@return String representing the full path of the ROM file. @return String representing the full path of the ROM file.
*/ */
const string& romFile() const { return myRomFile; } const string& romFile() const { return myRomFile.getPath(); }
/** /**
Creates a new game console from the specified romfile, and correctly Creates a new game console from the specified romfile, and correctly
initializes the system state to start emulation of the Console. initializes the system state to start emulation of the Console.
@param romfile The full pathname of the ROM to use @param rom The FSNode of the ROM to use (contains path, etc)
@param md5 The MD5sum of the ROM @param md5 The MD5sum of the ROM
@return True on successful creation, otherwise false @return True on successful creation, otherwise false
*/ */
bool createConsole(const string& romfile = "", const string& md5 = ""); bool createConsole(const FilesystemNode& rom, const string& md5 = "");
/** /**
Deletes the currently defined console, if it exists. Deletes the currently defined console, if it exists.
@ -382,6 +383,14 @@ class OSystem
*/ */
void deleteConsole(); void deleteConsole();
/**
Reloads the current console (essentially deletes and re-creates it).
This can be thought of as a real console off/on toggle.
@return True on successful creation, otherwise false
*/
bool reloadConsole();
/** /**
Creates a new ROM launcher, to select a new ROM to emulate. Creates a new ROM launcher, to select a new ROM to emulate.
@ -404,10 +413,10 @@ class OSystem
Gets all possible info about the ROM by creating a temporary Gets all possible info about the ROM by creating a temporary
Console object and querying it. Console object and querying it.
@param romfile The full pathname of the ROM to use @param romfile The file node of the ROM to use
@return Some information about this ROM @return Some information about this ROM
*/ */
string getROMInfo(const string& romfile); string getROMInfo(const FilesystemNode& romfile);
/** /**
The features which are conditionally compiled into Stella. The features which are conditionally compiled into Stella.
@ -426,9 +435,9 @@ class OSystem
/** /**
Calculate the MD5sum of the given file. Calculate the MD5sum of the given file.
@param filename Filename of potential ROM file @param file File node of potential ROM file
*/ */
string MD5FromFile(const string& filename); string MD5FromFile(const FilesystemNode& file);
/** /**
Issue a quit event to the OSystem. Issue a quit event to the OSystem.
@ -617,7 +626,7 @@ class OSystem
string myPaletteFile; string myPaletteFile;
string myPropertiesFile; string myPropertiesFile;
string myRomFile; FilesystemNode myRomFile;
string myRomMD5; string myRomMD5;
string myFeatures; string myFeatures;
@ -666,7 +675,7 @@ class OSystem
/** /**
Creates an actual Console object based on the given info. Creates an actual Console object based on the given info.
@param romfile The full pathname of the ROM to use @param romfile The file node of the ROM to use (contains path)
@param md5 The MD5sum of the ROM @param md5 The MD5sum of the ROM
@param type The bankswitch type of the ROM @param type The bankswitch type of the ROM
@param id The additional id (if any) used by the ROM @param id The additional id (if any) used by the ROM
@ -674,14 +683,15 @@ class OSystem
@return The actual Console object, otherwise NULL @return The actual Console object, otherwise NULL
(calling method is responsible for deleting it) (calling method is responsible for deleting it)
*/ */
Console* openConsole(const string& romfile, string& md5, string& type, string& id); Console* openConsole(const FilesystemNode& romfile, string& md5,
string& type, string& id);
/** /**
Open the given ROM and return an array containing its contents. Open the given ROM and return an array containing its contents.
Also, the properties database is updated with a valid ROM name Also, the properties database is updated with a valid ROM name
for this ROM (if necessary). for this ROM (if necessary).
@param rom The absolute pathname of the ROM file @param rom The file node of the ROM to open (contains path)
@param md5 The md5 calculated from the ROM file @param md5 The md5 calculated from the ROM file
(will be recalculated if necessary) (will be recalculated if necessary)
@param size The amount of data read into the image array @param size The amount of data read into the image array
@ -689,7 +699,7 @@ class OSystem
@return Pointer to the array, with size >=0 indicating valid data @return Pointer to the array, with size >=0 indicating valid data
(calling method is responsible for deleting it) (calling method is responsible for deleting it)
*/ */
uInt8* openROM(string rom, string& md5, uInt32& size); uInt8* openROM(const FilesystemNode& rom, string& md5, uInt32& size);
/** /**
Open the given ZIP archive, parsing filename for the contents of the Open the given ZIP archive, parsing filename for the contents of the

View File

@ -177,8 +177,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
case kReloadRomCmd: case kReloadRomCmd:
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
instance().deleteConsole(); instance().reloadConsole();
instance().createConsole();
break; break;
case kExitCmd: case kExitCmd:

View File

@ -215,16 +215,19 @@ LauncherDialog::~LauncherDialog()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string& LauncherDialog::selectedRomMD5() const string& LauncherDialog::selectedRomMD5()
{ {
string extension;
int item = myList->getSelected(); int item = myList->getSelected();
if(item < 0 || myGameList->isDir(item) || if(item < 0)
!LauncherFilterDialog::isValidRomName(myGameList->name(item), extension)) return EmptyString;
string extension;
const FilesystemNode node(myGameList->path(item));
if(node.isDirectory() || !LauncherFilterDialog::isValidRomName(node, extension))
return EmptyString; return EmptyString;
// Make sure we have a valid md5 for this ROM // Make sure we have a valid md5 for this ROM
if(myGameList->md5(item) == "") if(myGameList->md5(item) == "")
{ {
const string& md5 = instance().MD5FromFile(myGameList->path(item)); const string& md5 = instance().MD5FromFile(node);
myGameList->setMd5(item, md5); myGameList->setMd5(item, md5);
} }
return myGameList->md5(item); return myGameList->md5(item);
@ -437,12 +440,12 @@ void LauncherDialog::loadRomInfo()
if(item < 0) return; if(item < 0) return;
string extension; string extension;
if(!myGameList->isDir(item) && const FilesystemNode node(myGameList->path(item));
LauncherFilterDialog::isValidRomName(myGameList->name(item), extension)) if(!node.isDirectory() && LauncherFilterDialog::isValidRomName(node, extension))
{ {
// Make sure we have a valid md5 for this ROM // Make sure we have a valid md5 for this ROM
if(myGameList->md5(item) == "") if(myGameList->md5(item) == "")
myGameList->setMd5(item, instance().MD5FromFile(myGameList->path(item))); myGameList->setMd5(item, instance().MD5FromFile(node));
// Get the properties for this entry // Get the properties for this entry
Properties props; Properties props;
@ -604,13 +607,9 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
int item = myList->getSelected(); int item = myList->getSelected();
if(item >= 0) if(item >= 0)
{ {
const string& rom = myGameList->path(item); const FilesystemNode romnode(myGameList->path(item));
const string& md5 = myGameList->md5(item);
string extension;
const FilesystemNode romnode(rom); int numFilesInArchive = -1;//filesInArchive(rom);
int numFilesInArchive = filesInArchive(rom);
bool isArchive = false;//!myGameList->isDir(item) && BSPF_endsWithIgnoreCase(rom, ".zip"); bool isArchive = false;//!myGameList->isDir(item) && BSPF_endsWithIgnoreCase(rom, ".zip");
// Directory's should be selected (ie, enter them and redisplay) // Directory's should be selected (ie, enter them and redisplay)
@ -638,9 +637,10 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
} }
else else
{ {
if(LauncherFilterDialog::isValidRomName(rom, extension)) string extension;
if(LauncherFilterDialog::isValidRomName(romnode, extension))
{ {
if(instance().createConsole(romnode.getPath(), md5)) if(instance().createConsole(romnode, myGameList->md5(item)))
instance().settings().setString("lastrom", myList->getSelectedString()); instance().settings().setString("lastrom", myList->getSelectedString());
else else
instance().frameBuffer().showMessage( instance().frameBuffer().showMessage(

View File

@ -144,8 +144,9 @@ bool LauncherFilterDialog::isValidRomName(const string& name,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool LauncherFilterDialog::isValidRomName(const string& name, string& ext) bool LauncherFilterDialog::isValidRomName(const FilesystemNode& node, string& ext)
{ {
const string& name = node.getPath();
string::size_type idx = name.find_last_of('.'); string::size_type idx = name.find_last_of('.');
if(idx != string::npos) if(idx != string::npos)
{ {

View File

@ -31,6 +31,7 @@ class OSystem;
class StringList; class StringList;
#include "Dialog.hxx" #include "Dialog.hxx"
#include "FSNode.hxx"
#include "Settings.hxx" #include "Settings.hxx"
#include "bspf.hxx" #include "bspf.hxx"
@ -55,10 +56,10 @@ class LauncherFilterDialog : public Dialog, public CommandSender
/** /**
Is this a valid ROM filename (does it have a valid extension?). Is this a valid ROM filename (does it have a valid extension?).
@param name Filename of potential ROM file @param name File node of potential ROM file
@param ext The extension extracted from the given file @param ext The extension extracted from the given file
*/ */
static bool isValidRomName(const string& name, string& ext); static bool isValidRomName(const FilesystemNode& name, string& ext);
private: private:
void loadConfig(); void loadConfig();

View File

@ -143,11 +143,11 @@ void RomAuditDialog::auditRoms()
{ {
string extension; string extension;
if(files[idx].isFile() && if(files[idx].isFile() &&
LauncherFilterDialog::isValidRomName(files[idx].getPath(), extension)) LauncherFilterDialog::isValidRomName(files[idx], extension))
{ {
// Calculate the MD5 so we can get the rest of the info // Calculate the MD5 so we can get the rest of the info
// from the PropertiesSet (stella.pro) // from the PropertiesSet (stella.pro)
const string& md5 = instance().MD5FromFile(files[idx].getPath()); const string& md5 = instance().MD5FromFile(files[idx]);
instance().propSet().getMD5(md5, props); instance().propSet().getMD5(md5, props);
const string& name = props.get(Cartridge_Name); const string& name = props.get(Cartridge_Name);