early-access version 1681
This commit is contained in:
parent
b195744abc
commit
e076db528d
@ -1,7 +1,7 @@
|
||||
yuzu emulator early access
|
||||
=============
|
||||
|
||||
This is the source code for early-access 1680.
|
||||
This is the source code for early-access 1681.
|
||||
|
||||
## Legal Notice
|
||||
|
||||
|
@ -26,51 +26,6 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Converts the file access mode and file type enums to a file access mode string.
|
||||
*
|
||||
* @param mode File access mode
|
||||
* @param type File type
|
||||
*
|
||||
* @returns A pointer to a string representing the file access mode.
|
||||
*/
|
||||
[[nodiscard]] constexpr const char* AccessModeToStr(FileAccessMode mode, FileType type) {
|
||||
switch (type) {
|
||||
case FileType::BinaryFile:
|
||||
switch (mode) {
|
||||
case FileAccessMode::Read:
|
||||
return "rb";
|
||||
case FileAccessMode::Write:
|
||||
return "wb";
|
||||
case FileAccessMode::Append:
|
||||
return "ab";
|
||||
case FileAccessMode::ReadWrite:
|
||||
return "r+b";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return "a+b";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
case FileType::TextFile:
|
||||
switch (mode) {
|
||||
case FileAccessMode::Read:
|
||||
return "r";
|
||||
case FileAccessMode::Write:
|
||||
return "w";
|
||||
case FileAccessMode::Append:
|
||||
return "a";
|
||||
case FileAccessMode::ReadWrite:
|
||||
return "r+";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return "a+";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/**
|
||||
@ -95,9 +50,8 @@ namespace {
|
||||
return L"r+b";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return L"a+b";
|
||||
default:
|
||||
return L"";
|
||||
}
|
||||
break;
|
||||
case FileType::TextFile:
|
||||
switch (mode) {
|
||||
case FileAccessMode::Read:
|
||||
@ -110,12 +64,11 @@ namespace {
|
||||
return L"r+";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return L"a+";
|
||||
default:
|
||||
return L"";
|
||||
}
|
||||
default:
|
||||
return L"";
|
||||
break;
|
||||
}
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +92,51 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Converts the file access mode and file type enums to a file access mode string.
|
||||
*
|
||||
* @param mode File access mode
|
||||
* @param type File type
|
||||
*
|
||||
* @returns A pointer to a string representing the file access mode.
|
||||
*/
|
||||
[[nodiscard]] constexpr const char* AccessModeToStr(FileAccessMode mode, FileType type) {
|
||||
switch (type) {
|
||||
case FileType::BinaryFile:
|
||||
switch (mode) {
|
||||
case FileAccessMode::Read:
|
||||
return "rb";
|
||||
case FileAccessMode::Write:
|
||||
return "wb";
|
||||
case FileAccessMode::Append:
|
||||
return "ab";
|
||||
case FileAccessMode::ReadWrite:
|
||||
return "r+b";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return "a+b";
|
||||
}
|
||||
break;
|
||||
case FileType::TextFile:
|
||||
switch (mode) {
|
||||
case FileAccessMode::Read:
|
||||
return "r";
|
||||
case FileAccessMode::Write:
|
||||
return "w";
|
||||
case FileAccessMode::Append:
|
||||
return "a";
|
||||
case FileAccessMode::ReadWrite:
|
||||
return "r+";
|
||||
case FileAccessMode::ReadAppend:
|
||||
return "a+";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -172,8 +170,8 @@ std::string ReadStringFromFile(const std::filesystem::path& path, FileType type)
|
||||
return io_file.ReadString(io_file.GetSize());
|
||||
}
|
||||
|
||||
std::size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string) {
|
||||
size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string) {
|
||||
if (!IsFile(path)) {
|
||||
return 0;
|
||||
}
|
||||
@ -183,8 +181,8 @@ std::size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
|
||||
return io_file.WriteString(string);
|
||||
}
|
||||
|
||||
std::size_t AppendStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string) {
|
||||
size_t AppendStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string) {
|
||||
|
||||
if (!Exists(path)) {
|
||||
return WriteStringToFile(path, type, string);
|
||||
@ -297,19 +295,16 @@ bool IOFile::IsOpen() const {
|
||||
return file != nullptr;
|
||||
}
|
||||
|
||||
std::string IOFile::ReadString(std::size_t length) const {
|
||||
std::string IOFile::ReadString(size_t length) const {
|
||||
std::vector<char> string_buffer(length);
|
||||
|
||||
const auto chars_read = ReadSpan<char>(string_buffer);
|
||||
const auto string_size = chars_read != length ? chars_read : length;
|
||||
|
||||
if (chars_read != length) {
|
||||
return std::string{string_buffer.data(), chars_read};
|
||||
}
|
||||
|
||||
return std::string{string_buffer.data(), string_buffer.size()};
|
||||
return std::string{string_buffer.data(), string_size};
|
||||
}
|
||||
|
||||
std::size_t IOFile::WriteString(std::span<const char> string) const {
|
||||
size_t IOFile::WriteString(std::span<const char> string) const {
|
||||
return WriteSpan(string);
|
||||
}
|
||||
|
||||
|
@ -18,16 +18,13 @@
|
||||
namespace Common::FS {
|
||||
|
||||
enum class SeekOrigin {
|
||||
/// Seeks from the start of the file.
|
||||
SetOrigin,
|
||||
/// Seeks from the current file pointer position.
|
||||
CurrentPosition,
|
||||
/// Seeks from the end of the file.
|
||||
End,
|
||||
SetOrigin, // Seeks from the start of the file.
|
||||
CurrentPosition, // Seeks from the current file pointer position.
|
||||
End, // Seeks from the end of the file.
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a file stream at path with a specified open mode.
|
||||
* Opens a file stream at path with the specified open mode.
|
||||
*
|
||||
* @param file_stream Reference to file stream
|
||||
* @param path Filesystem path
|
||||
@ -43,8 +40,7 @@ void OpenFileStream(FileStream& file_stream, const std::filesystem::path& path,
|
||||
|
||||
template <typename FileStream, typename Path>
|
||||
void OpenFileStream(FileStream& file_stream, const Path& path, std::ios_base::openmode open_mode) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
file_stream.open(ToU8String(path), open_mode);
|
||||
} else {
|
||||
file_stream.open(std::filesystem::path{path}, open_mode);
|
||||
@ -68,8 +64,7 @@ void OpenFileStream(FileStream& file_stream, const Path& path, std::ios_base::op
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] std::string ReadStringFromFile(const Path& path, FileType type) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return ReadStringFromFile(ToU8String(path), type);
|
||||
} else {
|
||||
return ReadStringFromFile(std::filesystem::path{path}, type);
|
||||
@ -88,16 +83,14 @@ template <typename Path>
|
||||
*
|
||||
* @returns Number of characters successfully written.
|
||||
*/
|
||||
[[nodiscard]] std::size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string);
|
||||
[[nodiscard]] size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] std::size_t WriteStringToFile(const Path& path, FileType type,
|
||||
std::string_view string) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
[[nodiscard]] size_t WriteStringToFile(const Path& path, FileType type, std::string_view string) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return WriteStringToFile(ToU8String(path), type, string);
|
||||
} else {
|
||||
return WriteStringToFile(std::filesystem::path{path}, type, string);
|
||||
@ -116,16 +109,14 @@ template <typename Path>
|
||||
*
|
||||
* @returns Number of characters successfully written.
|
||||
*/
|
||||
[[nodiscard]] std::size_t AppendStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string);
|
||||
[[nodiscard]] size_t AppendStringToFile(const std::filesystem::path& path, FileType type,
|
||||
std::string_view string);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] std::size_t AppendStringToFile(const Path& path, FileType type,
|
||||
std::string_view string) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
[[nodiscard]] size_t AppendStringToFile(const Path& path, FileType type, std::string_view string) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return AppendStringToFile(ToU8String(path), type, string);
|
||||
} else {
|
||||
return AppendStringToFile(std::filesystem::path{path}, type, string);
|
||||
@ -186,7 +177,7 @@ public:
|
||||
[[nodiscard]] FileType GetType() const;
|
||||
|
||||
/**
|
||||
* Opens a file at path with a specified file access mode.
|
||||
* Opens a file at path with the specified file access mode.
|
||||
* This function behaves differently depending on the FileAccessMode.
|
||||
* These behaviors are documented in each enum value of FileAccessMode.
|
||||
*
|
||||
@ -215,11 +206,11 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
/// Closes a file if it is opened.
|
||||
/// Closes the file if it is opened.
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* Returns whether the file is open.
|
||||
* Checks whether the file is open.
|
||||
* Use this to check whether the calls to Open() or Close() succeeded.
|
||||
*
|
||||
* @returns True if the file is open, false otherwise.
|
||||
@ -241,7 +232,7 @@ public:
|
||||
* @returns Count of T::value_type data or objects successfully read.
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::size_t Read(T& data) const {
|
||||
[[nodiscard]] size_t Read(T& data) const {
|
||||
if constexpr (IsSTLContainer<T>) {
|
||||
using ContiguousType = typename T::value_type;
|
||||
static_assert(std::is_trivially_copyable_v<ContiguousType>,
|
||||
@ -267,7 +258,7 @@ public:
|
||||
* @returns Count of T::value_type data or objects successfully written.
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::size_t Write(const T& data) const {
|
||||
[[nodiscard]] size_t Write(const T& data) const {
|
||||
if constexpr (IsSTLContainer<T>) {
|
||||
using ContiguousType = typename T::value_type;
|
||||
static_assert(std::is_trivially_copyable_v<ContiguousType>,
|
||||
@ -296,7 +287,7 @@ public:
|
||||
* @returns Count of T data successfully read.
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::size_t ReadSpan(std::span<T> data) const {
|
||||
[[nodiscard]] size_t ReadSpan(std::span<T> data) const {
|
||||
static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
|
||||
|
||||
if (!IsOpen()) {
|
||||
@ -322,7 +313,7 @@ public:
|
||||
* @returns Count of T data successfully written.
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::size_t WriteSpan(std::span<const T> data) const {
|
||||
[[nodiscard]] size_t WriteSpan(std::span<const T> data) const {
|
||||
static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
|
||||
|
||||
if (!IsOpen()) {
|
||||
@ -397,7 +388,7 @@ public:
|
||||
*
|
||||
* @returns A string read from the file.
|
||||
*/
|
||||
[[nodiscard]] std::string ReadString(std::size_t length) const;
|
||||
[[nodiscard]] std::string ReadString(size_t length) const;
|
||||
|
||||
/**
|
||||
* Specialized function to write a string to a file sequentially.
|
||||
@ -408,7 +399,7 @@ public:
|
||||
*
|
||||
* @returns Number of characters successfully written.
|
||||
*/
|
||||
[[nodiscard]] std::size_t WriteString(std::span<const char> string) const;
|
||||
[[nodiscard]] size_t WriteString(std::span<const char> string) const;
|
||||
|
||||
/**
|
||||
* Flushes any unwritten buffered data into the file.
|
||||
@ -442,7 +433,7 @@ public:
|
||||
[[nodiscard]] u64 GetSize() const;
|
||||
|
||||
/**
|
||||
* Moves the current position of the file pointer with a specified offset and seek origin.
|
||||
* Moves the current position of the file pointer with the specified offset and seek origin.
|
||||
*
|
||||
* @param offset Offset from seek origin
|
||||
* @param origin Seek origin
|
||||
@ -460,9 +451,7 @@ public:
|
||||
|
||||
private:
|
||||
std::filesystem::path file_path;
|
||||
|
||||
FileAccessMode file_access_mode;
|
||||
|
||||
FileType file_type;
|
||||
|
||||
std::FILE* file = nullptr;
|
||||
|
@ -17,7 +17,7 @@ class IOFile;
|
||||
// File Operations
|
||||
|
||||
/**
|
||||
* Creates a new file at path with a specified size.
|
||||
* Creates a new file at path with the specified size.
|
||||
*
|
||||
* Failures occur when:
|
||||
* - Input path is not valid
|
||||
@ -36,8 +36,7 @@ class IOFile;
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool NewFile(const Path& path, u64 size = 0) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return NewFile(ToU8String(path), size);
|
||||
} else {
|
||||
return NewFile(std::filesystem::path{path}, size);
|
||||
@ -64,8 +63,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool RemoveFile(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return RemoveFile(ToU8String(path));
|
||||
} else {
|
||||
return RemoveFile(std::filesystem::path{path});
|
||||
@ -112,7 +110,7 @@ template <typename Path1, typename Path2>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Opens a file at path with a specified file access mode.
|
||||
* Opens a file at path with the specified file access mode.
|
||||
* This function behaves differently depending on the FileAccessMode.
|
||||
* These behaviors are documented in each enum value of FileAccessMode.
|
||||
*
|
||||
@ -139,8 +137,7 @@ template <typename Path>
|
||||
[[nodiscard]] std::shared_ptr<IOFile> FileOpen(const Path& path, FileAccessMode mode,
|
||||
FileType type = FileType::BinaryFile,
|
||||
FileShareFlag flag = FileShareFlag::ShareReadOnly) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return FileOpen(ToU8String(path), mode, type, flag);
|
||||
} else {
|
||||
return FileOpen(std::filesystem::path{path}, mode, type, flag);
|
||||
@ -172,8 +169,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool CreateDir(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return CreateDir(ToU8String(path));
|
||||
} else {
|
||||
return CreateDir(std::filesystem::path{path});
|
||||
@ -203,8 +199,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool CreateDirs(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return CreateDirs(ToU8String(path));
|
||||
} else {
|
||||
return CreateDirs(std::filesystem::path{path});
|
||||
@ -227,8 +222,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool CreateParentDir(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return CreateParentDir(ToU8String(path));
|
||||
} else {
|
||||
return CreateParentDir(std::filesystem::path{path});
|
||||
@ -251,8 +245,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool CreateParentDirs(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return CreateParentDirs(ToU8String(path));
|
||||
} else {
|
||||
return CreateParentDirs(std::filesystem::path{path});
|
||||
@ -280,8 +273,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool RemoveDir(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return RemoveDir(ToU8String(path));
|
||||
} else {
|
||||
return RemoveDir(std::filesystem::path{path});
|
||||
@ -308,8 +300,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool RemoveDirRecursively(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return RemoveDirRecursively(ToU8String(path));
|
||||
} else {
|
||||
return RemoveDirRecursively(std::filesystem::path{path});
|
||||
@ -336,8 +327,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool RemoveDirContentsRecursively(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return RemoveDirContentsRecursively(ToU8String(path));
|
||||
} else {
|
||||
return RemoveDirContentsRecursively(std::filesystem::path{path});
|
||||
@ -407,8 +397,7 @@ void IterateDirEntries(const std::filesystem::path& path, const DirEntryCallable
|
||||
template <typename Path>
|
||||
void IterateDirEntries(const Path& path, const DirEntryCallable& callback,
|
||||
DirEntryFilter filter = DirEntryFilter::All) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
IterateDirEntries(ToU8String(path), callback, filter);
|
||||
} else {
|
||||
IterateDirEntries(std::filesystem::path{path}, callback, filter);
|
||||
@ -442,8 +431,7 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
|
||||
template <typename Path>
|
||||
void IterateDirEntriesRecursively(const Path& path, const DirEntryCallable& callback,
|
||||
DirEntryFilter filter = DirEntryFilter::All) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
IterateDirEntriesRecursively(ToU8String(path), callback, filter);
|
||||
} else {
|
||||
IterateDirEntriesRecursively(std::filesystem::path{path}, callback, filter);
|
||||
@ -467,8 +455,7 @@ void IterateDirEntriesRecursively(const Path& path, const DirEntryCallable& call
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool Exists(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return Exists(ToU8String(path));
|
||||
} else {
|
||||
return Exists(std::filesystem::path{path});
|
||||
@ -490,8 +477,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool IsFile(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return IsFile(ToU8String(path));
|
||||
} else {
|
||||
return IsFile(std::filesystem::path{path});
|
||||
@ -513,8 +499,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool IsDir(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return IsDir(ToU8String(path));
|
||||
} else {
|
||||
return IsDir(std::filesystem::path{path});
|
||||
@ -541,8 +526,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool SetCurrentDir(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return SetCurrentDir(ToU8String(path));
|
||||
} else {
|
||||
return SetCurrentDir(std::filesystem::path{path});
|
||||
@ -564,8 +548,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] std::filesystem::file_type GetEntryType(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return GetEntryType(ToU8String(path));
|
||||
} else {
|
||||
return GetEntryType(std::filesystem::path{path});
|
||||
@ -587,8 +570,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] u64 GetSize(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return GetSize(ToU8String(path));
|
||||
} else {
|
||||
return GetSize(std::filesystem::path{path});
|
||||
@ -610,8 +592,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] u64 GetFreeSpaceSize(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return GetFreeSpaceSize(ToU8String(path));
|
||||
} else {
|
||||
return GetFreeSpaceSize(std::filesystem::path{path});
|
||||
@ -633,8 +614,7 @@ template <typename Path>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] u64 GetTotalSpaceSize(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return GetTotalSpaceSize(ToU8String(path));
|
||||
} else {
|
||||
return GetTotalSpaceSize(std::filesystem::path{path});
|
||||
|
@ -47,14 +47,10 @@ enum class FileType {
|
||||
};
|
||||
|
||||
enum class FileShareFlag {
|
||||
/// Provides exclusive access to the file.
|
||||
ShareNone,
|
||||
/// Provides read only shared access to the file.
|
||||
ShareReadOnly,
|
||||
/// Provides write only shared access to the file.
|
||||
ShareWriteOnly,
|
||||
/// Provides read and write shared access to the file.
|
||||
ShareReadWrite,
|
||||
ShareNone, // Provides exclusive access to the file.
|
||||
ShareReadOnly, // Provides read only shared access to the file.
|
||||
ShareWriteOnly, // Provides write only shared access to the file.
|
||||
ShareReadWrite, // Provides read and write shared access to the file.
|
||||
};
|
||||
|
||||
enum class DirEntryFilter {
|
||||
|
@ -51,12 +51,6 @@ 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.
|
||||
@ -167,31 +161,20 @@ bool ValidatePath(const fs::path& path) {
|
||||
|
||||
#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());
|
||||
|
||||
if (second_has_dir_sep) {
|
||||
fs::path concat_path = first;
|
||||
|
||||
concat_path += second;
|
||||
|
||||
return concat_path.lexically_normal();
|
||||
if (!second_has_dir_sep) {
|
||||
return (first / second).lexically_normal();
|
||||
}
|
||||
|
||||
return (first / second).lexically_normal();
|
||||
fs::path concat_path = first;
|
||||
concat_path += second;
|
||||
|
||||
return concat_path.lexically_normal();
|
||||
}
|
||||
|
||||
fs::path ConcatPathSafe(const fs::path& base, const fs::path& offset) {
|
||||
@ -289,14 +272,10 @@ fs::path GetAppDataRoamingDirectory() {
|
||||
#else
|
||||
|
||||
fs::path GetHomeDirectory() {
|
||||
fs::path home_path;
|
||||
|
||||
const char* home_env_var = getenv("HOME");
|
||||
|
||||
if (home_env_var) {
|
||||
home_path = fs::path{home_env_var};
|
||||
|
||||
return home_path;
|
||||
return fs::path{home_env_var};
|
||||
}
|
||||
|
||||
LOG_INFO(Common_Filesystem,
|
||||
@ -305,35 +284,30 @@ fs::path GetHomeDirectory() {
|
||||
|
||||
const auto* pw = getpwuid(getuid());
|
||||
|
||||
if (pw) {
|
||||
home_path = fs::path{pw->pw_dir};
|
||||
} else {
|
||||
if (!pw) {
|
||||
LOG_ERROR(Common_Filesystem, "Failed to get the home path of the current user");
|
||||
return {};
|
||||
}
|
||||
|
||||
return home_path;
|
||||
return fs::path{pw->pw_dir};
|
||||
}
|
||||
|
||||
fs::path GetDataDirectory(const std::string& env_name) {
|
||||
fs::path data_path;
|
||||
|
||||
const char* data_env_var = getenv(env_name.c_str());
|
||||
|
||||
if (data_env_var) {
|
||||
data_path = fs::path{data_env_var};
|
||||
|
||||
return data_path;
|
||||
return fs::path{data_env_var};
|
||||
}
|
||||
|
||||
if (env_name == "XDG_DATA_HOME") {
|
||||
data_path = GetHomeDirectory() / ".local/share";
|
||||
return GetHomeDirectory() / ".local/share";
|
||||
} else if (env_name == "XDG_CACHE_HOME") {
|
||||
data_path = GetHomeDirectory() / ".cache";
|
||||
return GetHomeDirectory() / ".cache";
|
||||
} else if (env_name == "XDG_CONFIG_HOME") {
|
||||
data_path = GetHomeDirectory() / ".config";
|
||||
return GetHomeDirectory() / ".config";
|
||||
}
|
||||
|
||||
return data_path;
|
||||
return {};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -12,28 +12,17 @@
|
||||
namespace Common::FS {
|
||||
|
||||
enum class YuzuPath {
|
||||
/// Where yuzu stores its data.
|
||||
YuzuDir,
|
||||
/// Where cached filesystem data is stored.
|
||||
CacheDir,
|
||||
/// Where config files are stored.
|
||||
ConfigDir,
|
||||
/// Where dumped data is stored.
|
||||
DumpDir,
|
||||
/// Where key files are stored.
|
||||
KeysDir,
|
||||
/// Where cheat/mod files are stored.
|
||||
LoadDir,
|
||||
/// Where log files are stored.
|
||||
LogDir,
|
||||
/// Where the emulated NAND is stored.
|
||||
NANDDir,
|
||||
/// Where yuzu screenshots are stored.
|
||||
ScreenshotsDir,
|
||||
/// Where the emulated SDMC is stored.
|
||||
SDMCDir,
|
||||
/// Where shaders are stored.
|
||||
ShaderDir,
|
||||
YuzuDir, // Where yuzu stores its data.
|
||||
CacheDir, // Where cached filesystem data is stored.
|
||||
ConfigDir, // Where config files are stored.
|
||||
DumpDir, // Where dumped data is stored.
|
||||
KeysDir, // Where key files are stored.
|
||||
LoadDir, // Where cheat/mod files are stored.
|
||||
LogDir, // Where log files are stored.
|
||||
NANDDir, // Where the emulated NAND is stored.
|
||||
ScreenshotsDir, // Where yuzu screenshots are stored.
|
||||
SDMCDir, // Where the emulated SDMC is stored.
|
||||
ShaderDir, // Where shaders are stored.
|
||||
};
|
||||
|
||||
/**
|
||||
@ -51,8 +40,6 @@ enum class YuzuPath {
|
||||
* A given path is valid if it meets these conditions:
|
||||
* - The path is not empty
|
||||
* - The path is not too long
|
||||
* - The path relative to the platform-specific root path does not contain
|
||||
* any of the following characters: ':', '*', '?', '"', '<', '>', '|'
|
||||
*
|
||||
* @param path Filesystem path
|
||||
*
|
||||
@ -64,8 +51,7 @@ enum class YuzuPath {
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] bool ValidatePath(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return ValidatePath(ToU8String(path));
|
||||
} else {
|
||||
return ValidatePath(std::filesystem::path{path});
|
||||
@ -204,8 +190,7 @@ template <typename Path1, typename Path2>
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] std::filesystem::path RemoveTrailingSeparators(const Path& path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
return RemoveTrailingSeparators(ToU8String(path));
|
||||
} else {
|
||||
return RemoveTrailingSeparators(std::filesystem::path{path});
|
||||
@ -245,8 +230,7 @@ void SetYuzuPath(YuzuPath yuzu_path, const std::filesystem::path& new_path);
|
||||
|
||||
template <typename Path>
|
||||
[[nodiscard]] void SetYuzuPath(YuzuPath yuzu_path, const Path& new_path) {
|
||||
using ValueType = typename Path::value_type;
|
||||
if constexpr (IsChar<ValueType>) {
|
||||
if constexpr (IsChar<typename Path::value_type>) {
|
||||
SetYuzuPath(yuzu_path, ToU8String(new_path));
|
||||
} else {
|
||||
SetYuzuPath(yuzu_path, std::filesystem::path{new_path});
|
||||
|
@ -86,7 +86,7 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cache.insert_or_assign(path, backing);
|
||||
cache.insert_or_assign(path, std::move(backing));
|
||||
|
||||
// Cannot use make_shared as RealVfsFile constructor is private
|
||||
return std::shared_ptr<RealVfsFile>(new RealVfsFile(*this, backing, path, perms));
|
||||
@ -306,16 +306,16 @@ std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>(
|
||||
}
|
||||
|
||||
std::vector<VirtualFile> out;
|
||||
FS::IterateDirEntries(
|
||||
path,
|
||||
[this, &out](const std::filesystem::path& full_path) {
|
||||
const auto full_path_string = FS::PathToUTF8String(full_path);
|
||||
|
||||
out.emplace_back(base.OpenFile(full_path_string, perms));
|
||||
const FS::DirEntryCallable callback = [this, &out](const std::filesystem::path& full_path) {
|
||||
const auto full_path_string = FS::PathToUTF8String(full_path);
|
||||
|
||||
return true;
|
||||
},
|
||||
FS::DirEntryFilter::File);
|
||||
out.emplace_back(base.OpenFile(full_path_string, perms));
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
FS::IterateDirEntries(path, callback, FS::DirEntryFilter::File);
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -328,16 +328,15 @@ std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDi
|
||||
|
||||
std::vector<VirtualDir> out;
|
||||
|
||||
FS::IterateDirEntries(
|
||||
path,
|
||||
[this, &out](const std::filesystem::path& full_path) {
|
||||
const auto full_path_string = FS::PathToUTF8String(full_path);
|
||||
const FS::DirEntryCallable callback = [this, &out](const std::filesystem::path& full_path) {
|
||||
const auto full_path_string = FS::PathToUTF8String(full_path);
|
||||
|
||||
out.emplace_back(base.OpenDirectory(full_path_string, perms));
|
||||
out.emplace_back(base.OpenDirectory(full_path_string, perms));
|
||||
|
||||
return true;
|
||||
},
|
||||
FS::DirEntryFilter::Directory);
|
||||
return true;
|
||||
};
|
||||
|
||||
FS::IterateDirEntries(path, callback, FS::DirEntryFilter::Directory);
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -459,18 +458,17 @@ std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries()
|
||||
}
|
||||
|
||||
std::map<std::string, VfsEntryType, std::less<>> out;
|
||||
FS::IterateDirEntries(path,
|
||||
[&out](const std::filesystem::path& full_path) {
|
||||
const auto filename = FS::PathToUTF8String(full_path.filename());
|
||||
|
||||
out.insert_or_assign(filename, FS::IsDir(full_path)
|
||||
? VfsEntryType::Directory
|
||||
: VfsEntryType::File);
|
||||
const FS::DirEntryCallable callback = [&out](const std::filesystem::path& full_path) {
|
||||
const auto filename = FS::PathToUTF8String(full_path.filename());
|
||||
|
||||
return true;
|
||||
}
|
||||
out.insert_or_assign(filename,
|
||||
FS::IsDir(full_path) ? VfsEntryType::Directory : VfsEntryType::File);
|
||||
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
FS::IterateDirEntries(path, callback);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ PerfStats::~PerfStats() {
|
||||
|
||||
const auto path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::LogDir);
|
||||
// %F Date format expanded is "%Y-%m-%d"
|
||||
const auto filename =
|
||||
path / fmt::format("{:%F-%H-%M}_{:016X}.csv", *std::localtime(&t), title_id);
|
||||
const auto filename = fmt::format("{:%F-%H-%M}_{:016X}.csv", *std::localtime(&t), title_id);
|
||||
const auto filepath = path / filename;
|
||||
|
||||
if (Common::FS::CreateParentDir(path)) {
|
||||
Common::FS::IOFile file(filename, Common::FS::FileAccessMode::Write,
|
||||
if (Common::FS::CreateParentDir(filepath)) {
|
||||
Common::FS::IOFile file(filepath, Common::FS::FileAccessMode::Write,
|
||||
Common::FS::FileType::TextFile);
|
||||
void(file.WriteString(stream.str()));
|
||||
}
|
||||
|
@ -71,12 +71,13 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject(
|
||||
return generator();
|
||||
}
|
||||
|
||||
const auto path1 =
|
||||
Common::FS::PathToUTF8String(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
|
||||
"game_list" / fmt::format("{}.jpeg", filename));
|
||||
const auto path2 =
|
||||
Common::FS::PathToUTF8String(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
|
||||
"game_list" / fmt::format("{}.appname.txt", filename));
|
||||
const auto game_list_dir =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "game_list";
|
||||
const auto jpeg_name = fmt::format("{}.jpeg", filename);
|
||||
const auto app_name = fmt::format("{}.appname.txt", filename);
|
||||
|
||||
const auto path1 = Common::FS::PathToUTF8String(game_list_dir / jpeg_name);
|
||||
const auto path2 = Common::FS::PathToUTF8String(game_list_dir / app_name);
|
||||
|
||||
void(Common::FS::CreateParentDirs(path1));
|
||||
|
||||
|
@ -188,13 +188,11 @@ static void InitializeLogging() {
|
||||
}
|
||||
|
||||
static void RemoveCachedContents() {
|
||||
const auto offline_fonts = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "fonts";
|
||||
const auto offline_manual =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "offline_web_applet_manual";
|
||||
const auto offline_legal_information = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
|
||||
"offline_web_applet_legal_information";
|
||||
const auto offline_system_data =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "offline_web_applet_system_data";
|
||||
const auto cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir);
|
||||
const auto offline_fonts = cache_dir / "fonts";
|
||||
const auto offline_manual = cache_dir / "offline_web_applet_manual";
|
||||
const auto offline_legal_information = cache_dir / "offline_web_applet_legal_information";
|
||||
const auto offline_system_data = cache_dir / "offline_web_applet_system_data";
|
||||
|
||||
void(Common::FS::RemoveDirRecursively(offline_fonts));
|
||||
void(Common::FS::RemoveDirRecursively(offline_manual));
|
||||
@ -1572,16 +1570,19 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
||||
Service::Account::ProfileManager manager;
|
||||
const auto user_id = manager.GetUser(static_cast<std::size_t>(index));
|
||||
ASSERT(user_id);
|
||||
path = Common::FS::ConcatPathSafe(
|
||||
nand_dir, FileSys::SaveDataFactory::GetFullPath(
|
||||
system, FileSys::SaveDataSpaceId::NandUser,
|
||||
FileSys::SaveDataType::SaveData, program_id, user_id->uuid, 0));
|
||||
|
||||
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
||||
program_id, user_id->uuid, 0);
|
||||
|
||||
path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
|
||||
} else {
|
||||
// Device save data
|
||||
path = Common::FS::ConcatPathSafe(
|
||||
nand_dir, FileSys::SaveDataFactory::GetFullPath(
|
||||
system, FileSys::SaveDataSpaceId::NandUser,
|
||||
FileSys::SaveDataType::SaveData, program_id, {}, 0));
|
||||
const auto device_save_data_path = FileSys::SaveDataFactory::GetFullPath(
|
||||
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
|
||||
program_id, {}, 0);
|
||||
|
||||
path = Common::FS::ConcatPathSafe(nand_dir, device_save_data_path);
|
||||
}
|
||||
|
||||
if (!Common::FS::CreateDirs(path)) {
|
||||
@ -1613,8 +1614,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
||||
}
|
||||
|
||||
void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) {
|
||||
const auto transferable_shader_cache_folder_path =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir) / "opengl" / "transferable";
|
||||
const auto shader_cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir);
|
||||
const auto transferable_shader_cache_folder_path = shader_cache_dir / "opengl" / "transferable";
|
||||
const auto transferable_shader_cache_file_path =
|
||||
transferable_shader_cache_folder_path / fmt::format("{:016X}.bin", program_id);
|
||||
|
||||
@ -1809,9 +1810,9 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
|
||||
}
|
||||
|
||||
void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
|
||||
const auto shader_cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir);
|
||||
const auto transferable_shader_cache_file_path =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir) / "opengl" / "transferable" /
|
||||
fmt::format("{:016X}.bin", program_id);
|
||||
shader_cache_dir / "opengl" / "transferable" / fmt::format("{:016X}.bin", program_id);
|
||||
|
||||
if (!Common::FS::Exists(transferable_shader_cache_file_path)) {
|
||||
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
|
||||
@ -1875,9 +1876,10 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
||||
return;
|
||||
}
|
||||
|
||||
const auto path =
|
||||
Common::FS::PathToUTF8String(Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir) /
|
||||
fmt::format("{:016X}", *romfs_title_id) / "romfs");
|
||||
const auto dump_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir);
|
||||
const auto romfs_dir = fmt::format("{:016X}/romfs", *romfs_title_id);
|
||||
|
||||
const auto path = Common::FS::PathToUTF8String(dump_dir / romfs_dir);
|
||||
|
||||
FileSys::VirtualFile romfs;
|
||||
|
||||
@ -3263,9 +3265,8 @@ int main(int argc, char* argv[]) {
|
||||
QCoreApplication::setApplicationName(QStringLiteral("yuzu"));
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// Increases the maximum open file limit to 4096
|
||||
_setmaxstdio(4096);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -49,8 +49,7 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
|
||||
void(FS::CreateParentDir(sdl2_config_loc));
|
||||
void(FS::WriteStringToFile(sdl2_config_loc, FS::FileType::TextFile, default_contents));
|
||||
|
||||
sdl2_config =
|
||||
std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc)); // Reopen file
|
||||
sdl2_config = std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc));
|
||||
|
||||
return LoadINI(default_contents, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user