diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index 134d84f74b..dc8551767f 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -510,7 +510,10 @@ bool CreateFullPath(const Path &path) { Path root = path.GetRootVolume(); - std::string diff = root.PathTo(path); // always with forward slashes + std::string diff; + if (!root.ComputePathTo(path, diff)) { + return false; + } std::vector parts; SplitString(diff, '/', parts); diff --git a/Common/File/Path.cpp b/Common/File/Path.cpp index 86a43f20bd..2af4374937 100644 --- a/Common/File/Path.cpp +++ b/Common/File/Path.cpp @@ -299,27 +299,32 @@ bool Path::IsAbsolute() const { return false; } -std::string Path::PathTo(const Path &other) const { +bool Path::ComputePathTo(const Path &other, std::string &path) const { if (!other.StartsWith(*this)) { // Can't do this. Should return an error. - return std::string(); + return false; + } + + if (*this == other) { + // Equal, the path is empty. + path.clear(); + return true; } std::string diff; - if (type_ == PathType::CONTENT_URI) { AndroidContentURI a(path_); AndroidContentURI b(other.path_); if (a.RootPath() != b.RootPath()) { // No common root, can't do anything - return std::string(); + return false; } - diff = a.PathTo(b); + return a.ComputePathTo(b, path); } else if (path_ == "/") { - diff = other.path_.substr(1); + path = other.path_.substr(1); + return true; } else { - diff = other.path_.substr(path_.size() + 1); + path = other.path_.substr(path_.size() + 1); + return true; } - - return diff; } diff --git a/Common/File/Path.h b/Common/File/Path.h index afec18ac7e..4a0658e5f7 100644 --- a/Common/File/Path.h +++ b/Common/File/Path.h @@ -82,7 +82,7 @@ public: // For Android directory trees, navigates to the root of the tree. Path GetRootVolume() const; - std::string PathTo(const Path &child) const; + bool ComputePathTo(const Path &other, std::string &path) const; bool operator ==(const Path &other) const { return path_ == other.path_ && type_ == other.type_; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 71006d005b..18c8398060 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1257,6 +1257,12 @@ void GameSettingsScreen::sendMessage(const char *message, const char *value) { } } +void GameSettingsScreen::dialogFinished(const Screen *dialog, DialogResult result) { + if (result == DialogResult::DR_OK) { + RecreateViews(); + } +} + void GameSettingsScreen::CallbackMemstickFolder(bool yes) { auto sy = GetI18NCategory("System"); diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index ebc5d59f88..09127656ec 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -43,6 +43,7 @@ protected: void CallbackInflightFrames(bool yes); void CallbackMemstickFolder(bool yes); bool UseVerticalLayout() const; + void dialogFinished(const Screen *dialog, DialogResult result) override; private: void TriggerRestart(const char *why); diff --git a/UI/MemStickScreen.cpp b/UI/MemStickScreen.cpp index 0e62fd644d..2696ed4004 100644 --- a/UI/MemStickScreen.cpp +++ b/UI/MemStickScreen.cpp @@ -207,10 +207,18 @@ static bool ListFileSuffixesRecursively(const Path &root, Path folder, std::vect for (auto &file : files) { if (file.isDirectory) { - dirSuffixes.push_back(root.PathTo(folder)); - ListFileSuffixesRecursively(root, folder / file.name, dirSuffixes, fileSuffixes); + std::string dirSuffix; + if (root.ComputePathTo(file.fullName, dirSuffix)) { + dirSuffixes.push_back(dirSuffix); + ListFileSuffixesRecursively(root, folder / file.name, dirSuffixes, fileSuffixes); + } else { + ERROR_LOG(SYSTEM, "Failed to compute PathTo from '%s' to '%s'", root.c_str(), folder.c_str()); + } } else { - fileSuffixes.push_back(root.PathTo(file.fullName)); + std::string fileSuffix; + if (root.ComputePathTo(file.fullName, fileSuffix)) { + fileSuffixes.push_back(fileSuffix); + } } } @@ -307,7 +315,7 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { return UI::EVENT_DONE; } - bool dryRun = true; // Useful for debugging. + bool dryRun = false; // Useful for debugging. size_t moveFailures = 0; @@ -320,11 +328,13 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { if (dryRun) { INFO_LOG(SYSTEM, "dry run: Would have created dir '%s'", dir.c_str()); } else { + INFO_LOG(SYSTEM, "Creating dir '%s'", dir.c_str()); if (!File::Exists(dir)) { File::CreateDir(dir); } } } + for (auto &fileSuffix : fileSuffixesToMove) { Path from = moveSrc / fileSuffix; Path to = moveDest / fileSuffix; @@ -337,6 +347,8 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { ERROR_LOG(SYSTEM, "Failed to move file '%s' to '%s'", from.c_str(), to.c_str()); moveFailures++; // Should probably just bail? + } else { + INFO_LOG(SYSTEM, "Moved file '%s' to '%s'", from.c_str(), to.c_str()); } } } diff --git a/UI/MemStickScreen.h b/UI/MemStickScreen.h index 1a5d12b63d..84d6d4d84c 100644 --- a/UI/MemStickScreen.h +++ b/UI/MemStickScreen.h @@ -40,6 +40,15 @@ protected: void sendMessage(const char *message, const char *value) override; void dialogFinished(const Screen *dialog, DialogResult result) override; void update() override; + void render() override { + // Simple anti-flicker due to delayed finish. + if (!done_) { + // render as usual. + UIDialogScreenWithBackground::render(); + } else { + // no render. black frame insertion is better than flicker. + } + } private: // Event handlers diff --git a/android/jni/AndroidContentURI.h b/android/jni/AndroidContentURI.h index f9837a5ba4..92e77afb62 100644 --- a/android/jni/AndroidContentURI.h +++ b/android/jni/AndroidContentURI.h @@ -112,8 +112,16 @@ public: } // Only goes downwards in hierarchies. No ".." will ever be generated. - std::string PathTo(const AndroidContentURI &other) const { - return other.FilePath().substr(FilePath().size() + 1); + bool ComputePathTo(const AndroidContentURI &other, std::string &path) const { + size_t offset = FilePath().size() + 1; + std::string otherFilePath = other.FilePath(); + if (offset >= otherFilePath.size()) { + ERROR_LOG(SYSTEM, "Bad call to PathTo. '%s' -> '%s'", FilePath().c_str(), other.FilePath().c_str()); + return false; + } + + path = other.FilePath().substr(FilePath().size() + 1); + return true; } std::string GetFileExtension() const { diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 7c399f0f9c..f2ef8cdb88 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -607,8 +607,14 @@ static bool TestPath() { EXPECT_EQ_STR(Path("C:\\Yo\\Lo").GetDirectory(), std::string("C:/Yo")); EXPECT_EQ_STR(Path("C:\\Yo\\Lo").GetFilename(), std::string("Lo")); - EXPECT_EQ_STR(Path("/a/b").PathTo(Path("/a/b/c/d/e")), std::string("c/d/e")); - EXPECT_EQ_STR(Path("/").PathTo(Path("/home/foo/bar")), std::string("home/foo/bar")); + std::string computedPath; + + EXPECT_TRUE(Path("/a/b").ComputePathTo(Path("/a/b/c/d/e"), computedPath)); + + EXPECT_EQ_STR(computedPath, std::string("c/d/e")); + + EXPECT_TRUE(Path("/").ComputePathTo(Path("/home/foo/bar"), computedPath)); + EXPECT_EQ_STR(computedPath, std::string("home/foo/bar")); return true; } @@ -639,7 +645,8 @@ static bool TestAndroidContentURI() { EXPECT_EQ_STR(fileURI.ToString(), std::string(directoryURIString)); - std::string diff = dirURI.PathTo(fileURI); + std::string diff; + EXPECT_TRUE(dirURI.ComputePathTo(fileURI, diff)); EXPECT_EQ_STR(diff, std::string("Tekken 6.iso")); return true;