diff options
| author | 2020-08-15 08:33:16 -0400 | |
|---|---|---|
| committer | 2020-08-16 06:52:40 -0400 | |
| commit | c4ed791164df7e3e74042a37a62077b4dc4ade91 (patch) | |
| tree | 12bbcc09d0db32a0b6b5dc1bc49245964486da63 /src/core/file_sys | |
| parent | Merge pull request #4528 from lioncash/discard (diff) | |
| download | yuzu-c4ed791164df7e3e74042a37a62077b4dc4ade91.tar.gz yuzu-c4ed791164df7e3e74042a37a62077b4dc4ade91.tar.xz yuzu-c4ed791164df7e3e74042a37a62077b4dc4ade91.zip | |
common/fileutil: Convert namespace to Common::FS
Migrates a remaining common file over to the Common namespace, making it
consistent with the rest of common files.
This also allows for high-traffic FS related code to alias the
filesystem function namespace as
namespace FS = Common::FS;
for more concise typing.
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/bis_factory.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/registered_cache.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/vfs.cpp | 56 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_libzip.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 177 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.h | 8 | ||||
| -rw-r--r-- | src/core/file_sys/xts_archive.cpp | 2 |
7 files changed, 130 insertions, 119 deletions
diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp index 285277ef8..9ffda2e14 100644 --- a/src/core/file_sys/bis_factory.cpp +++ b/src/core/file_sys/bis_factory.cpp | |||
| @@ -86,7 +86,7 @@ VirtualFile BISFactory::OpenPartitionStorage(BisPartitionId id) const { | |||
| 86 | auto& keys = Core::Crypto::KeyManager::Instance(); | 86 | auto& keys = Core::Crypto::KeyManager::Instance(); |
| 87 | Core::Crypto::PartitionDataManager pdm{ | 87 | Core::Crypto::PartitionDataManager pdm{ |
| 88 | Core::System::GetInstance().GetFilesystem()->OpenDirectory( | 88 | Core::System::GetInstance().GetFilesystem()->OpenDirectory( |
| 89 | FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), Mode::Read)}; | 89 | Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir), Mode::Read)}; |
| 90 | keys.PopulateFromPartitionData(pdm); | 90 | keys.PopulateFromPartitionData(pdm); |
| 91 | 91 | ||
| 92 | switch (id) { | 92 | switch (id) { |
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index f831487dd..e42b677f7 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -728,7 +728,7 @@ InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFuncti | |||
| 728 | LOG_WARNING(Loader, "Overwriting existing NCA..."); | 728 | LOG_WARNING(Loader, "Overwriting existing NCA..."); |
| 729 | VirtualDir c_dir; | 729 | VirtualDir c_dir; |
| 730 | { c_dir = dir->GetFileRelative(path)->GetContainingDirectory(); } | 730 | { c_dir = dir->GetFileRelative(path)->GetContainingDirectory(); } |
| 731 | c_dir->DeleteFile(FileUtil::GetFilename(path)); | 731 | c_dir->DeleteFile(Common::FS::GetFilename(path)); |
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | auto out = dir->CreateFileRelative(path); | 734 | auto out = dir->CreateFileRelative(path); |
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index e33327ef0..a4c3f67c4 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp | |||
| @@ -30,7 +30,7 @@ bool VfsFilesystem::IsWritable() const { | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { | 32 | VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { |
| 33 | const auto path = FileUtil::SanitizePath(path_); | 33 | const auto path = Common::FS::SanitizePath(path_); |
| 34 | if (root->GetFileRelative(path) != nullptr) | 34 | if (root->GetFileRelative(path) != nullptr) |
| 35 | return VfsEntryType::File; | 35 | return VfsEntryType::File; |
| 36 | if (root->GetDirectoryRelative(path) != nullptr) | 36 | if (root->GetDirectoryRelative(path) != nullptr) |
| @@ -40,22 +40,22 @@ VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | VirtualFile VfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 42 | VirtualFile VfsFilesystem::OpenFile(std::string_view path_, Mode perms) { |
| 43 | const auto path = FileUtil::SanitizePath(path_); | 43 | const auto path = Common::FS::SanitizePath(path_); |
| 44 | return root->GetFileRelative(path); | 44 | return root->GetFileRelative(path); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 47 | VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) { |
| 48 | const auto path = FileUtil::SanitizePath(path_); | 48 | const auto path = Common::FS::SanitizePath(path_); |
| 49 | return root->CreateFileRelative(path); | 49 | return root->CreateFileRelative(path); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { | 52 | VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { |
| 53 | const auto old_path = FileUtil::SanitizePath(old_path_); | 53 | const auto old_path = Common::FS::SanitizePath(old_path_); |
| 54 | const auto new_path = FileUtil::SanitizePath(new_path_); | 54 | const auto new_path = Common::FS::SanitizePath(new_path_); |
| 55 | 55 | ||
| 56 | // VfsDirectory impls are only required to implement copy across the current directory. | 56 | // VfsDirectory impls are only required to implement copy across the current directory. |
| 57 | if (FileUtil::GetParentPath(old_path) == FileUtil::GetParentPath(new_path)) { | 57 | if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) { |
| 58 | if (!root->Copy(FileUtil::GetFilename(old_path), FileUtil::GetFilename(new_path))) | 58 | if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path))) |
| 59 | return nullptr; | 59 | return nullptr; |
| 60 | return OpenFile(new_path, Mode::ReadWrite); | 60 | return OpenFile(new_path, Mode::ReadWrite); |
| 61 | } | 61 | } |
| @@ -76,8 +76,8 @@ VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view new_path) { | 78 | VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view new_path) { |
| 79 | const auto sanitized_old_path = FileUtil::SanitizePath(old_path); | 79 | const auto sanitized_old_path = Common::FS::SanitizePath(old_path); |
| 80 | const auto sanitized_new_path = FileUtil::SanitizePath(new_path); | 80 | const auto sanitized_new_path = Common::FS::SanitizePath(new_path); |
| 81 | 81 | ||
| 82 | // Again, non-default impls are highly encouraged to provide a more optimized version of this. | 82 | // Again, non-default impls are highly encouraged to provide a more optimized version of this. |
| 83 | auto out = CopyFile(sanitized_old_path, sanitized_new_path); | 83 | auto out = CopyFile(sanitized_old_path, sanitized_new_path); |
| @@ -89,26 +89,26 @@ VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | bool VfsFilesystem::DeleteFile(std::string_view path_) { | 91 | bool VfsFilesystem::DeleteFile(std::string_view path_) { |
| 92 | const auto path = FileUtil::SanitizePath(path_); | 92 | const auto path = Common::FS::SanitizePath(path_); |
| 93 | auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write); | 93 | auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); |
| 94 | if (parent == nullptr) | 94 | if (parent == nullptr) |
| 95 | return false; | 95 | return false; |
| 96 | return parent->DeleteFile(FileUtil::GetFilename(path)); | 96 | return parent->DeleteFile(Common::FS::GetFilename(path)); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { | 99 | VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { |
| 100 | const auto path = FileUtil::SanitizePath(path_); | 100 | const auto path = Common::FS::SanitizePath(path_); |
| 101 | return root->GetDirectoryRelative(path); | 101 | return root->GetDirectoryRelative(path); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { | 104 | VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { |
| 105 | const auto path = FileUtil::SanitizePath(path_); | 105 | const auto path = Common::FS::SanitizePath(path_); |
| 106 | return root->CreateDirectoryRelative(path); | 106 | return root->CreateDirectoryRelative(path); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_view new_path_) { | 109 | VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_view new_path_) { |
| 110 | const auto old_path = FileUtil::SanitizePath(old_path_); | 110 | const auto old_path = Common::FS::SanitizePath(old_path_); |
| 111 | const auto new_path = FileUtil::SanitizePath(new_path_); | 111 | const auto new_path = Common::FS::SanitizePath(new_path_); |
| 112 | 112 | ||
| 113 | // Non-default impls are highly encouraged to provide a more optimized version of this. | 113 | // Non-default impls are highly encouraged to provide a more optimized version of this. |
| 114 | auto old_dir = OpenDirectory(old_path, Mode::Read); | 114 | auto old_dir = OpenDirectory(old_path, Mode::Read); |
| @@ -139,8 +139,8 @@ VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_ | |||
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_view new_path) { | 141 | VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_view new_path) { |
| 142 | const auto sanitized_old_path = FileUtil::SanitizePath(old_path); | 142 | const auto sanitized_old_path = Common::FS::SanitizePath(old_path); |
| 143 | const auto sanitized_new_path = FileUtil::SanitizePath(new_path); | 143 | const auto sanitized_new_path = Common::FS::SanitizePath(new_path); |
| 144 | 144 | ||
| 145 | // Non-default impls are highly encouraged to provide a more optimized version of this. | 145 | // Non-default impls are highly encouraged to provide a more optimized version of this. |
| 146 | auto out = CopyDirectory(sanitized_old_path, sanitized_new_path); | 146 | auto out = CopyDirectory(sanitized_old_path, sanitized_new_path); |
| @@ -152,17 +152,17 @@ VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_v | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | bool VfsFilesystem::DeleteDirectory(std::string_view path_) { | 154 | bool VfsFilesystem::DeleteDirectory(std::string_view path_) { |
| 155 | const auto path = FileUtil::SanitizePath(path_); | 155 | const auto path = Common::FS::SanitizePath(path_); |
| 156 | auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write); | 156 | auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); |
| 157 | if (parent == nullptr) | 157 | if (parent == nullptr) |
| 158 | return false; | 158 | return false; |
| 159 | return parent->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path)); | 159 | return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path)); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | VfsFile::~VfsFile() = default; | 162 | VfsFile::~VfsFile() = default; |
| 163 | 163 | ||
| 164 | std::string VfsFile::GetExtension() const { | 164 | std::string VfsFile::GetExtension() const { |
| 165 | return std::string(FileUtil::GetExtensionFromFilename(GetName())); | 165 | return std::string(Common::FS::GetExtensionFromFilename(GetName())); |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | VfsDirectory::~VfsDirectory() = default; | 168 | VfsDirectory::~VfsDirectory() = default; |
| @@ -203,7 +203,7 @@ std::string VfsFile::GetFullPath() const { | |||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) const { | 205 | std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) const { |
| 206 | auto vec = FileUtil::SplitPathComponents(path); | 206 | auto vec = Common::FS::SplitPathComponents(path); |
| 207 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), | 207 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), |
| 208 | vec.end()); | 208 | vec.end()); |
| 209 | if (vec.empty()) { | 209 | if (vec.empty()) { |
| @@ -239,7 +239,7 @@ std::shared_ptr<VfsFile> VfsDirectory::GetFileAbsolute(std::string_view path) co | |||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | std::shared_ptr<VfsDirectory> VfsDirectory::GetDirectoryRelative(std::string_view path) const { | 241 | std::shared_ptr<VfsDirectory> VfsDirectory::GetDirectoryRelative(std::string_view path) const { |
| 242 | auto vec = FileUtil::SplitPathComponents(path); | 242 | auto vec = Common::FS::SplitPathComponents(path); |
| 243 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), | 243 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), |
| 244 | vec.end()); | 244 | vec.end()); |
| 245 | if (vec.empty()) { | 245 | if (vec.empty()) { |
| @@ -301,7 +301,7 @@ std::size_t VfsDirectory::GetSize() const { | |||
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | std::shared_ptr<VfsFile> VfsDirectory::CreateFileRelative(std::string_view path) { | 303 | std::shared_ptr<VfsFile> VfsDirectory::CreateFileRelative(std::string_view path) { |
| 304 | auto vec = FileUtil::SplitPathComponents(path); | 304 | auto vec = Common::FS::SplitPathComponents(path); |
| 305 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), | 305 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), |
| 306 | vec.end()); | 306 | vec.end()); |
| 307 | if (vec.empty()) { | 307 | if (vec.empty()) { |
| @@ -320,7 +320,7 @@ std::shared_ptr<VfsFile> VfsDirectory::CreateFileRelative(std::string_view path) | |||
| 320 | } | 320 | } |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | return dir->CreateFileRelative(FileUtil::GetPathWithoutTop(path)); | 323 | return dir->CreateFileRelative(Common::FS::GetPathWithoutTop(path)); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path) { | 326 | std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path) { |
| @@ -332,7 +332,7 @@ std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path) | |||
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryRelative(std::string_view path) { | 334 | std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryRelative(std::string_view path) { |
| 335 | auto vec = FileUtil::SplitPathComponents(path); | 335 | auto vec = Common::FS::SplitPathComponents(path); |
| 336 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), | 336 | vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), |
| 337 | vec.end()); | 337 | vec.end()); |
| 338 | if (vec.empty()) { | 338 | if (vec.empty()) { |
| @@ -351,7 +351,7 @@ std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryRelative(std::string_ | |||
| 351 | } | 351 | } |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | return dir->CreateDirectoryRelative(FileUtil::GetPathWithoutTop(path)); | 354 | return dir->CreateDirectoryRelative(Common::FS::GetPathWithoutTop(path)); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryAbsolute(std::string_view path) { | 357 | std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryAbsolute(std::string_view path) { |
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp index d69952940..429d7bc8b 100644 --- a/src/core/file_sys/vfs_libzip.cpp +++ b/src/core/file_sys/vfs_libzip.cpp | |||
| @@ -49,7 +49,7 @@ VirtualDir ExtractZIP(VirtualFile file) { | |||
| 49 | if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size())) | 49 | if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size())) |
| 50 | return nullptr; | 50 | return nullptr; |
| 51 | 51 | ||
| 52 | const auto parts = FileUtil::SplitPathComponents(stat.name); | 52 | const auto parts = Common::FS::SplitPathComponents(stat.name); |
| 53 | const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back()); | 53 | const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back()); |
| 54 | 54 | ||
| 55 | std::shared_ptr<VectorVfsDirectory> dtrv = out; | 55 | std::shared_ptr<VectorVfsDirectory> dtrv = out; |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 0db0091f6..1dbf632c1 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -14,6 +14,8 @@ | |||
| 14 | 14 | ||
| 15 | namespace FileSys { | 15 | namespace FileSys { |
| 16 | 16 | ||
| 17 | namespace FS = Common::FS; | ||
| 18 | |||
| 17 | static std::string ModeFlagsToString(Mode mode) { | 19 | static std::string ModeFlagsToString(Mode mode) { |
| 18 | std::string mode_str; | 20 | std::string mode_str; |
| 19 | 21 | ||
| @@ -57,17 +59,19 @@ bool RealVfsFilesystem::IsWritable() const { | |||
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { | 61 | VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { |
| 60 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 62 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 61 | if (!FileUtil::Exists(path)) | 63 | if (!FS::Exists(path)) { |
| 62 | return VfsEntryType::None; | 64 | return VfsEntryType::None; |
| 63 | if (FileUtil::IsDirectory(path)) | 65 | } |
| 66 | if (FS::IsDirectory(path)) { | ||
| 64 | return VfsEntryType::Directory; | 67 | return VfsEntryType::Directory; |
| 68 | } | ||
| 65 | 69 | ||
| 66 | return VfsEntryType::File; | 70 | return VfsEntryType::File; |
| 67 | } | 71 | } |
| 68 | 72 | ||
| 69 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 73 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { |
| 70 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 74 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 71 | if (cache.find(path) != cache.end()) { | 75 | if (cache.find(path) != cache.end()) { |
| 72 | auto weak = cache[path]; | 76 | auto weak = cache[path]; |
| 73 | if (!weak.expired()) { | 77 | if (!weak.expired()) { |
| @@ -75,11 +79,11 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | |||
| 75 | } | 79 | } |
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) { | 82 | if (!FS::Exists(path) && True(perms & Mode::WriteAppend)) { |
| 79 | FileUtil::CreateEmptyFile(path); | 83 | FS::CreateEmptyFile(path); |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | auto backing = std::make_shared<FileUtil::IOFile>(path, ModeFlagsToString(perms).c_str()); | 86 | auto backing = std::make_shared<FS::IOFile>(path, ModeFlagsToString(perms).c_str()); |
| 83 | cache[path] = backing; | 87 | cache[path] = backing; |
| 84 | 88 | ||
| 85 | // Cannot use make_shared as RealVfsFile constructor is private | 89 | // Cannot use make_shared as RealVfsFile constructor is private |
| @@ -87,33 +91,31 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | |||
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 93 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { |
| 90 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 94 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 91 | const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); | 95 | const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash); |
| 92 | if (!FileUtil::Exists(path)) { | 96 | if (!FS::Exists(path)) { |
| 93 | FileUtil::CreateFullPath(path_fwd); | 97 | FS::CreateFullPath(path_fwd); |
| 94 | if (!FileUtil::CreateEmptyFile(path)) | 98 | if (!FS::CreateEmptyFile(path)) { |
| 95 | return nullptr; | 99 | return nullptr; |
| 100 | } | ||
| 96 | } | 101 | } |
| 97 | return OpenFile(path, perms); | 102 | return OpenFile(path, perms); |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { | 105 | VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { |
| 101 | const auto old_path = | 106 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); |
| 102 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); | 107 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); |
| 103 | const auto new_path = | ||
| 104 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 105 | 108 | ||
| 106 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 109 | if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) || |
| 107 | FileUtil::IsDirectory(old_path) || !FileUtil::Copy(old_path, new_path)) | 110 | !FS::Copy(old_path, new_path)) { |
| 108 | return nullptr; | 111 | return nullptr; |
| 112 | } | ||
| 109 | return OpenFile(new_path, Mode::ReadWrite); | 113 | return OpenFile(new_path, Mode::ReadWrite); |
| 110 | } | 114 | } |
| 111 | 115 | ||
| 112 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { | 116 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { |
| 113 | const auto old_path = | 117 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); |
| 114 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); | 118 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); |
| 115 | const auto new_path = | ||
| 116 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 117 | 119 | ||
| 118 | if (cache.find(old_path) != cache.end()) { | 120 | if (cache.find(old_path) != cache.end()) { |
| 119 | auto file = cache[old_path].lock(); | 121 | auto file = cache[old_path].lock(); |
| @@ -122,8 +124,8 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_ | |||
| 122 | file->Close(); | 124 | file->Close(); |
| 123 | } | 125 | } |
| 124 | 126 | ||
| 125 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 127 | if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) || |
| 126 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) { | 128 | !FS::Rename(old_path, new_path)) { |
| 127 | return nullptr; | 129 | return nullptr; |
| 128 | } | 130 | } |
| 129 | 131 | ||
| @@ -139,28 +141,30 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_ | |||
| 139 | } | 141 | } |
| 140 | 142 | ||
| 141 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { | 143 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { |
| 142 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 144 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 143 | if (cache.find(path) != cache.end()) { | 145 | if (cache.find(path) != cache.end()) { |
| 144 | if (!cache[path].expired()) | 146 | if (!cache[path].expired()) { |
| 145 | cache[path].lock()->Close(); | 147 | cache[path].lock()->Close(); |
| 148 | } | ||
| 146 | cache.erase(path); | 149 | cache.erase(path); |
| 147 | } | 150 | } |
| 148 | return FileUtil::Delete(path); | 151 | return FS::Delete(path); |
| 149 | } | 152 | } |
| 150 | 153 | ||
| 151 | VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { | 154 | VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { |
| 152 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 155 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 153 | // Cannot use make_shared as RealVfsDirectory constructor is private | 156 | // Cannot use make_shared as RealVfsDirectory constructor is private |
| 154 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); | 157 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); |
| 155 | } | 158 | } |
| 156 | 159 | ||
| 157 | VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { | 160 | VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { |
| 158 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 161 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 159 | const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); | 162 | const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash); |
| 160 | if (!FileUtil::Exists(path)) { | 163 | if (!FS::Exists(path)) { |
| 161 | FileUtil::CreateFullPath(path_fwd); | 164 | FS::CreateFullPath(path_fwd); |
| 162 | if (!FileUtil::CreateDir(path)) | 165 | if (!FS::CreateDir(path)) { |
| 163 | return nullptr; | 166 | return nullptr; |
| 167 | } | ||
| 164 | } | 168 | } |
| 165 | // Cannot use make_shared as RealVfsDirectory constructor is private | 169 | // Cannot use make_shared as RealVfsDirectory constructor is private |
| 166 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); | 170 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); |
| @@ -168,35 +172,33 @@ VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms | |||
| 168 | 172 | ||
| 169 | VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, | 173 | VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, |
| 170 | std::string_view new_path_) { | 174 | std::string_view new_path_) { |
| 171 | const auto old_path = | 175 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); |
| 172 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); | 176 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); |
| 173 | const auto new_path = | 177 | if (!FS::Exists(old_path) || FS::Exists(new_path) || !FS::IsDirectory(old_path)) { |
| 174 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 175 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | ||
| 176 | !FileUtil::IsDirectory(old_path)) | ||
| 177 | return nullptr; | 178 | return nullptr; |
| 178 | FileUtil::CopyDir(old_path, new_path); | 179 | } |
| 180 | FS::CopyDir(old_path, new_path); | ||
| 179 | return OpenDirectory(new_path, Mode::ReadWrite); | 181 | return OpenDirectory(new_path, Mode::ReadWrite); |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, | 184 | VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, |
| 183 | std::string_view new_path_) { | 185 | std::string_view new_path_) { |
| 184 | const auto old_path = | 186 | const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault); |
| 185 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); | 187 | const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault); |
| 186 | const auto new_path = | 188 | |
| 187 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | 189 | if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) || |
| 188 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 190 | !FS::Rename(old_path, new_path)) { |
| 189 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) | ||
| 190 | return nullptr; | 191 | return nullptr; |
| 192 | } | ||
| 191 | 193 | ||
| 192 | for (auto& kv : cache) { | 194 | for (auto& kv : cache) { |
| 193 | // Path in cache starts with old_path | 195 | // Path in cache starts with old_path |
| 194 | if (kv.first.rfind(old_path, 0) == 0) { | 196 | if (kv.first.rfind(old_path, 0) == 0) { |
| 195 | const auto file_old_path = | 197 | const auto file_old_path = |
| 196 | FileUtil::SanitizePath(kv.first, FileUtil::DirectorySeparator::PlatformDefault); | 198 | FS::SanitizePath(kv.first, FS::DirectorySeparator::PlatformDefault); |
| 197 | const auto file_new_path = | 199 | const auto file_new_path = |
| 198 | FileUtil::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()), | 200 | FS::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()), |
| 199 | FileUtil::DirectorySeparator::PlatformDefault); | 201 | FS::DirectorySeparator::PlatformDefault); |
| 200 | auto cached = cache[file_old_path]; | 202 | auto cached = cache[file_old_path]; |
| 201 | if (!cached.expired()) { | 203 | if (!cached.expired()) { |
| 202 | auto file = cached.lock(); | 204 | auto file = cached.lock(); |
| @@ -211,24 +213,24 @@ VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, | |||
| 211 | } | 213 | } |
| 212 | 214 | ||
| 213 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { | 215 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { |
| 214 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); | 216 | const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); |
| 215 | for (auto& kv : cache) { | 217 | for (auto& kv : cache) { |
| 216 | // Path in cache starts with old_path | 218 | // Path in cache starts with old_path |
| 217 | if (kv.first.rfind(path, 0) == 0) { | 219 | if (kv.first.rfind(path, 0) == 0) { |
| 218 | if (!cache[kv.first].expired()) | 220 | if (!cache[kv.first].expired()) { |
| 219 | cache[kv.first].lock()->Close(); | 221 | cache[kv.first].lock()->Close(); |
| 222 | } | ||
| 220 | cache.erase(kv.first); | 223 | cache.erase(kv.first); |
| 221 | } | 224 | } |
| 222 | } | 225 | } |
| 223 | return FileUtil::DeleteDirRecursively(path); | 226 | return FS::DeleteDirRecursively(path); |
| 224 | } | 227 | } |
| 225 | 228 | ||
| 226 | RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::shared_ptr<FileUtil::IOFile> backing_, | 229 | RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::shared_ptr<FS::IOFile> backing_, |
| 227 | const std::string& path_, Mode perms_) | 230 | const std::string& path_, Mode perms_) |
| 228 | : base(base_), backing(std::move(backing_)), path(path_), | 231 | : base(base_), backing(std::move(backing_)), path(path_), parent_path(FS::GetParentPath(path_)), |
| 229 | parent_path(FileUtil::GetParentPath(path_)), | 232 | path_components(FS::SplitPathComponents(path_)), |
| 230 | path_components(FileUtil::SplitPathComponents(path_)), | 233 | parent_components(FS::SliceVector(path_components, 0, path_components.size() - 1)), |
| 231 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | ||
| 232 | perms(perms_) {} | 234 | perms(perms_) {} |
| 233 | 235 | ||
| 234 | RealVfsFile::~RealVfsFile() = default; | 236 | RealVfsFile::~RealVfsFile() = default; |
| @@ -258,14 +260,16 @@ bool RealVfsFile::IsReadable() const { | |||
| 258 | } | 260 | } |
| 259 | 261 | ||
| 260 | std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { | 262 | std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { |
| 261 | if (!backing->Seek(offset, SEEK_SET)) | 263 | if (!backing->Seek(offset, SEEK_SET)) { |
| 262 | return 0; | 264 | return 0; |
| 265 | } | ||
| 263 | return backing->ReadBytes(data, length); | 266 | return backing->ReadBytes(data, length); |
| 264 | } | 267 | } |
| 265 | 268 | ||
| 266 | std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) { | 269 | std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) { |
| 267 | if (!backing->Seek(offset, SEEK_SET)) | 270 | if (!backing->Seek(offset, SEEK_SET)) { |
| 268 | return 0; | 271 | return 0; |
| 272 | } | ||
| 269 | return backing->WriteBytes(data, length); | 273 | return backing->WriteBytes(data, length); |
| 270 | } | 274 | } |
| 271 | 275 | ||
| @@ -282,16 +286,18 @@ bool RealVfsFile::Close() { | |||
| 282 | 286 | ||
| 283 | template <> | 287 | template <> |
| 284 | std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const { | 288 | std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const { |
| 285 | if (perms == Mode::Append) | 289 | if (perms == Mode::Append) { |
| 286 | return {}; | 290 | return {}; |
| 291 | } | ||
| 287 | 292 | ||
| 288 | std::vector<VirtualFile> out; | 293 | std::vector<VirtualFile> out; |
| 289 | FileUtil::ForeachDirectoryEntry( | 294 | FS::ForeachDirectoryEntry( |
| 290 | nullptr, path, | 295 | nullptr, path, |
| 291 | [&out, this](u64* entries_out, const std::string& directory, const std::string& filename) { | 296 | [&out, this](u64* entries_out, const std::string& directory, const std::string& filename) { |
| 292 | const std::string full_path = directory + DIR_SEP + filename; | 297 | const std::string full_path = directory + DIR_SEP + filename; |
| 293 | if (!FileUtil::IsDirectory(full_path)) | 298 | if (!FS::IsDirectory(full_path)) { |
| 294 | out.emplace_back(base.OpenFile(full_path, perms)); | 299 | out.emplace_back(base.OpenFile(full_path, perms)); |
| 300 | } | ||
| 295 | return true; | 301 | return true; |
| 296 | }); | 302 | }); |
| 297 | 303 | ||
| @@ -300,16 +306,18 @@ std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>( | |||
| 300 | 306 | ||
| 301 | template <> | 307 | template <> |
| 302 | std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const { | 308 | std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const { |
| 303 | if (perms == Mode::Append) | 309 | if (perms == Mode::Append) { |
| 304 | return {}; | 310 | return {}; |
| 311 | } | ||
| 305 | 312 | ||
| 306 | std::vector<VirtualDir> out; | 313 | std::vector<VirtualDir> out; |
| 307 | FileUtil::ForeachDirectoryEntry( | 314 | FS::ForeachDirectoryEntry( |
| 308 | nullptr, path, | 315 | nullptr, path, |
| 309 | [&out, this](u64* entries_out, const std::string& directory, const std::string& filename) { | 316 | [&out, this](u64* entries_out, const std::string& directory, const std::string& filename) { |
| 310 | const std::string full_path = directory + DIR_SEP + filename; | 317 | const std::string full_path = directory + DIR_SEP + filename; |
| 311 | if (FileUtil::IsDirectory(full_path)) | 318 | if (FS::IsDirectory(full_path)) { |
| 312 | out.emplace_back(base.OpenDirectory(full_path, perms)); | 319 | out.emplace_back(base.OpenDirectory(full_path, perms)); |
| 320 | } | ||
| 313 | return true; | 321 | return true; |
| 314 | }); | 322 | }); |
| 315 | 323 | ||
| @@ -317,29 +325,30 @@ std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDi | |||
| 317 | } | 325 | } |
| 318 | 326 | ||
| 319 | RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_) | 327 | RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_) |
| 320 | : base(base_), path(FileUtil::RemoveTrailingSlash(path_)), | 328 | : base(base_), path(FS::RemoveTrailingSlash(path_)), parent_path(FS::GetParentPath(path)), |
| 321 | parent_path(FileUtil::GetParentPath(path)), | 329 | path_components(FS::SplitPathComponents(path)), |
| 322 | path_components(FileUtil::SplitPathComponents(path)), | 330 | parent_components(FS::SliceVector(path_components, 0, path_components.size() - 1)), |
| 323 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | ||
| 324 | perms(perms_) { | 331 | perms(perms_) { |
| 325 | if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) { | 332 | if (!FS::Exists(path) && True(perms & Mode::WriteAppend)) { |
| 326 | FileUtil::CreateDir(path); | 333 | FS::CreateDir(path); |
| 327 | } | 334 | } |
| 328 | } | 335 | } |
| 329 | 336 | ||
| 330 | RealVfsDirectory::~RealVfsDirectory() = default; | 337 | RealVfsDirectory::~RealVfsDirectory() = default; |
| 331 | 338 | ||
| 332 | std::shared_ptr<VfsFile> RealVfsDirectory::GetFileRelative(std::string_view path) const { | 339 | std::shared_ptr<VfsFile> RealVfsDirectory::GetFileRelative(std::string_view path) const { |
| 333 | const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); | 340 | const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); |
| 334 | if (!FileUtil::Exists(full_path) || FileUtil::IsDirectory(full_path)) | 341 | if (!FS::Exists(full_path) || FS::IsDirectory(full_path)) { |
| 335 | return nullptr; | 342 | return nullptr; |
| 343 | } | ||
| 336 | return base.OpenFile(full_path, perms); | 344 | return base.OpenFile(full_path, perms); |
| 337 | } | 345 | } |
| 338 | 346 | ||
| 339 | std::shared_ptr<VfsDirectory> RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { | 347 | std::shared_ptr<VfsDirectory> RealVfsDirectory::GetDirectoryRelative(std::string_view path) const { |
| 340 | const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); | 348 | const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); |
| 341 | if (!FileUtil::Exists(full_path) || !FileUtil::IsDirectory(full_path)) | 349 | if (!FS::Exists(full_path) || !FS::IsDirectory(full_path)) { |
| 342 | return nullptr; | 350 | return nullptr; |
| 351 | } | ||
| 343 | return base.OpenDirectory(full_path, perms); | 352 | return base.OpenDirectory(full_path, perms); |
| 344 | } | 353 | } |
| 345 | 354 | ||
| @@ -352,17 +361,17 @@ std::shared_ptr<VfsDirectory> RealVfsDirectory::GetSubdirectory(std::string_view | |||
| 352 | } | 361 | } |
| 353 | 362 | ||
| 354 | std::shared_ptr<VfsFile> RealVfsDirectory::CreateFileRelative(std::string_view path) { | 363 | std::shared_ptr<VfsFile> RealVfsDirectory::CreateFileRelative(std::string_view path) { |
| 355 | const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); | 364 | const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); |
| 356 | return base.CreateFile(full_path, perms); | 365 | return base.CreateFile(full_path, perms); |
| 357 | } | 366 | } |
| 358 | 367 | ||
| 359 | std::shared_ptr<VfsDirectory> RealVfsDirectory::CreateDirectoryRelative(std::string_view path) { | 368 | std::shared_ptr<VfsDirectory> RealVfsDirectory::CreateDirectoryRelative(std::string_view path) { |
| 360 | const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path)); | 369 | const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path)); |
| 361 | return base.CreateDirectory(full_path, perms); | 370 | return base.CreateDirectory(full_path, perms); |
| 362 | } | 371 | } |
| 363 | 372 | ||
| 364 | bool RealVfsDirectory::DeleteSubdirectoryRecursive(std::string_view name) { | 373 | bool RealVfsDirectory::DeleteSubdirectoryRecursive(std::string_view name) { |
| 365 | auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(name)); | 374 | const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(name)); |
| 366 | return base.DeleteDirectory(full_path); | 375 | return base.DeleteDirectory(full_path); |
| 367 | } | 376 | } |
| 368 | 377 | ||
| @@ -387,8 +396,9 @@ std::string RealVfsDirectory::GetName() const { | |||
| 387 | } | 396 | } |
| 388 | 397 | ||
| 389 | std::shared_ptr<VfsDirectory> RealVfsDirectory::GetParentDirectory() const { | 398 | std::shared_ptr<VfsDirectory> RealVfsDirectory::GetParentDirectory() const { |
| 390 | if (path_components.size() <= 1) | 399 | if (path_components.size() <= 1) { |
| 391 | return nullptr; | 400 | return nullptr; |
| 401 | } | ||
| 392 | 402 | ||
| 393 | return base.OpenDirectory(parent_path, perms); | 403 | return base.OpenDirectory(parent_path, perms); |
| 394 | } | 404 | } |
| @@ -425,16 +435,17 @@ std::string RealVfsDirectory::GetFullPath() const { | |||
| 425 | } | 435 | } |
| 426 | 436 | ||
| 427 | std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const { | 437 | std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const { |
| 428 | if (perms == Mode::Append) | 438 | if (perms == Mode::Append) { |
| 429 | return {}; | 439 | return {}; |
| 440 | } | ||
| 430 | 441 | ||
| 431 | std::map<std::string, VfsEntryType, std::less<>> out; | 442 | std::map<std::string, VfsEntryType, std::less<>> out; |
| 432 | FileUtil::ForeachDirectoryEntry( | 443 | FS::ForeachDirectoryEntry( |
| 433 | nullptr, path, | 444 | nullptr, path, |
| 434 | [&out](u64* entries_out, const std::string& directory, const std::string& filename) { | 445 | [&out](u64* entries_out, const std::string& directory, const std::string& filename) { |
| 435 | const std::string full_path = directory + DIR_SEP + filename; | 446 | const std::string full_path = directory + DIR_SEP + filename; |
| 436 | out.emplace(filename, FileUtil::IsDirectory(full_path) ? VfsEntryType::Directory | 447 | out.emplace(filename, |
| 437 | : VfsEntryType::File); | 448 | FS::IsDirectory(full_path) ? VfsEntryType::Directory : VfsEntryType::File); |
| 438 | return true; | 449 | return true; |
| 439 | }); | 450 | }); |
| 440 | 451 | ||
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index a0a857a31..0b537b22c 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "core/file_sys/mode.h" | 9 | #include "core/file_sys/mode.h" |
| 10 | #include "core/file_sys/vfs.h" | 10 | #include "core/file_sys/vfs.h" |
| 11 | 11 | ||
| 12 | namespace FileUtil { | 12 | namespace Common::FS { |
| 13 | class IOFile; | 13 | class IOFile; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| @@ -36,7 +36,7 @@ public: | |||
| 36 | bool DeleteDirectory(std::string_view path) override; | 36 | bool DeleteDirectory(std::string_view path) override; |
| 37 | 37 | ||
| 38 | private: | 38 | private: |
| 39 | boost::container::flat_map<std::string, std::weak_ptr<FileUtil::IOFile>> cache; | 39 | boost::container::flat_map<std::string, std::weak_ptr<Common::FS::IOFile>> cache; |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | // An implmentation of VfsFile that represents a file on the user's computer. | 42 | // An implmentation of VfsFile that represents a file on the user's computer. |
| @@ -58,13 +58,13 @@ public: | |||
| 58 | bool Rename(std::string_view name) override; | 58 | bool Rename(std::string_view name) override; |
| 59 | 59 | ||
| 60 | private: | 60 | private: |
| 61 | RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<FileUtil::IOFile> backing, | 61 | RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<Common::FS::IOFile> backing, |
| 62 | const std::string& path, Mode perms = Mode::Read); | 62 | const std::string& path, Mode perms = Mode::Read); |
| 63 | 63 | ||
| 64 | bool Close(); | 64 | bool Close(); |
| 65 | 65 | ||
| 66 | RealVfsFilesystem& base; | 66 | RealVfsFilesystem& base; |
| 67 | std::shared_ptr<FileUtil::IOFile> backing; | 67 | std::shared_ptr<Common::FS::IOFile> backing; |
| 68 | std::string path; | 68 | std::string path; |
| 69 | std::string parent_path; | 69 | std::string parent_path; |
| 70 | std::vector<std::string> path_components; | 70 | std::vector<std::string> path_components; |
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index 81413c684..ccf5966d0 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp | |||
| @@ -44,7 +44,7 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) { | 46 | NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) { |
| 47 | std::string path = FileUtil::SanitizePath(file->GetFullPath()); | 47 | std::string path = Common::FS::SanitizePath(file->GetFullPath()); |
| 48 | static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca", | 48 | static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca", |
| 49 | std::regex_constants::ECMAScript | | 49 | std::regex_constants::ECMAScript | |
| 50 | std::regex_constants::icase); | 50 | std::regex_constants::icase); |