From 66f5b8ec574ccf5831145c7c22b42392eb722fd9 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Thu, 21 Aug 2025 17:40:19 +0200 Subject: [PATCH] Try both ntrboot.nds and boot.nds when loading nitrofs Bundle an installer.ver file in the nitrofiles so that it can be matched against the current version of the installer to ensure it's the right file being loaded --- arm9/include/version.h | 2 +- arm9/src/main.cpp | 44 ++++++++++++++++++++++++++-------------- nitrofiles/installer.ver | 1 + 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 nitrofiles/installer.ver diff --git a/arm9/include/version.h b/arm9/include/version.h index 3458667..e213f03 100644 --- a/arm9/include/version.h +++ b/arm9/include/version.h @@ -1,6 +1,6 @@ #ifndef VERSION_H #define VERSION_H -#define VERSION "v1.0" +#define VERSION "v1.3" #endif // VERSION_H diff --git a/arm9/src/main.cpp b/arm9/src/main.cpp index 8cbc510..f3678de 100644 --- a/arm9/src/main.cpp +++ b/arm9/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "bgMenu.h" #include "consoleInfo.h" @@ -273,6 +274,33 @@ void checkStage2Supported() { exit(0); } +std::vector getInstallerPaths(int argc, char **argv) { + if(argc > 0) + return {std::string_view{argv[0]}}; + DeviceList* deviceList = getDeviceList(); + + if(deviceList) return {std::string_view{ deviceList->appname}}; + + return {"sd:/ntrboot.nds", "sd:/boot.nds"}; +} + +void setupNitrofs(int argc, char **argv) { + for(const auto& path : getInstallerPaths(argc, argv)){ + if(!nitroFSInit(path.data())) + continue; + auto* file = fopen("nitro:/installer.ver", "rb"); + if(!file) + continue; + char verstring[10]{}; + fread(verstring, 1, sizeof(verstring) - 1, file); + fclose(file); + if(std::string_view{verstring} == VERSION) + return; + } + messageBox("nitroFSInit()...\x1B[31mFailed\n\x1B[47m"); + exit(0); +} + void checkNocashFooter(consoleInfo& info) { NocashFooter footer; @@ -324,16 +352,6 @@ void waitForBatteryChargedEnough() { } } -const char* getInstallerPath(int argc, char **argv) { - if(argc > 0) - return argv[0]; - DeviceList* deviceList = getDeviceList(); - - if(deviceList) return deviceList->appname; - - return "sd:/ntrboot.nds"; -} - void loadUnlaunchInstaller() { if (fileExists("sd:/unlaunch.dsi")) { @@ -688,11 +706,7 @@ int main(int argc, char **argv) { setup(); checkStage2Supported(); - - if (!nitroFSInit(getInstallerPath(argc, argv))) - { - messageBox("nitroFSInit()...\x1B[31mFailed\n\x1B[47m"); - } + setupNitrofs(argc, argv); loadUnlaunchInstaller(); diff --git a/nitrofiles/installer.ver b/nitrofiles/installer.ver new file mode 100644 index 0000000..26e5d19 --- /dev/null +++ b/nitrofiles/installer.ver @@ -0,0 +1 @@ +v1.3 \ No newline at end of file