From b3a1615170bbc7fe71728be8dac66149cc5b0451 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 26 Aug 2022 19:04:41 -0400 Subject: [PATCH 1/2] fix image paths --- src/process.cpp | 26 +++++++++++++++++++++++--- src_assets/linux/config/apps.json | 2 +- src_assets/windows/config/apps.json | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index 7fd900c5b89..a1b05e4614d 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -194,8 +194,9 @@ std::vector &proc_t::get_apps() { } /// Gets application image from application list. +/// Returns image from assets directory if found there. /// Returns default image if image configuration is not set. -/// returns http content-type header compatible image type +/// Returns http content-type header compatible image type. std::string proc_t::get_app_image(int app_id) { auto app_index = app_id - 1; if(app_index < 0 || app_index >= _apps.size()) { @@ -205,18 +206,37 @@ std::string proc_t::get_app_image(int app_id) { auto app_image_path = _apps[app_index].image_path; if(app_image_path.empty()) { + // image is empty, return default box image return SUNSHINE_ASSETS_DIR "/box.png"; } + // get the image extension and convert it to lowercase auto image_extension = std::filesystem::path(app_image_path).extension().string(); boost::to_lower(image_extension); + // return the default box image if extension is not "png" + if(image_extension != ".png") { + return SUNSHINE_ASSETS_DIR "/box.png"; + } + + // check if image is in assets directory + if(std::filesystem::exists(SUNSHINE_ASSETS_DIR + app_image_path)) { + return SUNSHINE_ASSETS_DIR + app_image_path; + } + else if(app_image_path == "./assets/steam.png") { + // handle old default steam image definition + return SUNSHINE_ASSETS_DIR "/steam.png"; + } + + // check if specified image exists std::error_code code; - if(!std::filesystem::exists(app_image_path, code) || image_extension != ".png") { + if(!std::filesystem::exists(app_image_path, code)) { + // return default box image if image does not exist return SUNSHINE_ASSETS_DIR "/box.png"; } - // return only "content-type" http header compatible image type. + // image is a png, and not in assets directory + // return only "content-type" http header compatible image type return app_image_path; } diff --git a/src_assets/linux/config/apps.json b/src_assets/linux/config/apps.json index 552dabe23cf..4a848bd89f5 100644 --- a/src_assets/linux/config/apps.json +++ b/src_assets/linux/config/apps.json @@ -14,7 +14,7 @@ "output":"steam.txt", "detached":["setsid steam steam://open/bigpicture"], - "image-path":"./assets/steam.png" + "image-path":"steam.png" } ] } diff --git a/src_assets/windows/config/apps.json b/src_assets/windows/config/apps.json index 419f2be486d..379dd2fb516 100644 --- a/src_assets/windows/config/apps.json +++ b/src_assets/windows/config/apps.json @@ -8,7 +8,7 @@ "output":"steam.txt", "detached":["steam steam://open/bigpicture"], - "image-path":"./assets/steam.png" + "image-path":"steam.png" } ] } From 264c9272df8d443456e405476983cc8bb41687a4 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:37:18 -0400 Subject: [PATCH 2/2] fix string concatenation of image in assets dir --- src/process.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/process.cpp b/src/process.cpp index cd74a801368..2b6c1507119 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -202,10 +202,11 @@ std::string proc_t::get_app_image(int app_id) { return SUNSHINE_ASSETS_DIR "/box.png"; } + auto default_image = SUNSHINE_ASSETS_DIR "/box.png"; auto app_image_path = _apps[app_index].image_path; if(app_image_path.empty()) { // image is empty, return default box image - return SUNSHINE_ASSETS_DIR "/box.png"; + return default_image; } // get the image extension and convert it to lowercase @@ -214,12 +215,13 @@ std::string proc_t::get_app_image(int app_id) { // return the default box image if extension is not "png" if(image_extension != ".png") { - return SUNSHINE_ASSETS_DIR "/box.png"; + return default_image; } // check if image is in assets directory - if(std::filesystem::exists(SUNSHINE_ASSETS_DIR + app_image_path)) { - return SUNSHINE_ASSETS_DIR + app_image_path; + auto full_image_path = std::filesystem::path(SUNSHINE_ASSETS_DIR) / app_image_path; + if(std::filesystem::exists(full_image_path)) { + return full_image_path.string(); } else if(app_image_path == "./assets/steam.png") { // handle old default steam image definition @@ -230,7 +232,7 @@ std::string proc_t::get_app_image(int app_id) { std::error_code code; if(!std::filesystem::exists(app_image_path, code)) { // return default box image if image does not exist - return SUNSHINE_ASSETS_DIR "/box.png"; + return default_image; } // image is a png, and not in assets directory