Skip to content

Commit

Permalink
- Add SD support
Browse files Browse the repository at this point in the history
- Disable auto shutdown
  • Loading branch information
Maschell committed Oct 16, 2021
1 parent 47cca11 commit 1ba090a
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 78 deletions.
30 changes: 22 additions & 8 deletions source/ApplicationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,29 @@ class ApplicationState {

virtual eSubState update(Input *input) = 0;

virtual void proccessMenuNavigation(Input *input, int32_t maxOptionValue) {
virtual void proccessMenuNavigationY(Input *input, int32_t maxOptionValue) {
if (input->data.buttons_d & Input::BUTTON_UP) {
this->selectedOption--;
this->selectedOptionY--;
} else if (input->data.buttons_d & Input::BUTTON_DOWN) {
this->selectedOption++;
this->selectedOptionY++;
}
if (this->selectedOption < 0) {
this->selectedOption = maxOptionValue;
} else if (this->selectedOption >= maxOptionValue) {
this->selectedOption = 0;
if (this->selectedOptionY < 0) {
this->selectedOptionY = maxOptionValue;
} else if (this->selectedOptionY >= maxOptionValue) {
this->selectedOptionY = 0;
}
}

virtual void proccessMenuNavigationX(Input *input, int32_t maxOptionValue) {
if (input->data.buttons_d & Input::BUTTON_LEFT) {
this->selectedOptionX--;
} else if (input->data.buttons_d & Input::BUTTON_RIGHT) {
this->selectedOptionX++;
}
if (this->selectedOptionX < 0) {
this->selectedOptionX = maxOptionValue;
} else if (this->selectedOptionX >= maxOptionValue) {
this->selectedOptionX = 0;
}
}

Expand All @@ -46,5 +59,6 @@ class ApplicationState {
}


int selectedOption = 0;
int selectedOptionY = 0;
int selectedOptionX = 0;
};
30 changes: 22 additions & 8 deletions source/GMPartitionsDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#define READ_BUFFER_SIZE (SECTOR_SIZE * 128)

GMPartitionsDumperState::GMPartitionsDumperState() {
GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : targetDevice(pTargetDevice) {
this->sectorBufSize = SECTOR_SIZE;
this->state = STATE_OPEN_ODD1;
}
Expand Down Expand Up @@ -77,11 +77,11 @@ void GMPartitionsDumperState::render() {
for (auto &content: partitionPair.second->tmd->contentList) {
size += ROUNDUP(content->encryptedFileSize, 16);
}
WiiUScreen::drawLinef("%s %s (~%0.2f MiB)", index == (uint32_t) selectedOption ? ">" : " ", partitionPair.first->getVolumeId().c_str(), (float) size / 1024.0f / 1024.0f);
WiiUScreen::drawLinef("%s %s (~%0.2f MiB)", index == (uint32_t) selectedOptionY ? ">" : " ", partitionPair.first->getVolumeId().c_str(), (float) size / 1024.0f / 1024.0f);
index++;
}
WiiUScreen::drawLine();
WiiUScreen::drawLinef("%s Back", index == (uint32_t) selectedOption ? ">" : " ");
WiiUScreen::drawLinef("%s Back", index == (uint32_t) selectedOptionY ? ">" : " ");
}
} else if (this->state == STATE_CREATE_DATA_PROVIDER) {
WiiUScreen::drawLine("Create data provider from partition");
Expand Down Expand Up @@ -227,12 +227,12 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return SUBSTATE_RETURN;
}
}
proccessMenuNavigation(input, (int32_t) gmPartitionPairs.size() + 1);
proccessMenuNavigationY(input, (int32_t) gmPartitionPairs.size() + 1);
if (entrySelected(input)) {
if (selectedOption >= (int32_t) gmPartitionPairs.size()) {
if (selectedOptionY >= (int32_t) gmPartitionPairs.size()) {
return SUBSTATE_RETURN;
}
auto gmPartitionPair = gmPartitionPairs[selectedOption];
auto gmPartitionPair = gmPartitionPairs[selectedOptionY];
if (gmPartitionPair.first != nullptr) {
this->curPartition = gmPartitionPair.first;
this->curNUSTitle = gmPartitionPair.second;
Expand All @@ -243,8 +243,11 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return SUBSTATE_RUNNING;
}

this->targetPath = StringTools::strfmt("%swudump/%s/%s", "ntfs0:/", this->discId, curPartition->getVolumeId().c_str());
FSUtils::CreateSubfolder(targetPath.c_str());
this->targetPath = StringTools::strfmt("%swudump/%s/%s", getPathForDevice(targetDevice).c_str(), this->discId, curPartition->getVolumeId().c_str());
if (!FSUtils::CreateSubfolder(targetPath.c_str())) {
this->setError(ERROR_CREATE_DIR);
return SUBSTATE_RUNNING;
}

this->state = STATE_DUMP_PARTITION_TMD;
}
Expand Down Expand Up @@ -388,6 +391,14 @@ void GMPartitionsDumperState::setError(GMPartitionsDumperState::eErrorState err)
//OSEnableHomeButtonMenu(true);
}

