Skip to content

Commit a54e920

Browse files
committed
DSi-based themes: Check for DSi binaries while idle
1 parent ec8e0ab commit a54e920

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

romsel_dsimenutheme/arm9/source/fileBrowse.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,8 +3106,10 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
31063106
controlTopBright = false;
31073107
fadeSpeed = true; // Fast fade speed
31083108
bool gameTapped = false;
3109+
bool dsiBinariesChecked = false;
3110+
bool hasDsiBinaries = true;
31093111
bool apChecked = false;
3110-
int apCheckTimer = 0;
3112+
int infoCheckTimer = 0;
31113113
bool hasAP = false;
31123114

31133115
while (1) {
@@ -3147,14 +3149,18 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
31473149
logPrint("\n");
31483150
}
31493151
updateBoxArt();
3150-
if (!apChecked && (bnrRomType[CURPOS] == 0) && !isDSiWare[CURPOS]) {
3151-
if (apCheckTimer == 30) {
3152-
if (checkIfShowAPMsg(dirContents[scrn].at(CURPOS + PAGENUM * 40).name)) {
3152+
if ((infoCheckTimer < 30) && (bnrRomType[CURPOS] == 0) && (isHomebrew[CURPOS] == 0) && !isDSiWare[CURPOS]) {
3153+
infoCheckTimer++;
3154+
if (infoCheckTimer == 30) {
3155+
if (!dsiBinariesChecked) {
3156+
hasDsiBinaries = checkDsiBinaries(dirContents[scrn].at(CURPOS + PAGENUM * 40).name.c_str());
3157+
}
3158+
dsiBinariesChecked = true;
3159+
if (!apChecked && checkIfShowAPMsg(dirContents[scrn].at(CURPOS + PAGENUM * 40).name)) {
31533160
hasAP = checkRomAP(dirContents[scrn].at(CURPOS + PAGENUM * 40).name.c_str(), CURPOS);
31543161
}
31553162
apChecked = true;
31563163
}
3157-
apCheckTimer++;
31583164
}
31593165
if (ms().theme < 4) {
31603166
while (dboxInFrame) {
@@ -3208,12 +3214,14 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
32083214

32093215
if ((held & KEY_LEFT) || ((held & KEY_TOUCH) && touch.py > 171 && touch.px < 19 && ms().theme == TWLSettings::EThemeDSi)) { // Left or button arrow (DSi theme)
32103216
moveCursor(false, dirContents[scrn]);
3217+
dsiBinariesChecked = false;
32113218
apChecked = false;
3212-
apCheckTimer = 0;
3219+
infoCheckTimer = 0;
32133220
} else if ((held & KEY_RIGHT) || ((held & KEY_TOUCH) && touch.py > 171 && touch.px > 236 && ms().theme == TWLSettings::EThemeDSi)) { // Right or button arrow (DSi theme)
32143221
moveCursor(true, dirContents[scrn]);
3222+
dsiBinariesChecked = false;
32153223
apChecked = false;
3216-
apCheckTimer = 0;
3224+
infoCheckTimer = 0;
32173225
} else if ((pressed & KEY_UP) && (PAGENUM > 0 || CURPOS > 0 || !backFound) && (ms().theme != TWLSettings::EThemeSaturn && ms().theme != TWLSettings::EThemeHBL) && !dirInfoIniFound && (ms().sortMethod == 4) && (CURPOS + PAGENUM * 40 < ((int)dirContents[scrn].size()))) { // Move apps (DSi & 3DS themes)
32183226
bannerTextShown = false; // Redraw the title when done
32193227
showSTARTborder = false;
@@ -3752,12 +3760,9 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
37523760
if (proceedToLaunch && useBootstrapAnyway && bnrRomType[CURPOS] == 0 && !isDSiWare[CURPOS]
37533761
&& isHomebrew[CURPOS] == 0
37543762
&& checkIfDSiMode(dirContents[scrn].at(CURPOS + PAGENUM * 40).name)) {
3755-
bool hasDsiBinaries = true;
3756-
if (dsiFeatures() && (!ms().secondaryDevice || !bs().b4dsMode)) {
3757-
FILE *f_nds_file = fopen(
3758-
dirContents[scrn].at(CURPOS + PAGENUM * 40).name.c_str(), "rb");
3759-
hasDsiBinaries = checkDsiBinaries(f_nds_file);
3760-
fclose(f_nds_file);
3763+
if (!dsiBinariesChecked && dsiFeatures() && (!ms().secondaryDevice || !bs().b4dsMode)) {
3764+
hasDsiBinaries = checkDsiBinaries(dirContents[scrn].at(CURPOS + PAGENUM * 40).name.c_str());
3765+
dsiBinariesChecked = true;
37613766
}
37623767

37633768
if (!hasDsiBinaries) {
@@ -4403,7 +4408,7 @@ std::string browseForFile(const std::vector<std::string_view> extensionList) {
44034408
}
44044409

44054410
if ((pressed & KEY_Y) && !ms().kioskMode && isValid[CURPOS] && !isTwlm[CURPOS] && !isDirectory[CURPOS] && bannerTextShown && showSTARTborder) {
4406-
perGameSettings(dirContents[scrn].at(CURPOS + PAGENUM * 40).name);
4411+
perGameSettings(dirContents[scrn].at(CURPOS + PAGENUM * 40).name, hasDsiBinaries, &dsiBinariesChecked);
44074412
bannerTextShown = false;
44084413
}
44094414

romsel_dsimenutheme/arm9/source/ndsheaderbanner.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ u8 unitCode[40] = {0};
2020
u16 headerCRC[40] = {0};
2121
u32 a7mbk6[40] = {0};
2222

23-
bool checkDsiBinaries(FILE* ndsFile) {
23+
bool checkDsiBinaries(const char* filename) {
24+
FILE *ndsFile = fopen(filename, "rb");
25+
2426
sNDSHeaderExt ndsHeader;
2527

26-
fseek(ndsFile, 0, SEEK_SET);
2728
fread(&ndsHeader, 1, sizeof(ndsHeader), ndsFile);
2829

2930
if (ndsHeader.unitCode == 0) {
31+
fclose(ndsFile);
3032
return true;
3133
}
3234

3335
if (ndsHeader.arm9iromOffset < 0x8000 || ndsHeader.arm9iromOffset >= 0x20000000
3436
|| ndsHeader.arm7iromOffset < 0x8000 || ndsHeader.arm7iromOffset >= 0x20000000) {
37+
fclose(ndsFile);
3538
return false;
3639
}
3740

@@ -48,6 +51,7 @@ bool checkDsiBinaries(FILE* ndsFile) {
4851
fread(arm9Sig[1], sizeof(u32), 4, ndsFile);
4952
fseek(ndsFile, ndsHeader.arm7iromOffset, SEEK_SET);
5053
fread(arm9Sig[2], sizeof(u32), 4, ndsFile);
54+
fclose(ndsFile);
5155
for (int i = 1; i < 3; i++) {
5256
if (arm9Sig[i][0] == arm9Sig[0][0]
5357
&& arm9Sig[i][1] == arm9Sig[0][1]

romsel_dsimenutheme/arm9/source/ndsheaderbanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ typedef enum {
252252
N3DS_LANG_CHINESE_TRADITIONAL = 11,
253253
} sNDSLanguage;
254254

255-
bool checkDsiBinaries(FILE* ndsFile);
255+
bool checkDsiBinaries(const char* filename);
256256

257257
/**
258258
* Get SDK version from an NDS file.

romsel_dsimenutheme/arm9/source/perGameSettings.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ const char* getRegionString(char region) {
397397
return "N/A";
398398
}
399399

400-
void perGameSettings (std::string filename) {
400+
void perGameSettings (std::string filename, bool dsiBinariesFound, bool* dsiBinariesChecked) {
401401
int pressed = 0, held = 0;
402402

403403
keysSetRepeat(25, 5); // Slow down key repeat
@@ -472,7 +472,6 @@ void perGameSettings (std::string filename) {
472472
u32 pubSize = 0;
473473
u32 prvSize = 0;
474474
bool usesCloneboot = false;
475-
bool dsiBinariesFound = false;
476475
if (bnrRomType[CURPOS] == 0) {
477476
fseek(f_nds_file, 0x20, SEEK_SET);
478477
fread(&arm9off, sizeof(u32), 1, f_nds_file);
@@ -494,7 +493,10 @@ void perGameSettings (std::string filename) {
494493
u32 clonebootFlag = 0;
495494
fread(&clonebootFlag, sizeof(u32), 1, f_nds_file);
496495
usesCloneboot = (clonebootFlag == 0x16361);
497-
dsiBinariesFound = checkDsiBinaries(f_nds_file);
496+
if (!(*dsiBinariesChecked)) {
497+
dsiBinariesFound = checkDsiBinaries(filenameForInfo.c_str());
498+
*dsiBinariesChecked = true;
499+
}
498500
}
499501
fclose(f_nds_file);
500502

romsel_dsimenutheme/arm9/source/perGameSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void dontShowAPMsgAgain (std::string filename);
2929
bool checkIfShowRAMLimitMsg (std::string filename);
3030
void dontShowRAMLimitMsgAgain (std::string filename);
3131
bool checkIfDSiMode (std::string filename);
32-
void perGameSettings(std::string filename);
32+
void perGameSettings(std::string filename, bool dsiBinariesFound, bool* dsiBinariesChecked);
3333
std::string getSavExtension(void);
3434
std::string getPubExtension(void);
3535
std::string getPrvExtension(void);

0 commit comments

Comments
 (0)