summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-12-09 00:36:49 +0100
committerLioncash <mathew1800@gmail.com>2020-12-09 00:36:53 +0100
commit0e54aa17e64a5c5b62d60a70414742be29eccff9 (patch)
tree13c55de6081891fa19afe4526fa83328520c9026 /src/common
parentMerge pull request #5171 from lat9nq/ci-unicorn-cleanup (diff)
downloadyuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar.gz
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar.bz2
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar.lz
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar.xz
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.tar.zst
yuzu-0e54aa17e64a5c5b62d60a70414742be29eccff9.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/file_util.cpp61
-rw-r--r--src/common/file_util.h9
2 files changed, 13 insertions, 57 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 18fbfa25b..67fcef3e4 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <array>
+#include <filesystem>
#include <limits>
#include <memory>
#include <sstream>
@@ -75,62 +76,16 @@
// The code still needs a ton of cleanup.
// REMEMBER: strdup considered harmful!
namespace Common::FS {
+namespace fs = std::filesystem;
-// Remove any ending forward slashes from directory paths
-// Modifies argument.
-static void StripTailDirSlashes(std::string& fname) {
- if (fname.length() <= 1) {
- return;
- }
-
- std::size_t i = fname.length();
- while (i > 0 && fname[i - 1] == DIR_SEP_CHR) {
- --i;
- }
- fname.resize(i);
+bool Exists(const fs::path& path) {
+ std::error_code ec;
+ return fs::exists(path, ec);
}
-bool Exists(const std::string& filename) {
- struct stat file_info;
-
- std::string copy(filename);
- StripTailDirSlashes(copy);
-
-#ifdef _WIN32
- // Windows needs a slash to identify a driver root
- if (copy.size() != 0 && copy.back() == ':')
- copy += DIR_SEP_CHR;
-
- int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
-#else
- int result = stat(copy.c_str(), &file_info);
-#endif
-
- return (result == 0);
-}
-
-bool IsDirectory(const std::string& filename) {
- struct stat file_info;
-
- std::string copy(filename);
- StripTailDirSlashes(copy);
-
-#ifdef _WIN32
- // Windows needs a slash to identify a driver root
- if (copy.size() != 0 && copy.back() == ':')
- copy += DIR_SEP_CHR;
-
- int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
-#else
- int result = stat(copy.c_str(), &file_info);
-#endif
-
- if (result < 0) {
- LOG_DEBUG(Common_Filesystem, "stat failed on {}: {}", filename, GetLastErrorMsg());
- return false;
- }
-
- return S_ISDIR(file_info.st_mode);
+bool IsDirectory(const fs::path& path) {
+ std::error_code ec;
+ return fs::is_directory(path, ec);
}
bool Delete(const std::string& filename) {
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 840cde2a6..be0906434 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -6,6 +6,7 @@
#include <array>
#include <cstdio>
+#include <filesystem>
#include <fstream>
#include <functional>
#include <limits>
@@ -47,11 +48,11 @@ struct FSTEntry {
std::vector<FSTEntry> children;
};
-// Returns true if file filename exists
-[[nodiscard]] bool Exists(const std::string& filename);
+// Returns true if the exists
+[[nodiscard]] bool Exists(const std::filesystem::path& path);
-// Returns true if filename is a directory
-[[nodiscard]] bool IsDirectory(const std::string& filename);
+// Returns true if path is a directory
+[[nodiscard]] bool IsDirectory(const std::filesystem::path& path);
// Returns the size of filename (64bit)
[[nodiscard]] u64 GetSize(const std::string& filename);