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

Basic custom icon support #17759

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
45 changes: 31 additions & 14 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ class GameInfoWorkItem : public Task {
}

// Then, ICON0.PNG.
if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
Path customIcon = GetSysDirectory(DIRECTORY_TEXTURES) / info_->id / "icon.png";
if (g_Config.bReplaceTextures && File::Exists(customIcon)) {
File::ReadFileToString(false, customIcon, info_->icon.data);
} else if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->icon.data);
} else {
Expand Down Expand Up @@ -471,17 +474,22 @@ class GameInfoWorkItem : public Task {
info_->paramSFOLoaded = true;
}
{
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.jpg");
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
if (File::Exists(screenshot_png)) {
File::ReadFileToString(false, screenshot_png, info_->icon.data);
} else if (File::Exists(screenshot_jpg)) {
File::ReadFileToString(false, screenshot_jpg, info_->icon.data);
Path customIcon = GetSysDirectory(DIRECTORY_TEXTURES) / info_->id / "icon.png";
if (g_Config.bReplaceTextures && File::Exists(customIcon)) {
File::ReadFileToString(false, customIcon, info_->icon.data);
} else {
// Read standard icon
VERBOSE_LOG(LOADER, "Loading unknown.png because there was an ELF");
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.jpg");
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
if (File::Exists(screenshot_png)) {
File::ReadFileToString(false, screenshot_png, info_->icon.data);
} else if (File::Exists(screenshot_jpg)) {
File::ReadFileToString(false, screenshot_jpg, info_->icon.data);
} else {
// Read standard icon
VERBOSE_LOG(LOADER, "Loading unknown.png because there was an ELF");
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
}
}
info_->icon.dataLoaded = true;
}
Expand Down Expand Up @@ -557,7 +565,12 @@ class GameInfoWorkItem : public Task {
info_->ParseParamSFO();
}

ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
Path customIcon = GetSysDirectory(DIRECTORY_TEXTURES) / info_->id / "icon.png";
if (g_Config.bReplaceTextures && File::Exists(customIcon)) {
File::ReadFileToString(false, customIcon, info_->icon.data);
} else {
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
}
info_->icon.dataLoaded = true;
if (info_->wantFlags & GAMEINFO_WANTBG) {
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, &info_->lock);
Expand Down Expand Up @@ -606,8 +619,12 @@ class GameInfoWorkItem : public Task {
}
}

// Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though
if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock)) {
Path customIcon = GetSysDirectory(DIRECTORY_TEXTURES) / info_->id / "icon.png";
if (g_Config.bReplaceTextures && File::Exists(customIcon)) {
File::ReadFileToString(false, customIcon, info_->icon.data);
info_->icon.dataLoaded = true;
} else if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock)) {
// Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.jpg");
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
// Try using png/jpg screenshots first
Expand Down