From a6e2c31c14bdd5c206ae64708a92ed049b987f90 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Thu, 25 Apr 2024 15:15:19 +0200 Subject: [PATCH] Fix various errors from last commit --- arm9/src/storage.c | 2 +- arm9/src/unlaunch.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arm9/src/storage.c b/arm9/src/storage.c index 60406e0..d2aecd1 100644 --- a/arm9/src/storage.c +++ b/arm9/src/storage.c @@ -214,7 +214,7 @@ bool writeToFile(FILE* fd, const char* buffer, size_t size) toWrite -= written; buffer += written; } - return toWrite != 0; + return toWrite == 0; } //directories diff --git a/arm9/src/unlaunch.c b/arm9/src/unlaunch.c index 311439c..cb20f27 100644 --- a/arm9/src/unlaunch.c +++ b/arm9/src/unlaunch.c @@ -1,6 +1,7 @@ #include "message.h" #include "storage.h" #include "unlaunch.h" +#include #include #include @@ -137,6 +138,7 @@ static bool writeUnlaunchTmd(const char* path) if(!writeToFile(targetTmd, unlaunchInstallerBuffer, sizeof(unlaunchInstallerBuffer))) { fclose(targetTmd); + remove(path); messageBox("\x1B[31mError:\x1B[33m Failed write unlaunch to tmd\n"); return false; } @@ -204,7 +206,6 @@ static bool installUnlaunchRetailConsole(const char* retailLauncherTmdPath) #endif } } - messageBox("Unlaunch has been installed.\n"); return true; } @@ -261,19 +262,26 @@ bool readUnlaunchInstaller(void) messageBox("\x1B[31mError:\x1B[33m Failed to open unlaunch installer\n(sd:/unlaunch.dsi)\n"); return false; } + + int toRead = sizeof(unlaunchInstallerBuffer) - 520; + size_t installerFilesize = getFileSize(unlaunchInstaller); + if(installerFilesize != toRead) + { + messageBox("\x1B[31mError:\x1B[33m Unlaunch installer wrong file size\n"); + return false; + } char* buff = unlaunchInstallerBuffer; // Pad the installer with 520 bytes, those being the size of a valid tmd buff += 520; - int toRead = sizeof(unlaunchInstallerBuffer) - 520; size_t n = 0; while (toRead != 0 && (n = fread(buff, sizeof(char), toRead, unlaunchInstaller)) > 0) { toRead -= n; buff += n; } - if (toRead != 0 || !feof(unlaunchInstaller) || ferror(unlaunchInstaller)) + if (toRead != 0 || ferror(unlaunchInstaller)) { fclose(unlaunchInstaller); messageBox("\x1B[31mError:\x1B[33m Failed read unlaunch installer\n");