diff options
| author | 2020-08-17 22:35:30 -0400 | |
|---|---|---|
| committer | 2020-08-17 22:35:30 -0400 | |
| commit | 56c6a5def85cfd3001c88d69374e3fb164272b9e (patch) | |
| tree | dfdceb64cc5c6c4f80f384206a080f77d7cc40ae /src/core/file_sys/vfs.cpp | |
| parent | Merge pull request #4537 from lioncash/tz (diff) | |
| parent | common/fileutil: Convert namespace to Common::FS (diff) | |
| download | yuzu-56c6a5def85cfd3001c88d69374e3fb164272b9e.tar.gz yuzu-56c6a5def85cfd3001c88d69374e3fb164272b9e.tar.xz yuzu-56c6a5def85cfd3001c88d69374e3fb164272b9e.zip | |
Merge pull request #4535 from lioncash/fileutil
common/fileutil: Convert namespace to Common::FS
Diffstat (limited to 'src/core/file_sys/vfs.cpp')
| -rw-r--r-- | src/core/file_sys/vfs.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
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) { |