Fix various errors from last commit

This commit is contained in:
Edoardo Lolletti 2024-04-25 15:15:19 +02:00
parent 6d5cff81c3
commit a6e2c31c14
2 changed files with 12 additions and 4 deletions

View File

@ -214,7 +214,7 @@ bool writeToFile(FILE* fd, const char* buffer, size_t size)
toWrite -= written; toWrite -= written;
buffer += written; buffer += written;
} }
return toWrite != 0; return toWrite == 0;
} }
//directories //directories

View File

@ -1,6 +1,7 @@
#include "message.h" #include "message.h"
#include "storage.h" #include "storage.h"
#include "unlaunch.h" #include "unlaunch.h"
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -137,6 +138,7 @@ static bool writeUnlaunchTmd(const char* path)
if(!writeToFile(targetTmd, unlaunchInstallerBuffer, sizeof(unlaunchInstallerBuffer))) if(!writeToFile(targetTmd, unlaunchInstallerBuffer, sizeof(unlaunchInstallerBuffer)))
{ {
fclose(targetTmd); fclose(targetTmd);
remove(path);
messageBox("\x1B[31mError:\x1B[33m Failed write unlaunch to tmd\n"); messageBox("\x1B[31mError:\x1B[33m Failed write unlaunch to tmd\n");
return false; return false;
} }
@ -204,7 +206,6 @@ static bool installUnlaunchRetailConsole(const char* retailLauncherTmdPath)
#endif #endif
} }
} }
messageBox("Unlaunch has been installed.\n");
return true; return true;
} }
@ -262,18 +263,25 @@ bool readUnlaunchInstaller(void)
return false; 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; char* buff = unlaunchInstallerBuffer;
// Pad the installer with 520 bytes, those being the size of a valid tmd // Pad the installer with 520 bytes, those being the size of a valid tmd
buff += 520; buff += 520;
int toRead = sizeof(unlaunchInstallerBuffer) - 520;
size_t n = 0; size_t n = 0;
while (toRead != 0 && (n = fread(buff, sizeof(char), toRead, unlaunchInstaller)) > 0) while (toRead != 0 && (n = fread(buff, sizeof(char), toRead, unlaunchInstaller)) > 0)
{ {
toRead -= n; toRead -= n;
buff += n; buff += n;
} }
if (toRead != 0 || !feof(unlaunchInstaller) || ferror(unlaunchInstaller)) if (toRead != 0 || ferror(unlaunchInstaller))
{ {
fclose(unlaunchInstaller); fclose(unlaunchInstaller);
messageBox("\x1B[31mError:\x1B[33m Failed read unlaunch installer\n"); messageBox("\x1B[31mError:\x1B[33m Failed read unlaunch installer\n");