Skip to content

Commit

Permalink
Fix handling of discs without a discId
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jul 28, 2022
1 parent 05aea57 commit 7c39977
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Features:
- Dump the GM Partitions (Game, Updates, DLCs) of an Wii U Disc as *.app,*.h3, .tmd, .tik, .cert files
- Supports dumping to SD (FAT32) and USB (NTFS only). When dumping to SD the files get slitted in 2 GiB parts.

Files will be dumped to `/wudump/[DISC-ID]/`. The DiscID of a game can be found on the disc (e.g. WUP-P-ARDP for the EUR version of Super Mario 3D World).
Files will be dumped to `/wudump/[DISC-ID]/`. The disc id of a game can be found on the disc (e.g. WUP-P-ARDP for the EUR version of Super Mario 3D World). If WUDD fails to determine the disc id, "DISC" with a timestamp will be used instead.

## How to merge splitted files

Expand Down
19 changes: 13 additions & 6 deletions source/GMPartitionsDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : ta
this->sectorBufSize = SECTOR_SIZE;
this->state = STATE_OPEN_ODD1;
gBlockHomeButton = true;
dumpStartDate = OSGetTime();
}

GMPartitionsDumperState::~GMPartitionsDumperState() {
Expand Down Expand Up @@ -198,11 +199,6 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
this->discId[10] = '\0';
memcpy(this->discId.data(), sectorBuf, 10);
if (this->discId[0] == 0) {
setError(ERROR_NO_DISC_ID);
return ApplicationState::SUBSTATE_RUNNING;
}

this->state = STATE_READ_DISC_INFO_DONE;
return ApplicationState::SUBSTATE_RUNNING;
}
Expand Down Expand Up @@ -278,7 +274,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return SUBSTATE_RUNNING;
}

this->targetPath = string_format("%swudump/%s/%s", getPathForDevice(targetDevice).c_str(), this->discId, curPartition->getVolumeId().c_str());
this->targetPath = string_format("%swudump/%s/%s", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str(), curPartition->getVolumeId().c_str());
if (!FSUtils::CreateSubfolder(targetPath.c_str())) {
this->setError(ERROR_CREATE_DIR);
return SUBSTATE_RUNNING;
Expand Down Expand Up @@ -557,3 +553,14 @@ std::string GMPartitionsDumperState::ErrorDescription() const {
}
return "UNKNOWN_ERROR";
}

std::string GMPartitionsDumperState::getPathNameForDisc() {
if (this->discId[0] == '\0') {
OSCalendarTime tm;
OSTicksToCalendarTime(this->dumpStartDate, &tm);
return string_format("DISC-%04d-%02d-%02d-%02d-%02d-%02d",
tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
return std::string((char *) &discId[0]);
}
4 changes: 4 additions & 0 deletions source/GMPartitionsDumperState.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ class GMPartitionsDumperState : public ApplicationState {
std::vector<std::pair<std::shared_ptr<WiiUGMPartition>, std::shared_ptr<NUSTitle>>> gmPartitionPairs;

eDumpTarget targetDevice = TARGET_SD;

std::string getPathNameForDisc();

OSTime dumpStartDate;
};
30 changes: 19 additions & 11 deletions source/WUDDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat,
this->sectorBufSize = READ_SECTOR_SIZE * READ_NUM_SECTORS;
this->state = STATE_OPEN_ODD1;
gBlockHomeButton = true;
this->dumpStartDate = OSGetTime();
}

WUDDumperState::~WUDDumperState() {
Expand Down Expand Up @@ -85,10 +86,6 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
this->discId[10] = '\0';
memcpy(this->discId.data(), sectorBuf, 10);
if (this->discId[0] == 0) {
setError(ERROR_NO_DISC_ID);
return ApplicationState::SUBSTATE_RUNNING;
}
this->state = STATE_READ_DISC_INFO_DONE;
return ApplicationState::SUBSTATE_RUNNING;
}
Expand All @@ -112,26 +109,26 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
}

