2020-05-24 08:29:29 +00:00
|
|
|
//
|
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
|
|
|
|
// (launching initiated by the ViewController).
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#pragma once
|
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
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "MetaData.h"
|
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-06-21 12:25:28 +00:00
|
|
|
GAME = 1, // Cannot have children.
|
|
|
|
FOLDER = 2,
|
|
|
|
PLACEHOLDER = 3
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
enum FileChangeType {
|
2020-06-21 12:25:28 +00:00
|
|
|
FILE_ADDED,
|
|
|
|
FILE_METADATA_CHANGED,
|
|
|
|
FILE_REMOVED,
|
|
|
|
FILE_SORTED
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Used for loading/saving gamelist.xml.
|
|
|
|
const char* fileTypeToString(FileType type);
|
|
|
|
FileType stringToFileType(const char* str);
|
|
|
|
|
|
|
|
// A tree node that holds information for a file.
|
|
|
|
class FileData
|
|
|
|
{
|
|
|
|
public:
|
2020-07-13 18:13:48 +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();
|
2020-07-26 20:19:29 +00:00
|
|
|
const bool getHidden();
|
2020-07-29 17:01:49 +00:00
|
|
|
const bool getCountAsGame();
|
2020-07-28 13:19:54 +00:00
|
|
|
const std::vector<FileData*> getChildrenRecursive() const;
|
2020-06-21 12:25:28 +00:00
|
|
|
inline FileType getType() const { return mType; }
|
|
|
|
inline const std::string& getPath() const { return mPath; }
|
|
|
|
inline FileData* getParent() const { return mParent; }
|
|
|
|
inline const std::unordered_map<std::string, FileData*>& getChildrenByFilename() const
|
|
|
|
{ return mChildrenByFilename; }
|
|
|
|
inline const std::vector<FileData*>& getChildren() const { return mChildren; }
|
|
|
|
inline SystemData* getSystem() const { return mSystem; }
|
|
|
|
inline SystemEnvironmentData* getSystemEnvData() const { return mEnvData; }
|
|
|
|
const std::vector<std::string>& getFirstLetterIndex() const
|
|
|
|
{ return mFirstLetterIndex; };
|
2020-07-28 17:44:17 +00:00
|
|
|
const bool getOnlyFoldersFlag() { return mOnlyFolders; }
|
2020-06-21 12:25:28 +00:00
|
|
|
static const std::string getROMDirectory();
|
|
|
|
static const std::string getMediaDirectory();
|
2020-07-13 18:13:48 +00:00
|
|
|
const std::string getMediafilePath(std::string subdirectory, std::string mediatype) const;
|
|
|
|
const std::string getImagePath() const;
|
|
|
|
const std::string get3DBoxPath() const;
|
|
|
|
const std::string getCoverPath() const;
|
|
|
|
const std::string getMarqueePath() const;
|
|
|
|
const std::string getMiximagePath() const;
|
|
|
|
const std::string getScreenshotPath() const;
|
|
|
|
const std::string getThumbnailPath() const;
|
|
|
|
const std::string getVideoPath() const;
|
|
|
|
|
|
|
|
bool getDeletionFlag() { return mDeletionFlag; };
|
|
|
|
void setDeletionFlag() { mDeletionFlag = true; };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
const std::vector<FileData*>& getChildrenListToDisplay();
|
|
|
|
std::vector<FileData*> getFilesRecursive(unsigned int typeMask,
|
2020-07-29 17:01:49 +00:00
|
|
|
bool displayedOnly = false, bool countAllGames = true) const;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
void addChild(FileData* file); // Error if mType != FOLDER
|
|
|
|
void removeChild(FileData* file); //Error if mType != FOLDER
|
|
|
|
|
|
|
|
inline bool isPlaceHolder() { return mType == PLACEHOLDER; };
|
|
|
|
|
|
|
|
virtual inline void refreshMetadata() { return; };
|
|
|
|
|
|
|
|
virtual std::string getKey();
|
|
|
|
const bool isArcadeAsset();
|
|
|
|
inline std::string getFullPath() { return getPath(); };
|
|
|
|
inline std::string getFileName() { return Utils::FileSystem::getFileName(getPath()); };
|
|
|
|
virtual FileData* getSourceFileData();
|
|
|
|
inline std::string getSystemName() const { return mSystemName; };
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
void launchGame(Window* window);
|
|
|
|
|
|
|
|
typedef bool ComparisonFunction(const FileData* a, const FileData* b);
|
|
|
|
struct SortType {
|
|
|
|
ComparisonFunction* comparisonFunction;
|
|
|
|
bool ascending;
|
|
|
|
std::string description;
|
|
|
|
|
|
|
|
SortType(ComparisonFunction* sortFunction,
|
|
|
|
bool sortAscending,
|
|
|
|
const std::string& sortDescription)
|
|
|
|
: comparisonFunction(sortFunction),
|
|
|
|
ascending(sortAscending),
|
|
|
|
description(sortDescription) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sort(ComparisonFunction& comparator, bool ascending = true);
|
|
|
|
void sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending = true);
|
|
|
|
void sort(const SortType& type, bool mFavoritesOnTop = false);
|
|
|
|
MetaDataList metadata;
|
|
|
|
|
|
|
|
inline void setSortTypeString(std::string typestring) { mSortTypeString = typestring; }
|
|
|
|
inline std::string getSortTypeString() { return mSortTypeString; }
|
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;
|
|
|
|
std::unordered_map<std::string,FileData*> mChildrenByFilename;
|
|
|
|
std::vector<FileData*> mChildren;
|
|
|
|
std::vector<FileData*> mFilteredChildren;
|
|
|
|
std::vector<std::string> mFirstLetterIndex;
|
2020-07-28 17:44:17 +00:00
|
|
|
bool mOnlyFolders;
|
2020-07-13 18:13:48 +00:00
|
|
|
// Used for flagging a game for deletion from its gamelist.xml file.
|
|
|
|
bool mDeletionFlag;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
const std::string FAVORITE_CHAR = "\uF005";
|
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();
|
|
|
|
FileData* getSourceFileData();
|
|
|
|
std::string getKey();
|
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
|
|
|
FileData::SortType getSortTypeFromString(std::string desc);
|
|
|
|
|
|
|
|
#endif // ES_APP_FILE_DATA_H
|