Basic flow of setting up and moving the PSP directory works now.

This commit is contained in:
Henrik Rydgård committed 2021-08-04 23:22:43 +02:00
1 parent 3be1ff6ce4
commit f51b8116a0
9 files changed
+71 -20

No files matched your search

+4 -1
View File
@@ -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<std::string> parts;
SplitString(diff, '/', parts);
+14 -9
View File
@@ -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;
}
+1 -1
View File
@@ -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_;
+6
View File
@@ -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");
+1
View File
@@ -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);
+16 -4
View File
@@ -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 &params) {
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 &params) {
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 &params) {
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());
}
}
}
+9
View File
@@ -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
+10 -2
View File
@@ -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 {
+10 -3
View File
@@ -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;