From 175a152dbf02fdcb427bba6dbd0c2091ece454e1 Mon Sep 17 00:00:00 2001 From: Xpl0itU Date: Thu, 18 Aug 2022 16:18:06 +0200 Subject: [PATCH] Revert "Make it compile" This reverts commit 229c5ee09905c5c17ed95edad424f44ee53ac8fd. --- include/savemng.h | 1 - src/main.cpp | 6 +++--- src/savemng.cpp | 44 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/include/savemng.h b/include/savemng.h index d27af64..2383ce2 100644 --- a/include/savemng.h +++ b/include/savemng.h @@ -72,7 +72,6 @@ extern Account *wiiuacc; extern Account *sdacc; extern uint8_t wiiuaccn, sdaccn; -FSCmdBlock *getCmdBlk(); void console_print_pos(int x, int y, const char *format, ...); bool promptConfirm(Style st, std::string question); void promptError(const char *message, ...); diff --git a/src/main.cpp b/src/main.cpp index 12b7a9d..5e9562b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -463,10 +463,10 @@ auto main() -> int { } setFSAFD(fsaFd); - + FSInit(); - FSInitCmdBlock(getCmdBlk()); - FSSetCmdPriority(getCmdBlk(), 0); + FSInitCmdBlock(getCmdBlk()); + FSSetCmdPriority(getCmdBlk(), 0); fatMountSimple("sd", &IOSUHAX_sdio_disc_interface); mount_fs("slc", fsaFd, "/dev/slccmpt01", "/vol/storage_slccmpt01"); diff --git a/src/savemng.cpp b/src/savemng.cpp index bd6d9e4..a1e2dc2 100644 --- a/src/savemng.cpp +++ b/src/savemng.cpp @@ -19,8 +19,26 @@ KPADStatus kpad[4], kpad_status; static FSCmdBlock cmdBlk; -FSCmdBlock *getCmdBlk() { - return &cmdBlk; +FSCmdBlock *getCmdBlk() +{ + return &cmdBlk; +} + +static std::string newlibToFSA(std::string path) { + if (path[3] == ':') { + switch (path[0]) { + case 'u': + replace(path, "usb:", "/vol/storage_usb01"); + break; + case 'm': + replace(path, "mlc:", "/vol/storage_mlc01"); + break; + case 's': + replace(path, "slc:", "/vol/storage_slccmpt01"); + break; + } + } + return path; } void setFSAFD(int fd) { @@ -129,9 +147,11 @@ static auto folderEmpty(const char *fPath) -> int { FSDirectoryHandle *dirHandle; FSStatus dir = FSOpenDir(__wut_devoptab_fs_client, &cmdBlk, fPath, dirHandle, -1); + DIR *dir = opendir(fPath); + if (dir == nullptr) + return -1; int c = 0; - FSDirectoryEntry entry; while (FSReadDir(__wut_devoptab_fs_client, &cmdBlk, dir, &entry, FS_ERROR_FLAG_ALL) == FS_STATUS_OK) { if (++c > 2) break; @@ -160,10 +180,10 @@ bool createFolder(const char *dir) { do { needle = strchr(needle, '/'); if (needle == NULL) - return (checkEntry(d) == 2) ? true : createDirectory(d) == FS_STATUS_OK; + return dirExists(d) ? true : createDirectory(d) == FS_STATUS_OK; *needle = '\0'; - if (!(checkEntry(d) == 2) && createDirectory(d) != FS_STATUS_OK) + if (!dirExists(d) && createDirectory(d) != FS_STATUS_OK) return false; *needle = '/'; @@ -409,10 +429,16 @@ void getAccountsSD(Title *title, uint8_t slot) { static auto DumpFile(std::string pPath, std::string oPath) -> int { FSFileHandle source; - FSOpenFile(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), "r", &source, FS_ERROR_FLAG_ALL); + FSOpenFile(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), "r", &source, FS_ERROR_FLAG_ALL); + if (source == nullptr) + return -1; FSFileHandle dest; - FSOpenFile(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), "w", &dest, FS_ERROR_FLAG_ALL); + FSOpenFile(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), "w", &dest, FS_ERROR_FLAG_ALL); + if (dest == nullptr) { + FSCloseFile(__wut_devoptab_fs_client, &cmdBlk, source, FS_ERROR_FLAG_ALL); + return -1; + } char *buffer; buffer = (char *) aligned_alloc(0x40, IO_MAX_FILE_BUFFER); @@ -425,7 +451,7 @@ static auto DumpFile(std::string pPath, std::string oPath) -> int { } FSStat stat; - if (FSGetStat(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), &stat, FS_ERROR_FLAG_ALL) < 0) + if (FSGetStat(__wut_devoptab_fs_client, &cmdBlk, pPath.c_str(), &stat, FS_ERROR_FLAG_ALL), &st < 0) return -1; int sizef = stat.size; int sizew = 0; @@ -439,7 +465,7 @@ static auto DumpFile(std::string pPath, std::string oPath) -> int { if (bytesWritten < size) { promptError("Write %d,%s", bytesWritten, oPath.c_str()); FSCloseFile(__wut_devoptab_fs_client, &cmdBlk, source, FS_ERROR_FLAG_ALL); - FSCloseFile(__wut_devoptab_fs_client, &cmdBlk, dest, FS_ERROR_FLAG_ALL); + FSCloseFile(__wut_devoptab_fs_client, &cmdBlk, dest, FS_ERROR_FLAG_ALL); free(buffer); return -1; }