Skip to content

Commit

Permalink
Fix non-ascii usernames, switch GUI to wide strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Crementif committed Jan 19, 2023
1 parent 5dc5131 commit ddd92b1
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 379 deletions.
2 changes: 1 addition & 1 deletion source/app/cfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CFWVersion testCFW() {
return currCFWVersion;
}
else if (ret == MOCHA_RESULT_UNSUPPORTED_API_VERSION) {
uint8_t forceTiramisu = showDialogPrompt("Using an outdated Tiramisu version\nwithout FS client support!\n\nPlease update Tiramisu with this guide:\nhttps://wiiu.hacks.guide/#/tiramisu/sd-preparation\n\nForcing internal CFW will temporarily stop Tiramisu!", "Exit Dumpling To Update (Recommended)", "Force Internal CFW And Continue");
uint8_t forceTiramisu = showDialogPrompt(L"Using an outdated Tiramisu version\nwithout FS client support!\n\nPlease update Tiramisu with this guide:\nhttps://wiiu.hacks.guide/#/tiramisu/sd-preparation\n\nForcing internal CFW will temporarily stop Tiramisu!", L"Exit Dumpling To Update (Recommended)", L"Force Internal CFW And Continue");
if (forceTiramisu == 1) {
if (stopTiramisuServer()) {
WHBLogFreetypeClear();
Expand Down
25 changes: 15 additions & 10 deletions source/app/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,39 @@ typename std::enable_if<enable_bitmask_operators<E>::enable, E>::type operator&
// String trim functions

[[maybe_unused]]
static inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char8_t ch) {
static inline void ltrim(std::wstring &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](wchar_t ch) {
return !std::isspace(ch);
}));
}

[[maybe_unused]]
static inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](char8_t ch) {
static inline void rtrim(std::wstring &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](wchar_t ch) {
return !std::isspace(ch);
}).base(), s.end());
}

