mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
preserve native paths when creating directories
This commit is contained in:
+30
-45
@@ -275,63 +275,48 @@ bool File::DeleteDirectory(const std::filesystem::path& path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool File::CreateDirectories(const std::filesystem::path& path) {
|
bool File::CreateDirectories(const std::filesystem::path& path) {
|
||||||
std::string real_path = Common::ReplaceChar(PathToGenericString(path), '\\', '/');
|
const auto normalized_path =
|
||||||
|
WithoutTrailingSeparator(path);
|
||||||
|
|
||||||
std::vector<std::string> list = Common::Split(real_path, "/");
|
auto current_path = normalized_path.root_path();
|
||||||
|
|
||||||
std::string p;
|
for (const auto& component:
|
||||||
|
normalized_path.relative_path()) {
|
||||||
|
current_path /= component;
|
||||||
|
|
||||||
for (uint32_t si = 0; si < list.size(); si++) {
|
if (IsDirectoryExisting(current_path)) {
|
||||||
const std::string& s = list[si];
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (si != 0 || real_path.starts_with("/")) {
|
if (!CreateDirectory(current_path)) {
|
||||||
p += "/";
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p += s;
|
return true;
|
||||||
|
|
||||||
if (IsDirectoryExisting(p)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CreateDirectory(p)) // @suppress("Invalid arguments")
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::DeleteDirectories(const std::filesystem::path& path) {
|
bool File::DeleteDirectories(const std::filesystem::path& path) {
|
||||||
std::string real_path = Common::ReplaceChar(PathToGenericString(path), '\\', '/');
|
const auto normalized_path =
|
||||||
|
WithoutTrailingSeparator(path);
|
||||||
|
|
||||||
std::vector<std::string> list = Common::Split(real_path, "/");
|
std::vector<std::filesystem::path> directories;
|
||||||
|
auto current_path = normalized_path.root_path();
|
||||||
|
|
||||||
std::string p;
|
for (const auto& component:
|
||||||
std::vector<std::string> list2;
|
normalized_path.relative_path()) {
|
||||||
|
current_path /= component;
|
||||||
|
directories.push_back(current_path);
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t si = 0; si < list.size(); si++) {
|
for (auto it = directories.rbegin();
|
||||||
const std::string& s = list[si];
|
it != directories.rend(); ++it) {
|
||||||
|
if (!DeleteDirectory(*it)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (si != 0 || real_path.starts_with("/")) {
|
return true;
|
||||||
p += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
p += s;
|
|
||||||
|
|
||||||
list2.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t num = list2.size();
|
|
||||||
|
|
||||||
for (uint32_t si = num - 1; si < num; si--) {
|
|
||||||
if (!DeleteDirectory(list2[si])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::DeleteFile(
|
bool File::DeleteFile(
|
||||||
|
|||||||
@@ -137,20 +137,21 @@ void CheckUnicodePaths(const std::filesystem::path &root) {
|
|||||||
|
|
||||||
const auto unicode_root =
|
const auto unicode_root =
|
||||||
root / Common::PathFromUtf8(HostDirectory);
|
root / Common::PathFromUtf8(HostDirectory);
|
||||||
|
const auto nested_root = unicode_root / "nested";
|
||||||
|
|
||||||
Check(std::filesystem::create_directories(unicode_root),
|
Check(Common::File::CreateDirectories(nested_root),
|
||||||
"create Unicode host directory");
|
"create nested Unicode host directory");
|
||||||
|
|
||||||
CheckMountRoot(unicode_root);
|
CheckMountRoot(nested_root);
|
||||||
|
|
||||||
const auto native_file =
|
const auto native_file =
|
||||||
unicode_root / Common::PathFromUtf8(GuestFilename);
|
nested_root / Common::PathFromUtf8(GuestFilename);
|
||||||
|
|
||||||
Common::File fixture;
|
Common::File fixture;
|
||||||
Check(fixture.Create(native_file), "create Unicode filename");
|
Check(fixture.Create(native_file), "create Unicode filename");
|
||||||
fixture.Close();
|
fixture.Close();
|
||||||
|
|
||||||
FileSystem::Mount(unicode_root, "/app0");
|
FileSystem::Mount(nested_root, "/app0");
|
||||||
|
|
||||||
const auto guest_file =
|
const auto guest_file =
|
||||||
std::string("/app0/") + std::string(GuestFilename);
|
std::string("/app0/") + std::string(GuestFilename);
|
||||||
|
|||||||
Reference in New Issue
Block a user