From c4ed791164df7e3e74042a37a62077b4dc4ade91 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 15 Aug 2020 08:33:16 -0400 Subject: 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. --- src/core/file_sys/vfs.cpp | 56 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/core/file_sys/vfs.cpp') 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 { } VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { - const auto path = FileUtil::SanitizePath(path_); + const auto path = Common::FS::SanitizePath(path_); if (root->GetFileRelative(path) != nullptr) return VfsEntryType::File; if (root->GetDirectoryRelative(path) != nullptr) @@ -40,22 +40,22 @@ VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { } VirtualFile VfsFilesystem::OpenFile(std::string_view path_, Mode perms) { - const auto path = FileUtil::SanitizePath(path_); + const auto path = Common::FS::SanitizePath(path_); return root->GetFileRelative(path); } VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) { - const auto path = FileUtil::SanitizePath(path_); + const auto path = Common::FS::SanitizePath(path_); return root->CreateFileRelative(path); } VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { - const auto old_path = FileUtil::SanitizePath(old_path_); - const auto new_path = FileUtil::SanitizePath(new_path_); + const auto old_path = Common::FS::SanitizePath(old_path_); + const auto new_path = Common::FS::SanitizePath(new_path_); // VfsDirectory impls are only required to implement copy across the current directory. - if (FileUtil::GetParentPath(old_path) == FileUtil::GetParentPath(new_path)) { - if (!root->Copy(FileUtil::GetFilename(old_path), FileUtil::GetFilename(new_path))) + if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) { + if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path))) return nullptr; return OpenFile(new_path, Mode::ReadWrite); } @@ -76,8 +76,8 @@ VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view } VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view new_path) { - const auto sanitized_old_path = FileUtil::SanitizePath(old_path); - const auto sanitized_new_path = FileUtil::SanitizePath(new_path); + const auto sanitized_old_path = Common::FS::SanitizePath(old_path); + const auto sanitized_new_path = Common::FS::SanitizePath(new_path); // Again, non-default impls are highly encouraged to provide a more optimized version of this. auto out = CopyFile(sanitized_old_path, sanitized_new_path); @@ -89,26 +89,26 @@ VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view } bool VfsFilesystem::DeleteFile(std::string_view path_) { - const auto path = FileUtil::SanitizePath(path_); - auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write); + const auto path = Common::FS::SanitizePath(path_); + auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); if (parent == nullptr) return false; - return parent->DeleteFile(FileUtil::GetFilename(path)); + return parent->DeleteFile(Common::FS::GetFilename(path)); } VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { - const auto path = FileUtil::SanitizePath(path_); + const auto path = Common::FS::SanitizePath(path_); return root->GetDirectoryRelative(path); } VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { - const auto path = FileUtil::SanitizePath(path_); + const auto path = Common::FS::SanitizePath(path_); return root->CreateDirectoryRelative(path); } VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_view new_path_) { - const auto old_path = FileUtil::SanitizePath(old_path_); - const auto new_path = FileUtil::SanitizePath(new_path_); + const auto old_path = Common::FS::SanitizePath(old_path_); + const auto new_path = Common::FS::SanitizePath(new_path_); // Non-default impls are highly encouraged to provide a more optimized version of this. auto old_dir = OpenDirectory(old_path, Mode::Read); @@ -139,8 +139,8 @@ VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_ } VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_view new_path) { - const auto sanitized_old_path = FileUtil::SanitizePath(old_path); - const auto sanitized_new_path = FileUtil::SanitizePath(new_path); + const auto sanitized_old_path = Common::FS::SanitizePath(old_path); + const auto sanitized_new_path = Common::FS::SanitizePath(new_path); // Non-default impls are highly encouraged to provide a more optimized version of this. auto out = CopyDirectory(sanitized_old_path, sanitized_new_path); @@ -152,17 +152,17 @@ VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_v } bool VfsFilesystem::DeleteDirectory(std::string_view path_) { - const auto path = FileUtil::SanitizePath(path_); - auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write); + const auto path = Common::FS::SanitizePath(path_); + auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); if (parent == nullptr) return false; - return parent->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path)); + return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path)); } VfsFile::~VfsFile() = default; std::string VfsFile::GetExtension() const { - return std::string(FileUtil::GetExtensionFromFilename(GetName())); + return std::string(Common::FS::GetExtensionFromFilename(GetName())); } VfsDirectory::~VfsDirectory() = default; @@ -203,7 +203,7 @@ std::string VfsFile::GetFullPath() const { } std::shared_ptr VfsDirectory::GetFileRelative(std::string_view path) const { - auto vec = FileUtil::SplitPathComponents(path); + auto vec = Common::FS::SplitPathComponents(path); vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), vec.end()); if (vec.empty()) { @@ -239,7 +239,7 @@ std::shared_ptr VfsDirectory::GetFileAbsolute(std::string_view path) co } std::shared_ptr VfsDirectory::GetDirectoryRelative(std::string_view path) const { - auto vec = FileUtil::SplitPathComponents(path); + auto vec = Common::FS::SplitPathComponents(path); vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), vec.end()); if (vec.empty()) { @@ -301,7 +301,7 @@ std::size_t VfsDirectory::GetSize() const { } std::shared_ptr VfsDirectory::CreateFileRelative(std::string_view path) { - auto vec = FileUtil::SplitPathComponents(path); + auto vec = Common::FS::SplitPathComponents(path); vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), vec.end()); if (vec.empty()) { @@ -320,7 +320,7 @@ std::shared_ptr VfsDirectory::CreateFileRelative(std::string_view path) } } - return dir->CreateFileRelative(FileUtil::GetPathWithoutTop(path)); + return dir->CreateFileRelative(Common::FS::GetPathWithoutTop(path)); } std::shared_ptr VfsDirectory::CreateFileAbsolute(std::string_view path) { @@ -332,7 +332,7 @@ std::shared_ptr VfsDirectory::CreateFileAbsolute(std::string_view path) } std::shared_ptr VfsDirectory::CreateDirectoryRelative(std::string_view path) { - auto vec = FileUtil::SplitPathComponents(path); + auto vec = Common::FS::SplitPathComponents(path); vec.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }), vec.end()); if (vec.empty()) { @@ -351,7 +351,7 @@ std::shared_ptr VfsDirectory::CreateDirectoryRelative(std::string_ } } - return dir->CreateDirectoryRelative(FileUtil::GetPathWithoutTop(path)); + return dir->CreateDirectoryRelative(Common::FS::GetPathWithoutTop(path)); } std::shared_ptr VfsDirectory::CreateDirectoryAbsolute(std::string_view path) { -- cgit v1.2.3