From eb7233a1f5fd434a31286a676916c80dfaee3349 Mon Sep 17 00:00:00 2001 From: BernardoGiordano Date: Mon, 28 May 2018 22:05:13 +0200 Subject: [PATCH] fix bugs introduced by last commit --- 3ds/include/scrollable.hpp | 1 + 3ds/source/io.cpp | 45 ++++++++++++++++++++++---------------- 3ds/source/main.cpp | 1 + 3ds/source/scrollable.cpp | 6 +++++ common/iscrollable.hpp | 2 +- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/3ds/include/scrollable.hpp b/3ds/include/scrollable.hpp index 3231487..97fd47d 100644 --- a/3ds/include/scrollable.hpp +++ b/3ds/include/scrollable.hpp @@ -50,6 +50,7 @@ public: void draw(void) override; void push_back(u32 color, u32 colorMessage, const std::string& message) override; + void resetIndex(void) override; void updateSelection(void) override; protected: diff --git a/3ds/source/io.cpp b/3ds/source/io.cpp index 5503290..66e2518 100644 --- a/3ds/source/io.cpp +++ b/3ds/source/io.cpp @@ -166,21 +166,24 @@ void io::backup(size_t index) std::u16string customPath; if (Gui::multipleSelectionEnabled()) { - customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16(Gui::nameFromCell(cellIndex).c_str()); + customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16(""); } else { - customPath = isNewFolder ? StringUtils::removeForbiddenCharacters(swkbd(suggestion)) : StringUtils::UTF8toUTF16(Gui::nameFromCell(cellIndex).c_str()); + customPath = isNewFolder ? StringUtils::removeForbiddenCharacters(swkbd(suggestion)) : StringUtils::UTF8toUTF16(""); } - if (!customPath.compare(StringUtils::UTF8toUTF16(" "))) + std::u16string dstPath; + if (customPath.empty()) { - FSUSER_CloseArchive(archive); - return; + // we're overriding an existing folder + dstPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex); } - - std::u16string dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath(); - dstPath += StringUtils::UTF8toUTF16("/") + customPath; + else + { + dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath(); + dstPath += StringUtils::UTF8toUTF16("/") + customPath; + } if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath)) { @@ -234,20 +237,24 @@ void io::backup(size_t index) std::u16string customPath; if (Gui::multipleSelectionEnabled()) { - customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16(Gui::nameFromCell(cellIndex).c_str()); + customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16(""); } else { - customPath = isNewFolder ? swkbd(suggestion) : StringUtils::UTF8toUTF16(Gui::nameFromCell(cellIndex).c_str()); - } - - if (!customPath.compare(StringUtils::UTF8toUTF16(" "))) - { - return; + customPath = isNewFolder ? swkbd(suggestion) : StringUtils::UTF8toUTF16(""); } - std::u16string dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath(); - dstPath += StringUtils::UTF8toUTF16("/") + customPath; + std::u16string dstPath; + if (customPath.empty()) + { + // we're overriding an existing folder + dstPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex); + } + else + { + dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath(); + dstPath += StringUtils::UTF8toUTF16("/") + customPath; + } if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath)) { @@ -389,8 +396,8 @@ void io::restore(size_t index) u32 saveSize = SPIGetCapacity(cardType); u32 pageSize = SPIGetPageSize(cardType); - std::u16string srcPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath(); - srcPath += StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(Gui::nameFromCell(cellIndex).c_str()) + StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"); + std::u16string srcPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex) + StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"); + srcPath += StringUtils::UTF8toUTF16("/"); u8* saveFile = new u8[saveSize]; FSStream stream(Archive::sdmc(), srcPath, FS_OPEN_READ); diff --git a/3ds/source/main.cpp b/3ds/source/main.cpp index 29cb2f6..652fcca 100644 --- a/3ds/source/main.cpp +++ b/3ds/source/main.cpp @@ -51,6 +51,7 @@ int main() { Gui::bottomScroll(false); Gui::updateButtonsColor(); Gui::clearSelectedEntries(); + Gui::resetScrollableIndex(); } if (kDown & KEY_X) diff --git a/3ds/source/scrollable.cpp b/3ds/source/scrollable.cpp index 47dfcf7..2c16d0b 100644 --- a/3ds/source/scrollable.cpp +++ b/3ds/source/scrollable.cpp @@ -26,6 +26,12 @@ #include "scrollable.hpp" +void Scrollable::resetIndex(void) +{ + mHid->index(0); + mHid->page(0); +} + void Scrollable::push_back(u32 color, u32 colorMessage, const std::string& message) { static const float spacing = mh / mVisibleEntries; diff --git a/common/iscrollable.hpp b/common/iscrollable.hpp index a91de31..c9b8246 100644 --- a/common/iscrollable.hpp +++ b/common/iscrollable.hpp @@ -91,7 +91,7 @@ public: } } - void resetIndex(void) + virtual void resetIndex(void) { mIndex = 0; mPage = 0;