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-12-23 17:06:30 +00:00
|
|
|
#include "CollectionSystemsManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#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"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
2022-01-17 20:53:23 +00:00
|
|
|
#include "UIModeController.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Window.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2022-01-10 17:56:04 +00:00
|
|
|
#include "utils/PlatformUtil.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "utils/TimeUtil.h"
|
2022-04-11 21:28:18 +00:00
|
|
|
#include "views/GamelistView.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "views/ViewController.h"
|
2020-07-07 19:25:15 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <assert.h>
|
2022-12-17 17:37:58 +00:00
|
|
|
#include <regex>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
FileData::FileData(FileType type,
|
|
|
|
const std::string& path,
|
|
|
|
SystemEnvironmentData* envData,
|
|
|
|
SystemData* system)
|
2022-01-16 17:18:28 +00:00
|
|
|
: metadata {type == GAME ? GAME_METADATA : FOLDER_METADATA}
|
|
|
|
, mSourceFileData {nullptr}
|
|
|
|
, mParent {nullptr}
|
|
|
|
, mType {type}
|
|
|
|
, mPath {path}
|
|
|
|
, mEnvData {envData}
|
|
|
|
, mSystem {system}
|
|
|
|
, mOnlyFolders {false}
|
2022-12-14 16:30:34 +00:00
|
|
|
, mHasFolders {false}
|
2022-02-13 19:03:34 +00:00
|
|
|
, mUpdateChildrenLastPlayed {false}
|
|
|
|
, mUpdateChildrenMostPlayed {false}
|
2022-01-16 17:18:28 +00:00
|
|
|
, mDeletionFlag {false}
|
2020-06-21 12:25:28 +00:00
|
|
|
{
|
|
|
|
// Metadata needs at least a name field (since that's what getName() will return).
|
2022-12-20 17:42:28 +00:00
|
|
|
if ((system->hasPlatformId(PlatformIds::ARCADE) ||
|
|
|
|
system->hasPlatformId(PlatformIds::SNK_NEO_GEO)) &&
|
|
|
|
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()));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2022-12-20 17:42:28 +00:00
|
|
|
else {
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2018-04-25 05:07:25 +00:00
|
|
|
const std::string& FileData::getSortName()
|
|
|
|
{
|
2022-01-15 10:50:51 +00:00
|
|
|
if (mSystem->isCustomCollection() && mType == GAME) {
|
|
|
|
if (!metadata.get("collectionsortname").empty())
|
|
|
|
return metadata.get("collectionsortname");
|
|
|
|
else if (!metadata.get("sortname").empty())
|
|
|
|
return metadata.get("sortname");
|
|
|
|
else
|
|
|
|
return metadata.get("name");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-05 09:45:32 +00:00
|
|
|
const bool FileData::getKidgame()
|
|
|
|
{
|
|
|
|
if (metadata.get("kidgame") == "true")
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildrenByFilename.cbegin(); it != mChildrenByFilename.cend(); ++it) {
|
2021-11-09 21:40:08 +00:00
|
|
|
childrenRecursive.emplace_back((*it).second);
|
2020-07-26 20:19:29 +00:00
|
|
|
// Recurse through any subdirectories.
|
|
|
|
if ((*it).second->getType() == FOLDER) {
|
2022-05-21 12:48:29 +00:00
|
|
|
std::vector<FileData*> childrenSubdirectory {(*it).second->getChildrenRecursive()};
|
2021-07-07 18:03:42 +00:00
|
|
|
childrenRecursive.insert(childrenRecursive.end(), childrenSubdirectory.begin(),
|
|
|
|
childrenSubdirectory.end());
|
2020-07-26 20:19:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return childrenRecursive;
|
|
|
|
}
|
|
|
|
|
2020-06-18 15:09:32 +00:00
|
|
|
const std::string FileData::getROMDirectory()
|
|
|
|
{
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& romDirSetting {Settings::getInstance()->getString("ROMDirectory")};
|
2022-05-21 12:48:29 +00:00
|
|
|
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
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
if (romDirPath.back() != '\\')
|
2021-03-10 18:49:06 +00:00
|
|
|
romDirPath = romDirPath + "\\";
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
|
|
|
if (romDirPath.back() != '/')
|
2020-06-21 12:25:28 +00:00
|
|
|
romDirPath = romDirPath + "/";
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-06-18 15:09:32 +00:00
|
|
|
|
2021-06-29 15:19:47 +00:00
|
|
|
// If %ESPATH% is used for the ROM path configuration, then expand it to the binary
|
|
|
|
// directory of ES-DE.
|
2020-07-10 19:20:52 +00:00
|
|
|
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
|
|
|
{
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& mediaDirSetting {Settings::getInstance()->getString("MediaDirectory")};
|
2022-05-21 12:48:29 +00:00
|
|
|
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);
|
2021-06-29 15:19:47 +00:00
|
|
|
|
|
|
|
// If %ESPATH% is used for the media directory configuration, then expand it to the
|
|
|
|
// binary directory of ES-DE.
|
2021-07-07 18:03:42 +00:00
|
|
|
mediaDirPath =
|
|
|
|
Utils::String::replace(mediaDirPath, "%ESPATH%", Utils::FileSystem::getExePath());
|
2020-07-10 19:20:52 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
if (mediaDirPath.back() != '/')
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string FileData::getMediafilePath(const std::string& subdirectory) const
|
2020-05-18 17:00:43 +00:00
|
|
|
{
|
2022-05-21 12:48:29 +00:00
|
|
|
const std::vector<std::string> extList {".png", ".jpg"};
|
2021-01-31 18:53:55 +00:00
|
|
|
std::string subFolders;
|
|
|
|
|
|
|
|
// Extract possible subfolders from the path.
|
|
|
|
if (mEnvData->mStartPath != "")
|
2021-07-07 18:03:42 +00:00
|
|
|
subFolders =
|
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(mPath), mEnvData->mStartPath, "");
|
2021-01-31 18:53:55 +00:00
|
|
|
|
2022-05-21 12:48:29 +00:00
|
|
|
const std::string tempPath {getMediaDirectory() + mSystemName + "/" + subdirectory +
|
|
|
|
subFolders + "/" + getDisplayName()};
|
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.
|
2022-12-14 16:30:34 +00:00
|
|
|
for (size_t i {0}; i < extList.size(); ++i) {
|
2022-05-21 12:48:29 +00:00
|
|
|
std::string mediaPath {tempPath + extList[i]};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::exists(mediaPath))
|
|
|
|
return mediaPath;
|
|
|
|
}
|
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).
|
2022-05-21 12:48:29 +00:00
|
|
|
std::string image {getMediafilePath("miximages")};
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
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.
|
2021-10-28 19:00:23 +00:00
|
|
|
image = getMediafilePath("screenshots");
|
|
|
|
if (image != "")
|
|
|
|
return image;
|
|
|
|
|
|
|
|
// If no screenshot image was found, try title screen instead.
|
|
|
|
image = getMediafilePath("titlescreens");
|
2020-06-21 12:25:28 +00:00
|
|
|
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.
|
2021-10-28 19:00:23 +00:00
|
|
|
return getMediafilePath("covers");
|
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
|
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
// Return path to the 3D box image.
|
2021-10-28 19:00:23 +00:00
|
|
|
return getMediafilePath("3dboxes");
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string FileData::getBackCoverPath() const
|
|
|
|
{
|
|
|
|
// Return path to the box back cover image.
|
|
|
|
return getMediafilePath("backcovers");
|
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
|
|
|
|
{
|
2021-10-28 19:00:23 +00:00
|
|
|
// Return path to the box cover image.
|
|
|
|
return getMediafilePath("covers");
|
2017-10-22 23:04:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 12:16:23 +00:00
|
|
|
const std::string FileData::getFanArtPath() const
|
|
|
|
{
|
|
|
|
// Return path to the fan art image.
|
|
|
|
return getMediafilePath("fanart");
|
|
|
|
}
|
|
|
|
|
2017-10-22 23:04:17 +00:00
|
|
|
const std::string FileData::getMarqueePath() const
|
2016-12-04 23:47:34 +00:00
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
// Return path to the marquee image.
|
2021-10-28 19:00:23 +00:00
|
|
|
return getMediafilePath("marquees");
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string FileData::getPhysicalMediaPath() const
|
|
|
|
{
|
|
|
|
// Return path to the physical media image.
|
|
|
|
return getMediafilePath("physicalmedia");
|
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
|
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
// Return path to the miximage.
|
2021-10-28 19:00:23 +00:00
|
|
|
return getMediafilePath("miximages");
|
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
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
// Return path to the screenshot image.
|
2021-10-28 19:00:23 +00:00
|
|
|
return getMediafilePath("screenshots");
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string FileData::getTitleScreenPath() const
|
|
|
|
{
|
|
|
|
// Return path to the title screen image.
|
|
|
|
return getMediafilePath("titlescreens");
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2023-09-23 17:09:14 +00:00
|
|
|
const std::string FileData::getCustomImagePath() const
|
|
|
|
{
|
|
|
|
// Return path to the custom image.
|
|
|
|
return getMediafilePath("custom");
|
|
|
|
}
|
|
|
|
|
2020-06-06 11:10:33 +00:00
|
|
|
const std::string FileData::getVideoPath() const
|
|
|
|
{
|
2022-05-21 12:48:29 +00:00
|
|
|
const std::vector<std::string> extList {".avi", ".mkv", ".mov", ".mp4", ".wmv"};
|
2021-01-31 18:53:55 +00:00
|
|
|
std::string subFolders;
|
|
|
|
|
|
|
|
// Extract possible subfolders from the path.
|
|
|
|
if (mEnvData->mStartPath != "")
|
2021-07-07 18:03:42 +00:00
|
|
|
subFolders =
|
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(mPath), mEnvData->mStartPath, "");
|
2021-01-31 18:53:55 +00:00
|
|
|
|
2022-05-21 12:48:29 +00:00
|
|
|
const std::string tempPath {getMediaDirectory() + mSystemName + "/videos" + subFolders + "/" +
|
|
|
|
getDisplayName()};
|
2020-05-18 17:00:43 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Look for media in the media directory.
|
2022-12-14 16:30:34 +00:00
|
|
|
for (size_t i {0}; i < extList.size(); ++i) {
|
2022-05-21 12:48:29 +00:00
|
|
|
std::string mediaPath {tempPath + extList[i]};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::exists(mediaPath))
|
|
|
|
return mediaPath;
|
2023-05-08 15:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string FileData::getManualPath() const
|
|
|
|
{
|
|
|
|
const std::vector<std::string> extList {".pdf"};
|
|
|
|
std::string subFolders;
|
|
|
|
|
|
|
|
// Extract possible subfolders from the path.
|
|
|
|
if (mEnvData->mStartPath != "")
|
|
|
|
subFolders =
|
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(mPath), mEnvData->mStartPath, "");
|
|
|
|
|
|
|
|
const std::string tempPath {getMediaDirectory() + mSystemName + "/manuals" + subFolders + "/" +
|
|
|
|
getDisplayName()};
|
|
|
|
|
|
|
|
// Look for manuals in the media directory.
|
|
|
|
for (size_t i {0}; i < extList.size(); ++i) {
|
|
|
|
std::string mediaPath {tempPath + extList[i]};
|
|
|
|
if (Utils::FileSystem::exists(mediaPath))
|
|
|
|
return mediaPath;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-05-18 17:00:43 +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()
|
|
|
|
{
|
2022-05-21 12:48:29 +00:00
|
|
|
FileFilterIndex* idx {mSystem->getIndex()};
|
2021-01-05 09:45:32 +00:00
|
|
|
if (idx->isFiltered() || UIModeController::getInstance()->isUIModeKid()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
mFilteredChildren.clear();
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (idx->showFile((*it))) {
|
2021-11-09 21:40:08 +00:00
|
|
|
mFilteredChildren.emplace_back(*it);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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,
|
2021-07-07 18:03:42 +00:00
|
|
|
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;
|
2022-05-21 12:48:29 +00:00
|
|
|
FileFilterIndex* idx {mSystem->getIndex()};
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*it)->getType() & typeMask) {
|
2020-07-29 17:01:49 +00:00
|
|
|
if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) {
|
|
|
|
if (countAllGames)
|
2021-11-09 21:40:08 +00:00
|
|
|
out.emplace_back(*it);
|
2020-07-29 17:01:49 +00:00
|
|
|
else if ((*it)->getCountAsGame())
|
2021-11-09 21:40:08 +00:00
|
|
|
out.emplace_back(*it);
|
2020-07-29 17:01:49 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
if ((*it)->getChildren().size() > 0) {
|
2022-05-21 12:48:29 +00:00
|
|
|
std::vector<FileData*> subChildren {(*it)->getFilesRecursive(typeMask, displayedOnly)};
|
2020-07-29 17:01:49 +00:00
|
|
|
if (countAllGames) {
|
|
|
|
out.insert(out.cend(), subChildren.cbegin(), subChildren.cend());
|
|
|
|
}
|
|
|
|
else {
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it2 = subChildren.cbegin(); it2 != subChildren.cend(); ++it2) {
|
2021-09-19 17:46:59 +00:00
|
|
|
if ((*it2)->getCountAsGame())
|
2021-11-09 21:40:08 +00:00
|
|
|
out.emplace_back(*it2);
|
2020-07-29 17:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
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,
|
2021-07-07 18:03:42 +00:00
|
|
|
bool excludeRecursively,
|
|
|
|
bool respectExclusions) const
|
2020-08-06 13:12:04 +00:00
|
|
|
{
|
|
|
|
std::vector<FileData*> out;
|
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-08-06 13:12:04 +00:00
|
|
|
if (includeFolders && (*it)->getType() == FOLDER) {
|
|
|
|
if (!(respectExclusions && (*it)->getExcludeFromScraper()))
|
2021-11-09 21:40:08 +00:00
|
|
|
out.emplace_back(*it);
|
2020-08-06 13:12:04 +00:00
|
|
|
}
|
|
|
|
else if ((*it)->getType() == GAME) {
|
|
|
|
if (!(respectExclusions && (*it)->getExcludeFromScraper()))
|
2021-11-09 21:40:08 +00:00
|
|
|
out.emplace_back(*it);
|
2020-08-06 13:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2022-05-21 12:48:29 +00:00
|
|
|
std::vector<FileData*> subChildren {(*it)->getScrapeFilesRecursive(
|
|
|
|
includeFolders, excludeRecursively, respectExclusions)};
|
2020-08-06 13:12:04 +00:00
|
|
|
out.insert(out.cend(), subChildren.cbegin(), subChildren.cend());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool FileData::isArcadeAsset() const
|
2018-05-10 01:29:46 +00:00
|
|
|
{
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& stem {Utils::FileSystem::getStem(mPath)};
|
2020-09-17 20:00:07 +00:00
|
|
|
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
2021-07-07 18:03:42 +00:00
|
|
|
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
2021-11-17 20:32:40 +00:00
|
|
|
(MameNames::getInstance().isBios(stem) || MameNames::getInstance().isDevice(stem)));
|
2018-05-10 01:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool FileData::isArcadeGame() const
|
2020-11-14 14:30:49 +00:00
|
|
|
{
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& stem {Utils::FileSystem::getStem(mPath)};
|
2020-11-14 14:30:49 +00:00
|
|
|
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
2021-07-07 18:03:42 +00:00
|
|
|
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
2021-11-17 20:32:40 +00:00
|
|
|
(!MameNames::getInstance().isBios(stem) && !MameNames::getInstance().isDevice(stem)));
|
2020-11-14 14:30:49 +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);
|
2022-05-18 17:47:51 +00:00
|
|
|
if (!mSystem->getFlattenFolders())
|
|
|
|
assert(file->getParent() == nullptr);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& key {file->getKey()};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mChildrenByFilename.find(key) == mChildrenByFilename.cend()) {
|
|
|
|
mChildrenByFilename[key] = file;
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildren.emplace_back(file);
|
2020-06-21 12:25:28 +00:00
|
|
|
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());
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-08 19:30:21 +00:00
|
|
|
void FileData::sort(ComparisonFunction& comparator,
|
2021-07-07 18:03:42 +00:00
|
|
|
std::pair<unsigned int, unsigned int>& gameCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-08-07 21:33:05 +00:00
|
|
|
mOnlyFolders = true;
|
2020-10-31 10:32:18 +00:00
|
|
|
mHasFolders = false;
|
2022-05-21 12:48:29 +00:00
|
|
|
bool foldersOnTop {Settings::getInstance()->getBool("FoldersOnTop")};
|
|
|
|
bool showHiddenGames {Settings::getInstance()->getBool("ShowHiddenGames")};
|
|
|
|
bool isKidMode {UIModeController::getInstance()->isUIModeKid()};
|
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-30 10:49:51 +00:00
|
|
|
if (mSystem->isGroupedCustomCollection())
|
2022-12-14 16:30:34 +00:00
|
|
|
gameCount = {0, 0};
|
2020-10-30 10:49:51 +00:00
|
|
|
|
2020-11-08 17:33:28 +00:00
|
|
|
if (!showHiddenGames) {
|
|
|
|
for (auto it = mChildren.begin(); it != mChildren.end();) {
|
2021-07-07 18:03:42 +00:00
|
|
|
// If the option to hide hidden games has been set and the game is hidden,
|
|
|
|
// then skip it. Normally games are hidden during loading of the gamelists in
|
|
|
|
// Gamelist::parseGamelist() and this code should only run when a user has marked
|
|
|
|
// an entry manually as hidden. So upon the next application startup, this game
|
|
|
|
// should be filtered already at that earlier point.
|
2020-11-08 17:33:28 +00:00
|
|
|
if ((*it)->getHidden())
|
|
|
|
it = mChildren.erase(it);
|
2021-02-04 18:57:13 +00:00
|
|
|
// Also hide folders where all its entries have been hidden, unless it's a
|
|
|
|
// grouped custom collection.
|
|
|
|
else if ((*it)->getType() == FOLDER && (*it)->getChildren().size() == 0 &&
|
2021-07-07 18:03:42 +00:00
|
|
|
!(*it)->getSystem()->isGroupedCustomCollection())
|
2020-11-08 17:33:28 +00:00
|
|
|
it = mChildren.erase(it);
|
|
|
|
else
|
2021-11-17 16:35:34 +00:00
|
|
|
++it;
|
2020-11-08 17:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
// The main custom collections view is sorted during startup in CollectionSystemsManager.
|
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") {
|
2022-12-14 16:30:34 +00:00
|
|
|
std::pair<unsigned int, unsigned int> tempGameCount {0, 0};
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-10-21 19:56:31 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sort(comparator, gameCount);
|
2020-10-30 10:49:51 +00:00
|
|
|
tempGameCount.first += gameCount.first;
|
|
|
|
tempGameCount.second += gameCount.second;
|
2022-12-14 16:30:34 +00:00
|
|
|
gameCount = {0, 0};
|
2020-10-21 19:56:31 +00:00
|
|
|
}
|
2020-10-30 10:49:51 +00:00
|
|
|
gameCount = tempGameCount;
|
2020-10-21 19:56:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
if (foldersOnTop) {
|
2022-12-14 16:30:34 +00:00
|
|
|
for (unsigned int i {0}; i < mChildren.size(); ++i) {
|
2020-09-20 10:17:38 +00:00
|
|
|
if (mChildren[i]->getType() == FOLDER) {
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenFolders.emplace_back(mChildren[i]);
|
2020-09-20 10:17:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenOthers.emplace_back(mChildren[i]);
|
2020-09-20 10:17:38 +00:00
|
|
|
mOnlyFolders = false;
|
|
|
|
}
|
2020-07-28 17:44:17 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 16:19:25 +00:00
|
|
|
// If the requested sorting is not by name, then sort in ascending name order as a first
|
|
|
|
// step, in order to get a correct secondary sorting.
|
|
|
|
if (getSortTypeFromString("name, ascending").comparisonFunction != comparator &&
|
|
|
|
getSortTypeFromString("name, descending").comparisonFunction != comparator) {
|
2021-01-08 19:30:21 +00:00
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2021-01-08 19:30:21 +00:00
|
|
|
}
|
2020-09-20 18:25:32 +00:00
|
|
|
|
2022-12-05 20:08:20 +00:00
|
|
|
if (foldersOnTop)
|
2020-09-20 10:17:38 +00:00
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(), comparator);
|
2020-10-30 17:34:05 +00:00
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(), comparator);
|
|
|
|
|
|
|
|
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 {
|
2023-08-13 16:19:25 +00:00
|
|
|
// If the requested sorting is not by name, then sort in ascending name order as a first
|
|
|
|
// step, in order to get a correct secondary sorting.
|
|
|
|
if (getSortTypeFromString("name, ascending").comparisonFunction != comparator &&
|
|
|
|
getSortTypeFromString("name, descending").comparisonFunction != comparator)
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildren.begin(), mChildren.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
|
2020-07-28 17:44:17 +00:00
|
|
|
std::stable_sort(mChildren.begin(), mChildren.end(), comparator);
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-11-17 16:35:34 +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()) {
|
2021-01-05 09:45:32 +00:00
|
|
|
if (!isKidMode || (isKidMode && (*it)->getKidgame())) {
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.first;
|
2021-01-05 09:45:32 +00:00
|
|
|
if ((*it)->getFavorite())
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.second;
|
2021-01-05 09:45:32 +00:00
|
|
|
}
|
2020-09-21 16:13:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 21:33:05 +00:00
|
|
|
if ((*it)->getType() != FOLDER)
|
|
|
|
mOnlyFolders = false;
|
2020-10-31 10:32:18 +00:00
|
|
|
else
|
|
|
|
mHasFolders = true;
|
2020-08-07 21:33:05 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Iterate through any child folders.
|
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sort(comparator, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-10-30 10:49:51 +00:00
|
|
|
if (mSystem->isGroupedCustomCollection())
|
|
|
|
mGameCount = gameCount;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 19:30:21 +00:00
|
|
|
void FileData::sortFavoritesOnTop(ComparisonFunction& comparator,
|
2021-07-07 18:03:42 +00:00
|
|
|
std::pair<unsigned int, unsigned int>& gameCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-08-07 21:33:05 +00:00
|
|
|
mOnlyFolders = true;
|
2020-10-31 10:32:18 +00:00
|
|
|
mHasFolders = false;
|
2022-05-21 12:48:29 +00:00
|
|
|
bool foldersOnTop {Settings::getInstance()->getBool("FoldersOnTop")};
|
|
|
|
bool showHiddenGames {Settings::getInstance()->getBool("ShowHiddenGames")};
|
|
|
|
bool isKidMode {UIModeController::getInstance()->isUIModeKid()};
|
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-10-30 10:49:51 +00:00
|
|
|
if (mSystem->isGroupedCustomCollection())
|
2022-12-14 16:30:34 +00:00
|
|
|
gameCount = {0, 0};
|
2020-10-30 10:49:51 +00:00
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
// The main custom collections view is sorted during startup in CollectionSystemsManager.
|
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") {
|
2022-12-14 16:30:34 +00:00
|
|
|
std::pair<unsigned int, unsigned int> tempGameCount = {0, 0};
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-10-21 19:56:31 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, gameCount);
|
2020-10-30 10:49:51 +00:00
|
|
|
tempGameCount.first += gameCount.first;
|
|
|
|
tempGameCount.second += gameCount.second;
|
2022-12-14 16:30:34 +00:00
|
|
|
gameCount = {0, 0};
|
2020-10-21 19:56:31 +00:00
|
|
|
}
|
2020-10-30 10:49:51 +00:00
|
|
|
gameCount = tempGameCount;
|
2020-10-21 19:56:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (unsigned int i {0}; i < mChildren.size(); ++i) {
|
2020-11-08 17:33:28 +00:00
|
|
|
// If the option to hide hidden games has been set and the game is hidden,
|
|
|
|
// then skip it. Normally games are hidden during loading of the gamelists in
|
|
|
|
// Gamelist::parseGamelist() and this code should only run when a user has marked
|
|
|
|
// an entry manually as hidden. So upon the next application startup, this game
|
|
|
|
// should be filtered already at that earlier point.
|
|
|
|
if (!showHiddenGames && mChildren[i]->getHidden())
|
|
|
|
continue;
|
|
|
|
// Also hide folders where all its entries have been hidden.
|
|
|
|
else if (mChildren[i]->getType() == FOLDER && mChildren[i]->getChildren().size() == 0)
|
|
|
|
continue;
|
|
|
|
|
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()) {
|
2021-01-05 09:45:32 +00:00
|
|
|
if (!isKidMode || (isKidMode && mChildren[i]->getKidgame())) {
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.first;
|
2021-01-05 09:45:32 +00:00
|
|
|
if (mChildren[i]->getFavorite())
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.second;
|
2021-01-05 09:45:32 +00:00
|
|
|
}
|
2020-09-21 16:13:27 +00:00
|
|
|
}
|
|
|
|
|
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())
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenFolders.emplace_back(mChildren[i]);
|
2020-09-20 18:25:32 +00:00
|
|
|
else
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenFavoritesFolders.emplace_back(mChildren[i]);
|
2020-07-28 17:44:17 +00:00
|
|
|
}
|
|
|
|
else if (mChildren[i]->getFavorite()) {
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenFavorites.emplace_back(mChildren[i]);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-11-09 21:40:08 +00:00
|
|
|
mChildrenOthers.emplace_back(mChildren[i]);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-08-07 21:33:05 +00:00
|
|
|
|
|
|
|
if (mChildren[i]->getType() != FOLDER)
|
|
|
|
mOnlyFolders = false;
|
2020-10-31 10:32:18 +00:00
|
|
|
else
|
|
|
|
mHasFolders = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 10:49:51 +00:00
|
|
|
if (mSystem->isGroupedCustomCollection())
|
|
|
|
mGameCount = gameCount;
|
|
|
|
|
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(),
|
2021-07-07 18:03:42 +00:00
|
|
|
mChildrenFavoritesFolders.end());
|
2020-09-20 18:25:32 +00:00
|
|
|
mChildrenFavoritesFolders.erase(mChildrenFavoritesFolders.begin(),
|
2021-07-07 18:03:42 +00:00
|
|
|
mChildrenFavoritesFolders.end());
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 16:19:25 +00:00
|
|
|
// If the requested sorting is not by name, then sort in ascending name order as a first
|
|
|
|
// step, in order to get a correct secondary sorting.
|
|
|
|
if (getSortTypeFromString("name, ascending").comparisonFunction != comparator &&
|
|
|
|
getSortTypeFromString("name, descending").comparisonFunction != comparator) {
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenFolders.begin(), mChildrenFolders.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenFavoritesFolders.begin(), mChildrenFavoritesFolders.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenFavorites.begin(), mChildrenFavorites.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
std::stable_sort(mChildrenOthers.begin(), mChildrenOthers.end(),
|
2023-08-13 16:19:25 +00:00
|
|
|
getSortTypeFromString("name, ascending").comparisonFunction);
|
2020-09-20 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sort favorite games and the other games separately.
|
2022-12-05 20:08:20 +00:00
|
|
|
if (foldersOnTop) {
|
2021-07-07 18:03:42 +00:00
|
|
|
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.
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto it = mChildrenFavoritesFolders.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mChildrenFavoritesFolders.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through any child folders.
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildrenFolders.cbegin(); it != mChildrenFolders.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 17:34:05 +00:00
|
|
|
// If folders are not sorted on top, mChildrenFavoritesFolders and mChildrenFolders
|
|
|
|
// could be empty. So due to this, step through all mChildren and see if there are
|
|
|
|
// any folders that we need to iterate.
|
|
|
|
if (mChildrenFavoritesFolders.size() == 0 && mChildrenFolders.size() == 0) {
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-10-30 17:34:05 +00:00
|
|
|
if ((*it)->getChildren().size() > 0)
|
2021-01-08 19:30:21 +00:00
|
|
|
(*it)->sortFavoritesOnTop(comparator, gameCount);
|
2020-09-20 18:25:32 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() +
|
2021-07-07 18:03:42 +00:00
|
|
|
mChildrenFavorites.size() + mChildrenOthers.size());
|
2020-09-20 18:25:32 +00:00
|
|
|
mChildren.insert(mChildren.end(), mChildrenFavoritesFolders.begin(),
|
2021-07-07 18:03:42 +00:00
|
|
|
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)
|
2021-01-08 19:30:21 +00:00
|
|
|
sortFavoritesOnTop(*type.comparisonFunction, mGameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2021-01-08 19:30:21 +00:00
|
|
|
sort(*type.comparisonFunction, mGameCount);
|
2022-02-13 19:03:34 +00:00
|
|
|
|
|
|
|
updateLastPlayedList();
|
|
|
|
updateMostPlayedList();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-10-30 11:53:35 +00:00
|
|
|
void FileData::countGames(std::pair<unsigned int, unsigned int>& gameCount)
|
|
|
|
{
|
2022-05-21 12:48:29 +00:00
|
|
|
bool isKidMode {(Settings::getInstance()->getString("UIMode") == "kid" ||
|
|
|
|
Settings::getInstance()->getBool("ForceKid"))};
|
2021-01-05 09:45:32 +00:00
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (unsigned int i {0}; i < mChildren.size(); ++i) {
|
2020-10-30 11:53:35 +00:00
|
|
|
if (mChildren[i]->getType() == GAME && mChildren[i]->getCountAsGame()) {
|
2021-01-05 09:45:32 +00:00
|
|
|
if (!isKidMode || (isKidMode && mChildren[i]->getKidgame())) {
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.first;
|
2021-01-05 09:45:32 +00:00
|
|
|
if (mChildren[i]->getFavorite())
|
2021-11-17 16:35:34 +00:00
|
|
|
++gameCount.second;
|
2021-01-05 09:45:32 +00:00
|
|
|
}
|
2020-10-30 11:53:35 +00:00
|
|
|
}
|
|
|
|
// Iterate through any folders.
|
|
|
|
else if (mChildren[i]->getType() == FOLDER)
|
|
|
|
mChildren[i]->countGames(gameCount);
|
|
|
|
}
|
|
|
|
mGameCount = gameCount;
|
|
|
|
}
|
|
|
|
|
2022-02-13 19:03:34 +00:00
|
|
|
void FileData::updateLastPlayedList()
|
|
|
|
{
|
2022-02-14 18:32:07 +00:00
|
|
|
if (mUpdateListCallback)
|
|
|
|
mUpdateListCallback();
|
|
|
|
|
2022-02-13 19:03:34 +00:00
|
|
|
if (!mUpdateChildrenLastPlayed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mChildrenLastPlayed.clear();
|
|
|
|
mChildrenLastPlayed = getChildrenRecursive();
|
|
|
|
|
|
|
|
std::stable_sort(mChildrenLastPlayed.begin(), mChildrenLastPlayed.end());
|
|
|
|
std::sort(std::begin(mChildrenLastPlayed), std::end(mChildrenLastPlayed),
|
|
|
|
[](FileData* a, FileData* b) {
|
|
|
|
return a->metadata.get("lastplayed") > b->metadata.get("lastplayed");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileData::updateMostPlayedList()
|
|
|
|
{
|
2022-02-14 18:32:07 +00:00
|
|
|
if (mUpdateListCallback)
|
|
|
|
mUpdateListCallback();
|
|
|
|
|
2022-02-13 19:03:34 +00:00
|
|
|
if (!mUpdateChildrenMostPlayed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mChildrenMostPlayed.clear();
|
|
|
|
mChildrenMostPlayed = getChildrenRecursive();
|
|
|
|
|
|
|
|
std::stable_sort(mChildrenMostPlayed.begin(), mChildrenMostPlayed.end());
|
|
|
|
std::sort(std::begin(mChildrenMostPlayed), std::end(mChildrenMostPlayed),
|
|
|
|
[](FileData* a, FileData* b) {
|
|
|
|
return a->metadata.getInt("playcount") > b->metadata.getInt("playcount");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const FileData::SortType& FileData::getSortTypeFromString(const std::string& desc) const
|
2021-07-07 18:03:42 +00:00
|
|
|
{
|
2022-12-14 16:30:34 +00:00
|
|
|
std::vector<FileData::SortType> SortTypes {FileSorts::SortTypes};
|
2020-09-17 20:18:13 +00:00
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (unsigned int i {0}; i < FileSorts::SortTypes.size(); ++i) {
|
2022-05-21 12:48:29 +00:00
|
|
|
const FileData::SortType& sort {FileSorts::SortTypes.at(i)};
|
2020-09-17 20:18:13 +00:00
|
|
|
if (sort.description == desc)
|
|
|
|
return sort;
|
|
|
|
}
|
2023-08-13 16:19:25 +00:00
|
|
|
// If no type was found then default to "name, ascending".
|
2020-09-17 20:18:13 +00:00
|
|
|
return FileSorts::SortTypes.at(0);
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
void FileData::launchGame()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-01-19 17:01:54 +00:00
|
|
|
Window* window {Window::getInstance()};
|
|
|
|
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\" from system \""
|
|
|
|
<< getSourceFileData()->getSystem()->getFullName() << " ("
|
|
|
|
<< getSourceFileData()->getSystem()->getName() << ")\"...";
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2022-04-22 19:01:58 +00:00
|
|
|
SystemData* gameSystem {nullptr};
|
|
|
|
std::string command;
|
2021-09-23 15:07:27 +00:00
|
|
|
std::string alternativeEmulator;
|
|
|
|
|
|
|
|
if (mSystem->isCollection())
|
|
|
|
gameSystem = SystemData::getSystemByName(mSystemName);
|
|
|
|
else
|
|
|
|
gameSystem = mSystem;
|
|
|
|
|
|
|
|
// This is just a precaution as getSystemByName() should always return a valid result.
|
|
|
|
if (gameSystem == nullptr)
|
|
|
|
gameSystem = mSystem;
|
|
|
|
|
|
|
|
alternativeEmulator = gameSystem->getAlternativeEmulator();
|
2021-09-04 09:21:55 +00:00
|
|
|
|
|
|
|
// Check if there is a game-specific alternative emulator configured.
|
|
|
|
// This takes precedence over any system-wide alternative emulator configuration.
|
|
|
|
if (Settings::getInstance()->getBool("AlternativeEmulatorPerGame") &&
|
|
|
|
!metadata.get("altemulator").empty()) {
|
2021-09-23 15:07:27 +00:00
|
|
|
command = gameSystem->getLaunchCommandFromLabel(metadata.get("altemulator"));
|
2021-09-04 09:21:55 +00:00
|
|
|
if (command == "") {
|
|
|
|
LOG(LogWarning) << "Invalid alternative emulator \"" << metadata.get("altemulator")
|
|
|
|
<< "\" configured for game";
|
2021-08-22 13:26:38 +00:00
|
|
|
}
|
2021-09-04 09:21:55 +00:00
|
|
|
else {
|
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Using alternative emulator \""
|
2021-09-05 15:29:51 +00:00
|
|
|
<< metadata.get("altemulator")
|
|
|
|
<< "\" as configured for the specific game";
|
2021-08-22 13:26:38 +00:00
|
|
|
}
|
2021-09-04 09:21:55 +00:00
|
|
|
}
|
|
|
|
// Check if there is a system-wide alternative emulator configured.
|
2023-10-09 19:47:32 +00:00
|
|
|
else if (command == "" && alternativeEmulator != "") {
|
2021-09-23 15:07:27 +00:00
|
|
|
command = gameSystem->getLaunchCommandFromLabel(alternativeEmulator);
|
2021-09-04 09:21:55 +00:00
|
|
|
if (command == "") {
|
|
|
|
LOG(LogWarning) << "Invalid alternative emulator \""
|
|
|
|
<< alternativeEmulator.substr(9, alternativeEmulator.length() - 9)
|
2021-09-23 15:07:27 +00:00
|
|
|
<< "\" configured for system \"" << gameSystem->getName() << "\"";
|
2021-09-04 09:21:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Using alternative emulator \""
|
2021-09-23 15:07:27 +00:00
|
|
|
<< gameSystem->getAlternativeEmulator() << "\""
|
|
|
|
<< " as configured for system \"" << gameSystem->getName() << "\"";
|
2021-09-04 09:21:55 +00:00
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
2023-10-09 19:47:32 +00:00
|
|
|
else {
|
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Using default emulator \""
|
|
|
|
<< mEnvData->mLaunchCommands.front().second << "\"";
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2021-09-04 09:21:55 +00:00
|
|
|
if (command.empty())
|
|
|
|
command = mEnvData->mLaunchCommands.front().first;
|
|
|
|
|
2022-04-22 19:01:58 +00:00
|
|
|
std::string commandRaw {command};
|
|
|
|
std::string romPath {Utils::FileSystem::getEscapedPath(mPath)};
|
2022-05-19 21:36:12 +00:00
|
|
|
std::string baseName {Utils::FileSystem::getStem(mPath)};
|
2022-04-22 19:01:58 +00:00
|
|
|
|
|
|
|
// For the special case where a directory has a supported file extension and is therefore
|
|
|
|
// interpreted as a file, check if there is a matching filename inside the directory.
|
|
|
|
// This is used as a shortcut to be able to launch games directly inside folders.
|
|
|
|
if (mType == GAME && Utils::FileSystem::isDirectory(mPath)) {
|
|
|
|
for (std::string& file : Utils::FileSystem::getDirContent(mPath)) {
|
|
|
|
if (Utils::FileSystem::getFileName(file) == Utils::FileSystem::getFileName(mPath) &&
|
|
|
|
(Utils::FileSystem::isRegularFile(file) || Utils::FileSystem::isSymlink(file))) {
|
|
|
|
romPath = Utils::FileSystem::getEscapedPath(file);
|
2022-05-19 21:36:12 +00:00
|
|
|
baseName = baseName.substr(0, baseName.find("."));
|
2022-04-22 19:01:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-07 19:25:15 +00:00
|
|
|
|
2022-07-15 20:01:28 +00:00
|
|
|
const std::string fileName {baseName + Utils::FileSystem::getExtension(romPath)};
|
2022-04-22 19:01:58 +00:00
|
|
|
const std::string romRaw {Utils::FileSystem::getPreferredPath(mPath)};
|
|
|
|
const std::string esPath {Utils::FileSystem::getExePath()};
|
|
|
|
bool runInBackground {false};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2021-11-22 19:03:05 +00:00
|
|
|
// In addition to the global RunInBackground setting it's possible to define this flag
|
|
|
|
// per launch command in es_systems.xml.
|
2022-04-22 19:01:58 +00:00
|
|
|
size_t inBackgroundPos {command.find("%RUNINBACKGROUND%")};
|
2021-11-22 19:03:05 +00:00
|
|
|
|
|
|
|
if (inBackgroundPos != std::string::npos) {
|
|
|
|
runInBackground = true;
|
|
|
|
command = Utils::String::replace(command, "%RUNINBACKGROUND%", "");
|
|
|
|
// Trim any leading whitespaces as they could cause the script execution to fail.
|
|
|
|
command.erase(command.begin(), std::find_if(command.begin(), command.end(), [](char c) {
|
|
|
|
return !std::isspace(static_cast<unsigned char>(c));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The global setting always applies.
|
|
|
|
if (Settings::getInstance()->getBool("RunInBackground"))
|
|
|
|
runInBackground = true;
|
2021-07-16 15:56:16 +00:00
|
|
|
|
2022-05-31 20:25:36 +00:00
|
|
|
#if !defined(_WIN64)
|
|
|
|
// Whether to parse .desktop files on Unix or open apps or alias files on macOS.
|
|
|
|
bool isShortcut {false};
|
|
|
|
size_t enableShortcutsPos {command.find("%ENABLESHORTCUTS%")};
|
|
|
|
|
|
|
|
if (enableShortcutsPos != std::string::npos) {
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
if (Utils::FileSystem::getExtension(romRaw) == ".app")
|
|
|
|
#else
|
|
|
|
if (Utils::FileSystem::getExtension(romRaw) == ".desktop")
|
|
|
|
#endif
|
|
|
|
isShortcut = true;
|
|
|
|
|
|
|
|
command = Utils::String::replace(command, "%ENABLESHORTCUTS%", "");
|
|
|
|
// Trim any leading whitespaces as they could cause the script execution to fail.
|
|
|
|
command.erase(command.begin(), std::find_if(command.begin(), command.end(), [](char c) {
|
|
|
|
return !std::isspace(static_cast<unsigned char>(c));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
std::string coreEntry;
|
|
|
|
std::string coreName;
|
2022-05-21 12:48:29 +00:00
|
|
|
size_t coreEntryPos {0};
|
|
|
|
size_t coreFilePos {0};
|
|
|
|
bool foundCoreFile {false};
|
2021-06-19 12:09:14 +00:00
|
|
|
std::vector<std::string> emulatorCorePaths;
|
|
|
|
|
2021-07-16 15:56:16 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-08 12:25:27 +00:00
|
|
|
bool hideWindow {false};
|
2021-11-22 19:03:05 +00:00
|
|
|
|
2021-07-16 15:56:16 +00:00
|
|
|
// If the %HIDEWINDOW% variable is defined, we pass a flag to launchGameWindows() to
|
|
|
|
// hide the window. This is intended primarily for hiding console windows when launching
|
|
|
|
// scripts (used for example by Steam games and source ports).
|
2022-05-08 12:25:27 +00:00
|
|
|
if (command.find("%HIDEWINDOW%") != std::string::npos) {
|
2021-07-16 15:56:16 +00:00
|
|
|
hideWindow = true;
|
|
|
|
command = Utils::String::replace(command, "%HIDEWINDOW%", "");
|
|
|
|
// Trim any leading whitespaces as they could cause the script execution to fail.
|
|
|
|
command.erase(command.begin(), std::find_if(command.begin(), command.end(), [](char c) {
|
|
|
|
return !std::isspace(static_cast<unsigned char>(c));
|
|
|
|
}));
|
|
|
|
}
|
2022-05-08 12:25:27 +00:00
|
|
|
|
|
|
|
bool escapeSpecials {false};
|
|
|
|
|
|
|
|
// If calling scripts and links using some binaries like cmd.exe then the special characters
|
|
|
|
// &()^=;, must be escaped.
|
|
|
|
if (command.find("%ESCAPESPECIALS%") != std::string::npos) {
|
|
|
|
escapeSpecials = true;
|
|
|
|
command = Utils::String::replace(command, "%ESCAPESPECIALS%", "");
|
|
|
|
// Trim any leading whitespaces as they could cause the script execution to fail.
|
|
|
|
command.erase(command.begin(), std::find_if(command.begin(), command.end(), [](char c) {
|
|
|
|
return !std::isspace(static_cast<unsigned char>(c));
|
|
|
|
}));
|
|
|
|
}
|
2021-07-16 15:56:16 +00:00
|
|
|
#endif
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
// If there's a quotation mark before the %CORE_ variable, then remove it.
|
|
|
|
// The closing quotation mark will be removed later below.
|
2022-05-02 15:25:10 +00:00
|
|
|
bool hasCoreQuotation {false};
|
|
|
|
if (command.find("\"%CORE_") != std::string::npos) {
|
|
|
|
command = Utils::String::replace(command, "\"%CORE_", "%CORE_");
|
|
|
|
hasCoreQuotation = true;
|
|
|
|
}
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
coreEntryPos = command.find("%CORE_");
|
|
|
|
if (coreEntryPos != std::string::npos) {
|
|
|
|
coreFilePos = command.find("%", coreEntryPos + 6);
|
|
|
|
if (coreFilePos != std::string::npos)
|
|
|
|
coreEntry = command.substr(coreEntryPos + 6, coreFilePos - (coreEntryPos + 6));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coreEntry != "")
|
|
|
|
emulatorCorePaths = SystemData::sFindRules.get()->mCores[coreEntry].corePaths;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-07-10 18:58:53 +00:00
|
|
|
// Expand home path if ~ is used.
|
|
|
|
command = Utils::FileSystem::expandHomePath(command);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2023-09-22 15:35:32 +00:00
|
|
|
std::string preCommandPath;
|
|
|
|
|
|
|
|
// Check for any pre-command entry, and if it exists then expand it using the find rules.
|
|
|
|
if (command.find("%PRECOMMAND_") != std::string::npos) {
|
|
|
|
preCommandPath = findEmulatorPath(command, true);
|
|
|
|
// Show an error message if there was no matching emulator entry in es_find_rules.xml.
|
|
|
|
if (preCommandPath.substr(0, 18) == "NO EMULATOR RULE: ") {
|
|
|
|
const std::string& preCommandEntry {
|
|
|
|
preCommandPath.substr(18, preCommandPath.size() - 18)};
|
|
|
|
LOG(LogError)
|
|
|
|
<< "Couldn't launch game, either there is no emulator entry for pre-command \""
|
|
|
|
<< preCommandEntry << "\" in es_find_rules.xml or there are no rules defined";
|
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
|
|
|
window->queueInfoPopup("ERROR: MISSING PRE-COMMAND FIND RULES CONFIGURATION FOR '" +
|
|
|
|
preCommandEntry + "'",
|
|
|
|
6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (preCommandPath.empty()) {
|
|
|
|
LOG(LogError) << "Couldn't launch game, pre-command binary not found";
|
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
|
|
|
std::string emulatorName;
|
|
|
|
size_t startPos {0};
|
|
|
|
size_t endPos {0};
|
|
|
|
|
|
|
|
if ((startPos = command.find("%PRECOMMAND_")) != std::string::npos) {
|
|
|
|
endPos = command.find("%", startPos + 1);
|
|
|
|
if (endPos != std::string::npos)
|
|
|
|
emulatorName = command.substr(startPos + 12, endPos - startPos - 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emulatorName == "")
|
|
|
|
window->queueInfoPopup(
|
|
|
|
"ERROR: COULDN'T FIND PRE-COMMAND, HAS IT BEEN PROPERLY INSTALLED?", 6000);
|
|
|
|
else
|
|
|
|
window->queueInfoPopup("ERROR: COULDN'T FIND PRE-COMMAND '" + emulatorName +
|
|
|
|
"', HAS IT BEEN PROPERLY INSTALLED?",
|
|
|
|
6000);
|
|
|
|
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-09-22 15:48:40 +00:00
|
|
|
else {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Pre-command binary set to \""
|
|
|
|
<< preCommandPath << "\"";
|
2023-09-22 15:48:40 +00:00
|
|
|
}
|
2023-09-22 15:35:32 +00:00
|
|
|
}
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
// Check that the emulator binary actually exists, and if so, get its path.
|
2023-09-22 15:35:32 +00:00
|
|
|
const std::string& binaryPath {findEmulatorPath(command, false)};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2023-09-22 15:35:32 +00:00
|
|
|
// Show an error message if there was no matching emulator entry in es_find_rules.xml.
|
2021-06-23 18:37:18 +00:00
|
|
|
if (binaryPath.substr(0, 18) == "NO EMULATOR RULE: ") {
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& emulatorEntry {binaryPath.substr(18, binaryPath.size() - 18)};
|
2021-12-16 17:05:36 +00:00
|
|
|
LOG(LogError) << "Couldn't launch game, either there is no emulator entry for \""
|
|
|
|
<< emulatorEntry << "\" in es_find_rules.xml or there are no rules defined";
|
2021-06-19 12:09:14 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
2022-02-20 20:28:23 +00:00
|
|
|
window->queueInfoPopup(
|
|
|
|
"ERROR: MISSING EMULATOR FIND RULES CONFIGURATION FOR '" + emulatorEntry + "'", 6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2021-06-19 12:09:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-23 18:37:18 +00:00
|
|
|
else if (binaryPath.empty()) {
|
2021-01-10 21:55:17 +00:00
|
|
|
LOG(LogError) << "Couldn't launch game, emulator binary not found";
|
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
2022-02-20 20:28:23 +00:00
|
|
|
std::string emulatorName;
|
|
|
|
size_t startPos {0};
|
|
|
|
size_t endPos {0};
|
|
|
|
|
|
|
|
if ((startPos = command.find("%EMULATOR_")) != std::string::npos) {
|
|
|
|
endPos = command.find("%", startPos + 1);
|
|
|
|
if (endPos != std::string::npos)
|
|
|
|
emulatorName = command.substr(startPos + 10, endPos - startPos - 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emulatorName == "")
|
|
|
|
window->queueInfoPopup("ERROR: COULDN'T FIND EMULATOR, HAS IT BEEN PROPERLY INSTALLED?",
|
|
|
|
6000);
|
|
|
|
else
|
|
|
|
window->queueInfoPopup("ERROR: COULDN'T FIND EMULATOR '" + emulatorName +
|
|
|
|
"', HAS IT BEEN PROPERLY INSTALLED?",
|
|
|
|
6000);
|
|
|
|
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2021-01-10 21:55:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-31 21:07:24 +00:00
|
|
|
else {
|
2022-07-01 14:42:21 +00:00
|
|
|
std::string binaryLogPath {Utils::String::replace(
|
|
|
|
Utils::String::replace(binaryPath, "%ESPATH%", esPath), "/", "\\")};
|
|
|
|
if (binaryLogPath.front() != '\"' && binaryLogPath.back() != '\"')
|
|
|
|
binaryLogPath = "\"" + binaryLogPath + "\"";
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Emulator binary set to " << binaryLogPath;
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2022-05-31 21:07:24 +00:00
|
|
|
else if (!isShortcut) {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Emulator binary set to \""
|
2021-07-07 18:03:42 +00:00
|
|
|
<< Utils::String::replace(binaryPath, "%ESPATH%", esPath) << "\"";
|
|
|
|
#endif
|
2021-06-30 15:37:17 +00:00
|
|
|
}
|
2020-07-07 19:25:15 +00:00
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
// If %EMUPATH% is used in es_systems.xml for this system, then check that the core
|
|
|
|
// file actually exists.
|
2022-05-21 12:48:29 +00:00
|
|
|
size_t emuPathPos {command.find("%EMUPATH%")};
|
2021-01-11 17:21:14 +00:00
|
|
|
if (emuPathPos != std::string::npos) {
|
2022-05-21 12:48:29 +00:00
|
|
|
bool hasQuotationMark {false};
|
|
|
|
unsigned int quotationMarkPos {0};
|
2021-01-11 17:21:14 +00:00
|
|
|
if (command.find("\"%EMUPATH%", emuPathPos - 1) != std::string::npos) {
|
|
|
|
hasQuotationMark = true;
|
2021-07-07 18:03:42 +00:00
|
|
|
quotationMarkPos =
|
|
|
|
static_cast<unsigned int>(command.find("\"", emuPathPos + 9) - emuPathPos);
|
2021-01-11 17:21:14 +00:00
|
|
|
}
|
2022-12-14 16:30:34 +00:00
|
|
|
const size_t spacePos {command.find(" ", emuPathPos + quotationMarkPos)};
|
2021-01-11 17:21:14 +00:00
|
|
|
std::string coreRaw;
|
|
|
|
std::string coreFile;
|
|
|
|
if (spacePos != std::string::npos) {
|
|
|
|
coreRaw = command.substr(emuPathPos, spacePos - emuPathPos);
|
2022-05-02 15:25:10 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
coreFile = Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")) +
|
|
|
|
command.substr(emuPathPos + 9, spacePos - emuPathPos - 9);
|
|
|
|
coreFile = Utils::String::replace(coreFile, "/", "\\");
|
|
|
|
#else
|
2021-06-23 18:37:18 +00:00
|
|
|
coreFile = Utils::FileSystem::getParent(binaryPath) +
|
2021-07-07 18:03:42 +00:00
|
|
|
command.substr(emuPathPos + 9, spacePos - emuPathPos - 9);
|
2022-05-02 15:25:10 +00:00
|
|
|
#endif
|
2021-01-11 17:21:14 +00:00
|
|
|
if (hasQuotationMark) {
|
|
|
|
coreRaw.pop_back();
|
|
|
|
coreFile.pop_back();
|
|
|
|
}
|
|
|
|
if (!Utils::FileSystem::isRegularFile(coreFile) &&
|
2021-07-07 18:03:42 +00:00
|
|
|
!Utils::FileSystem::isSymlink(coreFile)) {
|
|
|
|
LOG(LogError) << "Couldn't launch game, emulator core file \""
|
|
|
|
<< Utils::FileSystem::getFileName(coreFile) << "\" not found";
|
2021-01-11 17:21:14 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup(
|
2021-07-07 18:03:42 +00:00
|
|
|
"ERROR: COULDN'T FIND EMULATOR CORE FILE '" +
|
|
|
|
Utils::String::toUpper(Utils::FileSystem::getFileName(coreFile)) + "'",
|
|
|
|
6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2021-01-11 17:21:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (hasQuotationMark) {
|
|
|
|
command = command.replace(emuPathPos + quotationMarkPos, 1, "");
|
2021-11-17 16:35:34 +00:00
|
|
|
--emuPathPos;
|
2021-01-11 17:21:14 +00:00
|
|
|
command = command.replace(emuPathPos, 1, "");
|
|
|
|
}
|
|
|
|
coreFile = Utils::FileSystem::getEscapedPath(coreFile);
|
|
|
|
command = command.replace(emuPathPos, coreRaw.size(), coreFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "Invalid entry in systems configuration file es_systems.xml";
|
2021-01-11 17:21:14 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2021-01-11 17:21:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
// Error handling in case of no core find rule.
|
|
|
|
if (coreEntry != "" && emulatorCorePaths.empty()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Couldn't launch game, either there is no core entry for \"" << coreEntry
|
|
|
|
<< "\" in es_find_rules.xml or there are no corepath rules defined";
|
2021-06-19 12:09:14 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
2021-01-11 17:21:14 +00:00
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup("ERROR: MISSING CORE CONFIGURATION FOR '" + coreEntry + "'", 6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2021-06-19 12:09:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a %CORE_ find rule entry is used in es_systems.xml for this system, then try to find
|
|
|
|
// the emulator core using the rules defined in es_find_rules.xml.
|
2022-12-14 16:30:34 +00:00
|
|
|
for (std::string& path : emulatorCorePaths) {
|
2021-06-20 10:30:14 +00:00
|
|
|
// The position of the %CORE_ variable could have changed as there may have been an
|
|
|
|
// %EMULATOR_ variable that was substituted for the actual emulator binary.
|
|
|
|
coreEntryPos = command.find("%CORE_");
|
|
|
|
coreFilePos = command.find("%", coreEntryPos + 6);
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
size_t separatorPos;
|
2023-10-08 19:02:14 +00:00
|
|
|
size_t quotePos {hasCoreQuotation ? command.find("\"", coreFilePos) : std::string::npos};
|
2021-06-19 12:09:14 +00:00
|
|
|
if (quotePos == std::string::npos)
|
|
|
|
separatorPos = command.find(" ", coreFilePos);
|
|
|
|
else
|
|
|
|
separatorPos = quotePos;
|
|
|
|
|
|
|
|
if (separatorPos != std::string::npos) {
|
2021-07-07 18:03:42 +00:00
|
|
|
coreName = command.substr(coreFilePos + 2, separatorPos - (coreFilePos + 2));
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-21 12:48:29 +00:00
|
|
|
std::string coreFile {Utils::FileSystem::expandHomePath(path + "\\" + coreName)};
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2022-05-21 12:48:29 +00:00
|
|
|
std::string coreFile {Utils::FileSystem::expandHomePath(path + "/" + coreName)};
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
// Expand %EMUPATH% if it has been used in the %CORE_ variable.
|
2022-05-21 12:48:29 +00:00
|
|
|
size_t stringPos {coreFile.find("%EMUPATH%")};
|
2021-06-20 10:30:14 +00:00
|
|
|
if (stringPos != std::string::npos) {
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-02 15:25:10 +00:00
|
|
|
coreFile = coreFile.replace(
|
|
|
|
stringPos, 9,
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")));
|
|
|
|
coreFile = Utils::String::replace(coreFile, "/", "\\");
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-06-23 18:37:18 +00:00
|
|
|
coreFile = coreFile.replace(stringPos, 9, Utils::FileSystem::getParent(binaryPath));
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-20 10:30:14 +00:00
|
|
|
}
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
// Expand %ESPATH% if it has been used in the %CORE_ variable.
|
|
|
|
stringPos = coreFile.find("%ESPATH%");
|
|
|
|
if (stringPos != std::string::npos) {
|
|
|
|
coreFile = coreFile.replace(stringPos, 8, esPath);
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-19 12:09:14 +00:00
|
|
|
coreFile = Utils::String::replace(coreFile, "/", "\\");
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils::FileSystem::isRegularFile(coreFile) ||
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::isSymlink(coreFile)) {
|
2021-06-19 12:09:14 +00:00
|
|
|
foundCoreFile = true;
|
|
|
|
// Escape any blankspaces.
|
|
|
|
if (coreFile.find(" ") != std::string::npos)
|
|
|
|
coreFile = Utils::FileSystem::getEscapedPath(coreFile);
|
2022-05-02 15:25:10 +00:00
|
|
|
command.replace(coreEntryPos,
|
|
|
|
separatorPos - coreEntryPos + (hasCoreQuotation ? 1 : 0), coreFile);
|
2021-06-19 12:09:14 +00:00
|
|
|
break;
|
2020-12-15 17:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "Invalid entry in systems configuration file es_systems.xml";
|
2020-12-15 17:42:38 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2020-12-15 17:42:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 12:09:14 +00:00
|
|
|
if (!foundCoreFile && coreName.size() > 0) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Couldn't launch game, emulator core file \""
|
|
|
|
<< coreName.substr(0, coreName.size()) << "\" not found";
|
2021-06-19 12:09:14 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError)
|
|
|
|
<< "Tried to find the core file using these paths as defined by es_find_rules.xml:";
|
2021-06-19 12:09:14 +00:00
|
|
|
LOG(LogError) << Utils::String::vectorToDelimitedString(emulatorCorePaths, ", ");
|
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup(
|
|
|
|
"ERROR: COULDN'T FIND EMULATOR CORE FILE '" +
|
|
|
|
Utils::String::toUpper(coreName.substr(0, coreName.size()) + "'"),
|
|
|
|
6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2020-12-15 17:42:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-30 18:43:29 +00:00
|
|
|
std::string startDirectory;
|
2022-12-14 16:30:34 +00:00
|
|
|
const size_t startDirPos {command.find("%STARTDIR%")};
|
2022-04-30 18:43:29 +00:00
|
|
|
|
|
|
|
if (startDirPos != std::string::npos) {
|
|
|
|
bool invalidEntry {false};
|
|
|
|
|
|
|
|
if (startDirPos + 12 >= command.size())
|
|
|
|
invalidEntry = true;
|
|
|
|
else if (command[startDirPos + 10] != '=')
|
|
|
|
invalidEntry = true;
|
|
|
|
|
|
|
|
if (!invalidEntry && command[startDirPos + 11] == '\"') {
|
|
|
|
size_t closingQuotation {command.find("\"", startDirPos + 12)};
|
|
|
|
|
|
|
|
if (closingQuotation != std::string::npos) {
|
|
|
|
startDirectory =
|
|
|
|
command.substr(startDirPos + 12, closingQuotation - startDirPos - 12);
|
|
|
|
command = command.replace(startDirPos, closingQuotation - startDirPos + 2, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
invalidEntry = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!invalidEntry) {
|
2022-12-14 16:30:34 +00:00
|
|
|
const size_t spacePos {command.find(" ", startDirPos)};
|
2022-04-30 18:43:29 +00:00
|
|
|
if (spacePos != std::string::npos) {
|
|
|
|
startDirectory = command.substr(startDirPos + 11, spacePos - startDirPos - 11);
|
|
|
|
command = command.replace(startDirPos, spacePos - startDirPos + 1, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
startDirectory = command.substr(startDirPos + 11, command.size() - startDirPos);
|
|
|
|
command = command.replace(startDirPos, command.size() - startDirPos, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invalidEntry) {
|
|
|
|
LOG(LogError) << "Couldn't launch game, invalid %STARTDIR% entry";
|
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
|
|
|
window->queueInfoPopup("ERROR: INVALID %STARTDIR% VARIABLE ENTRY", 6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startDirectory != "") {
|
|
|
|
startDirectory = Utils::FileSystem::expandHomePath(startDirectory);
|
|
|
|
#if defined(_WIN64)
|
|
|
|
startDirectory = Utils::String::replace(
|
|
|
|
startDirectory, "%EMUDIR%",
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\"", "")));
|
2022-05-13 17:18:38 +00:00
|
|
|
|
|
|
|
startDirectory = Utils::String::replace(
|
|
|
|
startDirectory, "%GAMEDIR%",
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\"", "")));
|
2022-07-12 17:57:47 +00:00
|
|
|
|
|
|
|
startDirectory = Utils::String::replace(startDirectory, "%GAMEENTRYDIR%",
|
|
|
|
Utils::String::replace(romPath, "\"", ""));
|
2022-04-30 18:43:29 +00:00
|
|
|
#else
|
|
|
|
startDirectory = Utils::String::replace(
|
|
|
|
startDirectory, "%EMUDIR%",
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(binaryPath, "\\", "")));
|
2022-05-13 17:18:38 +00:00
|
|
|
|
|
|
|
startDirectory = Utils::String::replace(
|
|
|
|
startDirectory, "%GAMEDIR%",
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")));
|
2022-07-12 17:57:47 +00:00
|
|
|
|
|
|
|
startDirectory = Utils::String::replace(startDirectory, "%GAMEENTRYDIR%",
|
|
|
|
Utils::String::replace(romPath, "\\", ""));
|
2022-04-30 18:43:29 +00:00
|
|
|
#endif
|
|
|
|
if (!Utils::FileSystem::isDirectory(startDirectory)) {
|
|
|
|
Utils::FileSystem::createDirectory(startDirectory);
|
|
|
|
|
|
|
|
if (!Utils::FileSystem::isDirectory(startDirectory)) {
|
2022-07-12 17:57:47 +00:00
|
|
|
LOG(LogError) << "Couldn't launch game, directory \"" << startDirectory
|
|
|
|
<< "\" defined by %STARTDIR% could not be created, "
|
|
|
|
"permission problems?";
|
2022-04-30 18:43:29 +00:00
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
|
|
|
|
|
|
|
window->queueInfoPopup("ERROR: DIRECTORY DEFINED BY %STARTDIR% COULD NOT BE "
|
|
|
|
"CREATED, PERMISSION PROBLEMS?",
|
|
|
|
6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(_WIN64)
|
|
|
|
startDirectory = Utils::String::replace(startDirectory, "/", "\\");
|
|
|
|
#else
|
|
|
|
startDirectory = Utils::FileSystem::getEscapedPath(startDirectory);
|
|
|
|
#endif
|
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Setting start directory to \""
|
|
|
|
<< startDirectory << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-21 09:43:17 +00:00
|
|
|
std::string injectFile;
|
2023-10-02 18:02:29 +00:00
|
|
|
size_t injectPos {command.find("%INJECT%")};
|
2022-05-21 09:43:17 +00:00
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
while (injectPos != std::string::npos) {
|
|
|
|
if (injectPos != std::string::npos) {
|
|
|
|
bool invalidEntry {false};
|
2022-05-21 09:43:17 +00:00
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
if (injectPos + 10 >= command.size())
|
|
|
|
invalidEntry = true;
|
|
|
|
else if (command[injectPos + 8] != '=')
|
|
|
|
invalidEntry = true;
|
2022-05-21 09:43:17 +00:00
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
if (!invalidEntry && command[injectPos + 9] == '\"') {
|
|
|
|
size_t closingQuotation {command.find("\"", injectPos + 10)};
|
2022-05-21 09:43:17 +00:00
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
if (closingQuotation != std::string::npos) {
|
|
|
|
injectFile = command.substr(injectPos + 10, closingQuotation - injectPos - 10);
|
|
|
|
command = command.replace(injectPos, closingQuotation - injectPos + 2, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
invalidEntry = true;
|
|
|
|
}
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
2023-10-02 18:02:29 +00:00
|
|
|
else if (!invalidEntry) {
|
|
|
|
const size_t spacePos {command.find(" ", injectPos)};
|
|
|
|
if (spacePos != std::string::npos) {
|
|
|
|
injectFile = command.substr(injectPos + 9, spacePos - injectPos - 9);
|
|
|
|
command = command.replace(injectPos, spacePos - injectPos + 1, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
injectFile = command.substr(injectPos + 9, command.size() - injectPos);
|
|
|
|
command = command.replace(injectPos, command.size() - injectPos, "");
|
|
|
|
}
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
if (invalidEntry) {
|
|
|
|
LOG(LogError) << "Couldn't launch game, invalid %INJECT% entry";
|
|
|
|
LOG(LogError) << "Raw emulator launch command:";
|
|
|
|
LOG(LogError) << commandRaw;
|
2022-05-21 09:43:17 +00:00
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
window->queueInfoPopup("ERROR: INVALID %INJECT% VARIABLE ENTRY", 6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 18:02:29 +00:00
|
|
|
if (injectFile != "") {
|
2022-05-21 09:43:17 +00:00
|
|
|
#if defined(_WIN64)
|
2023-10-02 18:02:29 +00:00
|
|
|
injectFile = Utils::String::replace(injectFile, "\\", "/");
|
|
|
|
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
|
|
|
Utils::String::replace(baseName, "\"", ""));
|
|
|
|
if (injectFile.size() < 3 || !(injectFile[1] == ':' && injectFile[2] == '/'))
|
|
|
|
injectFile =
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\"", "")) + "/" +
|
|
|
|
injectFile;
|
|
|
|
injectFile = Utils::String::replace(injectFile, "/", "\\");
|
2022-05-21 09:43:17 +00:00
|
|
|
#else
|
2023-10-02 18:02:29 +00:00
|
|
|
injectFile = Utils::String::replace(injectFile, "%BASENAME%",
|
|
|
|
Utils::String::replace(baseName, "\\", ""));
|
|
|
|
if (injectFile.front() != '/')
|
|
|
|
injectFile =
|
|
|
|
Utils::FileSystem::getParent(Utils::String::replace(romPath, "\\", "")) + "/" +
|
|
|
|
injectFile;
|
2022-05-21 09:43:17 +00:00
|
|
|
#endif
|
2023-10-02 18:02:29 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(injectFile) ||
|
|
|
|
Utils::FileSystem::isSymlink(injectFile)) {
|
|
|
|
LOG(LogDebug) << "FileData::launchGame(): Injecting from file \"" << injectFile
|
|
|
|
<< "\"";
|
|
|
|
std::string arguments;
|
|
|
|
std::ifstream injectFileStream;
|
|
|
|
injectFileStream.open(injectFile);
|
|
|
|
for (std::string line; getline(injectFileStream, line);)
|
|
|
|
arguments += line;
|
|
|
|
injectFileStream.close();
|
|
|
|
|
|
|
|
if (arguments.empty()) {
|
|
|
|
LOG(LogDebug)
|
|
|
|
<< "FileData::launchGame(): File empty or insufficient permissions, "
|
|
|
|
"nothing to inject";
|
|
|
|
}
|
|
|
|
else if (arguments.size() > 4096) {
|
|
|
|
LOG(LogWarning) << "FileData::launchGame(): Injection file exceeding maximum "
|
|
|
|
"allowed size of "
|
|
|
|
"4096 bytes, skipping \""
|
|
|
|
<< injectFile << "\"";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
command.insert(injectPos, arguments + " ");
|
|
|
|
}
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-10-02 18:02:29 +00:00
|
|
|
LOG(LogDebug) << "FileData::launchGame(): File \"" << injectFile
|
|
|
|
<< "\" does not exist, nothing to inject";
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-02 18:02:29 +00:00
|
|
|
|
|
|
|
injectPos = command.find("%INJECT%");
|
2022-05-21 09:43:17 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 12:25:27 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
if (escapeSpecials) {
|
|
|
|
bool foundSpecial {false};
|
|
|
|
|
|
|
|
// The special characters need to be procesed in this order.
|
|
|
|
std::string specialCharacters {"^&()=;,"};
|
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (size_t i {0}; i < specialCharacters.size(); ++i) {
|
2023-03-21 22:23:00 +00:00
|
|
|
// Don't modify this code, it breaks easily.
|
|
|
|
const std::string special(1, specialCharacters[i]);
|
2022-05-08 12:25:27 +00:00
|
|
|
if (romPath.find(special) != std::string::npos) {
|
|
|
|
romPath = Utils::String::replace(romPath, special, "^" + special);
|
|
|
|
foundSpecial = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundSpecial)
|
|
|
|
romPath = Utils::String::replace(romPath, " ", "^ ");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-31 20:25:36 +00:00
|
|
|
#if !defined(_WIN64)
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
if (isShortcut) {
|
|
|
|
if (Utils::FileSystem::exists(Utils::String::replace(romPath, "\\", ""))) {
|
|
|
|
LOG(LogInfo) << "Opening app or alias file \""
|
|
|
|
<< Utils::String::replace(romPath, "\\", "") << "\"";
|
2022-06-18 14:19:47 +00:00
|
|
|
command = Utils::String::replace(command, binaryPath, "open -W -a");
|
2022-05-31 20:25:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogError) << "App or alias file \"" << romPath
|
|
|
|
<< "\" doesn't exist or is unreadable";
|
|
|
|
window->queueInfoPopup("ERROR: APP OR ALIAS FILE DOESN'T EXIST OR IS UNREADABLE", 6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (isShortcut) {
|
2022-12-16 21:37:32 +00:00
|
|
|
// Note that the following is not an attempt to implement the entire FreeDesktop standard
|
|
|
|
// for .desktop files, for example argument parsing is not really usable in this context.
|
|
|
|
// There's essentially only enough functionality here to be able to run games and emulators.
|
2022-05-31 20:25:36 +00:00
|
|
|
if (Utils::FileSystem::exists(Utils::String::replace(romPath, "\\", "")) &&
|
|
|
|
!Utils::FileSystem::isDirectory(Utils::String::replace(romPath, "\\", ""))) {
|
|
|
|
LOG(LogInfo) << "Parsing desktop file \"" << Utils::String::replace(romPath, "\\", "")
|
|
|
|
<< "\"";
|
|
|
|
bool validFile {false};
|
|
|
|
bool execEntry {false};
|
|
|
|
std::ifstream desktopFileStream;
|
|
|
|
desktopFileStream.open(Utils::String::replace(romPath, "\\", ""));
|
|
|
|
for (std::string line; getline(desktopFileStream, line);) {
|
2022-08-28 10:06:03 +00:00
|
|
|
// Some non-standard .desktop files add a leading line such as
|
|
|
|
// "#!/usr/bin/env xdg-open" and some lines may also be indented by
|
|
|
|
// whitespace characters. So we need to handle such oddities in order
|
|
|
|
// to parse and run these files.
|
|
|
|
line = Utils::String::trim(line);
|
|
|
|
if (line.substr(0, 2) == "#!")
|
|
|
|
continue;
|
2022-05-31 20:25:36 +00:00
|
|
|
if (line.find("[Desktop Entry]") != std::string::npos)
|
|
|
|
validFile = true;
|
|
|
|
if (line.substr(0, 5) == "Exec=") {
|
|
|
|
romPath = {line.substr(5, line.size() - 5)};
|
2022-12-17 17:37:58 +00:00
|
|
|
const std::string regexString {"[^%]%"};
|
|
|
|
// Field codes, some of these are deprecated but may still exist in older
|
|
|
|
// .desktop files. Any matching codes escaped by double %% characters will
|
|
|
|
// be left as-is.
|
|
|
|
std::string codeCharacters {"fFuUdDnNickvm"};
|
|
|
|
std::smatch searchResult;
|
|
|
|
while (!codeCharacters.empty()) {
|
|
|
|
while (std::regex_search(romPath, searchResult,
|
|
|
|
std::regex(regexString + codeCharacters.back())))
|
|
|
|
romPath.replace(searchResult.position(0) + 1, searchResult.length() - 1,
|
|
|
|
"");
|
|
|
|
codeCharacters.pop_back();
|
|
|
|
}
|
2022-12-16 21:37:32 +00:00
|
|
|
romPath = Utils::String::replace(romPath, "%%", "%");
|
2022-05-31 20:25:36 +00:00
|
|
|
romPath = Utils::String::trim(romPath);
|
|
|
|
command = Utils::String::replace(command, binaryPath, "");
|
|
|
|
execEntry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
desktopFileStream.close();
|
|
|
|
if (!validFile || !execEntry) {
|
|
|
|
LOG(LogError) << "File is invalid or unreadable";
|
|
|
|
window->queueInfoPopup("ERROR: DESKTOP FILE IS INVALID OR UNREADABLE", 6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogError) << "Desktop file \"" << romPath << "\" doesn't exist or is unreadable";
|
|
|
|
window->queueInfoPopup("ERROR: DESKTOP FILE DOESN'T EXIST OR IS UNREADABLE", 6000);
|
|
|
|
window->setAllowTextScrolling(true);
|
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-06-20 10:30:14 +00:00
|
|
|
// Replace the remaining variables with their actual values.
|
|
|
|
command = Utils::String::replace(command, "%ROM%", romPath);
|
|
|
|
command = Utils::String::replace(command, "%BASENAME%", baseName);
|
2022-07-15 20:01:28 +00:00
|
|
|
command = Utils::String::replace(command, "%FILENAME%", fileName);
|
2021-06-20 10:30:14 +00:00
|
|
|
command = Utils::String::replace(command, "%ROMRAW%", romRaw);
|
2022-04-30 18:43:29 +00:00
|
|
|
command = Utils::String::replace(command, "%ROMPATH%",
|
|
|
|
Utils::FileSystem::getEscapedPath(getROMDirectory()));
|
|
|
|
#if defined(_WIN64)
|
2022-05-02 15:25:10 +00:00
|
|
|
command = Utils::String::replace(
|
|
|
|
command, "%ESPATH%", Utils::String::replace(Utils::FileSystem::getExePath(), "/", "\\"));
|
2022-04-30 18:43:29 +00:00
|
|
|
command = Utils::String::replace(command, "%EMUDIR%",
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
|
|
|
Utils::String::replace(binaryPath, "\"", ""))));
|
2022-05-19 21:36:12 +00:00
|
|
|
command = Utils::String::replace(command, "%GAMEDIR%",
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
|
|
|
Utils::String::replace(romPath, "\"", ""))));
|
2022-04-30 18:43:29 +00:00
|
|
|
#else
|
2022-05-02 15:25:10 +00:00
|
|
|
command = Utils::String::replace(command, "%ESPATH%", Utils::FileSystem::getExePath());
|
2022-04-30 18:43:29 +00:00
|
|
|
command = Utils::String::replace(command, "%EMUDIR%",
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
|
|
|
Utils::String::replace(binaryPath, "\\", ""))));
|
2022-05-19 21:36:12 +00:00
|
|
|
command = Utils::String::replace(command, "%GAMEDIR%",
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getParent(
|
|
|
|
Utils::String::replace(romPath, "\\", ""))));
|
2022-04-30 18:43:29 +00:00
|
|
|
#endif
|
2021-06-20 10:30:14 +00:00
|
|
|
|
2021-12-16 17:05:36 +00:00
|
|
|
// Trim any leading and trailing whitespace characters as they could cause launch issues.
|
|
|
|
command = Utils::String::trim(command);
|
|
|
|
|
2021-03-27 12:51:50 +00:00
|
|
|
// swapBuffers() is called here to turn the screen black to eliminate some potential
|
|
|
|
// flickering and to avoid showing the game launch message briefly when returning
|
|
|
|
// from the game.
|
2021-11-22 19:03:05 +00:00
|
|
|
if (!runInBackground)
|
2022-03-14 18:51:48 +00:00
|
|
|
Renderer::getInstance()->swapBuffers();
|
2021-03-27 12:51:50 +00:00
|
|
|
|
2021-12-05 10:28:09 +00:00
|
|
|
Scripting::fireEvent("game-start", romPath, getSourceFileData()->metadata.get("name"),
|
|
|
|
getSourceFileData()->getSystem()->getName(),
|
|
|
|
getSourceFileData()->getSystem()->getFullName());
|
2022-05-21 12:48:29 +00:00
|
|
|
int returnValue {0};
|
2020-07-07 19:25:15 +00:00
|
|
|
|
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:";
|
2021-01-11 17:21:14 +00:00
|
|
|
LOG(LogInfo) << command;
|
2021-07-07 18:03:42 +00:00
|
|
|
|
2022-04-26 19:30:36 +00:00
|
|
|
#if defined(FLATPAK_BUILD)
|
|
|
|
// Break out of the sandbox.
|
|
|
|
command = "flatpak-spawn --host " + command;
|
|
|
|
#endif
|
|
|
|
|
2022-07-07 16:15:35 +00:00
|
|
|
// Flush the log buffer to es_log.txt, otherwise game launch logging will only be written
|
|
|
|
// once we have returned from the game.
|
|
|
|
if (!runInBackground) {
|
|
|
|
Log::flush();
|
|
|
|
}
|
|
|
|
|
2021-03-27 12:49:09 +00:00
|
|
|
// Possibly keep ES-DE running in the background while the game is launched.
|
2021-07-07 18:03:42 +00:00
|
|
|
|
|
|
|
#if defined(_WIN64)
|
2022-04-30 18:43:29 +00:00
|
|
|
returnValue = Utils::Platform::launchGameWindows(
|
|
|
|
Utils::String::stringToWideString(command),
|
|
|
|
Utils::String::stringToWideString(startDirectory), runInBackground, hideWindow);
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2022-04-30 18:43:29 +00:00
|
|
|
returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBackground);
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
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) {
|
2021-01-10 21:55:17 +00:00
|
|
|
LOG(LogWarning) << "...launch terminated with nonzero return value " << returnValue;
|
2020-07-18 11:21:44 +00:00
|
|
|
|
2021-10-07 16:31:40 +00:00
|
|
|
window->queueInfoPopup("ERROR LAUNCHING GAME '" +
|
|
|
|
Utils::String::toUpper(metadata.get("name")) + "' (ERROR CODE " +
|
|
|
|
Utils::String::toUpper(std::to_string(returnValue) + ")"),
|
|
|
|
6000);
|
2021-12-02 19:42:49 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
2020-07-18 11:21:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-08-15 13:41:11 +00:00
|
|
|
// Stop showing the game launch notification.
|
|
|
|
window->stopInfoPopup();
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-11-22 19:03:05 +00:00
|
|
|
// If the RunInBackground setting has been enabled or if the %RUNINBACKGROUND% variable has
|
|
|
|
// been set for the specific launch command, then block the video player, stop scrolling
|
|
|
|
// game names and descriptions and keep the screensaver from getting activated.
|
|
|
|
if (runInBackground)
|
2022-02-20 17:49:35 +00:00
|
|
|
window->setLaunchedGame(true);
|
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();
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-03-27 12:49:09 +00:00
|
|
|
// For some game systems we need to keep ES-DE running while the game is launched.
|
2021-11-22 19:03:05 +00:00
|
|
|
// This blocks the video player, stops the scrolling of game names and descriptions and
|
|
|
|
// keeps the screensaver from getting activated.
|
|
|
|
if (runInBackground)
|
2022-02-19 16:04:23 +00:00
|
|
|
window->setLaunchedGame(true);
|
2020-07-20 07:54:38 +00:00
|
|
|
// Normalize deltaTime so that the screensaver does not start immediately
|
|
|
|
// when returning from the game.
|
|
|
|
window->normalizeNextUpdate();
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-25 17:52:38 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2022-05-16 20:34:51 +00:00
|
|
|
// If running in the background then don't trigger the game-end event, which will instead be
|
|
|
|
// triggered in ViewController when manually waking up the application.
|
|
|
|
if (!runInBackground) {
|
|
|
|
Scripting::fireEvent("game-end", romPath, getSourceFileData()->metadata.get("name"),
|
|
|
|
getSourceFileData()->getSystem()->getName(),
|
|
|
|
getSourceFileData()->getSystem()->getFullName());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::vector<std::string>& gameEndParams {
|
|
|
|
ViewController::getInstance()->getGameEndEventParams()};
|
|
|
|
gameEndParams.emplace_back("game-end");
|
|
|
|
gameEndParams.emplace_back(romPath);
|
|
|
|
gameEndParams.emplace_back(getSourceFileData()->metadata.get("name"));
|
|
|
|
gameEndParams.emplace_back(getSourceFileData()->getSystem()->getName());
|
|
|
|
gameEndParams.emplace_back(getSourceFileData()->getSystem()->getFullName());
|
|
|
|
}
|
2018-01-30 00:49:08 +00:00
|
|
|
|
2021-10-06 15:24:25 +00:00
|
|
|
// Unless we're running in the background while the game is launched, re-enable the text
|
|
|
|
// scrolling that was disabled in ViewController.
|
2022-01-09 12:43:42 +00:00
|
|
|
if (!runInBackground) {
|
2021-10-06 15:24:25 +00:00
|
|
|
window->setAllowTextScrolling(true);
|
2022-01-09 12:43:42 +00:00
|
|
|
window->setAllowFileAnimation(true);
|
|
|
|
}
|
2020-09-17 20:00:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update number of times the game has been launched.
|
2022-05-21 12:48:29 +00:00
|
|
|
FileData* gameToUpdate {getSourceFileData()};
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2022-04-11 21:28:18 +00:00
|
|
|
int timesPlayed {gameToUpdate->metadata.getInt("playcount") + 1};
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
|
2022-04-12 16:35:57 +00:00
|
|
|
// If the cursor is on a folder then a folder link must have been configured, so set the
|
|
|
|
// lastplayed timestamp for this folder to the same as the launched game.
|
2022-04-11 21:28:18 +00:00
|
|
|
FileData* cursor {
|
|
|
|
ViewController::getInstance()->getGamelistView(gameToUpdate->getSystem())->getCursor()};
|
|
|
|
if (cursor->getType() == FOLDER)
|
|
|
|
cursor->metadata.set("lastplayed", gameToUpdate->metadata.get("lastplayed"));
|
|
|
|
|
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.
|
2021-07-07 18:03:42 +00:00
|
|
|
if (gameToUpdate->getParent()->getType() == FOLDER &&
|
|
|
|
gameToUpdate->getParent()->getName() != gameToUpdate->getSystem()->getFullName()) {
|
2020-07-30 12:21:20 +00:00
|
|
|
gameToUpdate->getParent()->metadata.set("lastplayed",
|
2021-07-07 18:03:42 +00:00
|
|
|
gameToUpdate->metadata.get("lastplayed"));
|
2020-07-30 12:21:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 20:21:26 +00:00
|
|
|
CollectionSystemsManager::getInstance()->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
|
|
|
}
|
|
|
|
|
2023-09-22 15:35:32 +00:00
|
|
|
const std::string FileData::findEmulatorPath(std::string& command, const bool preCommand)
|
2021-01-10 21:55:17 +00:00
|
|
|
{
|
2021-06-19 12:09:14 +00:00
|
|
|
// Extract the emulator executable from the launch command string. There are two ways
|
|
|
|
// that the emulator can be defined in es_systems.xml, either using the find rules in
|
2021-12-16 17:05:36 +00:00
|
|
|
// es_find_rules.xml or via the explicit emulator binary name. In the former case, we
|
|
|
|
// need to process any configured systempath and staticpath rules (and for Windows also
|
|
|
|
// winregistrypath and winregistryvalue rules), and in the latter case we simply search
|
|
|
|
// for the emulator binary in the system path.
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2021-01-11 17:21:14 +00:00
|
|
|
std::string emuExecutable;
|
|
|
|
std::string exePath;
|
2021-01-10 21:55:17 +00:00
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
// Method 1, emulator binary is defined using find rules:
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-26 10:00:09 +00:00
|
|
|
std::vector<std::string> emulatorWinRegistryPaths;
|
2021-11-22 19:03:05 +00:00
|
|
|
std::vector<std::string> emulatorWinRegistryValues;
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
std::vector<std::string> emulatorSystemPaths;
|
|
|
|
std::vector<std::string> emulatorStaticPaths;
|
|
|
|
std::string emulatorEntry;
|
2022-01-16 11:09:55 +00:00
|
|
|
size_t startPos {0};
|
|
|
|
size_t endPos {0};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2023-09-22 15:35:32 +00:00
|
|
|
if (preCommand) {
|
|
|
|
if ((startPos = command.find("%PRECOMMAND_")) != std::string::npos) {
|
|
|
|
endPos = command.find("%", startPos + 1);
|
|
|
|
if (endPos != std::string::npos)
|
|
|
|
emulatorEntry = command.substr(startPos + 12, endPos - startPos - 12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((startPos = command.find("%EMULATOR_")) != std::string::npos) {
|
|
|
|
endPos = command.find("%", startPos + 1);
|
|
|
|
if (endPos != std::string::npos)
|
|
|
|
emulatorEntry = command.substr(startPos + 10, endPos - startPos - 10);
|
|
|
|
}
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (emulatorEntry != "") {
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-26 10:00:09 +00:00
|
|
|
emulatorWinRegistryPaths =
|
2021-07-07 18:03:42 +00:00
|
|
|
SystemData::sFindRules.get()->mEmulators[emulatorEntry].winRegistryPaths;
|
2021-11-22 19:03:05 +00:00
|
|
|
emulatorWinRegistryValues =
|
|
|
|
SystemData::sFindRules.get()->mEmulators[emulatorEntry].winRegistryValues;
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
emulatorSystemPaths = SystemData::sFindRules.get()->mEmulators[emulatorEntry].systemPaths;
|
2023-09-22 15:35:32 +00:00
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
emulatorStaticPaths = SystemData::sFindRules.get()->mEmulators[emulatorEntry].staticPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error handling in case of no emulator find rule.
|
2021-12-16 17:05:36 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
if (emulatorEntry != "" && emulatorWinRegistryPaths.empty() &&
|
|
|
|
emulatorWinRegistryValues.empty() && emulatorSystemPaths.empty() &&
|
|
|
|
emulatorStaticPaths.empty())
|
|
|
|
#else
|
2021-06-19 12:09:14 +00:00
|
|
|
if (emulatorEntry != "" && emulatorSystemPaths.empty() && emulatorStaticPaths.empty())
|
2021-12-16 17:05:36 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
return "NO EMULATOR RULE: " + emulatorEntry;
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-12-14 16:30:34 +00:00
|
|
|
for (std::string& path : emulatorWinRegistryPaths) {
|
2021-06-26 10:00:09 +00:00
|
|
|
// Search for the emulator using the App Paths keys in the Windows Registry.
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& registryKeyPath {
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + path};
|
2021-06-26 10:00:09 +00:00
|
|
|
|
|
|
|
HKEY registryKey;
|
2022-05-21 12:48:29 +00:00
|
|
|
LSTATUS keyStatus {-1};
|
|
|
|
LSTATUS pathStatus {-1};
|
2023-08-10 17:26:28 +00:00
|
|
|
std::wstring registryPath(1024, 0);
|
2022-05-21 12:48:29 +00:00
|
|
|
DWORD pathSize {1024};
|
2021-06-26 10:00:09 +00:00
|
|
|
|
|
|
|
// First look in HKEY_CURRENT_USER.
|
2023-08-10 18:36:15 +00:00
|
|
|
keyStatus = RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
Utils::String::stringToWideString(registryKeyPath).c_str(), 0,
|
|
|
|
KEY_QUERY_VALUE, ®istryKey);
|
2021-06-26 10:00:09 +00:00
|
|
|
|
|
|
|
// If not found, then try in HKEY_LOCAL_MACHINE.
|
|
|
|
if (keyStatus != ERROR_SUCCESS) {
|
2023-08-10 18:36:15 +00:00
|
|
|
keyStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
Utils::String::stringToWideString(registryKeyPath).c_str(), 0,
|
|
|
|
KEY_QUERY_VALUE, ®istryKey);
|
2021-06-26 10:00:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 19:03:05 +00:00
|
|
|
// If the key exists, then try to retrieve its default value.
|
2021-06-26 10:00:09 +00:00
|
|
|
if (keyStatus == ERROR_SUCCESS) {
|
2021-07-07 18:03:42 +00:00
|
|
|
pathStatus = RegGetValue(registryKey, nullptr, nullptr, RRF_RT_REG_SZ, nullptr,
|
2023-08-10 17:26:28 +00:00
|
|
|
®istryPath[0], &pathSize);
|
|
|
|
registryPath.erase(std::find(registryPath.begin(), registryPath.end(), '\0'),
|
|
|
|
registryPath.end());
|
2021-06-26 10:00:09 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
RegCloseKey(registryKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// That a value was found does not guarantee that the emulator binary actually exists,
|
|
|
|
// so check for that as well.
|
|
|
|
if (pathStatus == ERROR_SUCCESS) {
|
2023-08-10 17:26:28 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(Utils::String::wideStringToString(registryPath)) ||
|
|
|
|
Utils::FileSystem::isSymlink(Utils::String::wideStringToString(registryPath))) {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): "
|
|
|
|
<< (preCommand ? "Pre-command binary" : "Emulator binary")
|
|
|
|
<< " found via winregistrypath rule";
|
2023-08-10 17:26:28 +00:00
|
|
|
exePath = Utils::FileSystem::getEscapedPath(
|
|
|
|
Utils::String::wideStringToString(registryPath));
|
2022-07-01 14:42:21 +00:00
|
|
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
2021-06-26 10:00:09 +00:00
|
|
|
RegCloseKey(registryKey);
|
2022-07-01 14:42:21 +00:00
|
|
|
return exePath;
|
2021-06-26 10:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(registryKey);
|
|
|
|
}
|
2021-11-22 19:03:05 +00:00
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (std::string& value : emulatorWinRegistryValues) {
|
2021-12-24 11:26:34 +00:00
|
|
|
// If the pipe character is found, then the string following this should be appended
|
|
|
|
// to the key value, assuming the key is found.
|
|
|
|
std::string appendString;
|
2022-12-14 16:30:34 +00:00
|
|
|
const size_t pipePos {value.find('|')};
|
2021-12-24 11:26:34 +00:00
|
|
|
|
|
|
|
if (pipePos != std::string::npos) {
|
|
|
|
appendString = value.substr(pipePos + 1, std::string::npos);
|
|
|
|
value = value.substr(0, pipePos);
|
|
|
|
}
|
|
|
|
|
2021-11-22 19:03:05 +00:00
|
|
|
// Search for the defined value in the Windows Registry.
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& registryValueKey {
|
2022-05-21 12:48:29 +00:00
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(value), "/", "\\")};
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& registryValue {Utils::FileSystem::getFileName(value)};
|
2021-11-22 19:03:05 +00:00
|
|
|
|
|
|
|
HKEY registryKey;
|
2022-05-21 12:48:29 +00:00
|
|
|
LSTATUS keyStatus {-1};
|
|
|
|
LSTATUS pathStatus {-1};
|
2023-08-10 17:26:28 +00:00
|
|
|
std::wstring path(1024, 0);
|
2022-05-21 12:48:29 +00:00
|
|
|
DWORD pathSize {1024};
|
2021-11-22 19:03:05 +00:00
|
|
|
|
|
|
|
// First look in HKEY_CURRENT_USER.
|
2023-08-10 18:36:15 +00:00
|
|
|
keyStatus = RegOpenKeyExW(HKEY_CURRENT_USER,
|
|
|
|
Utils::String::stringToWideString(registryValueKey).c_str(), 0,
|
|
|
|
KEY_QUERY_VALUE, ®istryKey);
|
2021-11-22 19:03:05 +00:00
|
|
|
|
|
|
|
// If not found, then try in HKEY_LOCAL_MACHINE.
|
|
|
|
if (keyStatus != ERROR_SUCCESS) {
|
2023-08-10 18:36:15 +00:00
|
|
|
keyStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
Utils::String::stringToWideString(registryValueKey).c_str(),
|
|
|
|
0, KEY_QUERY_VALUE, ®istryKey);
|
2021-11-22 19:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the key exists, then try to retrieve the defined value.
|
|
|
|
if (keyStatus == ERROR_SUCCESS) {
|
2023-08-10 18:36:15 +00:00
|
|
|
pathStatus = RegGetValueW(registryKey, nullptr,
|
|
|
|
Utils::String::stringToWideString(registryValue).c_str(),
|
|
|
|
RRF_RT_REG_SZ, nullptr, &path[0], &pathSize);
|
2023-08-10 17:26:28 +00:00
|
|
|
path.erase(std::find(path.begin(), path.end(), '\0'), path.end());
|
2021-11-22 19:03:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
RegCloseKey(registryKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-10 17:26:28 +00:00
|
|
|
if (path.empty()) {
|
2021-12-24 11:26:34 +00:00
|
|
|
RegCloseKey(registryKey);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!appendString.empty())
|
2023-08-10 17:26:28 +00:00
|
|
|
path.append(Utils::String::stringToWideString(appendString));
|
2021-12-24 11:26:34 +00:00
|
|
|
|
2021-11-22 19:03:05 +00:00
|
|
|
// That a value was found does not guarantee that the emulator binary actually exists,
|
|
|
|
// so check for that as well.
|
|
|
|
if (pathStatus == ERROR_SUCCESS) {
|
2023-08-10 17:26:28 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(Utils::String::wideStringToString(path)) ||
|
|
|
|
Utils::FileSystem::isSymlink(Utils::String::wideStringToString(path))) {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): "
|
|
|
|
<< (preCommand ? "Pre-command binary" : "Emulator binary")
|
|
|
|
<< " found via winregistryvalue rule";
|
2023-08-10 17:26:28 +00:00
|
|
|
exePath =
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::String::wideStringToString(path));
|
2022-07-01 14:42:21 +00:00
|
|
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
2021-11-22 19:03:05 +00:00
|
|
|
RegCloseKey(registryKey);
|
2022-07-01 14:42:21 +00:00
|
|
|
return exePath;
|
2021-11-22 19:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(registryKey);
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-26 10:00:09 +00:00
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (std::string& path : emulatorSystemPaths) {
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-21 12:48:29 +00:00
|
|
|
std::wstring pathWide {Utils::String::stringToWideString(path)};
|
2022-01-02 20:02:43 +00:00
|
|
|
// Search for the emulator using the PATH environment variable.
|
2022-05-21 12:48:29 +00:00
|
|
|
DWORD size {SearchPathW(nullptr, pathWide.c_str(), L".exe", 0, nullptr, nullptr)};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
if (size) {
|
2021-07-07 18:03:42 +00:00
|
|
|
std::vector<wchar_t> pathBuffer(static_cast<size_t>(size) + 1);
|
2022-05-21 12:48:29 +00:00
|
|
|
wchar_t* fileName {nullptr};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
SearchPathW(nullptr, pathWide.c_str(), L".exe", size + 1, pathBuffer.data(), &fileName);
|
2022-05-21 12:48:29 +00:00
|
|
|
std::wstring pathString {pathBuffer.data()};
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
if (pathString.length()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
exePath = Utils::String::wideStringToString(
|
|
|
|
pathString.substr(0, pathString.size() - std::wstring(fileName).size()));
|
2021-06-19 12:09:14 +00:00
|
|
|
exePath.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 10:30:14 +00:00
|
|
|
if (exePath != "") {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): "
|
|
|
|
<< (preCommand ? "Pre-command binary" : "Emulator binary")
|
|
|
|
<< " found via systempath rule";
|
2021-06-20 10:30:14 +00:00
|
|
|
exePath += "\\" + path;
|
2022-07-01 14:42:21 +00:00
|
|
|
exePath = Utils::FileSystem::getEscapedPath(exePath);
|
2021-12-16 17:05:36 +00:00
|
|
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
2021-06-20 10:30:14 +00:00
|
|
|
return exePath;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-06-19 12:09:14 +00:00
|
|
|
exePath = Utils::FileSystem::getPathToBinary(path);
|
|
|
|
if (exePath != "") {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): "
|
|
|
|
<< (preCommand ? "Pre-command binary" : "Emulator binary")
|
|
|
|
<< " found via systempath rule";
|
2021-06-19 12:09:14 +00:00
|
|
|
exePath += "/" + path;
|
2021-12-16 17:05:36 +00:00
|
|
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
2021-06-19 12:09:14 +00:00
|
|
|
return exePath;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 16:30:34 +00:00
|
|
|
for (std::string& path : emulatorStaticPaths) {
|
2022-08-12 10:41:22 +00:00
|
|
|
// If a pipe character is present in the staticpath entry it means we should substitute
|
|
|
|
// the emulator binary with whatever is defined after the pipe character.
|
|
|
|
std::string replaceCommand;
|
2022-12-14 16:30:34 +00:00
|
|
|
const size_t pipePos {path.find('|')};
|
2022-08-12 10:41:22 +00:00
|
|
|
|
|
|
|
if (pipePos != std::string::npos) {
|
|
|
|
replaceCommand = path.substr(pipePos + 1);
|
|
|
|
path = path.substr(0, pipePos);
|
|
|
|
}
|
|
|
|
|
2021-06-23 15:49:47 +00:00
|
|
|
path = Utils::FileSystem::expandHomePath(path);
|
2021-06-30 15:37:17 +00:00
|
|
|
// If %ESPATH% is used for the rule, then expand it to the binary directory of ES-DE.
|
|
|
|
path = Utils::String::replace(path, "%ESPATH%", Utils::FileSystem::getExePath());
|
2021-07-01 15:55:00 +00:00
|
|
|
// Likewise for the %ROMPATH% variable which expands to the configured ROM directory.
|
|
|
|
path = Utils::String::replace(path, "%ROMPATH%", getROMDirectory());
|
2021-07-16 15:14:16 +00:00
|
|
|
|
2022-02-21 16:23:23 +00:00
|
|
|
// Find the first matching file if a wildcard was used for the emulator entry.
|
|
|
|
if (path.find('*') != std::string::npos) {
|
2022-02-21 18:14:41 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
Utils::FileSystem::StringList files {
|
|
|
|
Utils::FileSystem::getMatchingFiles(Utils::String::replace(path, "\\", "/"))};
|
|
|
|
if (files.size() > 0)
|
|
|
|
path = Utils::String::replace(files.front(), "/", "\\");
|
|
|
|
#else
|
2022-02-21 16:23:23 +00:00
|
|
|
Utils::FileSystem::StringList files {Utils::FileSystem::getMatchingFiles(path)};
|
|
|
|
if (files.size() > 0)
|
|
|
|
path = files.front();
|
2022-02-21 18:14:41 +00:00
|
|
|
#endif
|
2022-02-21 16:23:23 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
|
2023-10-09 19:47:32 +00:00
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): "
|
|
|
|
<< (preCommand ? "Pre-command binary" : "Emulator binary")
|
|
|
|
<< " found via staticpath rule";
|
2022-08-12 10:41:22 +00:00
|
|
|
if (replaceCommand == "") {
|
|
|
|
exePath = Utils::FileSystem::getEscapedPath(path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogDebug) << "FileData::findEmulatorPath(): Replacing emulator binary in "
|
|
|
|
"staticpath rule with explicitly defined command";
|
|
|
|
exePath = replaceCommand;
|
|
|
|
}
|
2022-07-01 14:42:21 +00:00
|
|
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
|
|
|
return exePath;
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method 2, exact emulator binary name:
|
|
|
|
|
2021-06-30 15:37:17 +00:00
|
|
|
// If %ESPATH% is used, then expand it to the binary directory of ES-DE.
|
|
|
|
command = Utils::String::replace(command, "%ESPATH%", Utils::FileSystem::getExePath());
|
|
|
|
|
2021-01-10 21:55:17 +00:00
|
|
|
// If the first character is a quotation mark, then we need to extract up to the
|
|
|
|
// next quotation mark, otherwise we'll only extract up to the first space character.
|
|
|
|
if (command.front() == '\"') {
|
2022-12-14 16:30:34 +00:00
|
|
|
const std::string& emuTemp {command.substr(1, std::string::npos)};
|
2021-01-10 21:55:17 +00:00
|
|
|
emuExecutable = emuTemp.substr(0, emuTemp.find('"'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emuExecutable = command.substr(0, command.find(' '));
|
|
|
|
}
|
|
|
|
|
2022-02-21 16:23:23 +00:00
|
|
|
if (emuExecutable.find('*') != std::string::npos) {
|
|
|
|
Utils::FileSystem::StringList files {Utils::FileSystem::getMatchingFiles(emuExecutable)};
|
|
|
|
if (files.size() > 0) {
|
|
|
|
command = Utils::String::replace(command, emuExecutable, files.front());
|
|
|
|
emuExecutable = files.front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-05-21 12:48:29 +00:00
|
|
|
std::wstring emuExecutableWide {Utils::String::stringToWideString(emuExecutable)};
|
2022-01-02 20:02:43 +00:00
|
|
|
// Search for the emulator using the PATH environment variable.
|
2022-12-14 16:30:34 +00:00
|
|
|
const DWORD size {
|
|
|
|
SearchPathW(nullptr, emuExecutableWide.c_str(), L".exe", 0, nullptr, nullptr)};
|
2021-01-10 21:55:17 +00:00
|
|
|
|
|
|
|
if (size) {
|
2021-07-07 18:03:42 +00:00
|
|
|
std::vector<wchar_t> pathBuffer(static_cast<size_t>(size) + 1);
|
2022-05-21 12:48:29 +00:00
|
|
|
wchar_t* fileName {nullptr};
|
2021-01-10 21:55:17 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
SearchPathW(nullptr, emuExecutableWide.c_str(), L".exe", size + 1, pathBuffer.data(),
|
|
|
|
&fileName);
|
2021-01-10 21:55:17 +00:00
|
|
|
|
2021-06-30 15:37:17 +00:00
|
|
|
exePath = Utils::String::wideStringToString(pathBuffer.data());
|
2021-01-10 21:55:17 +00:00
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-01-10 21:55:17 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(emuExecutable) ||
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::isSymlink(emuExecutable)) {
|
2022-04-30 18:43:29 +00:00
|
|
|
exePath = Utils::FileSystem::getEscapedPath(emuExecutable);
|
2021-06-30 15:37:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-04-30 18:43:29 +00:00
|
|
|
exePath =
|
|
|
|
Utils::FileSystem::getEscapedPath(Utils::FileSystem::getPathToBinary(emuExecutable));
|
2021-06-30 15:37:17 +00:00
|
|
|
if (exePath != "")
|
|
|
|
exePath += "/" + emuExecutable;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-01-11 17:21:14 +00:00
|
|
|
|
2021-01-10 21:55:17 +00:00
|
|
|
return exePath;
|
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
CollectionFileData::CollectionFileData(FileData* file, SystemData* system)
|
2021-07-07 18:03:42 +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();
|
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
|
|
|
}
|