2014-06-25 16:29:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-08-09 20:26:30 +00:00
|
|
|
#include <unordered_map>
|
2014-06-25 16:29:58 +00:00
|
|
|
#include <string>
|
2016-08-09 20:26:30 +00:00
|
|
|
#include <vector>
|
2014-06-25 16:29:58 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include "MetaData.h"
|
|
|
|
|
|
|
|
class SystemData;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Remove (.*) and [.*] from str
|
|
|
|
std::string removeParenthesis(const std::string& str);
|
|
|
|
|
|
|
|
// A tree node that holds information for a file.
|
|
|
|
class FileData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileData(FileType type, const boost::filesystem::path& path, SystemData* system);
|
|
|
|
virtual ~FileData();
|
|
|
|
|
|
|
|
inline const std::string& getName() const { return metadata.get("name"); }
|
|
|
|
inline FileType getType() const { return mType; }
|
|
|
|
inline const boost::filesystem::path& getPath() const { return mPath; }
|
|
|
|
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; }
|
|
|
|
|
|
|
|
virtual const std::string& getThumbnailPath() const;
|
2016-12-04 23:47:34 +00:00
|
|
|
virtual const std::string& getVideoPath() const;
|
|
|
|
virtual const std::string& getMarqueePath() const;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-03-18 17:54:39 +00:00
|
|
|
const std::vector<FileData*>& getChildrenListToDisplay();
|
|
|
|
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; };
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 sort(const SortType& type);
|
|
|
|
|
|
|
|
MetaDataList metadata;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileType mType;
|
|
|
|
boost::filesystem::path mPath;
|
|
|
|
SystemData* mSystem;
|
|
|
|
FileData* mParent;
|
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
|
|
|
};
|