diff --git a/src/common/mainSDL.cxx b/src/common/mainSDL.cxx index 132277014..ca7231fde 100644 --- a/src/common/mainSDL.cxx +++ b/src/common/mainSDL.cxx @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) theOSystem->logMessage("Showing output from 'rominfo' ...", 2); FilesystemNode romnode(romfile); if(argc > 1 && romnode.exists() && romnode.isFile()) - theOSystem->logMessage(theOSystem->getROMInfo(romfile), 0); + theOSystem->logMessage(theOSystem->getROMInfo(romnode), 0); else theOSystem->logMessage("ERROR: ROM doesn't exist", 0); @@ -175,7 +175,7 @@ int main(int argc, char* argv[]) return Cleanup(); } } - else if(theOSystem->createConsole(romnode.getPath())) + else if(theOSystem->createConsole(romnode)) { if(theOSystem->settings().getBool("takesnapshot")) { diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 0c2cc14fa..174512dab 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -593,8 +593,7 @@ void EventHandler::poll(uInt64 time) break; case KBDK_r: // Ctrl-r reloads the currently loaded ROM - myOSystem->deleteConsole(); - myOSystem->createConsole(); + myOSystem->reloadConsole(); break; case KBDK_PAGEUP: // Ctrl-PageUp increases Height diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 8931f889c..e6712b1e4 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -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; @@ -512,19 +512,14 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum) bool showmessage = false; - // If a blank ROM has been given, we reload the current one (assuming one exists) - if(romfile == "") + // If same ROM has been given, we reload the current one (assuming one exists) + if(rom == myRomFile) { showmessage = true; // we show a message if a ROM is being reloaded - if(myRomFile == "") - { - logMessage("ERROR: Rom file not specified ...", 0); - return false; - } } else { - myRomFile = romfile; + myRomFile = rom; myRomMD5 = md5sum; // 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); } buf << "Game console created:" << endl - << " ROM file: " << FilesystemNode(myRomFile).getShortPath() << endl << endl + << " ROM file: " << myRomFile.getShortPath() << endl << endl << getROMInfo(myConsole) << endl; logMessage(buf.str(), 1); @@ -590,7 +585,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum) } else { - buf << "ERROR: Couldn't create console for " << myRomFile << endl; + buf << "ERROR: Couldn't create console for " << myRomFile.getShortPath() << endl; logMessage(buf.str(), 0); return false; } @@ -620,6 +615,13 @@ void OSystem::deleteConsole() } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool OSystem::reloadConsole() +{ + deleteConsole(); + return createConsole(myRomFile); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 = ""; Console* console = openConsole(romfile, md5, type, id); @@ -655,19 +657,19 @@ string OSystem::getROMInfo(const string& romfile) delete console; } else - result = "ERROR: Couldn't get ROM info for " + romfile + " ..."; + result = "ERROR: Couldn't get ROM info for " + romfile.getShortPath() + " ..."; return result; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystem::MD5FromFile(const string& filename) +string OSystem::MD5FromFile(const FilesystemNode& file) { string md5 = ""; uInt8* image = 0; uInt32 size = 0; - if((image = openROM(filename, md5, size)) != 0) + if((image = openROM(file, md5, size)) != 0) if(image != 0 && size > 0) 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) { #define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \ @@ -757,7 +759,7 @@ Console* OSystem::openConsole(const string& romfile, string& md5, else { ostringstream buf; - buf << "ERROR: Couldn't open \'" << romfile << "\'" << endl; + buf << "ERROR: Couldn't open \'" << romfile.getShortPath() << "\'" << endl; 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: // 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; +// FIXME - this entire code to be replaced by romfile.read(...) +#if 0 // First try to load as ZIP archive if(loadFromZIP(file, &image, size)) { @@ -787,9 +791,10 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size) return image; } else +#endif { // 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) return image; @@ -817,12 +822,8 @@ uInt8* OSystem::openROM(string file, string& md5, uInt32& size) Properties 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_Name, file); + props.set(Cartridge_Name, romfile.getName()); myPropSet->insert(props, false); } diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index c4276d1d5..97225d20c 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -40,6 +40,7 @@ namespace GUI { } #include "Array.hxx" +#include "FSNode.hxx" #include "FrameBuffer.hxx" #include "PNGLibrary.hxx" #include "ZipHandler.hxx" @@ -363,18 +364,18 @@ class OSystem @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 initializes the system state to start emulation of the Console. - @param romfile The full pathname of the ROM to use - @param md5 The MD5sum of the ROM + @param rom The FSNode of the ROM to use (contains path, etc) + @param md5 The MD5sum of the ROM @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. @@ -382,6 +383,14 @@ class OSystem */ 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. @@ -404,10 +413,10 @@ class OSystem Gets all possible info about the ROM by creating a temporary 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 */ - string getROMInfo(const string& romfile); + string getROMInfo(const FilesystemNode& romfile); /** The features which are conditionally compiled into Stella. @@ -426,9 +435,9 @@ class OSystem /** 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. @@ -617,7 +626,7 @@ class OSystem string myPaletteFile; string myPropertiesFile; - string myRomFile; + FilesystemNode myRomFile; string myRomMD5; string myFeatures; @@ -666,7 +675,7 @@ class OSystem /** 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 type The bankswitch type of 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 (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. Also, the properties database is updated with a valid ROM name 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 (will be recalculated if necessary) @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 (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 diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index 5ae23e745..0277cddd1 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -177,8 +177,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd, case kReloadRomCmd: instance().eventHandler().leaveMenuMode(); - instance().deleteConsole(); - instance().createConsole(); + instance().reloadConsole(); break; case kExitCmd: diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 5821039b4..bd5a98408 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -215,16 +215,19 @@ LauncherDialog::~LauncherDialog() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& LauncherDialog::selectedRomMD5() { - string extension; int item = myList->getSelected(); - if(item < 0 || myGameList->isDir(item) || - !LauncherFilterDialog::isValidRomName(myGameList->name(item), extension)) + if(item < 0) + return EmptyString; + + string extension; + const FilesystemNode node(myGameList->path(item)); + if(node.isDirectory() || !LauncherFilterDialog::isValidRomName(node, extension)) return EmptyString; // Make sure we have a valid md5 for this ROM if(myGameList->md5(item) == "") { - const string& md5 = instance().MD5FromFile(myGameList->path(item)); + const string& md5 = instance().MD5FromFile(node); myGameList->setMd5(item, md5); } return myGameList->md5(item); @@ -437,12 +440,12 @@ void LauncherDialog::loadRomInfo() if(item < 0) return; string extension; - if(!myGameList->isDir(item) && - LauncherFilterDialog::isValidRomName(myGameList->name(item), extension)) + const FilesystemNode node(myGameList->path(item)); + if(!node.isDirectory() && LauncherFilterDialog::isValidRomName(node, extension)) { // Make sure we have a valid md5 for this ROM if(myGameList->md5(item) == "") - myGameList->setMd5(item, instance().MD5FromFile(myGameList->path(item))); + myGameList->setMd5(item, instance().MD5FromFile(node)); // Get the properties for this entry Properties props; @@ -604,13 +607,9 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, int item = myList->getSelected(); if(item >= 0) { - const string& rom = myGameList->path(item); - const string& md5 = myGameList->md5(item); - string extension; + const FilesystemNode romnode(myGameList->path(item)); - const FilesystemNode romnode(rom); - - int numFilesInArchive = filesInArchive(rom); + int numFilesInArchive = -1;//filesInArchive(rom); bool isArchive = false;//!myGameList->isDir(item) && BSPF_endsWithIgnoreCase(rom, ".zip"); // Directory's should be selected (ie, enter them and redisplay) @@ -638,9 +637,10 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, } 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()); else instance().frameBuffer().showMessage( diff --git a/src/gui/LauncherFilterDialog.cxx b/src/gui/LauncherFilterDialog.cxx index 85147d377..6b64f70f6 100644 --- a/src/gui/LauncherFilterDialog.cxx +++ b/src/gui/LauncherFilterDialog.cxx @@ -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('.'); if(idx != string::npos) { diff --git a/src/gui/LauncherFilterDialog.hxx b/src/gui/LauncherFilterDialog.hxx index 613728b36..c52f50378 100644 --- a/src/gui/LauncherFilterDialog.hxx +++ b/src/gui/LauncherFilterDialog.hxx @@ -31,6 +31,7 @@ class OSystem; class StringList; #include "Dialog.hxx" +#include "FSNode.hxx" #include "Settings.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?). - @param name Filename of potential ROM file + @param name File node of potential ROM 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: void loadConfig(); diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index 397db3abe..e972d35d0 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -143,11 +143,11 @@ void RomAuditDialog::auditRoms() { string extension; 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 // 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); const string& name = props.get(Cartridge_Name);