From cd2f2ee42b911711db6bd6e0276bea494a389e88 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Mon, 23 Oct 2017 01:04:17 +0200 Subject: [PATCH] Use local game art ( image, marquee and video ) from romfolder/images if the gamelist didn't specify a path --- es-app/src/FileData.cpp | 87 +++++++++++++++++-- es-app/src/FileData.h | 7 +- .../views/gamelist/DetailedGameListView.cpp | 2 +- .../src/views/gamelist/VideoGameListView.cpp | 30 +------ 4 files changed, 87 insertions(+), 39 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 892c701a3..9fa60a343 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -43,12 +43,32 @@ std::string FileData::getCleanName() const return removeParenthesis(this->getDisplayName()); } -const std::string& FileData::getThumbnailPath() const +const std::string FileData::getThumbnailPath() const { - if(!metadata.get("thumbnail").empty()) - return metadata.get("thumbnail"); - else - return metadata.get("image"); + std::string thumbnail = metadata.get("thumbnail"); + + // no thumbnail, try image + if(thumbnail.empty()) + { + thumbnail = metadata.get("image"); + + // no image, try to use local image + if(thumbnail.empty()) + { + const char* extList[2] = { ".png", ".jpg" }; + for(int i = 0; i < 2; i++) + { + if(thumbnail.empty()) + { + std::string path = mEnvData->mStartPath + "/images/" + getDisplayName() + "-image" + extList[i]; + if(boost::filesystem::exists(path)) + thumbnail = path; + } + } + } + } + + return thumbnail; } const std::string& FileData::getName() @@ -76,14 +96,63 @@ const std::vector& FileData::getChildrenListToDisplay() { } } -const std::string& FileData::getVideoPath() const +const std::string FileData::getVideoPath() const { - return metadata.get("video"); + std::string video = metadata.get("video"); + + // no video, try to use local video + if(video.empty()) + { + std::string path = mEnvData->mStartPath + "/images/" + getDisplayName() + "-video.mp4"; + if(boost::filesystem::exists(path)) + video = path; + } + + return video; } -const std::string& FileData::getMarqueePath() const +const std::string FileData::getMarqueePath() const { - return metadata.get("marquee"); + std::string marquee = metadata.get("marquee"); + + // no marquee, try to use local marquee + if(marquee.empty()) + { + const char* extList[2] = { ".png", ".jpg" }; + for(int i = 0; i < 2; i++) + { + if(marquee.empty()) + { + std::string path = mEnvData->mStartPath + "/images/" + getDisplayName() + "-marquee" + extList[i]; + if(boost::filesystem::exists(path)) + marquee = path; + } + } + } + + return marquee; +} + +const std::string FileData::getImagePath() const +{ + std::string image = metadata.get("image"); + + // no image, try to use local image + if(image.empty()) + { + const char* extList[2] = { ".png", ".jpg" }; + for(int i = 0; i < 2; i++) + { + if(image.empty()) + { + std::string path = mEnvData->mStartPath + "/images/" + getDisplayName() + "-image" + extList[i]; + if(boost::filesystem::exists(path)) + image = path; + } + } + } + + return image; } std::vector FileData::getFilesRecursive(unsigned int typeMask, bool displayedOnly) const diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index 0ce34f9bb..39c271a79 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -43,9 +43,10 @@ public: inline const std::vector& getChildren() const { return mChildren; } inline SystemData* getSystem() const { return mSystem; } inline SystemEnvironmentData* getSystemEnvData() const { return mEnvData; } - virtual const std::string& getThumbnailPath() const; - virtual const std::string& getVideoPath() const; - virtual const std::string& getMarqueePath() const; + virtual const std::string getThumbnailPath() const; + virtual const std::string getVideoPath() const; + virtual const std::string getMarqueePath() const; + virtual const std::string getImagePath() const; const std::vector& getChildrenListToDisplay(); std::vector getFilesRecursive(unsigned int typeMask, bool displayedOnly = false) const; diff --git a/es-app/src/views/gamelist/DetailedGameListView.cpp b/es-app/src/views/gamelist/DetailedGameListView.cpp index 9d5d95002..dfad3478b 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.cpp +++ b/es-app/src/views/gamelist/DetailedGameListView.cpp @@ -194,7 +194,7 @@ void DetailedGameListView::updateInfoPanel() //mDescription.setText(""); fadingOut = true; }else{ - mImage.setImage(file->metadata.get("image")); + mImage.setImage(file->getImagePath()); mDescription.setText(file->metadata.get("desc")); mDescContainer.reset(); diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index 729bc1c3d..62f66b9fe 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -240,37 +240,15 @@ void VideoGameListView::updateInfoPanel() fadingOut = true; }else{ - std::string video_path; - std::string marquee_path; - std::string thumbnail_path; - video_path = file->getVideoPath(); - marquee_path = file->getMarqueePath(); - thumbnail_path = file->getThumbnailPath(); - - if (!video_path.empty() && (video_path[0] == '~')) - { - video_path.erase(0, 1); - video_path.insert(0, getHomePath()); - } - if (!marquee_path.empty() && (marquee_path[0] == '~')) - { - marquee_path.erase(0, 1); - marquee_path.insert(0, getHomePath()); - } - if (!thumbnail_path.empty() && (thumbnail_path[0] == '~')) - { - thumbnail_path.erase(0, 1); - thumbnail_path.insert(0, getHomePath()); - } - if (!mVideo->setVideo(video_path)) + if (!mVideo->setVideo(file->getVideoPath())) { mVideo->setDefaultVideo(); } mVideoPlaying = true; - mVideo->setImage(thumbnail_path); - mMarquee.setImage(marquee_path); - mImage.setImage(thumbnail_path); + mVideo->setImage(file->getThumbnailPath()); + mMarquee.setImage(file->getMarqueePath()); + mImage.setImage(file->getThumbnailPath()); mDescription.setText(file->metadata.get("desc")); mDescContainer.reset();