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
// 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
// Copyright (C) 2002-2004 The ScummVM project
@ -31,10 +31,12 @@ void FSList::sort()
{
Int32 min = i;
for (Int32 j = i+1; j < _size; j++)
{
if (_data[j] < _data[min])
min = j;
if (min != i)
SWAP(_data[min], _data[i]);
}
if (min != i)
SWAP(_data[min], _data[i]);
}
}

View File

@ -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: 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
// Copyright (C) 2002-2004 The ScummVM project
@ -168,7 +168,12 @@ void BrowserDialog::updateListing()
StringList list;
int size = _nodeContent.size();
for (int i = 0; i < size; i++)
list.push_back(_nodeContent[i].displayName());
{
if(_nodeContent[i].isDirectory())
list.push_back(" [" + _nodeContent[i].displayName() + "]");
else
list.push_back(_nodeContent[i].displayName());
}
_fileList->setList(list);
if(size > 0)

View File

@ -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: 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
// Copyright (C) 2003-2005 Stephen Anthony
@ -38,12 +38,13 @@ GameList::~GameList()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameList::appendGame(const string& rom, const string& name,
const string& note)
const string& note, bool isDir)
{
Entry g;
g._rom = rom;
g._name = name;
g._note = note;
g._rom = rom;
g._name = name;
g._note = note;
g._isdir = isDir;
myArray.push_back(g);
}
@ -55,7 +56,7 @@ void GameList::sortByName()
return;
// Simple selection sort
for(unsigned int i = 0; i < myArray.size()-1; i++)
for (unsigned int i = 0; i < myArray.size()-1; i++)
{
unsigned int min = i;
for (unsigned int j = i+1; j < myArray.size(); j++)
@ -68,8 +69,8 @@ void GameList::sortByName()
if (atJ < atMin)
min = j;
if (min != i)
SWAP(myArray[min], myArray[i]);
}
if (min != i)
SWAP(myArray[min], myArray[i]);
}
}

View File

@ -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: 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
// Copyright (C) 2003-2005 Stephen Anthony
@ -35,6 +35,7 @@ class GameList
string _rom;
string _name;
string _note;
bool _isdir;
};
typedef Common::Array<Entry> EntryList;
@ -47,10 +48,12 @@ class GameList
inline const string& rom(int i) { return myArray[i]._rom; }
inline const string& name(int i) { return myArray[i]._name; }
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(); }
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();
};

View File

@ -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.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
// Copyright (C) 2002-2004 The ScummVM project
@ -51,7 +51,9 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
myList(NULL),
myGameList(NULL),
myProgressBar(NULL),
mySelectedItem(0)
mySelectedItem(0),
myBrowseModeFlag(false),
myCurrentDir("")
{
const GUI::Font& font = instance()->launcherFont();
@ -135,7 +137,7 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
wid.push_back(myReloadButton);
xpos += bwidth + 8;
myStartButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight,
"Start", kStartCmd, 'Q');
"Play", kStartCmd, 'Q');
myStartButton->setEditable(true);
wid.push_back(myStartButton);
xpos += bwidth + 8;
@ -203,22 +205,30 @@ void LauncherDialog::updateListing(bool fullReload)
return;
}
// 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).
// Otherwise, we can use the cache file (which is much faster).
string currentModTime = FilesystemNode::modTime(romdir);
string oldModTime = instance()->settings().getString("modtime");
/*
cerr << "old: \'" << oldModTime << "\'\n"
<< "current: \'" << currentModTime << "\'\n"
<< endl;
*/
if(currentModTime != oldModTime) // romdir has changed
loadListFromDisk();
else if(FilesystemNode::fileExists(cacheFile) && !fullReload)
loadListFromCache();
else // we have no other choice
loadListFromDisk();
// 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.
// If so, we do a full reload from disk (takes quite some time).
// Otherwise, we can use the cache file (which is much faster).
string currentModTime = FilesystemNode::modTime(romdir);
string oldModTime = instance()->settings().getString("modtime");
if(currentModTime != oldModTime) // romdir has changed
loadListFromDisk();
else if(FilesystemNode::fileExists(cacheFile) && !fullReload)
loadListFromCache();
else // we have no other choice
loadListFromDisk();
}
// Now fill the list widget with the contents of the GameList
StringList l;
@ -237,34 +247,61 @@ cerr << "old: \'" << oldModTime << "\'\n"
// Restore last selection
if(!myList->getList().isEmpty())
{
string lastrom = instance()->settings().getString("lastrom");
if(lastrom == "")
if(myBrowseModeFlag)
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())
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);
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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()
{
string romdir = instance()->settings().getString("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
// the ROMs, since this is usually a time-consuming operation
@ -452,13 +489,17 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
item = myList->getSelected();
if(item >= 0)
{
string s = myList->getSelectedString();
// Make sure the console creation actually succeeded
if(instance()->createConsole(myGameList->rom(item)))
// Directory's should be selected (ie, enter them and redisplay)
if(myBrowseModeFlag && myGameList->isDir(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
instance()->settings().setString("lastrom", s);
// Make sure the console creation actually succeeded
string selected = myList->getSelectedString();
instance()->settings().setString("lastrom", selected);
#endif
close();
}

View File

@ -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.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
// Copyright (C) 2002-2004 The ScummVM project
@ -75,6 +75,7 @@ class LauncherDialog : public Dialog
private:
void enableButtons(bool enable);
void loadDirListing(const string& path);
void loadListFromDisk();
void loadListFromCache();
void createListCache();
@ -82,6 +83,8 @@ class LauncherDialog : public Dialog
private:
int mySelectedItem;
bool myBrowseModeFlag;
string myCurrentDir;
enum {
kStartCmd = 'STRT',