Skip to content

Commit

Permalink
Wood theme: Fix leftover ? icons shown in place of folder icons
Browse files Browse the repository at this point in the history
ALSO: Add logging to `iconUpdate`
  • Loading branch information
RocketRobz committed Sep 17, 2024
1 parent 0cadfab commit 6ddfb9c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
13 changes: 11 additions & 2 deletions quickmenu/arm9/source/iconTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "graphics/graphics.h"
#include "graphics/fontHandler.h"
#include "common/lodepng.h"
#include "common/logging.h"
#include "ndsheaderbanner.h"
#include "myDSiMode.h"
#include "language.h"
Expand Down Expand Up @@ -678,14 +679,19 @@ void iconUpdate(int num, bool isDir, const char* name)
{
clearText(false);

logPrint("iconUpdate: ");

const auto isNds = (bnrRomType[num] == ROM_TYPE_NDS);

if (customIcon[num] > 0 || (customIcon[num] && isNds)) {
if (customIcon[num] == -1) {
logPrint(isDir ? "Custom icon invalid!" : "Banner not found or custom icon invalid!");
loadIconTileset(icon_unk, num);
} else if (bnriconisDSi[num]) {
logPrint("Custom icon found!");
loadIcon(num, ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[0], true);
} else {
logPrint("Custom icon found!");
loadIcon(num, ndsBanner.icon, ndsBanner.palette, false);
}
} else if (extension(name, {".argv"})) {
Expand All @@ -698,6 +704,7 @@ void iconUpdate(int num, bool isDir, const char* name)
// open the argv file
fp = fopen(name, "rb");
if (fp == NULL) {
logPrint("Icon not found!\n");
clearIcon(num);
fclose(fp);
return;
Expand Down Expand Up @@ -732,9 +739,11 @@ void iconUpdate(int num, bool isDir, const char* name)
rc = stat(p, &st);
if (rc != 0) {
// stat failed
logPrint("Icon not found!");
clearIcon(num);
} else if (S_ISDIR(st.st_mode)) {
// this is a directory!
logPrint("Folder found!");
clearIcon(num);
} else {
iconUpdate(num, false, p);
Expand All @@ -750,8 +759,7 @@ void iconUpdate(int num, bool isDir, const char* name)
free(line);
} else if (isNds) {
// this is an nds/app file!

// icon
logPrint("NDS icon found!");
if (bnriconisDSi[num]) {
loadIcon(num, ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[0], true);
} else {
Expand Down Expand Up @@ -806,6 +814,7 @@ void iconUpdate(int num, bool isDir, const char* name)
} else {
loadIconTileset(icon_unk, num);
}
logPrint("\n");
}

void titleUpdate(int num, bool top, bool isDir, const char* name)
Expand Down
16 changes: 14 additions & 2 deletions romsel_aktheme/arm9/source/iconTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "fileBrowse.h"
#include "graphics/fontHandler.h"
#include "common/lodepng.h"
#include "common/logging.h"
#include "language.h"
#include "ndsheaderbanner.h"
#include "myDSiMode.h"
Expand Down Expand Up @@ -872,7 +873,7 @@ void iconTitleInit()
blackPalette = new u16[16*8]();
tilesModified = new u8[(32 * 256) / 2];

for (int i = 0; i < 4; i++) {
for (int i = 0; i < 8; i++) {
clearIcon(i);
}
}
Expand Down Expand Up @@ -1363,19 +1364,25 @@ void getGameInfo(int num, bool isDir, const char* name)

void iconUpdate(int num, bool isDir, const char* name)
{
logPrint("iconUpdate: ");

const bool isNds = (bnrRomType[num] == 0);

if (customIcon[num] > 0 || (customIcon[num] && isNds)) {
if (customIcon[num] > 0 || (customIcon[num] && !isDir && isNds)) {
sNDSBannerExt &ndsBanner = bnriconTile[num];
if (customIcon[num] == -1) {
logPrint(isDir ? "Custom icon invalid!" : "Banner not found or custom icon invalid!");
loadUnkIcon(num);
} else if (bnriconisDSi[num]) {
logPrint("Custom icon found!");
loadIcon(num, ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[bnriconPalLine[num]], true);
bnriconPalLoaded[num] = bnriconPalLine[num];
} else {
logPrint("Custom icon found!");
loadIcon(num, ndsBanner.icon, ndsBanner.palette, false);
}
} else if (isDir) {
logPrint("Folder found!");
loadFolderIcon(num);
} else if (extension(name, {".argv"})) {
// look through the argv file for the corresponding nds/app file
Expand All @@ -1387,6 +1394,7 @@ void iconUpdate(int num, bool isDir, const char* name)
// open the argv file
fp = fopen(name, "rb");
if (fp == NULL) {
logPrint("Icon not found!\n");
clearIcon(num);
fclose(fp);
return;
Expand Down Expand Up @@ -1420,9 +1428,11 @@ void iconUpdate(int num, bool isDir, const char* name)
rc = stat(p, &st);
if (rc != 0) {
// stat failed
logPrint("Icon not found!");
clearIcon(num);
} else if (S_ISDIR(st.st_mode)) {
// this is a directory!
logPrint("Folder found!");
loadFolderIcon(num);
} else {
iconUpdate(num, false, p);
Expand All @@ -1438,6 +1448,7 @@ void iconUpdate(int num, bool isDir, const char* name)
free(line);
} else if (isNds) {
// this is an nds/app file!
logPrint("NDS icon found!");
sNDSBannerExt &ndsBanner = bnriconTile[num];
if (bnriconisDSi[num]) {
loadIcon(num, ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[bnriconPalLine[num]], true);
Expand Down Expand Up @@ -1494,6 +1505,7 @@ void iconUpdate(int num, bool isDir, const char* name)
} else {
loadUnkIcon(num);
}
logPrint("\n");
}

void titleUpdate(int num, bool isDir, const char* name, const bool highlighted)
Expand Down
14 changes: 13 additions & 1 deletion romsel_dsimenutheme/arm9/source/iconTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "graphics/fontHandler.h"
#include "graphics/iconHandler.h"
#include "common/lodepng.h"
#include "common/logging.h"
#include "graphics/paletteEffects.h"
#include "graphics/queueControl.h"
#include "graphics/ThemeConfig.h"
Expand Down Expand Up @@ -620,23 +621,29 @@ void getGameInfo(bool isDir, const char *name, int num, bool fromArgv) {
}

void iconUpdate(bool isDir, const char *name, int num) {
logPrint("iconUpdate: ");

int spriteIdx = num == -1 ? 6 : num % 6;
if (num == -1)
num = 40;

const bool isNds = (bnrRomType[num] == 0);

if (customIcon[num] > 0 || (customIcon[num] && isNds)) {
if (customIcon[num] > 0 || (customIcon[num] && !isDir && isNds)) {
sNDSBannerExt &ndsBanner = bnriconTile[num];
if (customIcon[num] == -1) {
logPrint(isDir ? "Custom icon invalid!" : "Banner not found or custom icon invalid!");
loadUnkIcon(spriteIdx);
} else if (bnriconisDSi[num]) {
logPrint("Custom icon found!");
loadIcon(ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[bnriconPalLine[num]], spriteIdx, true);
bnriconPalLoaded[num] = bnriconPalLine[num];
} else {
logPrint("Custom icon found!");
loadIcon(ndsBanner.icon, ndsBanner.palette, spriteIdx, false);
}
} else if (isDir) {
logPrint("Folder found!");
clearIcon(spriteIdx);
} else if (extension(name, {".argv"})) {
// look through the argv file for the corresponding nds file
Expand All @@ -648,6 +655,7 @@ void iconUpdate(bool isDir, const char *name, int num) {
// open the argv file
fp = fopen(name, "rb");
if (fp == NULL) {
logPrint("Icon not found!\n");
clearIcon(spriteIdx);
fclose(fp);
return;
Expand Down Expand Up @@ -681,9 +689,11 @@ void iconUpdate(bool isDir, const char *name, int num) {
rc = stat(p, &st);
if (rc != 0) {
// stat failed
logPrint("Icon not found!");
clearIcon(spriteIdx);
} else if (S_ISDIR(st.st_mode)) {
// this is a directory!
logPrint("Folder found!");
clearIcon(spriteIdx);
} else {
iconUpdate(false, p, spriteIdx);
Expand All @@ -699,6 +709,7 @@ void iconUpdate(bool isDir, const char *name, int num) {
free(line);
} else if (isNds) {
// this is an nds/app file!
logPrint("NDS icon found!");
sNDSBannerExt &ndsBanner = bnriconTile[num];
if (bnriconisDSi[num]) {
loadIcon(ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[bnriconPalLine[num]], spriteIdx, true);
Expand Down Expand Up @@ -778,6 +789,7 @@ void iconUpdate(bool isDir, const char *name, int num) {
} else {
loadUnkIcon(spriteIdx);
}
logPrint("\n");
}

void writeBannerText(std::string_view text) { writeBannerText(FontGraphic::utf8to16(text)); }
Expand Down
19 changes: 17 additions & 2 deletions romsel_r4theme/arm9/source/iconTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "fileBrowse.h"
#include "graphics/fontHandler.h"
#include "common/lodepng.h"
#include "common/logging.h"
#include "language.h"
#include "ndsheaderbanner.h"
#include "myDSiMode.h"
Expand Down Expand Up @@ -1316,17 +1317,23 @@ void iconUpdate(bool isDir, const char* name)
clearText(false);
}

logPrint("iconUpdate: ");

const bool isNds = (bnrRomType == 0);

if (customIcon > 0 || (customIcon && isNds)) {
if (customIcon > 0 || (customIcon && !isDir && isNds)) {
if (customIcon == -1) {
logPrint(isDir ? "Custom icon invalid!" : "Banner not found or custom icon invalid!");
loadUnkIcon();
} else if (bnriconisDSi) {
logPrint("Custom icon found!");
loadIcon(ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[0], true);
} else {
logPrint("Custom icon found!");
loadIcon(ndsBanner.icon, ndsBanner.palette, false);
}
} else if (isDir) {
logPrint("Folder found!");
loadFolderIcon();
} else if (extension(name, {".argv"})) {
// look through the argv file for the corresponding nds/app file
Expand All @@ -1338,6 +1345,7 @@ void iconUpdate(bool isDir, const char* name)
// open the argv file
fp = fopen(name, "rb");
if (fp == NULL) {
logPrint("Icon not found!\n");
clearIcon();
fclose(fp);
return;
Expand Down Expand Up @@ -1372,9 +1380,11 @@ void iconUpdate(bool isDir, const char* name)
rc = stat(p, &st);
if (rc != 0) {
// stat failed
logPrint("Icon not found!");
clearIcon();
} else if (S_ISDIR(st.st_mode)) {
// this is a directory!
logPrint("Folder found!");
clearIcon();
} else {
iconUpdate(false, p);
Expand All @@ -1398,12 +1408,12 @@ void iconUpdate(bool isDir, const char* name)
fp = fopen(name, "rb");
if (fp == NULL) {
// icon
logPrint("Icon not found!\n");
clearIcon();
fclose(fp);
return;
}


ret = fseek(fp, offsetof(tNDSHeader, bannerOffset), SEEK_SET);
if (ret == 0)
ret = fread(&iconTitleOffset, sizeof (int), 1, fp); // read if seek succeed
Expand All @@ -1412,13 +1422,15 @@ void iconUpdate(bool isDir, const char* name)

if (ret != 1) {
// icon
logPrint("Icon not found!\n");
loadUnkIcon();
fclose(fp);
return;
}

if (iconTitleOffset == 0) {
// icon
logPrint("Icon not found!\n");
loadUnkIcon();
fclose(fp);
return;
Expand All @@ -1439,6 +1451,7 @@ void iconUpdate(bool isDir, const char* name)

if (ret != 1) {
// icon
logPrint("Icon not found!\n");
loadUnkIcon();
fclose(fp);
return;
Expand All @@ -1449,6 +1462,7 @@ void iconUpdate(bool isDir, const char* name)
fclose(fp);

// icon
logPrint("NDS icon found!");
if (bnriconisDSi) {
loadIcon(ndsBanner.dsi_icon[0], ndsBanner.dsi_palette[0], true);
} else {
Expand Down Expand Up @@ -1503,6 +1517,7 @@ void iconUpdate(bool isDir, const char* name)
} else {
loadUnkIcon();
}
logPrint("\n");
}

void titleUpdate(bool isDir, const char* name)
Expand Down

0 comments on commit 6ddfb9c

Please sign in to comment.