[[maybe_unused]]
static inline void trim(std::string &s) {
static inline void trim(std::wstring &s) {
ltrim(s);
rtrim(s);
}

[[maybe_unused]]
static inline void replaceAll(std::string& str, const std::string& oldSubstr, const std::string& newSubstr) {
static inline void replaceAll(std::wstring& str, const std::wstring& oldSubstr, const std::wstring& newSubstr) {
size_t pos = 0;
while ((pos = str.find(oldSubstr, pos)) != std::string::npos) {
while ((pos = str.find(oldSubstr, pos)) != std::wstring::npos) {
str.replace(pos, oldSubstr.length(), newSubstr);
pos += newSubstr.length();
}
}

[[maybe_unused]]
static inline std::wstring toWstring(const std::string& stringToConvert) {
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(stringToConvert);
}

// Enums and Structs

enum class DUMP_METHOD {
Expand Down Expand Up @@ -182,7 +187,7 @@ struct userAccount {
bool defaultAccount = false;
bool networkAccount;
bool passwordCached;
std::string miiName;
std::wstring miiName;
std::string persistentIdString;
nn::act::SlotNo slot;
nn::act::PersistentId persistentId;
Expand Down Expand Up @@ -233,8 +238,8 @@ struct filePart {

struct titleEntry {
uint32_t titleLowId;
std::string shortTitle;
std::string productCode;
std::wstring shortTitle;
std::wstring productCode;
std::string folderName;

std::optional<titlePart> base;
Expand Down
238 changes: 117 additions & 121 deletions source/app/dumping.cpp

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions source/app/interfaces/fat32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ std::vector<std::pair<std::string, std::string>> Fat32Transfer::getDrives() {
else if (i == DEV_USB01_REF) volumeName = "USB 1";
else if (i == DEV_USB02_REF) volumeName = "USB 2";
if (volumeLabel[0]) volumeName += std::string(" - ") + volumeLabel;
else volumeName += " - Not Named";
else volumeName += " - Unnamed";

targets.emplace_back(std::make_pair((driveIdPath+Fat32Transfer::targetDirectoryName).c_str(), volumeName));
targets.emplace_back((driveIdPath+Fat32Transfer::targetDirectoryName).c_str(), volumeName);
}
return targets;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ bool Fat32Transfer::deletePath(const std::string &path, const std::function<void
f_unmount(path.c_str());
free(deleteFS);
if (res != FR_OK) {
std::string deleteError = "Error "+std::to_string(res)+" while deleting the following file:\n" + path + "\n";
std::wstring deleteError = L"Error "+std::to_wstring(res)+L" while deleting the following file:\n" + toWstring(path) + L"\n";
setErrorPrompt(deleteError);
return false;
}
Expand All @@ -117,8 +117,8 @@ bool Fat32Transfer::deletePath(const std::string &path, const std::function<void
recursiveDeletion = [driveIdx, &recursiveDeletion, callback_updateGUI](const std::filesystem::path& dirPath) -> FRESULT {
DIR dir;
if (FRESULT res = f_opendir(&dir, dirPath.c_str()); res != FR_OK) {
std::string deleteError = "Failed while deleting folder entry in recursive loop:\n";
deleteError += dirPath.string()+"\n";
std::wstring deleteError = L"Failed while deleting folder entry in recursive loop:\n";
deleteError += dirPath.wstring()+L"\n";
setErrorPrompt(deleteError);
return res;
}
Expand All @@ -137,8 +137,8 @@ bool Fat32Transfer::deletePath(const std::string &path, const std::function<void
}
else {
if (FRESULT res = f_unlink((dirPath / fno.fname).c_str()); res != FR_OK) {
std::string deleteError = "Failed to delete file:\n";
deleteError += (dirPath / fno.fname).string()+"\n";
std::wstring deleteError = L"Failed to delete file:\n";
deleteError += (dirPath / fno.fname).wstring()+L"\n";
setErrorPrompt(deleteError);
f_closedir(&dir);
return res;
Expand All @@ -149,8 +149,8 @@ bool Fat32Transfer::deletePath(const std::string &path, const std::function<void

f_closedir(&dir);
if (FRESULT res = f_unlink((dirPath).c_str()); res != FR_OK) {
std::string deleteError = "Couldn't delete folder!\n";
deleteError += dirPath.string()+"\n";
std::wstring deleteError = L"Couldn't delete folder!\n";
deleteError += dirPath.wstring()+L"\n";
setErrorPrompt(deleteError);
return res;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ void Fat32Transfer::transferThreadLoop(dumpingConfig config) {
this->fs = (FATFSPtr*)malloc(sizeof(FATFS));
if (FRESULT res = f_mount(this->fs, this->fatTarget.c_str(), 1); res != FR_OK) {
this->runThreadLoop = false;
this->error = "Drive "+this->fatTarget+" couldn't be mounted! Error #"+std::to_string(res)+"\n";
this->error = L"Drive "+toWstring(this->fatTarget)+L" couldn't be mounted! Error #"+std::to_wstring(res)+L"\n";
}

if (this->runThreadLoop) {
Expand All @@ -218,19 +218,19 @@ void Fat32Transfer::transferThreadLoop(dumpingConfig config) {
[this](CommandSwitchDir& arg) {
DEBUG_OSReport("Switch Directory: path=%s", arg.dirPath.c_str());
if (FRESULT res = f_chdir((this->fatTarget+arg.dirPath).c_str()); res != FR_OK) {
this->error += "Failed to switch to the given directory!\n";
this->error += "Error "+std::to_string(res)+" after changing directory:\n";
this->error += this->fatTarget+arg.dirPath;
this->error += L"Failed to switch to the given directory!\n";
this->error += L"Error "+std::to_wstring(res)+L" after changing directory:\n";
this->error += toWstring(this->fatTarget+arg.dirPath);
this->runThreadLoop = false;
}
},
[this](CommandMakeDir& arg) {
DEBUG_OSReport("Make Directory: path=%s", arg.dirPath.c_str());
if (FRESULT res = f_mkdir((this->fatTarget+arg.dirPath).c_str()); res != FR_OK && res != FR_EXIST/* && res != FR_NO_PATH*/) {
this->error += "Couldn't make the directory!\n";
this->error += "For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += "Error "+std::to_string(res)+" after creating directory:\n";
this->error += this->fatTarget+arg.dirPath;
this->error += L"Couldn't make the directory!\n";
this->error += L"For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += L"Error "+std::to_wstring(res)+L" after creating directory:\n";
this->error += toWstring(this->fatTarget+arg.dirPath);
this->runThreadLoop = false;
}
},
Expand All @@ -240,10 +240,10 @@ void Fat32Transfer::transferThreadLoop(dumpingConfig config) {
if (FRESULT res = (FRESULT) this->openFile(this->fatTarget + arg.filePath, arg.fileSize); res != FR_OK) {
free(arg.chunkBuffer);
this->closeFile(this->fatTarget + arg.filePath);
this->error += "Couldn't open the file to copy to!\n";
this->error += "For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += "Error "+std::to_string(res)+" after creating SD card file:\n";
this->error += this->fatTarget+arg.filePath;
this->error += L"Couldn't open the file to copy to!\n";
this->error += L"For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += L"Error "+std::to_wstring(res)+L" after creating SD card file:\n";
this->error += toWstring(this->fatTarget+arg.filePath);
this->runThreadLoop = false;
return;
}
Expand All @@ -252,11 +252,11 @@ void Fat32Transfer::transferThreadLoop(dumpingConfig config) {
if (FRESULT res = f_write(this->currFileHandle, arg.chunkBuffer, arg.chunkSize, &bytesWritten); res != FR_OK || bytesWritten != arg.chunkSize) {
free(arg.chunkBuffer);
this->closeFile(this->fatTarget + arg.filePath);
this->error += "Failed to write data to dumping device!\n";
if (res == FR_DENIED) this->error += "There's no space available on the USB/SD card!\n";
this->error += "\nDetails:\n";
this->error += "Error "+std::to_string(res)+" when writing data to:\n";
this->error += this->fatTarget+arg.filePath;
this->error += L"Failed to write data to dumping device!\n";
if (res == FR_DENIED) this->error += L"There's no space available on the USB/SD card!\n";
this->error += L"\nDetails:\n";
this->error += L"Error "+std::to_wstring(res)+L" when writing data to:\n";
this->error += toWstring(this->fatTarget+arg.filePath);
this->runThreadLoop = false;
return;
}
Expand All @@ -273,7 +273,7 @@ void Fat32Transfer::transferThreadLoop(dumpingConfig config) {
}

OSReport("Cleaning up the thread...\n");
OSReport(this->error.c_str());
//OSReport(this->error.c_str());

// Shutdown fatfs thread
if (this->currFileHandle != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion source/app/interfaces/fat32.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Fat32Transfer : public TransferInterface {
static constexpr const char* targetDirectoryName = "Dumpling";
std::string fatTarget;

std::string error;
std::wstring error;

struct DIRPtr;
std::unique_ptr<DIRPtr> currDir;
Expand Down
22 changes: 11 additions & 11 deletions source/app/interfaces/stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ void StubTransfer::transferThreadLoop(dumpingConfig config) {
if (destFileHandle == nullptr) {
this->closeFileHandle(arg.filePath);
free(arg.chunkBuffer);
this->error += "Couldn't open the file to copy to!\n";
this->error += "For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += "Error "+std::to_string(errno)+" after creating SD card file:\n";
this->error += arg.filePath;
this->error += L"Couldn't open the file to copy to!\n";
this->error += L"For SD cards: Make sure it isn't locked\nby the write-switch on the side!\n\nDetails:\n";
this->error += L"Error "+std::to_wstring(errno)+L" after creating SD card file:\n";
this->error += toWstring(arg.filePath);
this->runThreadLoop = false;
return;
}

if (size_t bytesWritten = fwrite(arg.chunkBuffer, sizeof(uint8_t), arg.chunkSize, destFileHandle); bytesWritten != arg.chunkSize) {
this->closeFileHandle(arg.filePath);
free(arg.chunkBuffer);
this->error += "Failed to write data to dumping device!\n";
if (errno == ENOSPC) this->error += "There's no space available on the USB/SD card!\n";
if (errno == EIO) this->error += "For discs: Make sure that its clean!\nDumping is very sensitive to tiny issues!\n";
this->error += "\nDetails:\n";
this->error += "Error "+std::to_string(errno)+" when writing data from:\n";
this->error += "to:\n";
this->error += arg.filePath;
this->error += L"Failed to write data to dumping device!\n";
if (errno == ENOSPC) this->error += L"There's no space available on the USB/SD card!\n";
if (errno == EIO) this->error += L"For discs: Make sure that its clean!\nDumping is very sensitive to tiny issues!\n";
this->error += L"\nDetails:\n";
this->error += L"Error "+std::to_wstring(errno)+L" when writing data from:\n";
this->error += L"to:\n";
this->error += toWstring(arg.filePath);
this->runThreadLoop = false;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion source/app/interfaces/stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class StubTransfer : public TransferInterface {

const std::string sdPath = "fs:/vol/external01";

std::string error;
std::wstring error;
std::unordered_map<std::string, FILE*> fileHandles;
};
2 changes: 1 addition & 1 deletion source/app/interfaces/transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ bool TransferInterface::hasStopped() {
return this->threadStopped;
}

std::optional<std::string> TransferInterface::getStopError() {
std::optional<std::wstring> TransferInterface::getStopError() {
return !this->threadStopped ? std::nullopt : this->threadStoppedError;
}
4 changes: 2 additions & 2 deletions source/app/interfaces/transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TransferInterface {
const uint32_t maxQueueSize = 64;

bool hasStopped();
std::optional<std::string> getStopError();
std::optional<std::wstring> getStopError();
protected:
virtual void transferThreadLoop(dumpingConfig config) = 0;

Expand All @@ -45,7 +45,7 @@ class TransferInterface {

bool runThreadLoop = true;
std::atomic<bool> threadStopped = false;
std::optional<std::string> threadStoppedError;
std::optional<std::wstring> threadStoppedError;

std::thread transferThread;

Expand Down
2 changes: 1 addition & 1 deletion source/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main() {
// Start Dumpling
showLoadingScreen();
if (testCFW() != FAILED && ((getCFWVersion() == MOCHA_FSCLIENT || getCFWVersion() == CEMU) || executeExploit()) && initCFW() && mountSystemDrives() && loadUsers() && loadTitles(true)) {
WHBLogFreetypePrint("");
WHBLogFreetypePrint(L"");
WHBLogPrint("Finished loading!");
WHBLogFreetypeDraw();
sleep_for(3s);
Expand Down
Loading

0 comments on commit ddd92b1

Please sign in to comment.