diff --git a/include/savemng.h b/include/savemng.h index ccc47a3..9152106 100644 --- a/include/savemng.h +++ b/include/savemng.h @@ -23,11 +23,6 @@ #define M_OFF 1 #define Y_OFF 1 -#define COLOR_WHITE Color(0xffffffff) -#define COLOR_BLACK Color(0, 0, 0, 255) -#define COLOR_BACKGROUND Color(0x00006F00) -#define COLOR_TEXT COLOR_WHITE - struct Title { uint32_t highID; uint32_t lowID; diff --git a/include/utils/Colors.h b/include/utils/Colors.h new file mode 100644 index 0000000..3e24658 --- /dev/null +++ b/include/utils/Colors.h @@ -0,0 +1,6 @@ +#pragma once + +#define COLOR_WHITE Color(0xffffffff) +#define COLOR_BLACK Color(0, 0, 0, 255) +#define COLOR_BACKGROUND Color(0x00006F00) +#define COLOR_TEXT COLOR_WHITE \ No newline at end of file diff --git a/include/utils/DrawUtils.h b/include/utils/DrawUtils.h index 44e829b..725eb76 100644 --- a/include/utils/DrawUtils.h +++ b/include/utils/DrawUtils.h @@ -39,8 +39,6 @@ class DrawUtils { static void LogConsoleFree(); - static void initBuffers(void *tvBuffer, void *drcBuffer); - static void beginDraw(); static void endDraw(); @@ -77,9 +75,9 @@ class DrawUtils { static void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent); - static uint32_t ConsoleProcCallbackAcquired(void *context); + static uint32_t initScreen(); - static uint32_t ConsoleProcCallbackReleased(void *context); + static uint32_t deinitScreen(); @@ -92,7 +90,6 @@ class DrawUtils { static uint8_t *tvBuffer; static uint8_t *drcBuffer; - static void *sBufferTV, *sBufferDRC; static uint32_t sBufferSizeTV, sBufferSizeDRC; static BOOL sConsoleHasForeground; }; diff --git a/include/utils/StateUtils.h b/include/utils/StateUtils.h index a469b9e..4c399fa 100644 --- a/include/utils/StateUtils.h +++ b/include/utils/StateUtils.h @@ -1,11 +1,15 @@ #pragma once +#include + class State { public: static void init(); static bool AppRunning(); static void shutdown(); static void registerProcUICallbacks(); + static uint32_t ConsoleProcCallbackAcquired(void *context); + static uint32_t ConsoleProcCallbackReleased(void *context); private: static bool aroma; diff --git a/include/version.h b/include/version.h index d98fc50..c784e46 100644 --- a/include/version.h +++ b/include/version.h @@ -2,4 +2,4 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 6 -#define VERSION_MICRO 1 +#define VERSION_MICRO 2 diff --git a/src/main.cpp b/src/main.cpp index b13c3cf..fd3deed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,3 @@ -#include -#include -#include #include #include #include @@ -10,11 +7,15 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include static int wiiuTitlesCount = 0, vWiiTitlesCount = 0; @@ -394,6 +395,8 @@ int main() { OSFatal("Failed to initialize OSSCreen"); } + State::registerProcUICallbacks(); + if (!DrawUtils::initFont()) { OSFatal("Failed to init font"); } diff --git a/src/menu/WiiUTitleListState.cpp b/src/menu/WiiUTitleListState.cpp index f9d8309..d25e93f 100644 --- a/src/menu/WiiUTitleListState.cpp +++ b/src/menu/WiiUTitleListState.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #define MAX_TITLE_SHOW 14 static int cursorPos = 0; diff --git a/src/menu/vWiiTitleListState.cpp b/src/menu/vWiiTitleListState.cpp index 8aa4b8b..0f336ee 100644 --- a/src/menu/vWiiTitleListState.cpp +++ b/src/menu/vWiiTitleListState.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #define MAX_TITLE_SHOW 14 static int cursorPos = 0; diff --git a/src/savemng.cpp b/src/savemng.cpp index 84090e0..e7bafc7 100644 --- a/src/savemng.cpp +++ b/src/savemng.cpp @@ -8,8 +8,10 @@ #include #include #include +#include #include + #define __FSAShimSend ((FSError(*)(FSAShimBuffer *, uint32_t))(0x101C400 + 0x042d90)) #define IO_MAX_FILE_BUFFER (1024 * 1024) // 1 MB @@ -202,14 +204,18 @@ static bool folderEmpty(const char *fPath) { if (dir == nullptr) return false; - int c = 0; + bool empty = true; struct dirent *data; - while ((data = readdir(dir)) != nullptr) - if (++c > 2) - break; + while ((data = readdir(dir)) != nullptr) { + // rewritten to work wether ./.. are returned or not + if(strcmp(data->d_name,".") == 0 || strcmp(data->d_name,"..") == 0) + continue; + empty = false; + break; + } closedir(dir); - return c < 3; + return empty; } static bool createFolder(const char *path) { @@ -851,16 +857,23 @@ void copySavedata(Title *title, Title *titleb, int8_t allusers, int8_t allusers_ std::string srcPath = StringUtils::stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, "user"); std::string dstPath = StringUtils::stringFormat("%s/%08x/%08x/%s", pathb.c_str(), highIDb, lowIDb, "user"); createFolderUnlocked(dstPath); - FSAMakeQuotaFromDir(srcPath.c_str(), dstPath.c_str(), titleb->accountSaveSize); - if (allusers > -1) - if (common) + if (allusers > -1) { + if (common) { + FSAMakeQuota(handle, newlibtoFSA(dstPath + "/common").c_str(), 0x666, titleb->accountSaveSize); if (!copyDir(srcPath + "/common", dstPath + "/common")) promptError(LanguageUtils::gettext("Common save not found.")); + } + srcPath.append(StringUtils::stringFormat("/%s", wiiuacc[allusers].persistentID)); + dstPath.append(StringUtils::stringFormat("/%s", wiiuacc[allusers_d].persistentID)); + FSAMakeQuota(handle, newlibtoFSA(dstPath).c_str(), 0x666, titleb->accountSaveSize); + } else { + FSAMakeQuotaFromDir(srcPath.c_str(), dstPath.c_str(), titleb->accountSaveSize); + } - if (!copyDir(srcPath + StringUtils::stringFormat("/%s", wiiuacc[allusers].persistentID), - dstPath + StringUtils::stringFormat("/%s", wiiuacc[allusers_d].persistentID))) + if (!copyDir(srcPath, dstPath)) promptError(LanguageUtils::gettext("Copy failed.")); + if (!titleb->saveInit) { std::string userPath = StringUtils::stringFormat("%s/%08x/%08x/user", pathb.c_str(), highIDb, lowIDb); @@ -1006,19 +1019,24 @@ void restoreSavedata(Title *title, uint8_t slot, int8_t sdusers, int8_t allusers srcPath = getBackupPath(highID, lowID, slot); std::string dstPath = StringUtils::stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user"); createFolderUnlocked(dstPath); - FSAMakeQuotaFromDir(srcPath.c_str(), dstPath.c_str(), title->accountSaveSize); - + if ((sdusers > -1) && !isWii) { if (common) { + FSAMakeQuota(handle, newlibtoFSA(dstPath + "/common").c_str(), 0x666, title->accountSaveSize); if (!copyDir(srcPath + "/common", dstPath + "/common")) promptError(LanguageUtils::gettext("Common save not found.")); } srcPath.append(StringUtils::stringFormat("/%s", sdacc[sdusers].persistentID)); dstPath.append(StringUtils::stringFormat("/%s", wiiuacc[allusers].persistentID)); + FSAMakeQuota(handle, newlibtoFSA(dstPath).c_str(), 0x666, title->accountSaveSize); + } else { + FSAMakeQuotaFromDir(srcPath.c_str(), dstPath.c_str(), title->accountSaveSize); } if (!copyDir(srcPath, dstPath)) promptError(LanguageUtils::gettext("Restore failed.")); + + if (!title->saveInit && !isWii) { std::string userPath = StringUtils::stringFormat("%s/%08x/%08x/user", path.c_str(), highID, lowID); diff --git a/src/utils/DrawUtils.cpp b/src/utils/DrawUtils.cpp index 2cda6b1..471de02 100644 --- a/src/utils/DrawUtils.cpp +++ b/src/utils/DrawUtils.cpp @@ -1,16 +1,14 @@ -#include -#include +#include +#include #include #include #include -#include -#include -#include #include +#include #include - -#include #include +#include +#include #include #include #include @@ -26,62 +24,50 @@ bool DrawUtils::isBackBuffer; uint8_t *DrawUtils::tvBuffer = nullptr; uint8_t *DrawUtils::drcBuffer = nullptr; -/* -uint32_t DrawUtils::sBufferSizeTV = 0; -uint32_t DrawUtils::sBufferSizeDRC = 0; -*/ +uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0; +BOOL DrawUtils::sConsoleHasForeground = TRUE; + static SFT pFont = {}; static Color font_col(0xFFFFFFFF); -static Color black(0x000000FF); - -void *DrawUtils::sBufferTV = NULL, *DrawUtils::sBufferDRC = NULL; -uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0; -BOOL DrawUtils::sConsoleHasForeground = TRUE; uint32_t -DrawUtils::ConsoleProcCallbackAcquired(void *context) +DrawUtils::initScreen() { MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1); MEMRecordStateForFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG); if (sBufferSizeTV) { - sBufferTV = MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4); + DrawUtils::tvBuffer = static_cast(MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4)); } if (sBufferSizeDRC) { - sBufferDRC = MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4); + DrawUtils::drcBuffer = static_cast(MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4)); } sConsoleHasForeground = TRUE; - OSScreenSetBufferEx(SCREEN_TV, sBufferTV); - OSScreenSetBufferEx(SCREEN_DRC, sBufferDRC); - DrawUtils::initBuffers(sBufferTV, sBufferDRC); + OSScreenSetBufferEx(SCREEN_TV, DrawUtils::tvBuffer); + OSScreenSetBufferEx(SCREEN_DRC, DrawUtils::drcBuffer); - OSScreenEnableEx(SCREEN_TV, 1); - OSScreenEnableEx(SCREEN_DRC, 1); - - - for (int i = 0; i<2; i++) // both buffers to black - { - DrawUtils::clear(black); - DrawUtils::endDraw(); - } + DrawUtils::endDraw(); // flip buffers DrawUtils::setRedraw(true); // force a redraw when reentering return 0; + } uint32_t -DrawUtils::ConsoleProcCallbackReleased(void *context) +DrawUtils::deinitScreen() { + MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1); MEMFreeByStateToFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG); sConsoleHasForeground = FALSE; return 0; + } @@ -92,9 +78,10 @@ DrawUtils::LogConsoleInit() sBufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV); sBufferSizeDRC = OSScreenGetBufferSizeEx(SCREEN_DRC); - ConsoleProcCallbackAcquired(NULL); - - State::registerProcUICallbacks(); + initScreen(); + + OSScreenEnableEx(SCREEN_TV, 1); + OSScreenEnableEx(SCREEN_DRC, 1); return FALSE; } @@ -103,8 +90,8 @@ void DrawUtils::LogConsoleFree() { if (sConsoleHasForeground) { + deinitScreen(); OSScreenShutdown(); - ConsoleProcCallbackReleased(NULL); } } @@ -120,11 +107,6 @@ void DrawUtils::setRedraw(bool value) { redraw = value; } -void DrawUtils::initBuffers(void *sBufferTV_, void *sBufferDRC_) { - DrawUtils::tvBuffer = (uint8_t *) sBufferTV_; - DrawUtils::drcBuffer = (uint8_t *) sBufferDRC_; -} - void DrawUtils::beginDraw() { uint32_t pixel = *(uint32_t *) tvBuffer; @@ -141,13 +123,6 @@ void DrawUtils::beginDraw() { } void DrawUtils::endDraw() { - // OSScreenFlipBuffersEx already flushes the cache? - // DCFlushRange(tvBuffer, sBufferSizeTV); - // DCFlushRange(drcBuffer, sBufferSizeDRC); - - DCFlushRange(sBufferTV, sBufferSizeTV); - DCFlushRange(sBufferDRC, sBufferSizeDRC); - OSScreenFlipBuffersEx(SCREEN_DRC); OSScreenFlipBuffersEx(SCREEN_TV); } diff --git a/src/utils/StateUtils.cpp b/src/utils/StateUtils.cpp index 6cd1164..da6b270 100644 --- a/src/utils/StateUtils.cpp +++ b/src/utils/StateUtils.cpp @@ -1,15 +1,13 @@ +#include +#include #include #include #include #include -#include -#include -#include #include #include -#include bool State::aroma = false; @@ -25,10 +23,22 @@ void State::init() { } +uint32_t +State::ConsoleProcCallbackAcquired(void *context) +{ + return DrawUtils::initScreen(); +} + +uint32_t +State::ConsoleProcCallbackReleased(void *context) +{ + return DrawUtils::deinitScreen(); +} + void State::registerProcUICallbacks() { if (aroma) { - ProcUIRegisterCallback(PROCUI_CALLBACK_ACQUIRE, DrawUtils::ConsoleProcCallbackAcquired, NULL, 100); - ProcUIRegisterCallback(PROCUI_CALLBACK_RELEASE, DrawUtils::ConsoleProcCallbackReleased, NULL, 100); + ProcUIRegisterCallback(PROCUI_CALLBACK_ACQUIRE, ConsoleProcCallbackAcquired, NULL, 100); + ProcUIRegisterCallback(PROCUI_CALLBACK_RELEASE, ConsoleProcCallbackReleased, NULL, 100); } }