diff --git a/3ds/include/main.hpp b/3ds/include/main.hpp index 05f66bc..137e5dc 100644 --- a/3ds/include/main.hpp +++ b/3ds/include/main.hpp @@ -40,4 +40,7 @@ inline std::string g_selectedCheatKey; inline std::vector g_selectedCheatCodes; inline volatile bool g_isLoadingTitles = false; +inline std::u16string g_currentFile; +inline bool g_isTransferringFile = false; + #endif \ No newline at end of file diff --git a/3ds/source/MainScreen.cpp b/3ds/source/MainScreen.cpp index e1f3f2e..6f83010 100644 --- a/3ds/source/MainScreen.cpp +++ b/3ds/source/MainScreen.cpp @@ -158,6 +158,17 @@ void MainScreen::drawTop(void) const C2D_DrawText(&version, C2D_WithColor, 400 - 4 - ceilf(0.45f * version.width), 3.0f, 0.5f, 0.45f, 0.45f, COLOR_GREY_LIGHT); C2D_DrawImageAt(flag, 400 - 24 - ceilf(version.width * 0.45f), 0.0f, 0.5f, NULL, 1.0f, 1.0f); C2D_DrawText(&checkpoint, C2D_WithColor, 400 - 6 - 0.45f * version.width - 0.5f * checkpoint.width - 19, 2.0f, 0.5f, 0.5f, 0.5f, COLOR_WHITE); + + if (g_isTransferringFile) { + C2D_DrawRectSolid(0, 0, 0.5f, 400, 240, COLOR_OVERLAY); + + float size = 0.7f; + C2D_Text text; + C2D_TextParse(&text, dynamicBuf, StringUtils::UTF16toUTF8(g_currentFile).c_str()); + C2D_TextOptimize(&text); + C2D_DrawText(&text, C2D_WithColor, ceilf((400 - StringUtils::textWidth(text, size)) / 2), + ceilf((240 - size * fontGetInfo(NULL)->lineFeed) / 2), 0.9f, size, size, COLOR_WHITE); + } } void MainScreen::drawBottom(void) const @@ -236,6 +247,10 @@ void MainScreen::drawBottom(void) const // play coins C2D_DrawText(&coins, C2D_WithColor, ceilf(318 - StringUtils::textWidth(coins, scaleInst)), -1, 0.5f, scaleInst, scaleInst, COLOR_WHITE); } + + if (g_isTransferringFile) { + C2D_DrawRectSolid(0, 0, 0.5f, 400, 240, COLOR_OVERLAY); + } } void MainScreen::update(touchPosition* touch) diff --git a/3ds/source/io.cpp b/3ds/source/io.cpp index f056d85..8def60b 100644 --- a/3ds/source/io.cpp +++ b/3ds/source/io.cpp @@ -42,6 +42,8 @@ bool io::fileExists(FS_Archive archive, const std::u16string& path) void io::copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath) { + g_isTransferringFile = true; + u32 size = 0; FSStream input(srcArch, srcPath, FS_OPEN_READ); if (input.good()) { @@ -55,11 +57,22 @@ void io::copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& FSStream output(dstArch, dstPath, FS_OPEN_WRITE, input.size()); if (output.good()) { + size_t slashpos = srcPath.rfind(StringUtils::UTF8toUTF16("/")); + g_currentFile = srcPath.substr(slashpos + 1, srcPath.length() - slashpos - 1); + u32 rd; u8* buf = new u8[size]; do { rd = input.read(buf, size); output.write(buf, rd); + + // avoid freezing the UI + // this will be made less horrible next time... + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + g_screen->drawTop(); + C2D_SceneBegin(g_bottom); + g_screen->drawBottom(); + Gui::frameEnd(); } while (!input.eof()); delete[] buf; } @@ -71,6 +84,8 @@ void io::copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& input.close(); output.close(); + + g_isTransferringFile = false; } Result io::copyDirectory(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath) diff --git a/3ds/source/thread.cpp b/3ds/source/thread.cpp index 257e748..8f7e7bc 100644 --- a/3ds/source/thread.cpp +++ b/3ds/source/thread.cpp @@ -28,7 +28,7 @@ static std::vector threads; -static bool forceRefresh = false; +static bool forceRefresh = false; void Threads::create(ThreadFunc entrypoint) { @@ -55,6 +55,6 @@ void Threads::titles(void) g_isLoadingTitles = true; loadTitles(forceRefresh); - forceRefresh = true; + forceRefresh = true; g_isLoadingTitles = false; } \ No newline at end of file diff --git a/switch/include/main.hpp b/switch/include/main.hpp index 8fd48a5..aac6398 100644 --- a/switch/include/main.hpp +++ b/switch/include/main.hpp @@ -44,4 +44,7 @@ inline std::string g_selectedCheatKey; inline std::vector g_selectedCheatCodes; inline u32 g_username_dotsize; +inline std::string g_currentFile = ""; +inline bool g_isTransferringFile = false; + #endif \ No newline at end of file diff --git a/switch/source/MainScreen.cpp b/switch/source/MainScreen.cpp index 7b38feb..4a0e660 100644 --- a/switch/source/MainScreen.cpp +++ b/switch/source/MainScreen.cpp @@ -204,6 +204,14 @@ void MainScreen::draw() const SDLH_DrawText(26, 16, 672 + (40 - checkpoint_h) / 2 + 2, theme().c6, "checkpoint"); SDLH_DrawText(20, 16 + checkpoint_w + 8, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - ver_h, theme().c6, ver); SDLH_DrawText(24, 16 * 3 + checkpoint_w + 8 + ver_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, theme().c6, "\ue046 Instructions"); + + if (g_isTransferringFile) { + SDLH_DrawRect(0, 0, 1280, 720, COLOR_OVERLAY); + + u32 w, h; + SDLH_GetTextDimensions(28, g_currentFile.c_str(), &w, &h); + SDLH_DrawText(28, (1280 - w) / 2, (720 - h) / 2, COLOR_WHITE, g_currentFile.c_str()); + } } void MainScreen::update(touchPosition* touch) diff --git a/switch/source/io.cpp b/switch/source/io.cpp index 3f52410..d131e26 100644 --- a/switch/source/io.cpp +++ b/switch/source/io.cpp @@ -34,6 +34,8 @@ bool io::fileExists(const std::string& path) void io::copyFile(const std::string& srcPath, const std::string& dstPath) { + g_isTransferringFile = true; + FILE* src = fopen(srcPath.c_str(), "rb"); if (src == NULL) { Logger::getInstance().log(Logger::ERROR, "Failed to open source file " + srcPath + " during copy with errno %d. Skipping...", errno); @@ -52,10 +54,19 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath) u8* buf = new u8[BUFFER_SIZE]; u64 offset = 0; + + size_t slashpos = srcPath.rfind("/"); + g_currentFile = srcPath.substr(slashpos + 1, srcPath.length() - slashpos - 1); + while (offset < sz) { u32 count = fread((char*)buf, 1, BUFFER_SIZE, src); fwrite((char*)buf, 1, count, dst); offset += count; + + // avoid freezing the UI + // this will be made less horrible next time... + g_screen->draw(); + SDLH_Render(); } delete[] buf; @@ -67,6 +78,8 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath) Logger::getInstance().log(Logger::ERROR, "Committing file " + dstPath + " to the save archive."); fsdevCommitDevice("save"); } + + g_isTransferringFile = false; } Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath) @@ -234,6 +247,7 @@ std::tuple io::backup(size_t index, u128 uid, size_t false, systemKeyboardAvailable.second, "System keyboard applet not accessible.\nThe suggested destination folder was used\ninstead."); } + ret = std::make_tuple(true, 0, "Progress correctly saved to disk."); Logger::getInstance().log(Logger::INFO, "Backup succeeded."); return ret; } diff --git a/switch/source/util.cpp b/switch/source/util.cpp index d816466..22a191f 100644 --- a/switch/source/util.cpp +++ b/switch/source/util.cpp @@ -110,9 +110,7 @@ Result servicesInit(void) } } - if (R_SUCCEEDED(res = pdmqryInitialize())) { - - } + if (R_SUCCEEDED(res = pdmqryInitialize())) {} else { Logger::getInstance().log(Logger::WARN, "pdmqryInitialize failed with result 0x%08lX.", res); }