Skip to content

Commit

Permalink
Write RPX files fully at once
Browse files Browse the repository at this point in the history
Workaround for disc dumping bug that has creeped in for whatever reason
  • Loading branch information
Crementif committed Jun 1, 2022
1 parent 32092b7 commit c5d9549
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions source/app/dumping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions source/app/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 ? '>' : ' ');
Expand Down

0 comments on commit c5d9549

Please sign in to comment.