diff --git a/stella/src/emucore/Settings.cxx b/stella/src/emucore/Settings.cxx index 093e4aade..4be76f5a5 100644 --- a/stella/src/emucore/Settings.cxx +++ b/stella/src/emucore/Settings.cxx @@ -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.133 2008-03-03 18:54:51 stephena Exp $ +// $Id: Settings.cxx,v 1.134 2008-03-12 19:42:36 stephena Exp $ //============================================================================ #include @@ -86,8 +86,6 @@ Settings::Settings(OSystem* osystem) setInternal("propsfile", ""); // ROM browser options - setInternal("rombrowse", "true"); - setInternal("lastrom", ""); setInternal("romviewer", "false"); // UI-related options @@ -316,7 +314,6 @@ void Settings::usage() << " -pspeed Speed of digital emulated paddle movement (1-15)\n" << " -sa1 Stelladaptor 1 emulates specified joystick port\n" << " -sa2 Stelladaptor 2 emulates specified joystick port\n" - << " -rombrowse <1|0> Use ROM browser mode (shows files and folders)\n" << " -romviewer <1|0> Show ROM info viewer in ROM launcher\n" << " -autoslot <1|0> Automatically switch to next save slot when state saving\n" << " -ssdir The directory to save snapshot files to\n" diff --git a/stella/src/gui/FileSnapDialog.cxx b/stella/src/gui/FileSnapDialog.cxx index 2c231a64a..5b213cf9b 100644 --- a/stella/src/gui/FileSnapDialog.cxx +++ b/stella/src/gui/FileSnapDialog.cxx @@ -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: FileSnapDialog.cxx,v 1.14 2008-02-06 13:45:23 stephena Exp $ +// $Id: FileSnapDialog.cxx,v 1.15 2008-03-12 19:42:36 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -110,23 +110,8 @@ FileSnapDialog::FileSnapDialog( _w - xpos - 10, font.getLineHeight(), ""); wid.push_back(mySnapPath); - // Use ROM browse mode - xpos = 30; ypos += mySnapPath->getHeight() + 8; - myBrowseCheckbox = - new CheckboxWidget(this, font, xpos, ypos, "Browse folders", kBrowseDirCmd); - wid.push_back(myBrowseCheckbox); - - // Reload current ROM listing (in non-browse mode) - xpos += myBrowseCheckbox->getWidth() + 20; - myReloadRomButton = - new ButtonWidget(this, font, xpos, ypos-2, - font.getStringWidth(" Reload ROM Listing "), bheight, - "Reload ROM Listing", kReloadRomDirCmd); - //myReloadButton->setEditable(true); - wid.push_back(myReloadRomButton); - // Snapshot single or multiple saves - xpos = 30; ypos += myBrowseCheckbox->getHeight() + 4; + xpos = 30; ypos += b->getHeight() + 5; mySnapSingleCheckbox = new CheckboxWidget(this, font, xpos, ypos, "Multiple snapshots"); wid.push_back(mySnapSingleCheckbox); @@ -157,8 +142,6 @@ FileSnapDialog::FileSnapDialog( { romButton->clearFlags(WIDGET_ENABLED); myRomPath->setEditable(false); - myBrowseCheckbox->clearFlags(WIDGET_ENABLED); - myReloadRomButton->clearFlags(WIDGET_ENABLED); } // Create file browser dialog @@ -180,9 +163,6 @@ void FileSnapDialog::loadConfig() myPaletteFile->setEditString(instance()->paletteFile()); myPropsFile->setEditString(instance()->propertiesFile()); mySnapPath->setEditString(instance()->settings().getString("ssdir")); - bool b = instance()->settings().getBool("rombrowse"); - myBrowseCheckbox->setState(b); - myReloadRomButton->setEnabled(myIsGlobal && !b); mySnapSingleCheckbox->setState(!instance()->settings().getBool("sssingle")); } @@ -195,7 +175,6 @@ void FileSnapDialog::saveConfig() instance()->settings().setString("palettefile", myPaletteFile->getEditString()); instance()->settings().setString("propsfile", myPropsFile->getEditString()); instance()->settings().setString("ssdir", mySnapPath->getEditString()); - instance()->settings().setBool("rombrowse", myBrowseCheckbox->getState()); instance()->settings().setBool("sssingle", !mySnapSingleCheckbox->getState()); // Flush changes to disk and inform the OSystem @@ -212,6 +191,7 @@ void FileSnapDialog::setDefaults() const string& cheatfile = basedir + BSPF_PATH_SEPARATOR + "stella.cht"; const string& palettefile = basedir + BSPF_PATH_SEPARATOR + "stella.pal"; const string& propsfile = basedir + BSPF_PATH_SEPARATOR + "stella.pro"; + const string& ssdir = basedir + BSPF_PATH_SEPARATOR; myRomPath->setEditString(romdir); myStatePath->setEditString(statedir); @@ -219,7 +199,7 @@ void FileSnapDialog::setDefaults() myPaletteFile->setEditString(palettefile); myPropsFile->setEditString(propsfile); - mySnapPath->setEditString(string(".") + BSPF_PATH_SEPARATOR); + mySnapPath->setEditString(ssdir); mySnapSingleCheckbox->setState(true); } @@ -244,10 +224,7 @@ void FileSnapDialog::handleCommand(CommandSender* sender, int cmd, saveConfig(); close(); if(myIsGlobal) - { - sendCommand(kBrowseChangedCmd, 0, 0); // Call this before refreshing ROMs sendCommand(kRomDirChosenCmd, 0, 0); // Let the boss know romdir has changed - } break; case kDefaultsCmd: diff --git a/stella/src/gui/FileSnapDialog.hxx b/stella/src/gui/FileSnapDialog.hxx index 17bc455db..5034cca7a 100644 --- a/stella/src/gui/FileSnapDialog.hxx +++ b/stella/src/gui/FileSnapDialog.hxx @@ -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: FileSnapDialog.hxx,v 1.9 2008-02-06 13:45:23 stephena Exp $ +// $Id: FileSnapDialog.hxx,v 1.10 2008-03-12 19:42:36 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -60,7 +60,6 @@ class FileSnapDialog : public Dialog, public CommandSender kChoosePaletteFileCmd = 'LOpf', // palette file (stella.pal) kChoosePropsFileCmd = 'LOpr', // properties file (stella.pro) kChooseSnapDirCmd = 'LOsn', // snapshot dir - kBrowseDirCmd = 'LObd', // browse mode kStateDirChosenCmd = 'LOsc', // state dir changed kCheatFileChosenCmd = 'LOcc', // cheatfile changed kPaletteFileChosenCmd = 'LOpc', // palette file changed @@ -78,9 +77,6 @@ class FileSnapDialog : public Dialog, public CommandSender EditTextWidget* mySnapPath; CheckboxWidget* mySnapSingleCheckbox; - CheckboxWidget* myBrowseCheckbox; - ButtonWidget* myReloadRomButton; - // Indicates if this dialog is used for global (vs. in-game) settings bool myIsGlobal; }; diff --git a/stella/src/gui/LauncherDialog.cxx b/stella/src/gui/LauncherDialog.cxx index 4f21be43f..2db85747d 100644 --- a/stella/src/gui/LauncherDialog.cxx +++ b/stella/src/gui/LauncherDialog.cxx @@ -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: LauncherDialog.cxx,v 1.76 2008-02-06 13:45:24 stephena Exp $ +// $Id: LauncherDialog.cxx,v 1.77 2008-03-12 19:42:36 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -55,7 +55,6 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, myProgressBar(NULL), myRomInfoWidget(NULL), mySelectedItem(0), - myBrowseModeFlag(true), myRomInfoFlag(false) { const GUI::Font& font = instance()->launcherFont(); @@ -109,15 +108,15 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent, xpos = 10; xpos += 5; ypos += myList->getHeight() + 4; lwidth = font.getStringWidth("Note:"); - myNoteLabel = new StaticTextWidget(this, font, xpos, ypos, lwidth, fontHeight, - "Note:", kTextAlignLeft); + myDirLabel = new StaticTextWidget(this, font, xpos, ypos, lwidth, fontHeight, + "Dir:", kTextAlignLeft); xpos += lwidth + 5; - myNote = new StaticTextWidget(this, font, xpos, ypos, + myDir = new StaticTextWidget(this, font, xpos, ypos, _w - xpos - 10, fontHeight, "", kTextAlignLeft); // Add four buttons at the bottom - xpos = 10; ypos += myNote->getHeight() + 4; + xpos = 10; ypos += myDir->getHeight() + 4; #ifndef MAC_OSX myStartButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Select", kStartCmd); @@ -179,9 +178,6 @@ string LauncherDialog::selectedRomMD5(string& file) if(item < 0 || myGameList->isDir(item)) return ""; -FilesystemNode node(myGameList->path(item)); -file = node.displayName(); - // Make sure we have a valid md5 for this ROM if(myGameList->md5(item) == "") { @@ -200,10 +196,7 @@ void LauncherDialog::loadConfig() // has been called (and we should reload the list). if(myList->getList().isEmpty()) { - // (De)activate browse mode - myBrowseModeFlag = instance()->settings().getBool("rombrowse"); - myPrevDirButton->setEnabled(myBrowseModeFlag); - myNoteLabel->setLabel(myBrowseModeFlag ? "Dir:" : "Note:"); + myPrevDirButton->setEnabled(false); myCurrentNode = instance()->settings().getString("romdir"); updateListing(); @@ -215,7 +208,7 @@ void LauncherDialog::loadConfig() void LauncherDialog::enableButtons(bool enable) { myStartButton->setEnabled(enable); - myPrevDirButton->setEnabled(enable && myBrowseModeFlag); + myPrevDirButton->setEnabled(enable); myOptionsButton->setEnabled(enable); myQuitButton->setEnabled(enable); } @@ -225,35 +218,16 @@ void LauncherDialog::updateListing(bool fullReload) { // Start with empty list myGameList->clear(); - myNote->setLabel(""); + myDir->setLabel(""); string romdir = instance()->settings().getString("romdir"); + loadDirListing(); - // If in ROM browse mode, just load the current directory and - // don't translate by md5sum at all - if(myBrowseModeFlag) - { - loadDirListing(); + // Only hilite the 'up' button if there's a parent directory + myPrevDirButton->setEnabled(myCurrentNode.hasParent()); - // Only hilite the 'up' button if there's a parent directory - myPrevDirButton->setEnabled(myCurrentNode.hasParent()); - - // Show current directory - myNote->setLabel(myCurrentNode.path()); - } - else - { - // Disable buttons, pending a reload from disk - enableButtons(false); - - if(FilesystemNode::fileExists(instance()->cacheFile()) && !fullReload) - loadListFromCache(); - else // we have no other choice - loadListFromDisk(); - - // Re-enable buttons - enableButtons(true); - } + // Show current directory + myDir->setLabel(myCurrentNode.path()); // Now fill the list widget with the contents of the GameList StringList l; @@ -264,40 +238,10 @@ void LauncherDialog::updateListing(bool fullReload) // Indicate how many files were found ostringstream buf; - buf << (myBrowseModeFlag ? myGameList->size() -1 : myGameList->size()) - << " items found"; + buf << (myGameList->size() - 1) << " items found"; myRomCount->setLabel(buf.str()); - // Restore last selection - if(!myList->getList().isEmpty()) - { - if(myBrowseModeFlag) - myList->setSelected(0); - else - { - string lastrom = instance()->settings().getString("lastrom"); - if(lastrom == "") - myList->setSelected(0); - else - { - unsigned int itemToSelect = 0; - StringList::const_iterator iter; - for (iter = myList->getList().begin(); iter != myList->getList().end(); - ++iter, ++itemToSelect) - { - if (lastrom == *iter) - { - myList->setSelected(itemToSelect); - break; - } - } - if(itemToSelect > myList->getList().size()) - myList->setSelected(0); - } - } - } - else - myList->setSelected(-1); // redraw the empty list + myList->setSelected(myList->getList().isEmpty() ? -1 : 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -327,6 +271,7 @@ void LauncherDialog::loadDirListing() myGameList->sortByName(); } +/* // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::loadListFromDisk() { @@ -421,34 +366,30 @@ void LauncherDialog::createListCache() } out.close(); } +*/ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::loadRomInfo() { + if(!myRomInfoFlag) return; int item = myList->getSelected(); - if(item < 0) return; + if(item < 0 || myGameList->isDir(item)) return; - if(myGameList->isDir(item)) + if(isValidRomName(myGameList->name(item))) { - if(myRomInfoFlag) - myRomInfoWidget->clearInfo(); - return; - } + // Make sure we have a valid md5 for this ROM + if(myGameList->md5(item) == "") + myGameList->setMd5(item, MD5FromFile(myGameList->path(item))); - // Make sure we have a valid md5 for this ROM - if(myGameList->md5(item) == "") - myGameList->setMd5(item, MD5FromFile(myGameList->path(item))); + // Get the properties for this entry + Properties props; + const string& md5 = myGameList->md5(item); + instance()->propSet().getMD5(md5, props); - // Get the properties for this entry - Properties props; - const string& md5 = myGameList->md5(item); - instance()->propSet().getMD5(md5, props); - - if(!myBrowseModeFlag) - myNote->setLabel(props.get(Cartridge_Note)); - - if(myRomInfoFlag) myRomInfoWidget->showInfo(props); + } + else + myRomInfoWidget->clearInfo(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -465,6 +406,22 @@ string LauncherDialog::MD5FromFile(const string& path) return md5; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool LauncherDialog::isValidRomName(const string& filename) +{ + string::size_type idx = filename.find_last_of('.'); + if(idx != string::npos) + { + string ext = filename.substr(idx+1); + return BSPF_strncasecmp(ext.c_str(), "bin", 3) == 0 || + BSPF_strncasecmp(ext.c_str(), "a26", 3) == 0 || + BSPF_strncasecmp(ext.c_str(), "zip", 3) == 0 || + BSPF_strncasecmp(ext.c_str(), "rom", 3) == 0 || + BSPF_strncasecmp(ext.c_str(), "gz", 2) == 0 ; + } + return false; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) @@ -482,7 +439,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, const string& md5 = myGameList->md5(item); // Directory's should be selected (ie, enter them and redisplay) - if(myBrowseModeFlag && myGameList->isDir(item)) + if(myGameList->isDir(item)) { if(myGameList->name(item) == " [..]") myCurrentNode = myCurrentNode.getParent(); @@ -490,11 +447,10 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, myCurrentNode = rom; updateListing(); } - else if(instance()->createConsole(rom, md5)) + else if(!isValidRomName(rom) || !instance()->createConsole(rom, md5)) { -#if !defined(GP2X) // Quick GP2X hack to spare flash-card saves - instance()->settings().setString("lastrom", myList->getSelectedString()); -#endif + // TODO - show messagebox that ROM couldn't be started + cerr << "Error: invalid ROM (name or file)\n"; } } break; @@ -506,7 +462,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, case kPrevDirCmd: myCurrentNode = myCurrentNode.getParent(); - updateListing(!myBrowseModeFlag); // Force full update in non-browse mode + updateListing(false); break; case kListSelectionChangedCmd: @@ -527,13 +483,6 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, // Stub just in case we need it break; - case kBrowseChangedCmd: - myCurrentNode = instance()->settings().getString("romdir"); - myBrowseModeFlag = instance()->settings().getBool("rombrowse"); - myPrevDirButton->setEnabled(myBrowseModeFlag); - myNoteLabel->setLabel(myBrowseModeFlag ? "Dir:" : "Note:"); - break; - case kReloadRomDirCmd: updateListing(true); break; diff --git a/stella/src/gui/LauncherDialog.hxx b/stella/src/gui/LauncherDialog.hxx index 19283f0a9..de398719b 100644 --- a/stella/src/gui/LauncherDialog.hxx +++ b/stella/src/gui/LauncherDialog.hxx @@ -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: LauncherDialog.hxx,v 1.31 2008-02-06 13:45:24 stephena Exp $ +// $Id: LauncherDialog.hxx,v 1.32 2008-03-12 19:42:36 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -44,7 +44,6 @@ class StringListWidget; enum { kRomDirChosenCmd = 'romc', // rom chosen kSnapDirChosenCmd = 'snpc', // snap chosen - kBrowseChangedCmd = 'broc', // browse mode toggled kReloadRomDirCmd = 'rdrl' // reload the current listing }; @@ -57,6 +56,13 @@ class LauncherDialog : public Dialog string selectedRomMD5(string& file); + /** + Is this a valid ROM filename (does it have a valid extension?) + + @param filename Filename of potential ROM file + */ + static bool isValidRomName(const string& filename); + protected: virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); @@ -70,8 +76,8 @@ class LauncherDialog : public Dialog ButtonWidget* myQuitButton; StringListWidget* myList; - StaticTextWidget* myNoteLabel; - StaticTextWidget* myNote; + StaticTextWidget* myDirLabel; + StaticTextWidget* myDir; StaticTextWidget* myRomCount; GameList* myGameList; @@ -83,15 +89,11 @@ class LauncherDialog : public Dialog private: void enableButtons(bool enable); void loadDirListing(); - void loadListFromDisk(); - void loadListFromCache(); - void createListCache(); void loadRomInfo(); string MD5FromFile(const string& path); private: int mySelectedItem; - bool myBrowseModeFlag; bool myRomInfoFlag; FilesystemNode myCurrentNode; diff --git a/stella/src/gui/OptionsDialog.cxx b/stella/src/gui/OptionsDialog.cxx index e023da8b1..3e1d4f345 100644 --- a/stella/src/gui/OptionsDialog.cxx +++ b/stella/src/gui/OptionsDialog.cxx @@ -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: OptionsDialog.cxx,v 1.62 2008-02-06 13:45:24 stephena Exp $ +// $Id: OptionsDialog.cxx,v 1.63 2008-03-12 19:42:36 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -126,7 +126,7 @@ OptionsDialog::OptionsDialog(OSystem* osystem, DialogContainer* parent, w = 200; h = 155; myUIDialog = new UIDialog(myOSystem, parent, font, x, y, w, h); - w = 280; h = 190; + w = 280; h = 180; myFileSnapDialog = new FileSnapDialog(myOSystem, parent, font, boss, x, y, w, h);