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.h
|
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
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_APP_FILE_DATA_H
|
|
|
|
#define ES_APP_FILE_DATA_H
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
#include "MetaData.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2020-09-17 20:00:07 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <unordered_map>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
class SystemData;
|
2017-11-01 22:21:10 +00:00
|
|
|
class Window;
|
2017-06-12 16:38:59 +00:00
|
|
|
struct SystemEnvironmentData;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
enum FileType {
|
2020-11-17 22:06:54 +00:00
|
|
|
GAME = 1, // Cannot have children.
|
2020-06-21 12:25:28 +00:00
|
|
|
FOLDER = 2,
|
|
|
|
PLACEHOLDER = 3
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A tree node that holds information for a file.
|
|
|
|
class FileData
|
|
|
|
{
|
|
|
|
public:
|
2021-07-07 18:03:42 +00:00
|
|
|
FileData(FileType type,
|
|
|
|
const std::string& path,
|
|
|
|
SystemEnvironmentData* envData,
|
|
|
|
SystemData* system);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
virtual ~FileData();
|
|
|
|
|
|
|
|
virtual const std::string& getName();
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string& getSortName();
|
|
|
|
const bool getFavorite();
|
2021-01-05 09:45:32 +00:00
|
|
|
const bool getKidgame();
|
2020-07-26 20:19:29 +00:00
|
|
|
const bool getHidden();
|
2020-07-29 17:01:49 +00:00
|
|
|
const bool getCountAsGame();
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::pair<unsigned int, unsigned int>& getGameCount() const { return mGameCount; }
|
2020-08-06 09:27:16 +00:00
|
|
|
const bool getExcludeFromScraper();
|
2020-07-28 13:19:54 +00:00
|
|
|
const std::vector<FileData*> getChildrenRecursive() const;
|
2021-07-07 18:03:42 +00:00
|
|
|
FileType getType() const { return mType; }
|
|
|
|
const std::string& getPath() const { return mPath; }
|
|
|
|
FileData* getParent() const { return mParent; }
|
|
|
|
const std::unordered_map<std::string, FileData*>& getChildrenByFilename() const
|
|
|
|
{
|
|
|
|
return mChildrenByFilename;
|
|
|
|
}
|
|
|
|
const std::vector<FileData*>& getChildren() const { return mChildren; }
|
|
|
|
SystemData* getSystem() const { return mSystem; }
|
|
|
|
SystemEnvironmentData* getSystemEnvData() const { return mEnvData; }
|
2022-02-13 19:03:34 +00:00
|
|
|
|
|
|
|
// These functions are used by GameSelectorComponent.
|
|
|
|
const std::vector<FileData*>& getChildrenLastPlayed() const { return mChildrenLastPlayed; }
|
|
|
|
const std::vector<FileData*>& getChildrenMostPlayed() const { return mChildrenMostPlayed; }
|
|
|
|
void setUpdateChildrenLastPlayed(bool state) { mUpdateChildrenLastPlayed = state; }
|
|
|
|
void setUpdateChildrenMostPlayed(bool state) { mUpdateChildrenMostPlayed = state; }
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool getOnlyFoldersFlag() const { return mOnlyFolders; }
|
|
|
|
const bool getHasFoldersFlag() const { return mHasFolders; }
|
2020-06-21 12:25:28 +00:00
|
|
|
static const std::string getROMDirectory();
|
|
|
|
static const std::string getMediaDirectory();
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string getMediafilePath(const std::string& subdirectory) const;
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getImagePath() const;
|
|
|
|
const std::string get3DBoxPath() const;
|
2021-10-28 19:00:23 +00:00
|
|
|
const std::string getBackCoverPath() const;
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getCoverPath() const;
|
2022-01-15 12:16:23 +00:00
|
|
|
const std::string getFanArtPath() const;
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getMarqueePath() const;
|
2021-10-28 19:00:23 +00:00
|
|
|
const std::string getPhysicalMediaPath() const;
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getMiximagePath() const;
|
|
|
|
const std::string getScreenshotPath() const;
|
2021-10-28 19:00:23 +00:00
|
|
|
const std::string getTitleScreenPath() const;
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getThumbnailPath() const;
|
|
|
|
const std::string getVideoPath() const;
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool getDeletionFlag() const { return mDeletionFlag; }
|
2021-07-07 18:03:42 +00:00
|
|
|
void setDeletionFlag(bool setting) { mDeletionFlag = setting; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
const std::vector<FileData*>& getChildrenListToDisplay();
|
|
|
|
std::vector<FileData*> getFilesRecursive(unsigned int typeMask,
|
2021-07-07 18:03:42 +00:00
|
|
|
bool displayedOnly = false,
|
|
|
|
bool countAllGames = true) const;
|
|
|
|
std::vector<FileData*> getScrapeFilesRecursive(bool includeFolders,
|
|
|
|
bool excludeRecursively,
|
|
|
|
bool respectExclusions) const;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
void addChild(FileData* file); // Error if mType != FOLDER
|
2021-07-07 18:03:42 +00:00
|
|
|
void removeChild(FileData* file); // Error if mType != FOLDER
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool isPlaceHolder() const { return mType == PLACEHOLDER; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
virtual void refreshMetadata() { return; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
virtual std::string getKey() { return getFileName(); }
|
|
|
|
const bool isArcadeAsset() const;
|
|
|
|
const bool isArcadeGame() const;
|
|
|
|
const std::string& getFullPath() const { return getPath(); }
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string getFileName() { return Utils::FileSystem::getFileName(getPath()); }
|
2021-11-09 21:40:08 +00:00
|
|
|
virtual FileData* getSourceFileData() { return this; }
|
|
|
|
const std::string& getSystemName() const { return mSystemName; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Returns our best guess at the "real" name for this file.
|
|
|
|
std::string getDisplayName() const;
|
|
|
|
|
|
|
|
// As above, but also remove parenthesis.
|
|
|
|
std::string getCleanName() const;
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
void launchGame();
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string findEmulatorPath(std::string& command);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-11 20:57:00 +00:00
|
|
|
using ComparisonFunction = bool(const FileData* a, const FileData* b);
|
2020-06-21 12:25:28 +00:00
|
|
|
struct SortType {
|
|
|
|
ComparisonFunction* comparisonFunction;
|
|
|
|
std::string description;
|
2021-01-08 19:30:21 +00:00
|
|
|
SortType(ComparisonFunction* sortFunction, const std::string& sortDescription)
|
2021-07-07 18:03:42 +00:00
|
|
|
: comparisonFunction(sortFunction)
|
|
|
|
, description(sortDescription)
|
|
|
|
{
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
};
|
|
|
|
|
2021-01-08 19:30:21 +00:00
|
|
|
void sort(ComparisonFunction& comparator, std::pair<unsigned int, unsigned int>& gameCount);
|
|
|
|
void sortFavoritesOnTop(ComparisonFunction& comparator,
|
2021-07-07 18:03:42 +00:00
|
|
|
std::pair<unsigned int, unsigned int>& gameCount);
|
2020-06-21 12:25:28 +00:00
|
|
|
void sort(const SortType& type, bool mFavoritesOnTop = false);
|
|
|
|
MetaDataList metadata;
|
2020-10-30 11:53:35 +00:00
|
|
|
// Only count the games, a cheaper alternative to a full sort when that is not required.
|
|
|
|
void countGames(std::pair<unsigned int, unsigned int>& gameCount);
|
2022-02-13 19:03:34 +00:00
|
|
|
void updateLastPlayedList();
|
|
|
|
void updateMostPlayedList();
|
2021-07-07 18:03:42 +00:00
|
|
|
void setSortTypeString(std::string typestring) { mSortTypeString = typestring; }
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string& getSortTypeString() const { return mSortTypeString; }
|
|
|
|
const FileData::SortType& getSortTypeFromString(const std::string& desc) const;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
protected:
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* mSourceFileData;
|
|
|
|
FileData* mParent;
|
|
|
|
std::string mSystemName;
|
|
|
|
std::string mSortTypeString = "";
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
FileType mType;
|
|
|
|
std::string mPath;
|
|
|
|
SystemEnvironmentData* mEnvData;
|
|
|
|
SystemData* mSystem;
|
2021-07-07 18:03:42 +00:00
|
|
|
std::unordered_map<std::string, FileData*> mChildrenByFilename;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<FileData*> mChildren;
|
|
|
|
std::vector<FileData*> mFilteredChildren;
|
2022-02-13 19:03:34 +00:00
|
|
|
std::vector<FileData*> mChildrenLastPlayed;
|
|
|
|
std::vector<FileData*> mChildrenMostPlayed;
|
2020-11-10 17:48:16 +00:00
|
|
|
// The pair includes all games, and favorite games.
|
2020-09-21 16:13:27 +00:00
|
|
|
std::pair<unsigned int, unsigned int> mGameCount;
|
2020-07-28 17:44:17 +00:00
|
|
|
bool mOnlyFolders;
|
2020-10-31 10:32:18 +00:00
|
|
|
bool mHasFolders;
|
2022-02-13 19:03:34 +00:00
|
|
|
bool mUpdateChildrenLastPlayed;
|
|
|
|
bool mUpdateChildrenMostPlayed;
|
2020-07-13 18:13:48 +00:00
|
|
|
// Used for flagging a game for deletion from its gamelist.xml file.
|
|
|
|
bool mDeletionFlag;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
2017-06-12 16:38:59 +00:00
|
|
|
|
|
|
|
class CollectionFileData : public FileData
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionFileData(FileData* file, SystemData* system);
|
|
|
|
~CollectionFileData();
|
|
|
|
const std::string& getName();
|
|
|
|
void refreshMetadata();
|
2021-07-07 18:03:42 +00:00
|
|
|
FileData* getSourceFileData() { return mSourceFileData; }
|
|
|
|
std::string getKey() { return getFullPath(); }
|
2020-09-17 20:00:07 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
// Needs to be updated when metadata changes.
|
|
|
|
std::string mCollectionFileName;
|
|
|
|
bool mDirty;
|
2017-07-18 09:45:50 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_APP_FILE_DATA_H
|