Minor changes to some media lookup functions

This commit is contained in:
Leon Styhre 2023-12-18 22:55:59 +01:00
parent 97d26718a3
commit c3747d4e51
2 changed files with 10 additions and 13 deletions

View file

@ -211,7 +211,6 @@ const std::string FileData::getMediaDirectory()
const std::string FileData::getMediafilePath(const std::string& subdirectory) const const std::string FileData::getMediafilePath(const std::string& subdirectory) const
{ {
const std::vector<std::string> extList {".png", ".jpg"};
std::string subFolders; std::string subFolders;
// Extract possible subfolders from the path. // Extract possible subfolders from the path.
@ -223,8 +222,8 @@ const std::string FileData::getMediafilePath(const std::string& subdirectory) co
subFolders + "/" + getDisplayName()}; subFolders + "/" + getDisplayName()};
// Look for an image file in the media directory. // Look for an image file in the media directory.
for (size_t i {0}; i < extList.size(); ++i) { for (auto& extension : sImageExtensions) {
std::string mediaPath {tempPath + extList[i]}; const std::string mediaPath {tempPath + extension};
if (Utils::FileSystem::exists(mediaPath)) if (Utils::FileSystem::exists(mediaPath))
return mediaPath; return mediaPath;
} }
@ -316,7 +315,6 @@ const std::string FileData::getCustomImagePath() const
const std::string FileData::getVideoPath() const const std::string FileData::getVideoPath() const
{ {
const std::vector<std::string> extList {".avi", ".mkv", ".mov", ".mp4", ".wmv"};
std::string subFolders; std::string subFolders;
// Extract possible subfolders from the path. // Extract possible subfolders from the path.
@ -328,8 +326,8 @@ const std::string FileData::getVideoPath() const
getDisplayName()}; getDisplayName()};
// Look for media in the media directory. // Look for media in the media directory.
for (size_t i {0}; i < extList.size(); ++i) { for (auto& extension : sVideoExtensions) {
std::string mediaPath {tempPath + extList[i]}; const std::string mediaPath {tempPath + extension};
if (Utils::FileSystem::exists(mediaPath)) if (Utils::FileSystem::exists(mediaPath))
return mediaPath; return mediaPath;
} }

View file

@ -40,11 +40,7 @@ public:
const std::string& getName() { return metadata.get("name"); } const std::string& getName() { return metadata.get("name"); }
const std::string& getSortName(); const std::string& getSortName();
// Returns our best guess at the "real" name for this file. // Returns our best guess at the "real" name for this file.
std::string getDisplayName() const std::string getDisplayName() const { return Utils::FileSystem::getStem(mPath); }
{
const std::string& stem {Utils::FileSystem::getStem(mPath)};
return stem;
}
std::string getCleanName() const std::string getCleanName() const
{ {
return Utils::String::removeParenthesis(this->getDisplayName()); return Utils::String::removeParenthesis(this->getDisplayName());
@ -112,8 +108,8 @@ public:
bool excludeRecursively, bool excludeRecursively,
bool respectExclusions) const; bool respectExclusions) const;
void addChild(FileData* file); // Error if mType != FOLDER void addChild(FileData* file);
void removeChild(FileData* file); // Error if mType != FOLDER void removeChild(FileData* file);
virtual std::string getKey() { return getFileName(); } virtual std::string getKey() { return getFileName(); }
const bool isArcadeAsset() const; const bool isArcadeAsset() const;
@ -175,6 +171,9 @@ private:
std::vector<FileData*> mChildrenLastPlayed; std::vector<FileData*> mChildrenLastPlayed;
std::vector<FileData*> mChildrenMostPlayed; std::vector<FileData*> mChildrenMostPlayed;
std::function<void()> mUpdateListCallback; std::function<void()> mUpdateListCallback;
static inline std::vector<std::string> sImageExtensions {".png", ".jpg"};
static inline std::vector<std::string> sVideoExtensions {".mp4", ".mkv", ".avi",
".mp4", ".wmv", ".mov"};
// The pair includes all games, and favorite games. // The pair includes all games, and favorite games.
std::pair<unsigned int, unsigned int> mGameCount; std::pair<unsigned int, unsigned int> mGameCount;
bool mOnlyFolders; bool mOnlyFolders;