if (hasDiscKey) {
if (!FSUtils::CreateSubfolder(string_format("%swudump/%s", getPathForDevice(targetDevice).c_str(), discId).c_str())) {
if (!FSUtils::CreateSubfolder(string_format("%swudump/%s", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str()).c_str())) {
setError(ERROR_WRITE_FAILED);
return SUBSTATE_RUNNING;
}
if (!FSUtils::saveBufferToFile(string_format("%swudump/%s/game.key", getPathForDevice(targetDevice).c_str(), discId).c_str(), discKey.key, 16)) {
if (!FSUtils::saveBufferToFile(string_format("%swudump/%s/game.key", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str()).c_str(), discKey.key, 16)) {
setError(ERROR_WRITE_FAILED);
return SUBSTATE_RUNNING;
}
}
this->state = STATE_DUMP_DISC_START;
} else if (this->state == STATE_DUMP_DISC_START) {
if (!FSUtils::CreateSubfolder(string_format("%swudump/%s", getPathForDevice(targetDevice).c_str(), discId).c_str())) {
if (!FSUtils::CreateSubfolder(string_format("%swudump/%s", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str()).c_str())) {
setError(ERROR_WRITE_FAILED);
return ApplicationState::SUBSTATE_RUNNING;
}
if (targetFormat == DUMP_AS_WUX) {
this->fileHandle = std::make_unique<WUXFileWriter>(string_format("%swudump/%s/game.wux", getPathForDevice(targetDevice).c_str(), discId).c_str(), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
this->fileHandle = std::make_unique<WUXFileWriter>(string_format("%swudump/%s/game.wux", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str()).c_str(), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
SECTOR_SIZE, targetDevice == TARGET_SD);
} else {
this->fileHandle = std::make_unique<WUDFileWriter>(string_format("%swudump/%s/game.wud", getPathForDevice(targetDevice).c_str(), discId).c_str(), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
this->fileHandle = std::make_unique<WUDFileWriter>(string_format("%swudump/%s/game.wud", getPathForDevice(targetDevice).c_str(), getPathNameForDisc().c_str()).c_str(), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
SECTOR_SIZE, targetDevice == TARGET_SD);
}
if (!this->fileHandle->isOpen()) {
Expand Down Expand Up @@ -264,9 +261,9 @@ void WUDDumperState::render() {
} else if (this->state == STATE_READ_DISC_INFO) {
WiiUScreen::drawLine("Read disc information");
} else if (this->state == STATE_READ_DISC_INFO_DONE) {
WiiUScreen::drawLinef("Dumping: %s", this->discId);
WiiUScreen::drawLinef("Dumping: %s", getPathNameForDisc().c_str());
} else if (this->state == STATE_DUMP_DISC_START || this->state == STATE_DUMP_DISC || this->state == STATE_WAIT_USER_ERROR_CONFIRM) {
WiiUScreen::drawLinef("Dumping: %s", this->discId);
WiiUScreen::drawLinef("Dumping: %s", getPathNameForDisc().c_str());

float percent = this->currentSector / (WUD_FILE_SIZE / READ_SECTOR_SIZE * 1.0f) * 100.0f;
WiiUScreen::drawLinef("Progress: %0.2f MiB / %5.2f MiB (%2.1f %%)", this->currentSector * (READ_SECTOR_SIZE / 1024.0f / 1024.0f), WUD_FILE_SIZE / 1024.0f / 1024.0f, percent);
Expand Down Expand Up @@ -362,3 +359,14 @@ std::string WUDDumperState::getPathForDevice(eDumpTarget target) const {
}
return "fs:/vol/external01/";
}

std::string WUDDumperState::getPathNameForDisc() {
if (this->discId[0] == '\0') {
OSCalendarTime tm;
OSTicksToCalendarTime(this->dumpStartDate, &tm);
return string_format("DISC-%04d-%02d-%02d-%02d-%02d-%02d",
tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
return std::string((char *) &discId[0]);
}
2 changes: 2 additions & 0 deletions source/WUDDumperState.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ class WUDDumperState : public ApplicationState {
int32_t writtenSectors{};

void *emptySector = nullptr;
std::string getPathNameForDisc();
OSTime dumpStartDate;
};

0 comments on commit 7c39977

Please sign in to comment.