2020-09-17 20:00:07 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-17 20:00:07 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// FileData.cpp
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Provides game file data structures and functions to access and sort this information.
|
|
|
|
// Also provides functions to look up paths to media files and for launching games
|
2020-08-19 20:17:32 +00:00
|
|
|
// (launching initiated in ViewController).
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "FileData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
#include "guis/GuiInfoPopup.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2017-11-29 19:57:43 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-22 21:01:12 +00:00
|
|
|
#include "utils/TimeUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "AudioManager.h"
|
|
|
|
#include "CollectionSystemManager.h"
|
|
|
|
#include "FileFilterIndex.h"
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "FileSorts.h"
|
|
|
|
#include "Log.h"
|
2018-02-09 17:23:58 +00:00
|
|
|
#include "MameNames.h"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
|
|
|
#include "VolumeControl.h"
|
|
|
|
#include "Window.h"
|
2020-07-07 19:25:15 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <assert.h>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
FileData::FileData(
|
2020-06-21 12:25:28 +00:00
|
|
|
FileType type,
|
|
|
|
const std::string& path,
|
|
|
|
SystemEnvironmentData* envData,
|
|
|
|
SystemData* system)
|
|
|
|
: mType(type),
|
|
|
|
mPath(path),
|
|
|
|
mSystem(system),
|
|
|
|
mEnvData(envData),
|
|
|
|
mSourceFileData(nullptr),
|
|
|
|
mParent(nullptr),
|
2020-07-28 17:44:17 +00:00
|
|
|
mOnlyFolders(false),
|
2020-07-13 18:13:48 +00:00
|
|
|
mDeletionFlag(false),
|
2020-09-17 20:00:07 +00:00
|
|
|
// Metadata is set in the constructor.
|
2020-06-21 12:25:28 +00:00
|
|
|
metadata(type == GAME ? GAME_METADATA : FOLDER_METADATA)
|
|
|
|
{
|
|
|
|
// Metadata needs at least a name field (since that's what getName() will return).
|
|
|
|
if (metadata.get("name").empty()) {
|
|
|
|
if ((system->hasPlatformId(PlatformIds::ARCADE) ||
|
|
|
|
system->hasPlatformId(PlatformIds::NEOGEO)) &&
|
|
|
|
metadata.getType() != FOLDER_METADATA) {
|
|
|
|
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
|
|
|
metadata.set("name",
|
|
|
|
MameNames::getInstance()->getCleanName(getCleanName()));
|
|
|
|
}
|
|
|
|
else {
|
2020-07-26 13:21:41 +00:00
|
|
|
if (metadata.getType() == FOLDER_METADATA && Utils::FileSystem::isHidden(mPath)) {
|
|
|
|
metadata.set("name", Utils::FileSystem::getFileName(mPath));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
metadata.set("name", getDisplayName());
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mSystemName = system->getName();
|
|
|
|
metadata.resetChangedFlag();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileData::~FileData()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mType == GAME)
|
|
|
|
mSystem->getIndex()->removeFromIndex(this);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-10-17 15:35:50 +00:00
|
|
|
while (mChildren.size() > 0)
|
|
|
|
delete (mChildren.front());
|
2020-10-18 17:14:34 +00:00
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
mParent->removeChild(this);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 15:33:19 +00:00
|
|
|
std::string FileData::getDisplayName() const
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string stem = Utils::FileSystem::getStem(mPath);
|
|
|
|
return stem;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 15:33:19 +00:00
|
|
|
std::string FileData::getCleanName() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return Utils::String::removeParenthesis(this->getDisplayName());
|
2016-03-29 15:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
const std::string& FileData::getName()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return metadata.get("name");
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:07:25 +00:00
|
|
|
const std::string& FileData::getSortName()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (metadata.get("sortname").empty())
|
|
|
|
return metadata.get("name");
|
|
|
|
else
|
|
|
|
return metadata.get("sortname");
|
2018-04-25 05:07:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 15:42:36 +00:00
|
|
|
const bool FileData::getFavorite()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (metadata.get("favorite") == "true")
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2020-05-15 15:42:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 20:19:29 +00:00
|
|
|
const bool FileData::getHidden()
|
|
|
|
{
|
|
|
|
if (metadata.get("hidden") == "true")
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-29 17:01:49 +00:00
|
|
|
const bool FileData::getCountAsGame()
|
|
|
|
{
|
2020-08-06 09:27:16 +00:00
|
|
|
if (metadata.get("nogamecount") == "true")
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool FileData::getExcludeFromScraper()
|
|
|
|
{
|
|
|
|
if (metadata.get("nomultiscrape") == "true")
|
2020-07-29 17:01:49 +00:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-28 13:19:54 +00:00
|
|
|
const std::vector<FileData*> FileData::getChildrenRecursive() const
|
2020-07-26 20:19:29 +00:00
|
|
|
{
|
|
|
|
std::vector<FileData*> childrenRecursive;
|
|
|
|
|
|
|
|
for (auto it = mChildrenByFilename.cbegin();
|
|
|
|
it != mChildrenByFilename.cend(); it++) {
|
|
|
|
childrenRecursive.push_back((*it).second);
|
|
|
|
// Recurse through any subdirectories.
|
|
|
|
if ((*it).second->getType() == FOLDER) {
|
2020-07-28 13:19:54 +00:00
|
|
|
std::vector<FileData*> childrenSubdirectory = (*it).second->getChildrenRecursive();
|
2020-07-26 20:19:29 +00:00
|
|
|
childrenRecursive.insert(childrenRecursive.end(),
|
|
|
|
childrenSubdirectory.begin(), childrenSubdirectory.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return childrenRecursive;
|
|
|
|
}
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
bool FileData::viewHasOnlyFolders()
|
|
|
|
{
|
|
|
|
bool onlyFolders = true;
|
|
|
|
std::vector<FileData*> entrySiblings = this->getParent()->getChildren();
|
|
|
|
for (auto it = entrySiblings.cbegin(); it != entrySiblings.cend(); it++) {
|
|
|
|
if ((*it)->getType() != FOLDER)
|
|
|
|
onlyFolders = false;
|
|
|
|
}
|
|
|
|
return onlyFolders;
|
|
|
|
}
|
|
|
|
|
2020-06-18 15:09:32 +00:00
|
|
|
const std::string FileData::getROMDirectory()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string romDirSetting = Settings::getInstance()->getString("ROMDirectory");
|
|
|
|
std::string romDirPath = "";
|
2020-06-18 15:09:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (romDirSetting == "") {
|
|
|
|
romDirPath = Utils::FileSystem::getHomePath() + "/ROMs/";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
romDirPath = romDirSetting;
|
2020-07-10 18:58:53 +00:00
|
|
|
// Expand home path if ~ is used.
|
|
|
|
romDirPath = Utils::FileSystem::expandHomePath(romDirPath);
|
2020-06-18 15:09:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (romDirPath.back() != '/')
|
|
|
|
romDirPath = romDirPath + "/";
|
|
|
|
}
|
2020-06-18 15:09:32 +00:00
|
|
|
|
2020-07-10 19:20:52 +00:00
|
|
|
// If %ESPATH% is used for the ROM path configuration, then expand it to the executable
|
|
|
|
// directory of ES. This is useful for a portable emulator installation, for instance on
|
|
|
|
// a USB memory stick.
|
|
|
|
romDirPath = Utils::String::replace(romDirPath, "%ESPATH%", Utils::FileSystem::getExePath());
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return romDirPath;
|
2020-06-18 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getMediaDirectory()
|
2020-05-18 17:00:43 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string mediaDirSetting = Settings::getInstance()->getString("MediaDirectory");
|
|
|
|
std::string mediaDirPath = "";
|
2017-05-18 10:16:57 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mediaDirSetting == "") {
|
|
|
|
mediaDirPath = Utils::FileSystem::getHomePath() + "/.emulationstation/downloaded_media/";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mediaDirPath = mediaDirSetting;
|
2020-07-10 19:20:52 +00:00
|
|
|
// Expand home path if ~ is used.
|
|
|
|
mediaDirPath = Utils::FileSystem::expandHomePath(mediaDirPath);
|
2020-06-21 12:25:28 +00:00
|
|
|
// Expand home symbol if the path starts with ~
|
2020-07-10 19:20:52 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mediaDirPath.back() != '/')
|
|
|
|
mediaDirPath = mediaDirPath + "/";
|
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mediaDirPath;
|
2020-05-18 17:00:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getMediafilePath(std::string subdirectory, std::string mediatype) const
|
2020-05-18 17:00:43 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const char* extList[2] = { ".png", ".jpg" };
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Look for an image file in the media directory.
|
|
|
|
std::string tempPath = getMediaDirectory() + mSystemName + "/" +
|
|
|
|
subdirectory + "/" + getDisplayName();
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
std::string mediaPath = tempPath + extList[i];
|
|
|
|
if (Utils::FileSystem::exists(mediaPath))
|
|
|
|
return mediaPath;
|
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// No media found in the media directory, so look
|
|
|
|
// for local art as well (if configured to do so).
|
|
|
|
if (Settings::getInstance()->getBool("LocalArt")) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
std::string localMediaPath = mEnvData->mStartPath + "/images/" +
|
|
|
|
getDisplayName() + "-" + mediatype + extList[i];
|
|
|
|
if (Utils::FileSystem::exists(localMediaPath))
|
|
|
|
return localMediaPath;
|
|
|
|
}
|
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return "";
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getImagePath() const
|
2017-10-22 23:04:17 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Look for a mix image (a combination of screenshot, 2D/3D box and marquee).
|
|
|
|
std::string image = getMediafilePath("miximages", "miximage");
|
|
|
|
if (image != "")
|
|
|
|
return image;
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If no mix image was found, try screenshot instead.
|
|
|
|
image = getMediafilePath("screenshots", "screenshot");
|
|
|
|
if (image != "")
|
|
|
|
return image;
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If no screenshot was found either, try cover.
|
|
|
|
return getMediafilePath("covers", "cover");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2017-10-22 23:04:17 +00:00
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::get3DBoxPath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("3dboxes", "3dbox");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2017-10-22 23:04:17 +00:00
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getCoverPath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("covers", "cover");
|
2017-10-22 23:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string FileData::getMarqueePath() const
|
2016-12-04 23:47:34 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("marquees", "marquee");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2017-10-22 23:04:17 +00:00
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getMiximagePath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("miximages", "miximage");
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getScreenshotPath() const
|
2016-12-04 23:47:34 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("screenshots", "screenshot");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getThumbnailPath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getMediafilePath("thumbnails", "thumbnail");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2017-10-22 23:04:17 +00:00
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getVideoPath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const char* extList[5] = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" };
|
|
|
|
std::string tempPath = getMediaDirectory() + mSystemName + "/videos/" + getDisplayName();
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Look for media in the media directory.
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
std::string mediaPath = tempPath + extList[i];
|
|
|
|
if (Utils::FileSystem::exists(mediaPath))
|
|
|
|
return mediaPath;
|
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// No media found in the media directory, so look
|
|
|
|
// for local art as well (if configured to do so).
|
|
|
|
if (Settings::getInstance()->getBool("LocalArt"))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
std::string localMediaPath = mEnvData->mStartPath + "/videos/" + getDisplayName() +
|
|
|
|
"-video" + extList[i];
|
|
|
|
if (Utils::FileSystem::exists(localMediaPath))
|
|
|
|
return localMediaPath;
|
|
|
|
}
|
|
|
|
}
|
2017-10-22 23:04:17 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return "";
|
2020-05-18 17:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<FileData*>& FileData::getChildrenListToDisplay()
|
|
|
|
{
|
|
|
|
|
2020-10-25 17:55:01 +00:00
|
|
|
FileFilterIndex* idx = mSystem->getIndex();
|
2020-06-21 12:25:28 +00:00
|
|
|
if (idx->isFiltered()) {
|
|
|
|
mFilteredChildren.clear();
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
if (idx->showFile((*it))) {
|
|
|
|
mFilteredChildren.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mFilteredChildren;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return mChildren;
|
|
|
|
}
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 17:01:49 +00:00
|
|
|
std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask,
|
|
|
|
bool displayedOnly, bool countAllGames) const
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<FileData*> out;
|
|
|
|
FileFilterIndex* idx = mSystem->getIndex();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
if ((*it)->getType() & typeMask) {
|
2020-07-29 17:01:49 +00:00
|
|
|
if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) {
|
|
|
|
if (countAllGames)
|
|
|
|
out.push_back(*it);
|
|
|
|
else if ((*it)->getCountAsGame())
|
|
|
|
out.push_back(*it);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
if ((*it)->getChildren().size() > 0) {
|
2020-07-29 17:01:49 +00:00
|
|
|
std::vector<FileData*> subChildren = (*it)->getFilesRecursive(typeMask, displayedOnly);
|
|
|
|
if (countAllGames) {
|
|
|
|
out.insert(out.cend(), subChildren.cbegin(), subChildren.cend());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (auto it = subChildren.cbegin(); it != subChildren.cend(); it++) {
|
|
|
|
if ((*it)->getCountAsGame())
|
|
|
|
out.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return out;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 13:12:04 +00:00
|
|
|
std::vector<FileData*> FileData::getScrapeFilesRecursive(bool includeFolders,
|
|
|
|
bool excludeRecursively, bool respectExclusions) const
|
|
|
|
{
|
|
|
|
std::vector<FileData*> out;
|
|
|
|
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
if (includeFolders && (*it)->getType() == FOLDER) {
|
|
|
|
if (!(respectExclusions && (*it)->getExcludeFromScraper()))
|
|
|
|
out.push_back(*it);
|
|
|
|
}
|
|
|
|
else if ((*it)->getType() == GAME) {
|
|
|
|
if (!(respectExclusions && (*it)->getExcludeFromScraper()))
|
|
|
|
out.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the flag has been passed to exclude directories recursively, then skip the entire
|
|
|
|
// folder at this point if the folder is marked for scrape exclusion.
|
|
|
|
if (excludeRecursively && (*it)->getType() == FOLDER && (*it)->getExcludeFromScraper())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((*it)->getChildren().size() > 0) {
|
|
|
|
std::vector<FileData*> subChildren = (*it)->getScrapeFilesRecursive(
|
|
|
|
includeFolders, excludeRecursively, respectExclusions);
|
|
|
|
out.insert(out.cend(), subChildren.cbegin(), subChildren.cend());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
std::string FileData::getKey() {
|
2020-06-21 12:25:28 +00:00
|
|
|
return getFileName();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 01:29:46 +00:00
|
|
|
const bool FileData::isArcadeAsset()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string stem = Utils::FileSystem::getStem(mPath);
|
2020-09-17 20:00:07 +00:00
|
|
|
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
|
|
|
mSystem->hasPlatformId(PlatformIds::NEOGEO))) &&
|
|
|
|
(MameNames::getInstance()->isBios(stem) ||
|
|
|
|
MameNames::getInstance()->isDevice(stem)));
|
2018-05-10 01:29:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
FileData* FileData::getSourceFileData()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return this;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void FileData::addChild(FileData* file)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(mType == FOLDER);
|
2020-06-23 18:07:00 +00:00
|
|
|
assert(file->getParent() == nullptr);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string key = file->getKey();
|
|
|
|
if (mChildrenByFilename.find(key) == mChildrenByFilename.cend()) {
|
|
|
|
mChildrenByFilename[key] = file;
|
|
|
|
mChildren.push_back(file);
|
|
|
|
file->mParent = this;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileData::removeChild(FileData* file)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(mType == FOLDER);
|
|
|
|
assert(file->getParent() == this);
|
|
|
|
mChildrenByFilename.erase(file->getKey());
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
if (*it == file) {
|
2020-06-23 18:07:00 +00:00
|
|
|
file->mParent = nullptr;
|
2020-06-21 12:25:28 +00:00
|
|
|
mChildren.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// File somehow wasn't in our children.
|
|
|
|
assert(false);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 16:13:27 +00:00
|
|
|
void FileData::sort(ComparisonFunction& comparator, bool ascending,
|
|
|
|
std::pair<unsigned int, unsigned int>& gameCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mFirstLetterIndex.clear();
|
2020-08-07 21:33:05 +00:00
|
|
|
mOnlyFolders = true;
|
2020-07-28 17:44:17 +00:00
|
|
|
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
|
2020-09-20 10:17:38 +00:00
|
|
|
bool hasFolders = false;
|
2020-07-28 17:44:17 +00:00
|
|
|
std::vector<FileData*> mChildrenFolders;
|
|
|
|
std::vector<FileData*> mChildrenOthers;
|
2020-07-26 20:19:29 +00:00
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
// The main custom collections view is sorted during startup in CollectionSystemManager.
|
2020-10-21 19:56:31 +00:00
|
|
|
// The individual collections are however sorted as any normal systems/folders.
|
|
|
|
if (mSystem->isCollection() && mSystem->getFullName() == "collections") {
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
// Build mFirstLetterIndex.
|
|
|
|
const char firstChar = toupper((*it)->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
if ((*it)->getChildren().size() > 0)
|
|
|
|
(*it)->sort(comparator, ascending, gameCount);
|
|
|
|
}
|
|
|
|
// Sort and make each entry unique in mFirstLetterIndex.
|
|
|
|
std::sort(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
auto last = std::unique(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
mFirstLetterIndex.erase(last, mFirstLetterIndex.end());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
if (foldersOnTop) {
|
|
|
|
for (unsigned int i = 0; i < mChildren.size(); i++) {
|
2020-09-20 10:17:38 +00:00
|
|
|
if (mChildren[i]->getType() == FOLDER) {
|
2020-07-28 17:44:17 +00:00
|
|
|
mChildrenFolders.push_back(mChildren[i]);
|
2020-09-20 10:17:38 +00:00
|
|
|
hasFolders = true;
|
|
|
|
}
|
|
|
|
else {
|
2020-07-28 17:44:17 +00:00
|
|
|
mChildrenOthers.push_back(mChildren[i]);
|
2020-09-20 10:17:38 +00:00
|
|
|
mOnlyFolders = false;
|
|
|
|
}
|
2020-07-28 17:44:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
// If descending sorting is requested, always perform a ascending sort by filename first.
|
|
|
|
// This adds a slight (probably negligible) overhead but it will avoid strange sorting
|
|
|
|
// issues where the secondary sorting is reversed for some sort types.
|
|
|
|
if (!ascending)
|
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
|
2020-09-20 10:17:38 +00:00
|
|
|
if (foldersOnTop && mOnlyFolders)
|
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
|
2020-07-28 17:44:17 +00:00
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(), comparator);
|
|
|
|
|
|
|
|
if (!ascending) {
|
2020-09-20 10:17:38 +00:00
|
|
|
if (foldersOnTop && mOnlyFolders)
|
|
|
|
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
|
2020-07-28 17:44:17 +00:00
|
|
|
std::reverse(mChildrenOthers.begin(), mChildrenOthers.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
mChildren.erase(mChildren.begin(), mChildren.end());
|
|
|
|
mChildren.reserve(mChildrenFolders.size() + mChildrenOthers.size());
|
|
|
|
mChildren.insert(mChildren.end(), mChildrenFolders.begin(), mChildrenFolders.end());
|
|
|
|
mChildren.insert(mChildren.end(), mChildrenOthers.begin(), mChildrenOthers.end());
|
|
|
|
}
|
|
|
|
else {
|
2020-09-20 18:25:32 +00:00
|
|
|
if (!ascending)
|
|
|
|
std::stable_sort(mChildren.begin(), mChildren.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
std::stable_sort(mChildren.begin(), mChildren.end(), comparator);
|
|
|
|
if (!ascending)
|
|
|
|
std::reverse(mChildren.begin(), mChildren.end());
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
2020-09-21 16:13:27 +00:00
|
|
|
// Game count, which will be displayed in the system view.
|
|
|
|
if ((*it)->getType() == GAME && (*it)->getCountAsGame()) {
|
|
|
|
if (!(*it)->getFavorite())
|
|
|
|
gameCount.first++;
|
|
|
|
else
|
|
|
|
gameCount.second++;
|
|
|
|
}
|
|
|
|
|
2020-08-07 21:33:05 +00:00
|
|
|
if ((*it)->getType() != FOLDER)
|
|
|
|
mOnlyFolders = false;
|
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
if (!(foldersOnTop && (*it)->getType() == FOLDER)) {
|
|
|
|
// Build mFirstLetterIndex.
|
|
|
|
const char firstChar = toupper((*it)->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
// Iterate through any child folders.
|
|
|
|
if ((*it)->getChildren().size() > 0)
|
2020-09-21 16:13:27 +00:00
|
|
|
(*it)->sort(comparator, ascending, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
// If there are only folders in the gamelist, then it makes sense to still
|
|
|
|
// generate a letter index.
|
2020-08-07 21:33:05 +00:00
|
|
|
if (mOnlyFolders) {
|
2020-07-28 17:44:17 +00:00
|
|
|
for (unsigned int i = 0; i < mChildrenFolders.size(); i++) {
|
|
|
|
const char firstChar = toupper(mChildrenFolders[i]->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
}
|
|
|
|
mOnlyFolders = true;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sort and make each entry unique in mFirstLetterIndex.
|
|
|
|
std::sort(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
auto last = std::unique(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
mFirstLetterIndex.erase(last, mFirstLetterIndex.end());
|
2020-09-20 10:17:38 +00:00
|
|
|
|
|
|
|
// If it's a mixed list and folders are sorted on top, add a folder icon to the index.
|
|
|
|
if (foldersOnTop && hasFolders && !mOnlyFolders)
|
|
|
|
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FOLDER_CHAR);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 16:13:27 +00:00
|
|
|
void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending,
|
|
|
|
std::pair<unsigned int, unsigned int>& gameCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mFirstLetterIndex.clear();
|
2020-08-07 21:33:05 +00:00
|
|
|
mOnlyFolders = true;
|
2020-07-28 17:44:17 +00:00
|
|
|
std::vector<FileData*> mChildrenFolders;
|
2020-09-20 18:25:32 +00:00
|
|
|
std::vector<FileData*> mChildrenFavoritesFolders;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<FileData*> mChildrenFavorites;
|
|
|
|
std::vector<FileData*> mChildrenOthers;
|
2020-07-28 17:44:17 +00:00
|
|
|
bool foldersOnTop = Settings::getInstance()->getBool("FoldersOnTop");
|
2020-09-20 10:17:38 +00:00
|
|
|
bool hasFolders = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
// The main custom collections view is sorted during startup in CollectionSystemManager.
|
2020-10-21 19:56:31 +00:00
|
|
|
// The individual collections are however sorted as any normal systems/folders.
|
|
|
|
if (mSystem->isCollection() && mSystem->getFullName() == "collections") {
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
// Build mFirstLetterIndex.
|
|
|
|
const char firstChar = toupper((*it)->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
if ((*it)->getChildren().size() > 0)
|
|
|
|
(*it)->sortFavoritesOnTop(comparator, ascending, gameCount);
|
|
|
|
}
|
|
|
|
// Sort and make each entry unique in mFirstLetterIndex.
|
|
|
|
std::sort(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
auto last = std::unique(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
mFirstLetterIndex.erase(last, mFirstLetterIndex.end());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < mChildren.size(); i++) {
|
2020-09-21 16:13:27 +00:00
|
|
|
// Game count, which will be displayed in the system view.
|
|
|
|
if (mChildren[i]->getType() == GAME && mChildren[i]->getCountAsGame()) {
|
|
|
|
if (!mChildren[i]->getFavorite())
|
|
|
|
gameCount.first++;
|
|
|
|
else
|
|
|
|
gameCount.second++;
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
if (foldersOnTop && mChildren[i]->getType() == FOLDER) {
|
2020-09-20 18:25:32 +00:00
|
|
|
if (!mChildren[i]->getFavorite())
|
|
|
|
mChildrenFolders.push_back(mChildren[i]);
|
|
|
|
else
|
|
|
|
mChildrenFavoritesFolders.push_back(mChildren[i]);
|
|
|
|
|
2020-09-20 10:17:38 +00:00
|
|
|
hasFolders = true;
|
2020-07-28 17:44:17 +00:00
|
|
|
}
|
|
|
|
else if (mChildren[i]->getFavorite()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
mChildrenFavorites.push_back(mChildren[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mChildrenOthers.push_back(mChildren[i]);
|
|
|
|
// Build mFirstLetterIndex.
|
|
|
|
const char firstChar = toupper(mChildren[i]->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
}
|
2020-08-07 21:33:05 +00:00
|
|
|
|
|
|
|
if (mChildren[i]->getType() != FOLDER)
|
|
|
|
mOnlyFolders = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
// If there are favorite folders and this is a mixed list, then don't handle these
|
|
|
|
// separately but instead merge them into the same vector. This is a quite wasteful
|
|
|
|
// approach but the scenario where a user has a mixed folder and files list and marks
|
|
|
|
// some folders as favorites is probably a rare situation.
|
|
|
|
if (!mOnlyFolders && mChildrenFavoritesFolders.size() > 0) {
|
|
|
|
mChildrenFolders.insert(mChildrenFolders.end(), mChildrenFavoritesFolders.begin(),
|
|
|
|
mChildrenFavoritesFolders.end());
|
|
|
|
mChildrenFavoritesFolders.erase(mChildrenFavoritesFolders.begin(),
|
|
|
|
mChildrenFavoritesFolders.end());
|
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If there are only favorites in the gamelist, it makes sense to still generate
|
|
|
|
// a letter index. For instance to be able to quick jump in the 'favorites'
|
|
|
|
// collection. Doing this additional work here only for the applicable gamelists is
|
|
|
|
// probably faster than building a redundant index for all gamelists during sorting.
|
|
|
|
if (mChildrenOthers.size() == 0 && mChildrenFavorites.size() > 0) {
|
|
|
|
for (unsigned int i = 0; i < mChildren.size(); i++) {
|
2020-07-28 17:44:17 +00:00
|
|
|
if (foldersOnTop && mChildren[i]->getType() == FOLDER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char firstChar = toupper(mChildren[i]->getSortName().front());
|
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there are only folders in the gamelist, then it also makes sense to generate
|
|
|
|
// a letter index.
|
2020-08-07 21:33:05 +00:00
|
|
|
else if (mOnlyFolders) {
|
2020-07-28 17:44:17 +00:00
|
|
|
for (unsigned int i = 0; i < mChildrenFolders.size(); i++) {
|
|
|
|
const char firstChar = toupper(mChildrenFolders[i]->getSortName().front());
|
2020-06-21 12:25:28 +00:00
|
|
|
mFirstLetterIndex.push_back(std::string(1, firstChar));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort and make each entry unique in mFirstLetterIndex.
|
|
|
|
std::sort(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
auto last = std::unique(mFirstLetterIndex.begin(), mFirstLetterIndex.end());
|
|
|
|
mFirstLetterIndex.erase(last, mFirstLetterIndex.end());
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
// If there were at least one favorite folder in the gamelist, insert the favorite
|
|
|
|
// unicode character in the first position.
|
|
|
|
if (foldersOnTop && mOnlyFolders && mChildrenFavoritesFolders.size() > 0)
|
|
|
|
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FAVORITE_CHAR);
|
2020-06-21 12:25:28 +00:00
|
|
|
// If there were at least one favorite in the gamelist, insert the favorite
|
|
|
|
// unicode character in the first position.
|
2020-09-20 18:25:32 +00:00
|
|
|
else if (mChildrenOthers.size() > 0 && mChildrenFavorites.size() > 0)
|
2020-06-21 12:25:28 +00:00
|
|
|
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FAVORITE_CHAR);
|
|
|
|
|
2020-09-20 10:17:38 +00:00
|
|
|
// If it's a mixed list and folders are sorted on top, add a folder icon to the index.
|
|
|
|
if (foldersOnTop && hasFolders && !mOnlyFolders)
|
|
|
|
mFirstLetterIndex.insert(mFirstLetterIndex.begin(), FOLDER_CHAR);
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
// If descending sorting is requested, always perform a ascending sort by filename first.
|
|
|
|
// This adds a slight (probably negligible) overhead but it will avoid strange sorting
|
|
|
|
// issues where the secondary sorting is reversed for some sort types.
|
|
|
|
if (!ascending) {
|
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
std::stable_sort(mChildrenFavoritesFolders.begin(), mChildrenFavoritesFolders.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
std::stable_sort(mChildrenFavorites.begin(), mChildrenFavorites.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(),
|
|
|
|
getSortTypeFromString("filename, ascending").comparisonFunction);
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sort favorite games and the other games separately.
|
2020-09-20 18:25:32 +00:00
|
|
|
if (foldersOnTop && mOnlyFolders) {
|
|
|
|
std::stable_sort(mChildrenFavoritesFolders.begin(),
|
|
|
|
mChildrenFavoritesFolders.end(), comparator);
|
2020-09-20 10:17:38 +00:00
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
|
2020-09-20 18:25:32 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
std::stable_sort(mChildrenFavorites.begin(), mChildrenFavorites.end(), comparator);
|
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(), comparator);
|
|
|
|
|
2020-09-20 18:25:32 +00:00
|
|
|
// Iterate through any child favorite folders.
|
|
|
|
for (auto it = mChildrenFavoritesFolders.cbegin(); it !=
|
|
|
|
mChildrenFavoritesFolders.cend(); it++) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2020-09-21 16:13:27 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, ascending, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through any child folders.
|
2020-09-20 18:25:32 +00:00
|
|
|
for (auto it = mChildrenFolders.cbegin(); it != mChildrenFolders.cend(); it++) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2020-09-21 16:13:27 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, ascending, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ascending) {
|
2020-09-20 18:25:32 +00:00
|
|
|
if (foldersOnTop && mOnlyFolders) {
|
|
|
|
std::reverse(mChildrenFavoritesFolders.begin(), mChildrenFavoritesFolders.end());
|
2020-09-20 10:17:38 +00:00
|
|
|
std::reverse(mChildrenFolders.begin(), mChildrenFolders.end());
|
2020-09-20 18:25:32 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
std::reverse(mChildrenFavorites.begin(), mChildrenFavorites.end());
|
|
|
|
std::reverse(mChildrenOthers.begin(), mChildrenOthers.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine the individually sorted favorite games and other games vectors.
|
|
|
|
mChildren.erase(mChildren.begin(), mChildren.end());
|
2020-09-20 18:25:32 +00:00
|
|
|
mChildren.reserve(mChildrenFavoritesFolders.size() + mChildrenFolders.size() +
|
|
|
|
mChildrenFavorites.size() + mChildrenOthers.size());
|
|
|
|
mChildren.insert(mChildren.end(), mChildrenFavoritesFolders.begin(),
|
|
|
|
mChildrenFavoritesFolders.end());
|
2020-07-28 17:44:17 +00:00
|
|
|
mChildren.insert(mChildren.end(), mChildrenFolders.begin(), mChildrenFolders.end());
|
2020-06-21 12:25:28 +00:00
|
|
|
mChildren.insert(mChildren.end(), mChildrenFavorites.begin(), mChildrenFavorites.end());
|
|
|
|
mChildren.insert(mChildren.end(), mChildrenOthers.begin(), mChildrenOthers.end());
|
2020-05-24 08:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileData::sort(const SortType& type, bool mFavoritesOnTop)
|
|
|
|
{
|
2020-09-21 16:13:27 +00:00
|
|
|
mGameCount = std::make_pair(0, 0);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mFavoritesOnTop)
|
2020-09-21 16:13:27 +00:00
|
|
|
sortFavoritesOnTop(*type.comparisonFunction, type.ascending, mGameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2020-09-21 16:13:27 +00:00
|
|
|
sort(*type.comparisonFunction, type.ascending, mGameCount);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-09-17 20:18:13 +00:00
|
|
|
FileData::SortType FileData::getSortTypeFromString(std::string desc) {
|
|
|
|
std::vector<FileData::SortType> SortTypes = FileSorts::SortTypes;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) {
|
|
|
|
const FileData::SortType& sort = FileSorts::SortTypes.at(i);
|
|
|
|
if (sort.description == desc)
|
|
|
|
return sort;
|
|
|
|
}
|
|
|
|
// If no type was found then default to "filename, ascending".
|
|
|
|
return FileSorts::SortTypes.at(0);
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void FileData::launchGame(Window* window)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
LOG(LogInfo) << "Attempting to launch game...";
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string command = "";
|
2020-05-19 15:52:11 +00:00
|
|
|
|
2020-07-10 18:58:53 +00:00
|
|
|
// Check if there is a launch command override for the game
|
2020-06-21 12:25:28 +00:00
|
|
|
// and the corresponding option to use it has been set.
|
2020-07-08 15:06:34 +00:00
|
|
|
if (Settings::getInstance()->getBool("LaunchCommandOverride") &&
|
|
|
|
!metadata.get("launchcommand").empty())
|
|
|
|
command = metadata.get("launchcommand");
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
|
|
|
command = mEnvData->mLaunchCommand;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-07-07 19:25:15 +00:00
|
|
|
std::string commandRaw = command;
|
|
|
|
|
2020-07-03 18:23:51 +00:00
|
|
|
const std::string rom = Utils::FileSystem::getEscapedPath(getPath());
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string basename = Utils::FileSystem::getStem(getPath());
|
2020-07-03 18:23:51 +00:00
|
|
|
const std::string rom_raw = Utils::FileSystem::getPreferredPath(getPath());
|
2020-07-07 19:25:15 +00:00
|
|
|
const std::string emupath = Utils::FileSystem::getExePath();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
command = Utils::String::replace(command, "%ROM%", rom);
|
|
|
|
command = Utils::String::replace(command, "%BASENAME%", basename);
|
|
|
|
command = Utils::String::replace(command, "%ROM_RAW%", rom_raw);
|
2020-07-10 18:58:53 +00:00
|
|
|
command = Utils::String::replace(command, "%ESPATH%", emupath);
|
|
|
|
|
|
|
|
// Expand home path if ~ is used.
|
|
|
|
command = Utils::FileSystem::expandHomePath(command);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-08-19 20:17:32 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
std::wstring commandWide = Utils::String::stringToWideString(command);
|
2020-07-07 19:25:15 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-05 12:49:54 +00:00
|
|
|
Scripting::fireEvent("game-start", rom, getSourceFileData()->metadata.get("name"));
|
2020-07-18 21:07:02 +00:00
|
|
|
int returnValue = 0;
|
2020-07-07 19:25:15 +00:00
|
|
|
|
|
|
|
if (command.find("%EMUPATH%") != std::string::npos) {
|
|
|
|
// Extract the emulator executable from the launch command string. This could either be
|
|
|
|
// just the program name, assuming the binary is in the PATH variable of the operating
|
|
|
|
// system, or it could be an absolute path to the emulator. (In the latter case, if
|
|
|
|
// there is a space in the the path, it needs to be enclosed by quotation marks in
|
|
|
|
// es_systems.cfg.)
|
|
|
|
std::string emuExecutable;
|
|
|
|
|
|
|
|
// If the first character is a quotation mark, then we need to extract up to the
|
|
|
|
// next quotation mark, otherwise we'll extract up to the first space character.
|
|
|
|
if (command.front() == '\"') {
|
|
|
|
std::string emuTemp = command.substr(1, std::string::npos);
|
|
|
|
emuExecutable = emuTemp.substr(0, emuTemp.find('"'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emuExecutable = command.substr(0, command.find(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
// For Windows, we need to handle UTF-16 encoding.
|
2020-08-19 20:17:32 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-07 19:25:15 +00:00
|
|
|
std::wstring emuExecutableWide;
|
|
|
|
std::wstring emuPathWide;
|
|
|
|
|
2020-07-10 16:32:23 +00:00
|
|
|
emuExecutableWide = Utils::String::stringToWideString(emuExecutable);
|
2018-01-30 00:49:08 +00:00
|
|
|
|
2020-07-07 19:25:15 +00:00
|
|
|
// Search for the emulator using the PATH environmental variable.
|
|
|
|
DWORD size = SearchPathW(nullptr, emuExecutableWide.c_str(), L".exe", 0, nullptr, nullptr);
|
|
|
|
|
|
|
|
if (size) {
|
|
|
|
std::vector<wchar_t> pathBuffer(static_cast<size_t>(size) + 1 );
|
|
|
|
wchar_t* fileName = nullptr;
|
|
|
|
|
|
|
|
SearchPathW(nullptr, emuExecutableWide.c_str(), L".exe", size + 1 ,
|
|
|
|
pathBuffer.data(), &fileName);
|
|
|
|
std::wstring pathString = pathBuffer.data();
|
|
|
|
|
|
|
|
if (pathString.length()) {
|
|
|
|
emuPathWide = pathString.substr(0, pathString.size() -
|
|
|
|
std::wstring(fileName).size());
|
|
|
|
emuPathWide.pop_back();
|
|
|
|
auto stringPos = commandWide.find(L"%EMUPATH%");
|
|
|
|
commandWide = commandWide.replace(stringPos, 9, emuPathWide);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2020-07-10 18:58:53 +00:00
|
|
|
std::string exePath;
|
|
|
|
if (Utils::FileSystem::isRegularFile(emuExecutable) ||
|
|
|
|
Utils::FileSystem::isSymlink(emuExecutable))
|
|
|
|
exePath = Utils::FileSystem::getParent(emuExecutable);
|
|
|
|
else
|
|
|
|
exePath = Utils::FileSystem::getPathToBinary(emuExecutable);
|
|
|
|
|
2020-07-10 17:53:33 +00:00
|
|
|
command = Utils::String::replace(command, "%EMUPATH%", exePath);
|
2020-07-07 19:25:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-08-05 13:07:17 +00:00
|
|
|
LOG(LogDebug) << "Raw emulator launch command:";
|
|
|
|
LOG(LogDebug) << commandRaw;
|
2020-07-07 19:25:15 +00:00
|
|
|
LOG(LogInfo) << "Expanded emulator launch command:";
|
|
|
|
|
2020-08-19 20:17:32 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
LOG(LogInfo) << Utils::String::wideStringToString(commandWide);
|
2020-07-18 21:07:02 +00:00
|
|
|
returnValue = launchEmulatorWindows(commandWide);
|
2020-07-07 19:25:15 +00:00
|
|
|
#else
|
|
|
|
LOG(LogInfo) << command;
|
2020-07-18 21:07:02 +00:00
|
|
|
returnValue = launchEmulatorUnix(command);
|
2020-07-07 19:25:15 +00:00
|
|
|
#endif
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-07-18 11:21:44 +00:00
|
|
|
// Notify the user in case of a failed game launch using a popup window.
|
2020-07-18 21:07:02 +00:00
|
|
|
if (returnValue != 0) {
|
|
|
|
LOG(LogWarning) << "...launch terminated with nonzero return value " << returnValue << "!";
|
2020-07-18 11:21:44 +00:00
|
|
|
|
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(window, "ERROR LAUNCHING GAME '" +
|
2020-07-18 21:07:02 +00:00
|
|
|
Utils::String::toUpper(metadata.get("name")) + "' (ERROR CODE " +
|
|
|
|
Utils::String::toUpper(std::to_string(returnValue) + ")"), 6000);
|
2020-07-18 11:21:44 +00:00
|
|
|
window->setInfoPopup(s);
|
|
|
|
}
|
|
|
|
else {
|
2020-08-15 13:41:11 +00:00
|
|
|
// Stop showing the game launch notification.
|
|
|
|
window->stopInfoPopup();
|
2020-08-19 20:17:32 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-20 07:54:38 +00:00
|
|
|
// This code is only needed for Windows, where we may need to keep ES running while
|
|
|
|
// the game/emulator is in use. It's basically used to pause any playing game video
|
|
|
|
// and to keep the screensaver from activating.
|
2020-07-19 20:08:14 +00:00
|
|
|
if (Settings::getInstance()->getBool("RunInBackground"))
|
|
|
|
window->setLaunchedGame();
|
2020-07-20 07:54:38 +00:00
|
|
|
else
|
|
|
|
// Normalize deltaTime so that the screensaver does not start immediately
|
|
|
|
// when returning from the game.
|
|
|
|
window->normalizeNextUpdate();
|
|
|
|
#else
|
|
|
|
// Normalize deltaTime so that the screensaver does not start immediately
|
|
|
|
// when returning from the game.
|
|
|
|
window->normalizeNextUpdate();
|
|
|
|
#endif
|
2020-06-25 17:52:38 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-08-05 12:49:54 +00:00
|
|
|
Scripting::fireEvent("game-end", rom, getSourceFileData()->metadata.get("name"));
|
2018-01-30 00:49:08 +00:00
|
|
|
|
2020-09-17 20:00:07 +00:00
|
|
|
// Re-enable the text scrolling that was disabled in ViewController on game launch.
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update number of times the game has been launched.
|
|
|
|
FileData* gameToUpdate = getSourceFileData();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
int timesPlayed = gameToUpdate->metadata.getInt("playcount") + 1;
|
|
|
|
gameToUpdate->metadata.set("playcount", std::to_string(static_cast<long long>(timesPlayed)));
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update last played time.
|
|
|
|
gameToUpdate->metadata.set("lastplayed", Utils::Time::DateTime(Utils::Time::now()));
|
2020-07-30 12:21:20 +00:00
|
|
|
|
|
|
|
// If the parent is a folder and it's not the root of the system, then update its lastplayed
|
|
|
|
// timestamp to the same time as the game that was just launched.
|
|
|
|
if (gameToUpdate->getParent()->getType() == FOLDER && gameToUpdate->getParent()->getName() !=
|
|
|
|
gameToUpdate->getSystem()->getFullName()) {
|
|
|
|
gameToUpdate->getParent()->metadata.set("lastplayed",
|
|
|
|
gameToUpdate->metadata.get("lastplayed"));
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemManager::get()->refreshCollectionSystems(gameToUpdate);
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
gameToUpdate->mSystem->onMetaDataSavePoint();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectionFileData::CollectionFileData(FileData* file, SystemData* system)
|
2020-06-21 12:25:28 +00:00
|
|
|
: FileData(file->getSourceFileData()->getType(), file->getSourceFileData()->getPath(),
|
|
|
|
file->getSourceFileData()->getSystemEnvData(), system)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We use this constructor to create a clone of the filedata, and change its system.
|
|
|
|
mSourceFileData = file->getSourceFileData();
|
|
|
|
refreshMetadata();
|
2020-06-23 18:07:00 +00:00
|
|
|
mParent = nullptr;
|
2020-06-21 12:25:28 +00:00
|
|
|
metadata = mSourceFileData->metadata;
|
|
|
|
mSystemName = mSourceFileData->getSystem()->getName();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectionFileData::~CollectionFileData()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Need to remove collection file data at the collection object destructor.
|
|
|
|
if (mParent)
|
|
|
|
mParent->removeChild(this);
|
2020-06-23 18:07:00 +00:00
|
|
|
mParent = nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CollectionFileData::getKey() {
|
2020-06-21 12:25:28 +00:00
|
|
|
return getFullPath();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileData* CollectionFileData::getSourceFileData()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mSourceFileData;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionFileData::refreshMetadata()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
metadata = mSourceFileData->metadata;
|
|
|
|
mDirty = true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 15:23:02 +00:00
|
|
|
const std::string& CollectionFileData::getName()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mDirty) {
|
|
|
|
mCollectionFileName =
|
|
|
|
Utils::String::removeParenthesis(mSourceFileData->metadata.get("name"));
|
|
|
|
mCollectionFileName +=
|
|
|
|
" [" + Utils::String::toUpper(mSourceFileData->getSystem()->getName()) + "]";
|
|
|
|
mDirty = false;
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Settings::getInstance()->getBool("CollectionShowSystemInfo"))
|
|
|
|
return mCollectionFileName;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mSourceFileData->metadata.get("name");
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|