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
|
|
|
|
|
|
|
enum FileType
|
|
|
|
{
|
|
|
|
GAME = 1, // Cannot have children.
|
2017-03-18 17:54:39 +00:00
|
|
|
FOLDER = 2,
|
|
|
|
PLACEHOLDER = 3
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum FileChangeType
|
|
|
|
{
|
|
|
|
FILE_ADDED,
|
|
|
|
FILE_METADATA_CHANGED,
|
|
|
|
FILE_REMOVED,
|
|
|
|
FILE_SORTED
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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:
|
2018-01-29 22:50:10 +00:00
|
|
|
FileData(FileType type, const std::string& path, SystemEnvironmentData* envData, SystemData* system);
|
2014-06-25 16:29:58 +00:00
|
|
|
virtual ~FileData();
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
virtual const std::string& getName();
|
2018-04-25 05:07:25 +00:00
|
|
|
virtual const std::string& getSortName();
|
2020-05-15 15:42:36 +00:00
|
|
|
virtual const bool getFavorite();
|
2014-06-25 16:29:58 +00:00
|
|
|
inline FileType getType() const { return mType; }
|
2018-01-29 22:50:10 +00:00
|
|
|
inline const std::string& getPath() const { return mPath; }
|
2014-06-25 16:29:58 +00:00
|
|
|
inline FileData* getParent() const { return mParent; }
|
2016-08-09 20:26:30 +00:00
|
|
|
inline const std::unordered_map<std::string, FileData*>& getChildrenByFilename() const { return mChildrenByFilename; }
|
2014-06-25 16:29:58 +00:00
|
|
|
inline const std::vector<FileData*>& getChildren() const { return mChildren; }
|
|
|
|
inline SystemData* getSystem() const { return mSystem; }
|
2017-06-12 16:38:59 +00:00
|
|
|
inline SystemEnvironmentData* getSystemEnvData() const { return mEnvData; }
|
2020-05-18 17:00:43 +00:00
|
|
|
virtual const std::string getMediaDirectory() const;
|
2017-10-22 23:04:17 +00:00
|
|
|
virtual const std::string getThumbnailPath() const;
|
|
|
|
virtual const std::string getVideoPath() const;
|
|
|
|
virtual const std::string getMarqueePath() const;
|
|
|
|
virtual const std::string getImagePath() const;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
const std::vector<FileData*>& getChildrenListToDisplay();
|
2017-05-18 10:16:57 +00:00
|
|
|
std::vector<FileData*> getFilesRecursive(unsigned int typeMask, bool displayedOnly = false) const;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
void addChild(FileData* file); // Error if mType != FOLDER
|
|
|
|
void removeChild(FileData* file); //Error if mType != FOLDER
|
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
inline bool isPlaceHolder() { return mType == PLACEHOLDER; };
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
virtual inline void refreshMetadata() { return; };
|
|
|
|
|
|
|
|
virtual std::string getKey();
|
2018-05-10 01:29:46 +00:00
|
|
|
const bool isArcadeAsset();
|
2018-01-29 22:50:10 +00:00
|
|
|
inline std::string getFullPath() { return getPath(); };
|
|
|
|
inline std::string getFileName() { return Utils::FileSystem::getFileName(getPath()); };
|
2017-06-12 16:38:59 +00:00
|
|
|
virtual FileData* getSourceFileData();
|
|
|
|
inline std::string getSystemName() const { return mSystemName; };
|
|
|
|
|
2016-03-29 15:33:19 +00:00
|
|
|
// Returns our best guess at the "real" name for this file (will attempt to perform MAME name translation)
|
|
|
|
std::string getDisplayName() const;
|
|
|
|
|
|
|
|
// As above, but also remove parenthesis
|
2014-06-25 16:29:58 +00:00
|
|
|
std::string getCleanName() const;
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void launchGame(Window* window);
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
typedef bool ComparisonFunction(const FileData* a, const FileData* b);
|
|
|
|
struct SortType
|
|
|
|
{
|
|
|
|
ComparisonFunction* comparisonFunction;
|
|
|
|
bool ascending;
|
|
|
|
std::string description;
|
|
|
|
|
2017-05-18 10:16:57 +00:00
|
|
|
SortType(ComparisonFunction* sortFunction, bool sortAscending, const std::string & sortDescription)
|
2014-06-25 16:29:58 +00:00
|
|
|
: comparisonFunction(sortFunction), ascending(sortAscending), description(sortDescription) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sort(ComparisonFunction& comparator, bool ascending = true);
|
|
|
|
void sort(const SortType& type);
|
|
|
|
MetaDataList metadata;
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
protected:
|
|
|
|
FileData* mSourceFileData;
|
|
|
|
FileData* mParent;
|
|
|
|
std::string mSystemName;
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
private:
|
|
|
|
FileType mType;
|
2018-01-29 22:50:10 +00:00
|
|
|
std::string mPath;
|
2017-06-12 16:38:59 +00:00
|
|
|
SystemEnvironmentData* mEnvData;
|
2014-06-25 16:29:58 +00:00
|
|
|
SystemData* mSystem;
|
2016-08-09 20:26:30 +00:00
|
|
|
std::unordered_map<std::string,FileData*> mChildrenByFilename;
|
2014-06-25 16:29:58 +00:00
|
|
|
std::vector<FileData*> mChildren;
|
2017-03-18 17:54:39 +00:00
|
|
|
std::vector<FileData*> mFilteredChildren;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
2017-06-12 16:38:59 +00:00
|
|
|
|
|
|
|
class CollectionFileData : public FileData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CollectionFileData(FileData* file, SystemData* system);
|
|
|
|
~CollectionFileData();
|
|
|
|
const std::string& getName();
|
|
|
|
void refreshMetadata();
|
|
|
|
FileData* getSourceFileData();
|
|
|
|
std::string getKey();
|
|
|
|
private:
|
|
|
|
// 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
|