From 70fe0cc2249d00a20f64d2fa8e34e12749159106 Mon Sep 17 00:00:00 2001
From: Zion Nimchuk <zionnimchuk@gmail.com>
Date: Fri, 26 Jan 2018 20:51:56 -0800
Subject: [PATCH] Install and load icons from Icons in executable directory,
 fixes local builds using Icons

---
 rpcs3/CMakeLists.txt             | 7 +++++++
 rpcs3/Emu/RSX/overlay_controls.h | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt
index 3e0b8d0ef2..0fc8c8cc90 100644
--- a/rpcs3/CMakeLists.txt
+++ b/rpcs3/CMakeLists.txt
@@ -457,6 +457,13 @@ endif()
 
 cotire(rpcs3)
 
+if (UNIX)
+# Copy icons to executable directory
+add_custom_command(TARGET rpcs3 POST_BUILD
+                   COMMAND ${CMAKE_COMMAND} -E copy_directory
+                       ${CMAKE_SOURCE_DIR}/bin/Icons $<TARGET_FILE_DIR:rpcs3>/Icons)
+endif()
+                       
 # Unix installation
 if(UNIX AND NOT APPLE)
 	# Install the binary
diff --git a/rpcs3/Emu/RSX/overlay_controls.h b/rpcs3/Emu/RSX/overlay_controls.h
index 4a148f1fc6..8fd4eede57 100644
--- a/rpcs3/Emu/RSX/overlay_controls.h
+++ b/rpcs3/Emu/RSX/overlay_controls.h
@@ -472,6 +472,7 @@ namespace rsx
 						//Resource was not found in config dir, try and grab from relative path (linux)
 						info = std::make_unique<image_info>(("Icons/ui/" + res).c_str());
 #ifndef _WIN32
+						// Check for Icons in ../share/rpcs3 for AppImages and /usr/bin/
 						if (info->data == nullptr)
 						{
 							char result[ PATH_MAX ];
@@ -483,6 +484,11 @@ namespace rsx
 							std::string executablePath = dirname(result);
 							info = std::make_unique<image_info>((executablePath + "/../share/rpcs3/Icons/ui/" + res).c_str());
 
+							// Check if the icons are in the same directory as the executable (local builds)
+							if (info->data == nullptr)
+							{
+								info = std::make_unique<image_info>((executablePath + "/Icons/ui/" + res).c_str());
+							}
 						}
 #endif
 						if (info->data != nullptr)