2013-11-06 01:41:49 +00:00
|
|
|
#pragma once
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
#include <vector>
|
2012-07-27 16:58:27 +00:00
|
|
|
#include <string>
|
2013-11-06 01:41:49 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include "MetaData.h"
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
class SystemData;
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
enum FileType
|
|
|
|
{
|
|
|
|
GAME = 1, // Cannot have children.
|
|
|
|
FOLDER = 2
|
|
|
|
};
|
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
enum FileChangeType
|
|
|
|
{
|
|
|
|
FILE_ADDED,
|
|
|
|
FILE_METADATA_CHANGED,
|
2013-11-25 20:49:02 +00:00
|
|
|
FILE_REMOVED,
|
|
|
|
FILE_SORTED
|
2013-11-12 23:28:15 +00:00
|
|
|
};
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
// Used for loading/saving gamelist.xml.
|
|
|
|
const char* fileTypeToString(FileType type);
|
|
|
|
FileType stringToFileType(const char* str);
|
|
|
|
|
|
|
|
std::string getCleanFileName(const boost::filesystem::path& path);
|
|
|
|
|
|
|
|
// A tree node that holds information for a file.
|
2012-07-27 16:58:27 +00:00
|
|
|
class FileData
|
|
|
|
{
|
|
|
|
public:
|
2013-11-12 23:28:15 +00:00
|
|
|
FileData(FileType type, const boost::filesystem::path& path, SystemData* system);
|
2013-11-06 01:41:49 +00:00
|
|
|
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; }
|
|
|
|
inline const std::vector<FileData*>& getChildren() const { return mChildren; }
|
2013-11-12 23:28:15 +00:00
|
|
|
inline SystemData* getSystem() const { return mSystem; }
|
2013-11-06 01:41:49 +00:00
|
|
|
|
|
|
|
virtual const std::string& getThumbnailPath() const;
|
|
|
|
|
|
|
|
std::vector<FileData*> getFilesRecursive(unsigned int typeMask) const;
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
void addChild(FileData* file); // Error if mType != FOLDER
|
|
|
|
void removeChild(FileData* file); //Error if mType != FOLDER
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2013-11-12 23:28:15 +00:00
|
|
|
SystemData* mSystem;
|
2013-11-06 01:41:49 +00:00
|
|
|
FileData* mParent;
|
|
|
|
std::vector<FileData*> mChildren;
|
|
|
|
};
|