2005-05-10 19:20:45 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2010-01-10 02:58:28 +00:00
|
|
|
// Copyright (c) 1995-2010 by Bradford W. Mott and the Stella team
|
2005-05-10 19:20:45 +00:00
|
|
|
//
|
|
|
|
// See the file "license" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2005-05-10 19:20:45 +00:00
|
|
|
//
|
2005-05-11 01:44:39 +00:00
|
|
|
// Based on code from KStella - Stella frontend
|
|
|
|
// Copyright (C) 2003-2005 Stephen Anthony
|
2005-05-10 19:20:45 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2005-10-18 18:49:46 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2005-05-10 19:20:45 +00:00
|
|
|
#include "GameList.hxx"
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
GameList::GameList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
GameList::~GameList()
|
|
|
|
{
|
2006-03-10 00:29:46 +00:00
|
|
|
clear();
|
2005-05-10 19:20:45 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 01:44:39 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2006-03-09 00:29:52 +00:00
|
|
|
void GameList::appendGame(const string& name, const string& path,
|
2007-09-01 23:31:18 +00:00
|
|
|
const string& md5, bool isDir)
|
2005-05-11 01:44:39 +00:00
|
|
|
{
|
2006-04-12 13:32:06 +00:00
|
|
|
Entry g;
|
|
|
|
g._name = name;
|
|
|
|
g._path = path;
|
2007-09-01 23:31:18 +00:00
|
|
|
g._md5 = md5;
|
2006-04-12 13:32:06 +00:00
|
|
|
g._isdir = isDir;
|
2005-05-11 01:44:39 +00:00
|
|
|
|
|
|
|
myArray.push_back(g);
|
|
|
|
}
|
|
|
|
|
2005-05-10 19:20:45 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void GameList::sortByName()
|
|
|
|
{
|
2005-05-11 23:06:52 +00:00
|
|
|
if(myArray.size() <= 1)
|
|
|
|
return;
|
|
|
|
|
2006-04-12 13:32:06 +00:00
|
|
|
sort(myArray.begin(), myArray.end());
|
2006-03-10 00:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2006-04-12 13:32:06 +00:00
|
|
|
bool GameList::Entry::operator< (const Entry& g) const
|
2006-03-10 00:29:46 +00:00
|
|
|
{
|
2006-04-12 13:32:06 +00:00
|
|
|
string::const_iterator it1 = _name.begin();
|
|
|
|
string::const_iterator it2 = g._name.begin();
|
2006-03-10 00:29:46 +00:00
|
|
|
|
2006-04-12 13:32:06 +00:00
|
|
|
// Account for ending ']' character in directory entries
|
|
|
|
string::const_iterator end1 = _isdir ? _name.end() - 1 : _name.end();
|
|
|
|
string::const_iterator end2 = g._isdir ? g._name.end() - 1 : g._name.end();
|
2006-03-10 00:29:46 +00:00
|
|
|
|
|
|
|
// Stop when either string's end has been reached
|
2006-04-12 13:32:06 +00:00
|
|
|
while((it1 != end1) && (it2 != end2))
|
2006-03-10 00:29:46 +00:00
|
|
|
{
|
2006-04-12 13:32:06 +00:00
|
|
|
if(toupper(*it1) != toupper(*it2)) // letters differ?
|
|
|
|
return toupper(*it1) < toupper(*it2);
|
2006-03-10 00:29:46 +00:00
|
|
|
|
|
|
|
// proceed to the next character in each string
|
|
|
|
++it1;
|
|
|
|
++it2;
|
|
|
|
}
|
2006-04-12 13:32:06 +00:00
|
|
|
return _name.size() < g._name.size();
|
2005-05-10 19:20:45 +00:00
|
|
|
}
|