Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix image paths #346

Merged
merged 5 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,29 +192,51 @@ std::vector<ctx_t> &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()) {
BOOST_LOG(error) << "Couldn't find app with ID ["sv << 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()) {
return SUNSHINE_ASSETS_DIR "/box.png";
// image is empty, return default box image
return default_image;
}

// 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 default_image;
}

// check if image is in assets directory
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
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") {
return SUNSHINE_ASSETS_DIR "/box.png";
if(!std::filesystem::exists(app_image_path, code)) {
// return default box image if image does not exist
return default_image;
}

// 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src_assets/linux/assets/apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"output":"steam.txt",
"detached":["setsid steam steam://open/bigpicture"],
"image-path":"./assets/steam.png"
"image-path":"steam.png"
}
]
}
2 changes: 1 addition & 1 deletion src_assets/windows/assets/apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"output":"steam.txt",
"detached":["steam steam://open/bigpicture"],
"image-path":"./assets/steam.png"
"image-path":"steam.png"
}
]
}