diff options
| author | 2018-08-06 23:21:37 -0400 | |
|---|---|---|
| committer | 2018-08-08 21:18:45 -0400 | |
| commit | 2b6128fe0b8788318a4bbe1fc55ea14aed2981e4 (patch) | |
| tree | 39a8c25dbea98e2f8b5761f408d62cf1669f89bc /src/core/file_sys | |
| parent | loader: Remove unused IdentifyFile overload (diff) | |
| download | yuzu-2b6128fe0b8788318a4bbe1fc55ea14aed2981e4.tar.gz yuzu-2b6128fe0b8788318a4bbe1fc55ea14aed2981e4.tar.xz yuzu-2b6128fe0b8788318a4bbe1fc55ea14aed2981e4.zip | |
file_util: Use enum instead of bool for specifing path behavior
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 21ea35aaf..1b5919737 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -53,7 +53,7 @@ bool RealVfsFilesystem::IsWritable() const { | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { | 55 | VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { |
| 56 | const auto path = FileUtil::SanitizePath(path_, true); | 56 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 57 | if (!FileUtil::Exists(path)) | 57 | if (!FileUtil::Exists(path)) |
| 58 | return VfsEntryType::None; | 58 | return VfsEntryType::None; |
| 59 | if (FileUtil::IsDirectory(path)) | 59 | if (FileUtil::IsDirectory(path)) |
| @@ -63,7 +63,7 @@ VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 65 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { |
| 66 | const auto path = FileUtil::SanitizePath(path_, true); | 66 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 67 | if (cache.find(path) != cache.end()) { | 67 | if (cache.find(path) != cache.end()) { |
| 68 | auto weak = cache[path]; | 68 | auto weak = cache[path]; |
| 69 | if (!weak.expired()) { | 69 | if (!weak.expired()) { |
| @@ -82,15 +82,17 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 84 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { |
| 85 | const auto path = FileUtil::SanitizePath(path_, true); | 85 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 86 | if (!FileUtil::Exists(path) && !FileUtil::CreateEmptyFile(path)) | 86 | if (!FileUtil::Exists(path) && !FileUtil::CreateEmptyFile(path)) |
| 87 | return nullptr; | 87 | return nullptr; |
| 88 | return OpenFile(path, perms); | 88 | return OpenFile(path, perms); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { | 91 | VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) { |
| 92 | const auto old_path = FileUtil::SanitizePath(old_path_, true); | 92 | const auto old_path = |
| 93 | const auto new_path = FileUtil::SanitizePath(new_path_, true); | 93 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 94 | const auto new_path = | ||
| 95 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 94 | 96 | ||
| 95 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 97 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || |
| 96 | FileUtil::IsDirectory(old_path) || !FileUtil::Copy(old_path, new_path)) | 98 | FileUtil::IsDirectory(old_path) || !FileUtil::Copy(old_path, new_path)) |
| @@ -99,8 +101,10 @@ VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_ | |||
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { | 103 | VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) { |
| 102 | const auto old_path = FileUtil::SanitizePath(old_path_, true); | 104 | const auto old_path = |
| 103 | const auto new_path = FileUtil::SanitizePath(new_path_, true); | 105 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 106 | const auto new_path = | ||
| 107 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 104 | 108 | ||
| 105 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 109 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || |
| 106 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) | 110 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) |
| @@ -119,7 +123,7 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_ | |||
| 119 | } | 123 | } |
| 120 | 124 | ||
| 121 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { | 125 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { |
| 122 | const auto path = FileUtil::SanitizePath(path_, true); | 126 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 123 | if (cache.find(path) != cache.end()) { | 127 | if (cache.find(path) != cache.end()) { |
| 124 | if (!cache[path].expired()) | 128 | if (!cache[path].expired()) |
| 125 | cache[path].lock()->Close(); | 129 | cache[path].lock()->Close(); |
| @@ -129,13 +133,13 @@ bool RealVfsFilesystem::DeleteFile(std::string_view path_) { | |||
| 129 | } | 133 | } |
| 130 | 134 | ||
| 131 | VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { | 135 | VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { |
| 132 | const auto path = FileUtil::SanitizePath(path_, true); | 136 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 133 | // Cannot use make_shared as RealVfsDirectory constructor is private | 137 | // Cannot use make_shared as RealVfsDirectory constructor is private |
| 134 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); | 138 | return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); |
| 135 | } | 139 | } |
| 136 | 140 | ||
| 137 | VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { | 141 | VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { |
| 138 | const auto path = FileUtil::SanitizePath(path_, true); | 142 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 139 | if (!FileUtil::Exists(path) && !FileUtil::CreateDir(path)) | 143 | if (!FileUtil::Exists(path) && !FileUtil::CreateDir(path)) |
| 140 | return nullptr; | 144 | return nullptr; |
| 141 | // Cannot use make_shared as RealVfsDirectory constructor is private | 145 | // Cannot use make_shared as RealVfsDirectory constructor is private |
| @@ -144,8 +148,10 @@ VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms | |||
| 144 | 148 | ||
| 145 | VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, | 149 | VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, |
| 146 | std::string_view new_path_) { | 150 | std::string_view new_path_) { |
| 147 | const auto old_path = FileUtil::SanitizePath(old_path_, true); | 151 | const auto old_path = |
| 148 | const auto new_path = FileUtil::SanitizePath(new_path_, true); | 152 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 153 | const auto new_path = | ||
| 154 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 149 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 155 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || |
| 150 | !FileUtil::IsDirectory(old_path)) | 156 | !FileUtil::IsDirectory(old_path)) |
| 151 | return nullptr; | 157 | return nullptr; |
| @@ -155,8 +161,10 @@ VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, | |||
| 155 | 161 | ||
| 156 | VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, | 162 | VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, |
| 157 | std::string_view new_path_) { | 163 | std::string_view new_path_) { |
| 158 | const auto old_path = FileUtil::SanitizePath(old_path_, true); | 164 | const auto old_path = |
| 159 | const auto new_path = FileUtil::SanitizePath(new_path_, true); | 165 | FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 166 | const auto new_path = | ||
| 167 | FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 160 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || | 168 | if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || |
| 161 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) | 169 | FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) |
| 162 | return nullptr; | 170 | return nullptr; |
| @@ -164,9 +172,11 @@ VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, | |||
| 164 | for (auto& kv : cache) { | 172 | for (auto& kv : cache) { |
| 165 | // Path in cache starts with old_path | 173 | // Path in cache starts with old_path |
| 166 | if (kv.first.rfind(old_path, 0) == 0) { | 174 | if (kv.first.rfind(old_path, 0) == 0) { |
| 167 | const auto file_old_path = FileUtil::SanitizePath(kv.first, true); | 175 | const auto file_old_path = |
| 176 | FileUtil::SanitizePath(kv.first, FileUtil::DirectorySeparator::PlatformDefault); | ||
| 168 | const auto file_new_path = | 177 | const auto file_new_path = |
| 169 | FileUtil::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()), true); | 178 | FileUtil::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()), |
| 179 | FileUtil::DirectorySeparator::PlatformDefault); | ||
| 170 | auto cached = cache[file_old_path]; | 180 | auto cached = cache[file_old_path]; |
| 171 | if (!cached.expired()) { | 181 | if (!cached.expired()) { |
| 172 | auto file = cached.lock(); | 182 | auto file = cached.lock(); |
| @@ -181,7 +191,7 @@ VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_, | |||
| 181 | } | 191 | } |
| 182 | 192 | ||
| 183 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { | 193 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { |
| 184 | const auto path = FileUtil::SanitizePath(path_, true); | 194 | const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault); |
| 185 | for (auto& kv : cache) { | 195 | for (auto& kv : cache) { |
| 186 | // Path in cache starts with old_path | 196 | // Path in cache starts with old_path |
| 187 | if (kv.first.rfind(path, 0) == 0) { | 197 | if (kv.first.rfind(path, 0) == 0) { |