overlays: fix background image logic

Also make the path getter more generic
This commit is contained in:
Megamouse 2025-03-18 23:16:17 +01:00
parent 12eacfa67b
commit b2ff24453c
5 changed files with 186 additions and 98 deletions

View file

@ -753,99 +753,6 @@ void Emulator::SetUsr(const std::string& user)
m_usr = user;
}
std::string Emulator::GetBackgroundPicturePath() const
{
// Try to find a custom icon first
std::string path = fs::get_config_dir() + "/Icons/game_icons/" + GetTitleID() + "/PIC1.PNG";
if (fs::is_file(path))
{
return path;
}
std::string disc_dir = vfs::get("/dev_bdvd/PS3_GAME");
if (m_sfo_dir == disc_dir)
{
disc_dir.clear();
}
constexpr auto search_barrier = "barrier";
const std::string locale_suffix = fmt::format("_%02d", static_cast<s32>(g_cfg.sys.language.get()));
std::initializer_list<std::string> testees =
{
m_sfo_dir + fmt::format("/PIC0%s.PNG", locale_suffix),
m_sfo_dir + fmt::format("/PIC1%s.PNG", locale_suffix),
m_sfo_dir + fmt::format("/PIC2%s.PNG", locale_suffix),
m_sfo_dir + fmt::format("/PIC3%s.PNG", locale_suffix),
search_barrier,
m_sfo_dir + "/PIC0.PNG",
m_sfo_dir + "/PIC1.PNG",
m_sfo_dir + "/PIC2.PNG",
m_sfo_dir + "/PIC3.PNG",
search_barrier,
!disc_dir.empty() ? (disc_dir + fmt::format("/PIC0%s.PNG", locale_suffix)) : disc_dir,
!disc_dir.empty() ? (disc_dir + fmt::format("/PIC1%s.PNG", locale_suffix)) : disc_dir,
!disc_dir.empty() ? (disc_dir + fmt::format("/PIC2%s.PNG", locale_suffix)) : disc_dir,
!disc_dir.empty() ? (disc_dir + fmt::format("/PIC3%s.PNG", locale_suffix)) : disc_dir,
search_barrier,
!disc_dir.empty() ? (disc_dir + "/PIC0.PNG") : disc_dir,
!disc_dir.empty() ? (disc_dir + "/PIC1.PNG") : disc_dir,
!disc_dir.empty() ? (disc_dir + "/PIC2.PNG") : disc_dir,
!disc_dir.empty() ? (disc_dir + "/PIC3.PNG") : disc_dir,
search_barrier,
m_sfo_dir + fmt::format("/ICON0%s.PNG", locale_suffix),
search_barrier,
m_sfo_dir + "/ICON0.PNG",
search_barrier,
!disc_dir.empty() ? (disc_dir + fmt::format("/ICON0%s.PNG", locale_suffix)) : disc_dir,
search_barrier,
!disc_dir.empty() ? (disc_dir + "/ICON0.PNG") : disc_dir,
};
// Try to return the picture with the highest resolution
// Be naive and assume that its the one that spans over the most bytes
usz max_file_size = 0;
usz index_of_largest_file = umax;
for (usz index = 0; index < testees.size(); index++)
{
const std::string& path = testees.begin()[index];
fs::stat_t file_stat{};
if (path == search_barrier)
{
if (index_of_largest_file != umax)
{
// Found a file in the preferred image group
break;
}
continue;
}
if (path.empty() || !fs::get_stat(path, file_stat) || file_stat.is_directory)
{
continue;
}
if (max_file_size < file_stat.size)
{
max_file_size = file_stat.size;
index_of_largest_file = index;
}
}
if (index_of_largest_file == umax)
{
return {};
}
return testees.begin()[index_of_largest_file];
}
bool Emulator::BootRsxCapture(const std::string& path)
{
if (m_state != system_state::stopped || m_restrict_emu_state_change)