From c5d954914a518291d2184fbb6ae58c14d587f41f Mon Sep 17 00:00:00 2001 From: Crementif <26669564+Crementif@users.noreply.github.com> Date: Wed, 1 Jun 2022 02:29:36 +0200 Subject: [PATCH] Write RPX files fully at once Workaround for disc dumping bug that has creeped in for whatever reason --- source/app/dumping.cpp | 21 +++++++++++++++++++-- source/app/menu.cpp | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/source/app/dumping.cpp b/source/app/dumping.cpp index c7a4bb8..04aebb7 100644 --- a/source/app/dumping.cpp +++ b/source/app/dumping.cpp @@ -14,6 +14,7 @@ #define BUFFER_SIZE (1024 * BUFFER_SIZE_ALIGNMENT) static uint8_t* copyBuffer = nullptr; +static uint8_t* rpxBuffer = nullptr; static bool cancelledScanning = false; static bool ignoreFileErrors = false; @@ -106,6 +107,20 @@ bool copyFile(const char* filename, std::string srcPath, std::string destPath, u } } + // Check if rpx file since we want to copy the whole thing at once + uint8_t* buffer = copyBuffer; + uint32_t bufferSize = BUFFER_SIZE; + if (srcPath.ends_with(".rpx") || srcPath.ends_with(".rpl")) { + // Allocate buffer to copy bytes between + rpxBuffer = (uint8_t*)aligned_alloc(BUFFER_SIZE_ALIGNMENT, fileStat.st_size+BUFFER_SIZE_ALIGNMENT); + if (rpxBuffer == nullptr) { + setErrorPrompt("Couldn't allocate the memory to copy rpx files!"); + return false; + } + buffer = rpxBuffer; + bufferSize = fileStat.st_size; + } + // Open source file int fileFlags = O_RDONLY; #ifdef O_OPEN_ENCRYPTED @@ -159,8 +174,8 @@ bool copyFile(const char* filename, std::string srcPath, std::string destPath, u size_t bytesWritten = 0; setFile(filename, fileStat.st_size); - while((bytesRead = fread(copyBuffer, sizeof(uint8_t), BUFFER_SIZE, readHandle)) > 0) { - bytesWritten = fwrite(copyBuffer, sizeof(uint8_t), bytesRead, writeHandle); + while((bytesRead = fread(buffer, sizeof(uint8_t), bufferSize, readHandle)) > 0) { + bytesWritten = fwrite(buffer, sizeof(uint8_t), bytesRead, writeHandle); // Check if the same amounts of bytes are written if (bytesWritten < bytesRead) { fclose(readHandle); @@ -512,6 +527,8 @@ void cleanDumpingProcess() { sleep_for(200ms); if (copyBuffer != nullptr) free(copyBuffer); copyBuffer = nullptr; + if (rpxBuffer != nullptr) free(rpxBuffer); + rpxBuffer = nullptr; unmountUSBDrive(); unmountSD(); if (isDiscMounted() && !loadTitles(true)) { diff --git a/source/app/menu.cpp b/source/app/menu.cpp index 4e57c9d..99dda6e 100644 --- a/source/app/menu.cpp +++ b/source/app/menu.cpp @@ -15,7 +15,7 @@ void showLoadingScreen() { WHBLogFreetypeSetBackgroundColor(0x0b5d5e00); WHBLogFreetypeSetFontColor(0xFFFFFFFF); WHBLogFreetypeSetFontSize(22, 0); - WHBLogPrint("Dumpling V2.4.1"); + WHBLogPrint("Dumpling V2.4.2"); WHBLogPrint("-- Made by Crementif and Emiyl --"); WHBLogPrint(""); WHBLogFreetypeDraw(); @@ -27,7 +27,7 @@ void showMainMenu() { while(!startSelectedOption) { // Print menu text WHBLogFreetypeStartScreen(); - WHBLogPrint("Dumpling V2.4.1"); + WHBLogPrint("Dumpling V2.4.2"); WHBLogPrint("==============================="); WHBLogPrintf("%c Dump a game disc", selectedOption==0 ? '>' : ' '); WHBLogPrintf("%c Dump digital games", selectedOption==1 ? '>' : ' ');