Added infrastructure for 'ROM browser' mode, which is an alternative to

the current ROM launcher functionality.  When in this mode, the ROM
launcher listing will act as a filesystem browser; activating folders
(which are now indicated by surrounding '[]' characters) will enter the
folder, and activating ROMs will start playing the ROM.  The major
difference in this new mode (vs. the current one) is that ROMs will
not be renamed according to their MD5SUM, but will be listed with
their real names (as they exist in the filesystem).


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1024 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-03-08 20:03:03 +00:00
parent df350864d0
commit 7ab6afbd74
6 changed files with 110 additions and 55 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FSNode.cxx,v 1.3 2005-06-16 00:55:58 stephena Exp $ // $Id: FSNode.cxx,v 1.4 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -31,8 +31,10 @@ void FSList::sort()
{ {
Int32 min = i; Int32 min = i;
for (Int32 j = i+1; j < _size; j++) for (Int32 j = i+1; j < _size; j++)
{
if (_data[j] < _data[min]) if (_data[j] < _data[min])
min = j; min = j;
}
if (min != i) if (min != i)
SWAP(_data[min], _data[i]); SWAP(_data[min], _data[i]);
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: BrowserDialog.cxx,v 1.14 2006-02-22 17:38:04 stephena Exp $ // $Id: BrowserDialog.cxx,v 1.15 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -168,7 +168,12 @@ void BrowserDialog::updateListing()
StringList list; StringList list;
int size = _nodeContent.size(); int size = _nodeContent.size();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{
if(_nodeContent[i].isDirectory())
list.push_back(" [" + _nodeContent[i].displayName() + "]");
else
list.push_back(_nodeContent[i].displayName()); list.push_back(_nodeContent[i].displayName());
}
_fileList->setList(list); _fileList->setList(list);
if(size > 0) if(size > 0)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: GameList.cxx,v 1.6 2005-10-18 18:49:46 stephena Exp $ // $Id: GameList.cxx,v 1.7 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from KStella - Stella frontend // Based on code from KStella - Stella frontend
// Copyright (C) 2003-2005 Stephen Anthony // Copyright (C) 2003-2005 Stephen Anthony
@ -38,12 +38,13 @@ GameList::~GameList()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameList::appendGame(const string& rom, const string& name, void GameList::appendGame(const string& rom, const string& name,
const string& note) const string& note, bool isDir)
{ {
Entry g; Entry g;
g._rom = rom; g._rom = rom;
g._name = name; g._name = name;
g._note = note; g._note = note;
g._isdir = isDir;
myArray.push_back(g); myArray.push_back(g);
} }
@ -68,8 +69,8 @@ void GameList::sortByName()
if (atJ < atMin) if (atJ < atMin)
min = j; min = j;
}
if (min != i) if (min != i)
SWAP(myArray[min], myArray[i]); SWAP(myArray[min], myArray[i]);
} }
} }
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: GameList.hxx,v 1.7 2005-12-09 01:16:13 stephena Exp $ // $Id: GameList.hxx,v 1.8 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from KStella - Stella frontend // Based on code from KStella - Stella frontend
// Copyright (C) 2003-2005 Stephen Anthony // Copyright (C) 2003-2005 Stephen Anthony
@ -35,6 +35,7 @@ class GameList
string _rom; string _rom;
string _name; string _name;
string _note; string _note;
bool _isdir;
}; };
typedef Common::Array<Entry> EntryList; typedef Common::Array<Entry> EntryList;
@ -47,10 +48,12 @@ class GameList
inline const string& rom(int i) { return myArray[i]._rom; } inline const string& rom(int i) { return myArray[i]._rom; }
inline const string& name(int i) { return myArray[i]._name; } inline const string& name(int i) { return myArray[i]._name; }
inline const string& note(int i) { return myArray[i]._note; } inline const string& note(int i) { return myArray[i]._note; }
inline const bool isDir(int i) { return myArray[i]._isdir; }
inline int size() { return myArray.size(); } inline int size() { return myArray.size(); }
void clear() { myArray.clear(); } void clear() { myArray.clear(); }
void appendGame(const string& rom, const string& name, const string& note); void appendGame(const string& rom, const string& name, const string& note,
bool isDir = false);
void sortByName(); void sortByName();
}; };

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: LauncherDialog.cxx,v 1.42 2006-03-07 18:56:36 stephena Exp $ // $Id: LauncherDialog.cxx,v 1.43 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -51,7 +51,9 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
myList(NULL), myList(NULL),
myGameList(NULL), myGameList(NULL),
myProgressBar(NULL), myProgressBar(NULL),
mySelectedItem(0) mySelectedItem(0),
myBrowseModeFlag(false),
myCurrentDir("")
{ {
const GUI::Font& font = instance()->launcherFont(); const GUI::Font& font = instance()->launcherFont();
@ -135,7 +137,7 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
wid.push_back(myReloadButton); wid.push_back(myReloadButton);
xpos += bwidth + 8; xpos += bwidth + 8;
myStartButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, myStartButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight,
"Start", kStartCmd, 'Q'); "Play", kStartCmd, 'Q');
myStartButton->setEditable(true); myStartButton->setEditable(true);
wid.push_back(myStartButton); wid.push_back(myStartButton);
xpos += bwidth + 8; xpos += bwidth + 8;
@ -203,22 +205,30 @@ void LauncherDialog::updateListing(bool fullReload)
return; return;
} }
// If in ROM browse mode, just load the current directory and
// don't translate by md5sum at all
if(myBrowseModeFlag)
{
if(myCurrentDir == "")
myCurrentDir = romdir;
loadDirListing(myCurrentDir);
}
else
{
// Figure out if the ROM dir has changed since we last accessed it. // Figure out if the ROM dir has changed since we last accessed it.
// If so, we do a full reload from disk (takes quite some time). // If so, we do a full reload from disk (takes quite some time).
// Otherwise, we can use the cache file (which is much faster). // Otherwise, we can use the cache file (which is much faster).
string currentModTime = FilesystemNode::modTime(romdir); string currentModTime = FilesystemNode::modTime(romdir);
string oldModTime = instance()->settings().getString("modtime"); string oldModTime = instance()->settings().getString("modtime");
/*
cerr << "old: \'" << oldModTime << "\'\n"
<< "current: \'" << currentModTime << "\'\n"
<< endl;
*/
if(currentModTime != oldModTime) // romdir has changed if(currentModTime != oldModTime) // romdir has changed
loadListFromDisk(); loadListFromDisk();
else if(FilesystemNode::fileExists(cacheFile) && !fullReload) else if(FilesystemNode::fileExists(cacheFile) && !fullReload)
loadListFromCache(); loadListFromCache();
else // we have no other choice else // we have no other choice
loadListFromDisk(); loadListFromDisk();
}
// Now fill the list widget with the contents of the GameList // Now fill the list widget with the contents of the GameList
StringList l; StringList l;
@ -236,6 +246,10 @@ cerr << "old: \'" << oldModTime << "\'\n"
// Restore last selection // Restore last selection
if(!myList->getList().isEmpty()) if(!myList->getList().isEmpty())
{
if(myBrowseModeFlag)
myList->setSelected(0);
else
{ {
string lastrom = instance()->settings().getString("lastrom"); string lastrom = instance()->settings().getString("lastrom");
if(lastrom == "") if(lastrom == "")
@ -258,13 +272,36 @@ cerr << "old: \'" << oldModTime << "\'\n"
} }
} }
} }
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::loadDirListing(const string& path)
{
cerr << "browse path = " << path << endl;
FilesystemNode dir(path);
FSList files = dir.listDir(FilesystemNode::kListAll);
for(unsigned int idx = 0; idx < files.size(); idx++)
{
string name = files[idx].displayName();
bool isDir = files[idx].isDirectory();
if(isDir)
name = " [" + name + "]";
myGameList->appendGame(files[idx].path(), name, "", isDir);
}
// Sort the list by rom name (since that's what we see in the listview)
myGameList->sortByName();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::loadListFromDisk() void LauncherDialog::loadListFromDisk()
{ {
string romdir = instance()->settings().getString("romdir"); string romdir = instance()->settings().getString("romdir");
FilesystemNode dir(romdir); FilesystemNode dir(romdir);
FSList files = dir.listDir(FilesystemNode::kListAll); FSList files = dir.listDir(FilesystemNode::kListFilesOnly);
// Create a progress dialog box to show the progress of processing // Create a progress dialog box to show the progress of processing
// the ROMs, since this is usually a time-consuming operation // the ROMs, since this is usually a time-consuming operation
@ -452,13 +489,17 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
item = myList->getSelected(); item = myList->getSelected();
if(item >= 0) if(item >= 0)
{ {
string s = myList->getSelectedString(); // Directory's should be selected (ie, enter them and redisplay)
if(myBrowseModeFlag && myGameList->isDir(item))
// Make sure the console creation actually succeeded {
if(instance()->createConsole(myGameList->rom(item))) cerr << "enter \'" << myGameList->rom(item) << "\' directory\n";
}
else if(instance()->createConsole(myGameList->rom(item)))
{ {
#if !defined(GP2X) // Quick GP2X hack to spare flash-card saves #if !defined(GP2X) // Quick GP2X hack to spare flash-card saves
instance()->settings().setString("lastrom", s); // Make sure the console creation actually succeeded
string selected = myList->getSelectedString();
instance()->settings().setString("lastrom", selected);
#endif #endif
close(); close();
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: LauncherDialog.hxx,v 1.14 2006-01-04 01:24:17 stephena Exp $ // $Id: LauncherDialog.hxx,v 1.15 2006-03-08 20:03:03 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -75,6 +75,7 @@ class LauncherDialog : public Dialog
private: private:
void enableButtons(bool enable); void enableButtons(bool enable);
void loadDirListing(const string& path);
void loadListFromDisk(); void loadListFromDisk();
void loadListFromCache(); void loadListFromCache();
void createListCache(); void createListCache();
@ -82,6 +83,8 @@ class LauncherDialog : public Dialog
private: private:
int mySelectedItem; int mySelectedItem;
bool myBrowseModeFlag;
string myCurrentDir;
enum { enum {
kStartCmd = 'STRT', kStartCmd = 'STRT',