early-access version 1670

This commit is contained in:
pineappleEA
2021-05-11 02:22:43 +02:00
parent 1148b01aac
commit 0301e95e45
23 changed files with 452 additions and 240 deletions

View File

@@ -37,10 +37,26 @@
#endif
#endif
#ifndef MAX_PATH
#ifdef _WIN32
// This is the maximum number of UTF-16 code units permissible in Windows file paths
#define MAX_PATH 260
#else
// This is the maximum number of UTF-8 code units permissible in all other OSes' file paths
#define MAX_PATH 1024
#endif
#endif
namespace Common::FS {
namespace fs = std::filesystem;
namespace {
constexpr std::array<char8_t, 7> INVALID_CHARS{u':', u'*', u'?', u'"', u'<', u'>', u'|'};
}
/**
* The PathManagerImpl is a singleton allowing to manage the mapping of
* YuzuPath enums to real filesystem paths.
@@ -129,6 +145,41 @@ std::string PathToUTF8String(const fs::path& path) {
return std::string{utf8_string.begin(), utf8_string.end()};
}
bool ValidatePath(const fs::path& path) {
if (path.empty()) {
LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path));
return false;
}
#ifdef _WIN32
if (path.u16string().size() >= MAX_PATH) {
LOG_ERROR(Common_Filesystem, "Input path is too long, path={}", PathToUTF8String(path));
return false;
}
#else
if (path.u8string().size() >= MAX_PATH) {
LOG_ERROR(Common_Filesystem, "Input path is too long, path={}", PathToUTF8String(path));
return false;
}
#endif
for (const auto path_char : path.relative_path().u8string()) {
for (const auto invalid_char : INVALID_CHARS) {
if (path_char == invalid_char) {
LOG_ERROR(Common_Filesystem, "Input path contains invalid characters, path={}",
PathToUTF8String(path));
return false;
}
}
}
return true;
}
fs::path ConcatPath(const fs::path& first, const fs::path& second) {
const bool second_has_dir_sep = IsDirSeparator(second.u8string().front());