2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-22 15:27:53 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-22 15:27:53 +00:00
|
|
|
// FileSorts.cpp
|
|
|
|
//
|
|
|
|
// Gamelist sorting functions.
|
|
|
|
// Actual sorting takes place in FileData.
|
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "FileSorts.h"
|
|
|
|
|
2018-01-09 21:59:23 +00:00
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
namespace FileSorts
|
|
|
|
{
|
2020-06-22 15:27:53 +00:00
|
|
|
const FileData::SortType typesArr[] = {
|
|
|
|
FileData::SortType(&compareName, true, "filename, ascending"),
|
|
|
|
FileData::SortType(&compareName, false, "filename, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareRating, true, "rating, ascending"),
|
|
|
|
FileData::SortType(&compareRating, false, "rating, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareTimesPlayed, true, "times played, ascending"),
|
|
|
|
FileData::SortType(&compareTimesPlayed, false, "times played, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareLastPlayed, true, "last played, ascending"),
|
|
|
|
FileData::SortType(&compareLastPlayed, false, "last played, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareNumPlayers, true, "number players, ascending"),
|
|
|
|
FileData::SortType(&compareNumPlayers, false, "number players, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareReleaseDate, true, "release date, ascending"),
|
|
|
|
FileData::SortType(&compareReleaseDate, false, "release date, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareGenre, true, "genre, ascending"),
|
|
|
|
FileData::SortType(&compareGenre, false, "genre, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareDeveloper, true, "developer, ascending"),
|
|
|
|
FileData::SortType(&compareDeveloper, false, "developer, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&comparePublisher, true, "publisher, ascending"),
|
|
|
|
FileData::SortType(&comparePublisher, false, "publisher, descending"),
|
|
|
|
|
|
|
|
FileData::SortType(&compareSystem, true, "system, ascending"),
|
|
|
|
FileData::SortType(&compareSystem, false, "system, descending")
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::vector<FileData::SortType> SortTypes(typesArr, typesArr +
|
|
|
|
sizeof(typesArr)/sizeof(typesArr[0]));
|
|
|
|
|
|
|
|
// Returns if file1 should come before file2.
|
|
|
|
bool compareName(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
// We compare the actual metadata name, as collection files have the system
|
|
|
|
// appended which messes up the order.
|
|
|
|
std::string name1 = Utils::String::toUpper(file1->metadata.get("sortname"));
|
|
|
|
std::string name2 = Utils::String::toUpper(file2->metadata.get("sortname"));
|
2020-07-13 18:58:25 +00:00
|
|
|
if (name1.empty()){
|
2020-06-22 15:27:53 +00:00
|
|
|
name1 = Utils::String::toUpper(file1->metadata.get("name"));
|
|
|
|
}
|
2020-07-13 18:58:25 +00:00
|
|
|
if (name2.empty()){
|
2020-06-22 15:27:53 +00:00
|
|
|
name2 = Utils::String::toUpper(file2->metadata.get("name"));
|
|
|
|
}
|
|
|
|
return name1.compare(name2) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareRating(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
return file1->metadata.getFloat("rating") < file2->metadata.getFloat("rating");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareTimesPlayed(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
//only games have playcount metadata
|
2020-07-13 18:58:25 +00:00
|
|
|
if (file1->metadata.getType() == GAME_METADATA && file2->metadata.getType() == GAME_METADATA)
|
2020-06-22 15:27:53 +00:00
|
|
|
return (file1)->metadata.getInt("playcount") < (file2)->metadata.getInt("playcount");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareLastPlayed(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
// Since it's stored as an ISO string (YYYYMMDDTHHMMSS), we can compare as a string
|
|
|
|
// which is a lot faster than the time casts and the time comparisons.
|
|
|
|
return (file1)->metadata.get("lastplayed") < (file2)->metadata.get("lastplayed");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareNumPlayers(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
return (file1)->metadata.getInt("players") < (file2)->metadata.getInt("players");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareReleaseDate(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
// Since it's stored as an ISO string (YYYYMMDDTHHMMSS), we can compare as a string
|
|
|
|
// which is a lot faster than the time casts and the time comparisons.
|
|
|
|
return (file1)->metadata.get("releasedate") < (file2)->metadata.get("releasedate");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareGenre(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
std::string genre1 = Utils::String::toUpper(file1->metadata.get("genre"));
|
|
|
|
std::string genre2 = Utils::String::toUpper(file2->metadata.get("genre"));
|
|
|
|
return genre1.compare(genre2) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareDeveloper(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
std::string developer1 = Utils::String::toUpper(file1->metadata.get("developer"));
|
|
|
|
std::string developer2 = Utils::String::toUpper(file2->metadata.get("developer"));
|
|
|
|
return developer1.compare(developer2) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool comparePublisher(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
std::string publisher1 = Utils::String::toUpper(file1->metadata.get("publisher"));
|
|
|
|
std::string publisher2 = Utils::String::toUpper(file2->metadata.get("publisher"));
|
|
|
|
return publisher1.compare(publisher2) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareSystem(const FileData* file1, const FileData* file2)
|
|
|
|
{
|
|
|
|
std::string system1 = Utils::String::toUpper(file1->getSystemName());
|
|
|
|
std::string system2 = Utils::String::toUpper(file2->getSystemName());
|
|
|
|
return system1.compare(system2) < 0;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|