diff --git a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_icons.cpp b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_icons.cpp index 31b8f81123..377d5260bc 100644 --- a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_icons.cpp +++ b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_icons.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" #include "overlay_home_icons.h" +#include "Emu/RSX/Overlays/overlay_controls.h" + #include namespace rsx::overlays::home_menu @@ -44,8 +46,8 @@ namespace rsx::overlays::home_menu void load_icon(fa_icon icon) { - const std::string image_path = fmt::format("%s/Icons/ui/home/32/%s", fs::get_config_dir(), fa_icon_to_filename(icon)); - g_icons_cache[icon] = std::make_unique(image_path); + const std::string image_path = fmt::format("home/32/%s", fa_icon_to_filename(icon)); + g_icons_cache[icon] = rsx::overlays::resource_config::load_icon(image_path); } const image_info* get_icon(fa_icon icon) diff --git a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_page.cpp b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_page.cpp index 3d5e6cb17c..567aae7267 100644 --- a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_page.cpp +++ b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_page.cpp @@ -314,7 +314,6 @@ namespace rsx void home_menu_page::set_size(u16 _w, u16 _h) { - const auto prev_w = w; list_view::set_size(_w, _h); for (auto& entry : m_items) diff --git a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_settings.cpp b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_settings.cpp index 7789f809ea..0eabc1668a 100644 --- a/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_settings.cpp +++ b/rpcs3/Emu/RSX/Overlays/HomeMenu/overlay_home_menu_settings.cpp @@ -25,7 +25,7 @@ namespace rsx m_tabs->set_selected_tab(0); } - void home_menu_settings::add_page(home_menu::fa_icon icon, std::shared_ptr page) + void home_menu_settings::add_page(home_menu::fa_icon /*icon*/, std::shared_ptr page) { auto panel = std::static_pointer_cast(page); page->on_deactivate(); diff --git a/rpcs3/Emu/RSX/Overlays/overlay_animated_icon.cpp b/rpcs3/Emu/RSX/Overlays/overlay_animated_icon.cpp index 7361856976..405d2f93fd 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_animated_icon.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_animated_icon.cpp @@ -1,8 +1,7 @@ #include "stdafx.h" +#include "Emu/RSX/Overlays/overlay_controls.h" #include "overlay_animated_icon.h" -#include "Utilities/File.h" - #include "Emu/Cell/timers.hpp" namespace rsx @@ -11,8 +10,7 @@ namespace rsx { animated_icon::animated_icon(const char* icon_name) { - const std::string image_path = fmt::format("%s/Icons/ui/%s", fs::get_config_dir(), icon_name); - m_icon = std::make_unique(image_path); + m_icon = overlays::resource_config::load_icon(icon_name); set_raw_image(m_icon.get()); } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp index aa361cb394..408ff6cc34 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp @@ -108,6 +108,89 @@ namespace rsx { } + std::unique_ptr resource_config::load_icon(std::string_view relative_path) + { + const std::string res = relative_path.data(); + + // First check the global config dir + const std::string image_path = fs::get_config_dir() + "Icons/ui/" + res; + auto info = std::make_unique(image_path); + +#if !defined(_WIN32) && !defined(__APPLE__) && defined(DATADIR) + // Check the DATADIR if defined + if (info->get_data() == nullptr) + { + const std::string data_dir (DATADIR); + const std::string image_data = data_dir + "/Icons/ui/" + res; + info = std::make_unique(image_data); + } +#endif + + if (info->get_data() == nullptr) + { + // Resource was not found in the DATADIR or config dir, try and grab from relative path (linux) + std::string src = "Icons/ui/" + res; + info = std::make_unique(src); +#ifndef _WIN32 + // Check for Icons in ../share/rpcs3 for AppImages, + // in rpcs3.app/Contents/Resources for App Bundles, and /usr/bin. + if (info->get_data() == nullptr) + { + char result[ PATH_MAX ]; +#if defined(__APPLE__) + u32 bufsize = PATH_MAX; + const bool success = _NSGetExecutablePath( result, &bufsize ) == 0; +#elif defined(KERN_PROC_PATHNAME) + usz bufsize = PATH_MAX; + int mib[] = { + CTL_KERN, +#if defined(__NetBSD__) + KERN_PROC_ARGS, + -1, + KERN_PROC_PATHNAME, +#else + KERN_PROC, + KERN_PROC_PATHNAME, + -1, +#endif + }; + const bool success = sysctl(mib, sizeof(mib)/sizeof(mib[0]), result, &bufsize, NULL, 0) >= 0; +#elif defined(__linux__) + const bool success = readlink( "/proc/self/exe", result, PATH_MAX ) >= 0; +#elif defined(__sun) + const bool success = readlink( "/proc/self/path/a.out", result, PATH_MAX ) >= 0; +#else + const bool success = readlink( "/proc/curproc/file", result, PATH_MAX ) >= 0; +#endif + if (success) + { + std::string executablePath = dirname(result); +#ifdef __APPLE__ + src = executablePath + "/../Resources/Icons/ui/" + res; +#else + src = executablePath + "/../share/rpcs3/Icons/ui/" + res; +#endif + info = std::make_unique(src); + // Check if the icons are in the same directory as the executable (local builds) + if (info->get_data() == nullptr) + { + src = executablePath + "/Icons/ui/" + res; + info = std::make_unique(src); + } + } + } +#endif + if (info->get_data()) + { + // Install the image to config dir + fs::create_path(fs::get_parent_dir(image_path)); + fs::copy_file(src, image_path, true); + } + } + + return info; + } + void resource_config::load_files() { const std::array texture_resource_files @@ -130,82 +213,7 @@ namespace rsx }; for (const std::string& res : texture_resource_files) { - // First check the global config dir - const std::string image_path = fs::get_config_dir() + "Icons/ui/" + res; - auto info = std::make_unique(image_path); - -#if !defined(_WIN32) && !defined(__APPLE__) && defined(DATADIR) - // Check the DATADIR if defined - if (info->get_data() == nullptr) - { - const std::string data_dir (DATADIR); - const std::string image_data = data_dir + "/Icons/ui/" + res; - info = std::make_unique(image_data); - } -#endif - - if (info->get_data() == nullptr) - { - // Resource was not found in the DATADIR or config dir, try and grab from relative path (linux) - std::string src = "Icons/ui/" + res; - info = std::make_unique(src); -#ifndef _WIN32 - // Check for Icons in ../share/rpcs3 for AppImages, - // in rpcs3.app/Contents/Resources for App Bundles, and /usr/bin. - if (info->get_data() == nullptr) - { - char result[ PATH_MAX ]; -#if defined(__APPLE__) - u32 bufsize = PATH_MAX; - const bool success = _NSGetExecutablePath( result, &bufsize ) == 0; -#elif defined(KERN_PROC_PATHNAME) - usz bufsize = PATH_MAX; - int mib[] = { - CTL_KERN, -#if defined(__NetBSD__) - KERN_PROC_ARGS, - -1, - KERN_PROC_PATHNAME, -#else - KERN_PROC, - KERN_PROC_PATHNAME, - -1, -#endif - }; - const bool success = sysctl(mib, sizeof(mib)/sizeof(mib[0]), result, &bufsize, NULL, 0) >= 0; -#elif defined(__linux__) - const bool success = readlink( "/proc/self/exe", result, PATH_MAX ) >= 0; -#elif defined(__sun) - const bool success = readlink( "/proc/self/path/a.out", result, PATH_MAX ) >= 0; -#else - const bool success = readlink( "/proc/curproc/file", result, PATH_MAX ) >= 0; -#endif - if (success) - { - std::string executablePath = dirname(result); -#ifdef __APPLE__ - src = executablePath + "/../Resources/Icons/ui/" + res; -#else - src = executablePath + "/../share/rpcs3/Icons/ui/" + res; -#endif - info = std::make_unique(src); - // Check if the icons are in the same directory as the executable (local builds) - if (info->get_data() == nullptr) - { - src = executablePath + "/Icons/ui/" + res; - info = std::make_unique(src); - } - } - } -#endif - if (info->get_data()) - { - // Install the image to config dir - fs::create_path(fs::get_parent_dir(image_path)); - fs::copy_file(src, image_path, true); - } - } - + auto info = load_icon(res); texture_raw_data.push_back(std::move(info)); } } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.h b/rpcs3/Emu/RSX/Overlays/overlay_controls.h index ba49c30cc6..81b51904ba 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.h @@ -89,6 +89,8 @@ namespace rsx void load_files(); void free_resources(); + + static std::unique_ptr load_icon(std::string_view relative_path); }; struct compiled_resource