std::string GMPartitionsDumperState::getPathForDevice(eDumpTarget target) const {
if(target == TARGET_SD){
return "fs:/vol/external01/";
} else if (target == TARGET_NTFS){
return "ntfs0:/";
}
}

std::string GMPartitionsDumperState::ErrorMessage() const {
if (this->errorState == ERROR_MALLOC_FAILED) {
return "ERROR_MALLOC_FAILED";
Expand All @@ -407,6 +418,9 @@ std::string GMPartitionsDumperState::ErrorMessage() const {
if (this->errorState == ERROR_NO_GM_PARTITION) {
return "ERROR_NO_GM_PARTITION";
}
if (this->errorState == ERROR_CREATE_DIR) {
return "ERROR_CREATE_DIR";
}
if (this->errorState == ERROR_FAILED_TO_GET_NUSTITLE) {
return "ERROR_FAILED_TO_GET_NUSTITLE";
}
Expand Down
7 changes: 6 additions & 1 deletion source/GMPartitionsDumperState.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class GMPartitionsDumperState : public ApplicationState {
ERROR_OPEN_ODD1,
ERROR_PARSE_DISCHEADER,
ERROR_NO_GM_PARTITION,
ERROR_CREATE_DIR,
ERROR_FAILED_TO_GET_NUSTITLE,
ERROR_FAILED_WRITE_TMD,
ERROR_FAILED_WRITE_TICKET,
Expand All @@ -69,7 +70,7 @@ class GMPartitionsDumperState : public ApplicationState {
ERROR_WRITE_CONTENT
};

explicit GMPartitionsDumperState();
explicit GMPartitionsDumperState(eDumpTarget pTargetDevice);

~GMPartitionsDumperState() override;

Expand All @@ -82,6 +83,8 @@ class GMPartitionsDumperState : public ApplicationState {

void setError(eErrorState err);

[[nodiscard]] std::string getPathForDevice(eDumpTarget target) const;

std::array<uint8_t, 11> discId{};
std::array<uint8_t, 0x10> cKey{};

Expand All @@ -107,4 +110,6 @@ class GMPartitionsDumperState : public ApplicationState {
[[nodiscard]] std::string ErrorDescription() const;

std::vector<std::pair<std::shared_ptr<WiiUGMPartition>, std::shared_ptr<NUSTitle>>> gmPartitionPairs;

eDumpTarget targetDevice = TARGET_SD;
};
45 changes: 32 additions & 13 deletions source/MainApplicationState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ void MainApplicationState::render() {
if (this->state == STATE_WELCOME_SCREEN) {
WiiUScreen::drawLine("Welcome to Wudump");
WiiUScreen::drawLine("");
WiiUScreen::drawLinef("%s Dump as WUX", this->selectedOption == 0 ? ">" : " ");
WiiUScreen::drawLinef("%s Dump as WUD", this->selectedOption == 1 ? ">" : " ");
WiiUScreen::drawLinef("%s Dump partition as .app", this->selectedOption == 2 ? ">" : " ");
WiiUScreen::drawLinef("%s Exit", this->selectedOption == 3 ? ">" : " ");
WiiUScreen::drawLinef("%s Dump as WUX", this->selectedOptionY == 0 ? ">" : " ");
WiiUScreen::drawLinef("%s Dump as WUD", this->selectedOptionY == 1 ? ">" : " ");
WiiUScreen::drawLinef("%s Dump partition as .app", this->selectedOptionY == 2 ? ">" : " ");
WiiUScreen::drawLine();
WiiUScreen::drawLinef("%s Dumptarget:", this->selectedOptionY == 3 ? ">" : " ");
if (ntfs_mount_count > 0) {
WiiUScreen::drawLinef(" [%s] SD [%s] NTFS (USB)", dumpTarget == TARGET_SD ? "x" : " ", dumpTarget == TARGET_NTFS ? "x" : " ");
} else {
WiiUScreen::drawLinef(" [%s] SD ??? NTFS (USB) (not connected)", dumpTarget == TARGET_SD ? "*" : " ");
}
WiiUScreen::drawLine();
WiiUScreen::drawLinef("%s Exit", this->selectedOptionY == 4 ? ">" : " ");
}

printFooter();
Expand All @@ -52,29 +60,40 @@ void MainApplicationState::render() {

ApplicationState::eSubState MainApplicationState::update(Input *input) {
if (this->state == STATE_WELCOME_SCREEN) {
proccessMenuNavigation(input, 4);
proccessMenuNavigationY(input, 5);
if (selectedOptionY == 3) {
if (ntfs_mount_count > 0) {
proccessMenuNavigationX(input, 2);
if (selectedOptionX == 0) {
dumpTarget = TARGET_SD;
} else {
dumpTarget = TARGET_NTFS;
}
}
}
if (entrySelected(input)) {
if (this->selectedOption == 0) {
if (this->selectedOptionY == 0) {
this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUX);
} else if (this->selectedOption == 1) {
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUX, dumpTarget);
} else if (this->selectedOptionY == 1) {
this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUD);
} else if (this->selectedOption == 2) {
this->subState = std::make_unique<WUDDumperState>(WUDDumperState::DUMP_AS_WUD, dumpTarget);
} else if (this->selectedOptionY == 2) {
this->state = STATE_DO_SUBSTATE;
this->subState = std::make_unique<GMPartitionsDumperState>();
this->subState = std::make_unique<GMPartitionsDumperState>(dumpTarget);
} else if (this->selectedOptionY == 3) {
//
} else {
SYSLaunchMenu();
}
this->selectedOption = 0;
this->selectedOptionY = 0;
}
} else if (this->state == STATE_DO_SUBSTATE) {
auto retSubState = this->subState->update(input);
if (retSubState == SUBSTATE_RUNNING) {
// keep running.
return SUBSTATE_RUNNING;
} else if (retSubState == SUBSTATE_RETURN) {
DEBUG_FUNCTION_LINE("Delete sub state");
this->subState.reset();
this->state = STATE_WELCOME_SCREEN;
}
Expand Down
3 changes: 3 additions & 0 deletions source/MainApplicationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <optional>
#include <queue>
#include <ctime>
#include <common/common.h>
#include "input/Input.h"
#include "fs/CFile.hpp"
#include "ApplicationState.h"
Expand All @@ -46,4 +47,6 @@ class MainApplicationState : public ApplicationState {
std::unique_ptr<ApplicationState> subState{};

eGameState state = STATE_WELCOME_SCREEN;

eDumpTarget dumpTarget = TARGET_SD;
};
32 changes: 21 additions & 11 deletions source/WUDDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <WUD/content/WiiUDiscContentsHeader.h>
#include "WUDDumperState.h"

WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTarget)
: target(pTarget) {
WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat, eDumpTarget pTargetDevice)
: targetFormat(pTargetFormat), targetDevice(pTargetDevice) {
this->sectorBufSize = READ_SECTOR_SIZE * READ_NUM_SECTORS;
this->state = STATE_OPEN_ODD1;
}
Expand All @@ -38,7 +38,6 @@ WUDDumperState::~WUDDumperState() {
free(emptySector);
}


ApplicationState::eSubState WUDDumperState::update(Input *input) {
if (this->state == STATE_RETURN) {
return ApplicationState::SUBSTATE_RETURN;
Expand Down Expand Up @@ -113,25 +112,27 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
}

if (hasDiscKey) {
if (!FSUtils::CreateSubfolder(StringTools::fmt("%swudump/%s", "ntfs0:/", discId))) {
if (!FSUtils::CreateSubfolder(StringTools::fmt("%swudump/%s", getPathForDevice(targetDevice).c_str(), discId))) {
setError(ERROR_WRITE_FAILED);
return SUBSTATE_RUNNING;
}
if (!FSUtils::saveBufferToFile(StringTools::fmt("%swudump/%s/game.key", "ntfs0:/", discId), discKey, 16)) {
if (!FSUtils::saveBufferToFile(StringTools::fmt("%swudump/%s/game.key", getPathForDevice(targetDevice).c_str(), discId), discKey, 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(StringTools::fmt("%swudump/%s", "ntfs0:/", discId))) {
if (!FSUtils::CreateSubfolder(StringTools::fmt("%swudump/%s", getPathForDevice(targetDevice).c_str(), discId))) {
setError(ERROR_WRITE_FAILED);
return ApplicationState::SUBSTATE_RUNNING;
}
if (target == DUMP_AS_WUX) {
this->fileHandle = std::make_unique<WUXFileWriter>(StringTools::fmt("%swudump/%s/game.wux", "ntfs0:/", discId), CFile::WriteOnly, READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS, SECTOR_SIZE);
if (targetFormat == DUMP_AS_WUX) {
this->fileHandle = std::make_unique<WUXFileWriter>(StringTools::fmt("%swudump/%s/game.wux", getPathForDevice(targetDevice).c_str(), discId), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
SECTOR_SIZE, true);
} else {
this->fileHandle = std::make_unique<WUXFileWriter>(StringTools::fmt("%swudump/%s/game.wud", "ntfs0:/", discId), CFile::WriteOnly, READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS, SECTOR_SIZE);
this->fileHandle = std::make_unique<WUDFileWriter>(StringTools::fmt("%swudump/%s/game.wud", getPathForDevice(targetDevice).c_str(), discId), READ_SECTOR_SIZE * WRITE_BUFFER_NUM_SECTORS,
SECTOR_SIZE, true);
}
if (!this->fileHandle->isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open file");
Expand Down Expand Up @@ -166,6 +167,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
this->setError(ERROR_WRITE_FAILED);
return ApplicationState::SUBSTATE_RUNNING;
}
this->fileHandle->finalize();
this->fileHandle->close();
}
}
Expand Down Expand Up @@ -224,7 +226,6 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
return ApplicationState::SUBSTATE_RUNNING;
}


void WUDDumperState::render() {
WiiUScreen::clearScreen();
ApplicationState::printHeader();
Expand All @@ -238,6 +239,8 @@ void WUDDumperState::render() {
WiiUScreen::drawLine("Open /dev/odd01");
} else if (this->state == STATE_PLEASE_INSERT_DISC) {
WiiUScreen::drawLine("Please insert a Wii U disc and try again.\n\nPress A to return");
} else if (this->state == STATE_DUMP_DISC_KEY) {
WiiUScreen::drawLine("Read disc key");
} else if (this->state == STATE_READ_DISC_INFO) {
WiiUScreen::drawLine("Read disc information");
} else if (this->state == STATE_READ_DISC_INFO_DONE) {
Expand All @@ -247,7 +250,7 @@ void WUDDumperState::render() {

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);
if (target == DUMP_AS_WUX) {
if (targetFormat == DUMP_AS_WUX) {
WiiUScreen::drawLinef("Written %0.2f MiB. Compression ratio 1:%0.2f", writtenSectors * (READ_SECTOR_SIZE / 1024.0f / 1024.0f),
1.0f / (writtenSectors / (float) this->currentSector));
}
Expand Down Expand Up @@ -324,3 +327,10 @@ std::string WUDDumperState::ErrorDescription() const {
}
return "UNKNOWN_ERROR";
}

std::string WUDDumperState::getPathForDevice(eDumpTarget target) const {
if (target == TARGET_NTFS) {
return "ntfs0:/";
}
return "fs:/vol/external01/";
}
10 changes: 8 additions & 2 deletions source/WUDDumperState.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>
#include <memory>
#include <input/Input.h>
#include <common/common.h>
#include "ApplicationState.h"
#include "fs/WriteOnlyFileWithCache.h"
#include "fs/WUXFileWriter.h"
Expand Down Expand Up @@ -61,12 +62,12 @@ class WUDDumperState : public ApplicationState {
ERROR_NO_DISC_FOUND
};

explicit WUDDumperState(eDumpTargetFormat pTarget);
explicit WUDDumperState(eDumpTargetFormat pTarget, eDumpTarget pTargetDevice);

~WUDDumperState() override;

eDumpState state;
eDumpTargetFormat target;
eDumpTargetFormat targetFormat;
WUDDumperState::eErrorState errorState = ERROR_NONE;

void render() override;
Expand All @@ -79,6 +80,10 @@ class WUDDumperState : public ApplicationState {

[[nodiscard]] std::string ErrorDescription() const;

[[nodiscard]] std::string getPathForDevice(eDumpTarget target) const;

eDumpTarget targetDevice = TARGET_SD;

void *sectorBuf = nullptr;

int readResult = 0;
Expand All @@ -105,4 +110,5 @@ class WUDDumperState : public ApplicationState {
int32_t writtenSectors{};

void *emptySector = nullptr;

};
5 changes: 4 additions & 1 deletion source/common/common.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "common.h"

int32_t gFSAfd = -1;
int32_t gFSAfd = -1;

ntfs_md *ntfs_mounts = nullptr;
int ntfs_mount_count = 0;
Loading

0 comments on commit 1ba090a

Please sign in to comment.