mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-23 08:50:57 +01:00
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.
This commit is contained in:
parent
db96034ea4
commit
c4ed791164
40 changed files with 639 additions and 547 deletions
|
@ -74,7 +74,7 @@
|
||||||
// This namespace has various generic functions related to files and paths.
|
// This namespace has various generic functions related to files and paths.
|
||||||
// The code still needs a ton of cleanup.
|
// The code still needs a ton of cleanup.
|
||||||
// REMEMBER: strdup considered harmful!
|
// REMEMBER: strdup considered harmful!
|
||||||
namespace FileUtil {
|
namespace Common::FS {
|
||||||
|
|
||||||
// Remove any ending forward slashes from directory paths
|
// Remove any ending forward slashes from directory paths
|
||||||
// Modifies argument.
|
// Modifies argument.
|
||||||
|
@ -196,7 +196,7 @@ bool CreateFullPath(const std::string& fullPath) {
|
||||||
int panicCounter = 100;
|
int panicCounter = 100;
|
||||||
LOG_TRACE(Common_Filesystem, "path {}", fullPath);
|
LOG_TRACE(Common_Filesystem, "path {}", fullPath);
|
||||||
|
|
||||||
if (FileUtil::Exists(fullPath)) {
|
if (Exists(fullPath)) {
|
||||||
LOG_DEBUG(Common_Filesystem, "path exists {}", fullPath);
|
LOG_DEBUG(Common_Filesystem, "path exists {}", fullPath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ bool CreateFullPath(const std::string& fullPath) {
|
||||||
|
|
||||||
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
||||||
std::string const subPath(fullPath.substr(0, position + 1));
|
std::string const subPath(fullPath.substr(0, position + 1));
|
||||||
if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) {
|
if (!IsDirectory(subPath) && !CreateDir(subPath)) {
|
||||||
LOG_ERROR(Common, "CreateFullPath: directory creation failed");
|
LOG_ERROR(Common, "CreateFullPath: directory creation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ bool DeleteDir(const std::string& filename) {
|
||||||
LOG_TRACE(Common_Filesystem, "directory {}", filename);
|
LOG_TRACE(Common_Filesystem, "directory {}", filename);
|
||||||
|
|
||||||
// check if a directory
|
// check if a directory
|
||||||
if (!FileUtil::IsDirectory(filename)) {
|
if (!IsDirectory(filename)) {
|
||||||
LOG_ERROR(Common_Filesystem, "Not a directory {}", filename);
|
LOG_ERROR(Common_Filesystem, "Not a directory {}", filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ u64 GetSize(FILE* f) {
|
||||||
bool CreateEmptyFile(const std::string& filename) {
|
bool CreateEmptyFile(const std::string& filename) {
|
||||||
LOG_TRACE(Common_Filesystem, "{}", filename);
|
LOG_TRACE(Common_Filesystem, "{}", filename);
|
||||||
|
|
||||||
if (!FileUtil::IOFile(filename, "wb").IsOpen()) {
|
if (!IOFile(filename, "wb").IsOpen()) {
|
||||||
LOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg());
|
LOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -488,29 +488,34 @@ bool DeleteDirRecursively(const std::string& directory, unsigned int recursion)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Delete the outermost directory
|
// Delete the outermost directory
|
||||||
FileUtil::DeleteDir(directory);
|
DeleteDir(directory);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyDir(const std::string& source_path, const std::string& dest_path) {
|
void CopyDir(const std::string& source_path, const std::string& dest_path) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (source_path == dest_path)
|
if (source_path == dest_path) {
|
||||||
return;
|
return;
|
||||||
if (!FileUtil::Exists(source_path))
|
}
|
||||||
|
if (!Exists(source_path)) {
|
||||||
return;
|
return;
|
||||||
if (!FileUtil::Exists(dest_path))
|
}
|
||||||
FileUtil::CreateFullPath(dest_path);
|
if (!Exists(dest_path)) {
|
||||||
|
CreateFullPath(dest_path);
|
||||||
|
}
|
||||||
|
|
||||||
DIR* dirp = opendir(source_path.c_str());
|
DIR* dirp = opendir(source_path.c_str());
|
||||||
if (!dirp)
|
if (!dirp) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (struct dirent* result = readdir(dirp)) {
|
while (struct dirent* result = readdir(dirp)) {
|
||||||
const std::string virtualName(result->d_name);
|
const std::string virtualName(result->d_name);
|
||||||
// check for "." and ".."
|
// check for "." and ".."
|
||||||
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
||||||
((virtualName[0] == '.') && (virtualName[1] == '.') && (virtualName[2] == '\0')))
|
((virtualName[0] == '.') && (virtualName[1] == '.') && (virtualName[2] == '\0'))) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
std::string source, dest;
|
std::string source, dest;
|
||||||
source = source_path + virtualName;
|
source = source_path + virtualName;
|
||||||
|
@ -518,11 +523,13 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
|
||||||
if (IsDirectory(source)) {
|
if (IsDirectory(source)) {
|
||||||
source += '/';
|
source += '/';
|
||||||
dest += '/';
|
dest += '/';
|
||||||
if (!FileUtil::Exists(dest))
|
if (!Exists(dest)) {
|
||||||
FileUtil::CreateFullPath(dest);
|
CreateFullPath(dest);
|
||||||
|
}
|
||||||
CopyDir(source, dest);
|
CopyDir(source, dest);
|
||||||
} else if (!FileUtil::Exists(dest))
|
} else if (!Exists(dest)) {
|
||||||
FileUtil::Copy(source, dest);
|
Copy(source, dest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
#endif
|
#endif
|
||||||
|
@ -538,7 +545,7 @@ std::optional<std::string> GetCurrentDir() {
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
#endif
|
#endif
|
||||||
LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
|
LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::string strDir = Common::UTF16ToUTF8(dir);
|
std::string strDir = Common::UTF16ToUTF8(dir);
|
||||||
|
@ -546,7 +553,7 @@ std::optional<std::string> GetCurrentDir() {
|
||||||
std::string strDir = dir;
|
std::string strDir = dir;
|
||||||
#endif
|
#endif
|
||||||
free(dir);
|
free(dir);
|
||||||
return strDir;
|
return std::move(strDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetCurrentDir(const std::string& directory) {
|
bool SetCurrentDir(const std::string& directory) {
|
||||||
|
@ -668,7 +675,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
|
||||||
if (user_path.empty()) {
|
if (user_path.empty()) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
user_path = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
user_path = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
if (!FileUtil::IsDirectory(user_path)) {
|
if (!IsDirectory(user_path)) {
|
||||||
user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Common_Filesystem, "Using the local user directory");
|
LOG_INFO(Common_Filesystem, "Using the local user directory");
|
||||||
|
@ -677,7 +684,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
|
||||||
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
||||||
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
||||||
#else
|
#else
|
||||||
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
|
if (Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
|
||||||
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
||||||
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
||||||
|
@ -704,7 +711,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new_path.empty()) {
|
if (!new_path.empty()) {
|
||||||
if (!FileUtil::IsDirectory(new_path)) {
|
if (!IsDirectory(new_path)) {
|
||||||
LOG_ERROR(Common_Filesystem, "Invalid path specified {}", new_path);
|
LOG_ERROR(Common_Filesystem, "Invalid path specified {}", new_path);
|
||||||
return paths[path];
|
return paths[path];
|
||||||
} else {
|
} else {
|
||||||
|
@ -946,17 +953,18 @@ bool IOFile::Open(const std::string& filename, const char openmode[], int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOFile::Close() {
|
bool IOFile::Close() {
|
||||||
if (!IsOpen() || 0 != std::fclose(m_file))
|
if (!IsOpen() || 0 != std::fclose(m_file)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_file = nullptr;
|
m_file = nullptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 IOFile::GetSize() const {
|
u64 IOFile::GetSize() const {
|
||||||
if (IsOpen())
|
if (IsOpen()) {
|
||||||
return FileUtil::GetSize(m_file);
|
return FS::GetSize(m_file);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -965,9 +973,9 @@ bool IOFile::Seek(s64 off, int origin) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 IOFile::Tell() const {
|
u64 IOFile::Tell() const {
|
||||||
if (IsOpen())
|
if (IsOpen()) {
|
||||||
return ftello(m_file);
|
return ftello(m_file);
|
||||||
|
}
|
||||||
return std::numeric_limits<u64>::max();
|
return std::numeric_limits<u64>::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1016,4 +1024,4 @@ bool IOFile::Resize(u64 size) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace FileUtil
|
} // namespace Common::FS
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace Common::FS {
|
||||||
|
|
||||||
// User paths for GetUserPath
|
// User paths for GetUserPath
|
||||||
enum class UserPath {
|
enum class UserPath {
|
||||||
|
@ -204,6 +204,16 @@ enum class DirectorySeparator {
|
||||||
std::string_view path,
|
std::string_view path,
|
||||||
DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
|
DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash);
|
||||||
|
|
||||||
|
// To deal with Windows being dumb at Unicode
|
||||||
|
template <typename T>
|
||||||
|
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
fstream.open(Common::UTF8ToUTF16W(filename), openmode);
|
||||||
|
#else
|
||||||
|
fstream.open(filename, openmode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// simple wrapper for cstdlib file functions to
|
// simple wrapper for cstdlib file functions to
|
||||||
// hopefully will make error checking easier
|
// hopefully will make error checking easier
|
||||||
// and make forgetting an fclose() harder
|
// and make forgetting an fclose() harder
|
||||||
|
@ -285,14 +295,4 @@ private:
|
||||||
std::FILE* m_file = nullptr;
|
std::FILE* m_file = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FileUtil
|
} // namespace Common::FS
|
||||||
|
|
||||||
// To deal with Windows being dumb at unicode:
|
|
||||||
template <typename T>
|
|
||||||
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) {
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
fstream.open(Common::UTF8ToUTF16W(filename), openmode);
|
|
||||||
#else
|
|
||||||
fstream.open(filename, openmode);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
void Write(const Entry& entry) override;
|
void Write(const Entry& entry) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileUtil::IOFile file;
|
Common::FS::IOFile file;
|
||||||
std::size_t bytes_written;
|
std::size_t bytes_written;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||||
return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(concat, dir->GetName());
|
return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(concat, dir->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUtil::IsDirectory(path))
|
if (Common::FS::IsDirectory(path))
|
||||||
return vfs->OpenFile(path + "/" + "main", FileSys::Mode::Read);
|
return vfs->OpenFile(path + "/" + "main", FileSys::Mode::Read);
|
||||||
|
|
||||||
return vfs->OpenFile(path, FileSys::Mode::Read);
|
return vfs->OpenFile(path, FileSys::Mode::Read);
|
||||||
|
|
|
@ -96,13 +96,13 @@ u64 GetSignatureTypePaddingSize(SignatureType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SignatureType Ticket::GetSignatureType() const {
|
SignatureType Ticket::GetSignatureType() const {
|
||||||
if (auto ticket = std::get_if<RSA4096Ticket>(&data)) {
|
if (const auto* ticket = std::get_if<RSA4096Ticket>(&data)) {
|
||||||
return ticket->sig_type;
|
return ticket->sig_type;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<RSA2048Ticket>(&data)) {
|
if (const auto* ticket = std::get_if<RSA2048Ticket>(&data)) {
|
||||||
return ticket->sig_type;
|
return ticket->sig_type;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<ECDSATicket>(&data)) {
|
if (const auto* ticket = std::get_if<ECDSATicket>(&data)) {
|
||||||
return ticket->sig_type;
|
return ticket->sig_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,13 +110,13 @@ SignatureType Ticket::GetSignatureType() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TicketData& Ticket::GetData() {
|
TicketData& Ticket::GetData() {
|
||||||
if (auto ticket = std::get_if<RSA4096Ticket>(&data)) {
|
if (auto* ticket = std::get_if<RSA4096Ticket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<RSA2048Ticket>(&data)) {
|
if (auto* ticket = std::get_if<RSA2048Ticket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<ECDSATicket>(&data)) {
|
if (auto* ticket = std::get_if<ECDSATicket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,13 +124,13 @@ TicketData& Ticket::GetData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const TicketData& Ticket::GetData() const {
|
const TicketData& Ticket::GetData() const {
|
||||||
if (auto ticket = std::get_if<RSA4096Ticket>(&data)) {
|
if (const auto* ticket = std::get_if<RSA4096Ticket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<RSA2048Ticket>(&data)) {
|
if (const auto* ticket = std::get_if<RSA2048Ticket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
if (auto ticket = std::get_if<ECDSATicket>(&data)) {
|
if (const auto* ticket = std::get_if<ECDSATicket>(&data)) {
|
||||||
return ticket->data;
|
return ticket->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,8 +233,9 @@ void KeyManager::DeriveGeneralPurposeKeys(std::size_t crypto_revision) {
|
||||||
}
|
}
|
||||||
|
|
||||||
RSAKeyPair<2048> KeyManager::GetETicketRSAKey() const {
|
RSAKeyPair<2048> KeyManager::GetETicketRSAKey() const {
|
||||||
if (IsAllZeroArray(eticket_extended_kek) || !HasKey(S128KeyType::ETicketRSAKek))
|
if (IsAllZeroArray(eticket_extended_kek) || !HasKey(S128KeyType::ETicketRSAKek)) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
const auto eticket_final = GetKey(S128KeyType::ETicketRSAKek);
|
const auto eticket_final = GetKey(S128KeyType::ETicketRSAKek);
|
||||||
|
|
||||||
|
@ -261,27 +262,30 @@ Key128 DeriveKeyblobMACKey(const Key128& keyblob_key, const Key128& mac_source)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Key128> DeriveSDSeed() {
|
std::optional<Key128> DeriveSDSeed() {
|
||||||
const FileUtil::IOFile save_43(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const Common::FS::IOFile save_43(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/8000000000000043",
|
"/system/save/8000000000000043",
|
||||||
"rb+");
|
"rb+");
|
||||||
if (!save_43.IsOpen())
|
if (!save_43.IsOpen()) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
const FileUtil::IOFile sd_private(
|
const Common::FS::IOFile sd_private(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir) +
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) + "/Nintendo/Contents/private", "rb+");
|
"/Nintendo/Contents/private",
|
||||||
if (!sd_private.IsOpen())
|
"rb+");
|
||||||
return {};
|
if (!sd_private.IsOpen()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
std::array<u8, 0x10> private_seed{};
|
std::array<u8, 0x10> private_seed{};
|
||||||
if (sd_private.ReadBytes(private_seed.data(), private_seed.size()) != private_seed.size()) {
|
if (sd_private.ReadBytes(private_seed.data(), private_seed.size()) != private_seed.size()) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<u8, 0x10> buffer{};
|
std::array<u8, 0x10> buffer{};
|
||||||
std::size_t offset = 0;
|
std::size_t offset = 0;
|
||||||
for (; offset + 0x10 < save_43.GetSize(); ++offset) {
|
for (; offset + 0x10 < save_43.GetSize(); ++offset) {
|
||||||
if (!save_43.Seek(offset, SEEK_SET)) {
|
if (!save_43.Seek(offset, SEEK_SET)) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
save_43.ReadBytes(buffer.data(), buffer.size());
|
save_43.ReadBytes(buffer.data(), buffer.size());
|
||||||
|
@ -291,23 +295,26 @@ std::optional<Key128> DeriveSDSeed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!save_43.Seek(offset + 0x10, SEEK_SET)) {
|
if (!save_43.Seek(offset + 0x10, SEEK_SET)) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key128 seed{};
|
Key128 seed{};
|
||||||
if (save_43.ReadBytes(seed.data(), seed.size()) != seed.size()) {
|
if (save_43.ReadBytes(seed.data(), seed.size()) != seed.size()) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys) {
|
Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys) {
|
||||||
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::SDKek)))
|
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::SDKek))) {
|
||||||
return Loader::ResultStatus::ErrorMissingSDKEKSource;
|
return Loader::ResultStatus::ErrorMissingSDKEKSource;
|
||||||
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKekGeneration)))
|
}
|
||||||
|
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKekGeneration))) {
|
||||||
return Loader::ResultStatus::ErrorMissingAESKEKGenerationSource;
|
return Loader::ResultStatus::ErrorMissingAESKEKGenerationSource;
|
||||||
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKeyGeneration)))
|
}
|
||||||
|
if (!keys.HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::AESKeyGeneration))) {
|
||||||
return Loader::ResultStatus::ErrorMissingAESKeyGenerationSource;
|
return Loader::ResultStatus::ErrorMissingAESKeyGenerationSource;
|
||||||
|
}
|
||||||
|
|
||||||
const auto sd_kek_source =
|
const auto sd_kek_source =
|
||||||
keys.GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::SDKek));
|
keys.GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::SDKek));
|
||||||
|
@ -320,14 +327,17 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& ke
|
||||||
GenerateKeyEncryptionKey(sd_kek_source, master_00, aes_kek_gen, aes_key_gen);
|
GenerateKeyEncryptionKey(sd_kek_source, master_00, aes_kek_gen, aes_key_gen);
|
||||||
keys.SetKey(S128KeyType::SDKek, sd_kek);
|
keys.SetKey(S128KeyType::SDKek, sd_kek);
|
||||||
|
|
||||||
if (!keys.HasKey(S128KeyType::SDSeed))
|
if (!keys.HasKey(S128KeyType::SDSeed)) {
|
||||||
return Loader::ResultStatus::ErrorMissingSDSeed;
|
return Loader::ResultStatus::ErrorMissingSDSeed;
|
||||||
|
}
|
||||||
const auto sd_seed = keys.GetKey(S128KeyType::SDSeed);
|
const auto sd_seed = keys.GetKey(S128KeyType::SDSeed);
|
||||||
|
|
||||||
if (!keys.HasKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::Save)))
|
if (!keys.HasKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::Save))) {
|
||||||
return Loader::ResultStatus::ErrorMissingSDSaveKeySource;
|
return Loader::ResultStatus::ErrorMissingSDSaveKeySource;
|
||||||
if (!keys.HasKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::NCA)))
|
}
|
||||||
|
if (!keys.HasKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::NCA))) {
|
||||||
return Loader::ResultStatus::ErrorMissingSDNCAKeySource;
|
return Loader::ResultStatus::ErrorMissingSDNCAKeySource;
|
||||||
|
}
|
||||||
|
|
||||||
std::array<Key256, 2> sd_key_sources{
|
std::array<Key256, 2> sd_key_sources{
|
||||||
keys.GetKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::Save)),
|
keys.GetKey(S256KeyType::SDKeySource, static_cast<u64>(SDKeyType::Save)),
|
||||||
|
@ -336,9 +346,10 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& ke
|
||||||
|
|
||||||
// Combine sources and seed
|
// Combine sources and seed
|
||||||
for (auto& source : sd_key_sources) {
|
for (auto& source : sd_key_sources) {
|
||||||
for (std::size_t i = 0; i < source.size(); ++i)
|
for (std::size_t i = 0; i < source.size(); ++i) {
|
||||||
source[i] ^= sd_seed[i & 0xF];
|
source[i] ^= sd_seed[i & 0xF];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AESCipher<Key128> cipher(sd_kek, Mode::ECB);
|
AESCipher<Key128> cipher(sd_kek, Mode::ECB);
|
||||||
// The transform manipulates sd_keys as part of the Transcode, so the return/output is
|
// The transform manipulates sd_keys as part of the Transcode, so the return/output is
|
||||||
|
@ -355,9 +366,10 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& ke
|
||||||
return Loader::ResultStatus::Success;
|
return Loader::ResultStatus::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Ticket> GetTicketblob(const FileUtil::IOFile& ticket_save) {
|
std::vector<Ticket> GetTicketblob(const Common::FS::IOFile& ticket_save) {
|
||||||
if (!ticket_save.IsOpen())
|
if (!ticket_save.IsOpen()) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<u8> buffer(ticket_save.GetSize());
|
std::vector<u8> buffer(ticket_save.GetSize());
|
||||||
if (ticket_save.ReadBytes(buffer.data(), buffer.size()) != buffer.size()) {
|
if (ticket_save.ReadBytes(buffer.data(), buffer.size()) != buffer.size()) {
|
||||||
|
@ -417,7 +429,7 @@ static std::optional<u64> FindTicketOffset(const std::array<u8, size>& data) {
|
||||||
offset = i + 1;
|
offset = i + 1;
|
||||||
break;
|
break;
|
||||||
} else if (data[i] != 0x0) {
|
} else if (data[i] != 0x0) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,16 +439,18 @@ static std::optional<u64> FindTicketOffset(const std::array<u8, size>& data) {
|
||||||
std::optional<std::pair<Key128, Key128>> ParseTicket(const Ticket& ticket,
|
std::optional<std::pair<Key128, Key128>> ParseTicket(const Ticket& ticket,
|
||||||
const RSAKeyPair<2048>& key) {
|
const RSAKeyPair<2048>& key) {
|
||||||
const auto issuer = ticket.GetData().issuer;
|
const auto issuer = ticket.GetData().issuer;
|
||||||
if (IsAllZeroArray(issuer))
|
if (IsAllZeroArray(issuer)) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
}
|
||||||
if (issuer[0] != 'R' || issuer[1] != 'o' || issuer[2] != 'o' || issuer[3] != 't') {
|
if (issuer[0] != 'R' || issuer[1] != 'o' || issuer[2] != 'o' || issuer[3] != 't') {
|
||||||
LOG_INFO(Crypto, "Attempting to parse ticket with non-standard certificate authority.");
|
LOG_INFO(Crypto, "Attempting to parse ticket with non-standard certificate authority.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Key128 rights_id = ticket.GetData().rights_id;
|
Key128 rights_id = ticket.GetData().rights_id;
|
||||||
|
|
||||||
if (rights_id == Key128{})
|
if (rights_id == Key128{}) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
if (!std::any_of(ticket.GetData().title_key_common_pad.begin(),
|
if (!std::any_of(ticket.GetData().title_key_common_pad.begin(),
|
||||||
ticket.GetData().title_key_common_pad.end(), [](u8 b) { return b != 0; })) {
|
ticket.GetData().title_key_common_pad.end(), [](u8 b) { return b != 0; })) {
|
||||||
|
@ -468,15 +482,17 @@ std::optional<std::pair<Key128, Key128>> ParseTicket(const Ticket& ticket,
|
||||||
std::array<u8, 0xDF> m_2;
|
std::array<u8, 0xDF> m_2;
|
||||||
std::memcpy(m_2.data(), rsa_step.data() + 0x21, m_2.size());
|
std::memcpy(m_2.data(), rsa_step.data() + 0x21, m_2.size());
|
||||||
|
|
||||||
if (m_0 != 0)
|
if (m_0 != 0) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
m_1 = m_1 ^ MGF1<0x20>(m_2);
|
m_1 = m_1 ^ MGF1<0x20>(m_2);
|
||||||
m_2 = m_2 ^ MGF1<0xDF>(m_1);
|
m_2 = m_2 ^ MGF1<0xDF>(m_1);
|
||||||
|
|
||||||
const auto offset = FindTicketOffset(m_2);
|
const auto offset = FindTicketOffset(m_2);
|
||||||
if (!offset)
|
if (!offset) {
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
}
|
||||||
ASSERT(*offset > 0);
|
ASSERT(*offset > 0);
|
||||||
|
|
||||||
Key128 key_temp{};
|
Key128 key_temp{};
|
||||||
|
@ -487,8 +503,8 @@ std::optional<std::pair<Key128, Key128>> ParseTicket(const Ticket& ticket,
|
||||||
|
|
||||||
KeyManager::KeyManager() {
|
KeyManager::KeyManager() {
|
||||||
// Initialize keys
|
// Initialize keys
|
||||||
const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
|
const std::string hactool_keys_dir = Common::FS::GetHactoolConfigurationPath();
|
||||||
const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
|
const std::string yuzu_keys_dir = Common::FS::GetUserPath(Common::FS::UserPath::KeysDir);
|
||||||
if (Settings::values.use_dev_keys) {
|
if (Settings::values.use_dev_keys) {
|
||||||
dev_mode = true;
|
dev_mode = true;
|
||||||
AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
|
AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
|
||||||
|
@ -506,34 +522,39 @@ KeyManager::KeyManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ValidCryptoRevisionString(std::string_view base, size_t begin, size_t length) {
|
static bool ValidCryptoRevisionString(std::string_view base, size_t begin, size_t length) {
|
||||||
if (base.size() < begin + length)
|
if (base.size() < begin + length) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return std::all_of(base.begin() + begin, base.begin() + begin + length,
|
return std::all_of(base.begin() + begin, base.begin() + begin + length,
|
||||||
[](u8 c) { return std::isxdigit(c); });
|
[](u8 c) { return std::isxdigit(c); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
OpenFStream(file, filename, std::ios_base::in);
|
Common::FS::OpenFStream(file, filename, std::ios_base::in);
|
||||||
if (!file.is_open())
|
if (!file.is_open()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
std::vector<std::string> out;
|
std::vector<std::string> out;
|
||||||
std::stringstream stream(line);
|
std::stringstream stream(line);
|
||||||
std::string item;
|
std::string item;
|
||||||
while (std::getline(stream, item, '='))
|
while (std::getline(stream, item, '=')) {
|
||||||
out.push_back(std::move(item));
|
out.push_back(std::move(item));
|
||||||
|
}
|
||||||
|
|
||||||
if (out.size() != 2)
|
if (out.size() != 2) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
out[0].erase(std::remove(out[0].begin(), out[0].end(), ' '), out[0].end());
|
out[0].erase(std::remove(out[0].begin(), out[0].end(), ' '), out[0].end());
|
||||||
out[1].erase(std::remove(out[1].begin(), out[1].end(), ' '), out[1].end());
|
out[1].erase(std::remove(out[1].begin(), out[1].end(), ' '), out[1].end());
|
||||||
|
|
||||||
if (out[0].compare(0, 1, "#") == 0)
|
if (out[0].compare(0, 1, "#") == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_title_keys) {
|
if (is_title_keys) {
|
||||||
auto rights_id_raw = Common::HexStringToArray<16>(out[0]);
|
auto rights_id_raw = Common::HexStringToArray<16>(out[0]);
|
||||||
|
@ -553,14 +574,16 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
||||||
s256_keys[{index.type, index.field1, index.field2}] = key;
|
s256_keys[{index.type, index.field1, index.field2}] = key;
|
||||||
} else if (out[0].compare(0, 8, "keyblob_") == 0 &&
|
} else if (out[0].compare(0, 8, "keyblob_") == 0 &&
|
||||||
out[0].compare(0, 9, "keyblob_k") != 0) {
|
out[0].compare(0, 9, "keyblob_k") != 0) {
|
||||||
if (!ValidCryptoRevisionString(out[0], 8, 2))
|
if (!ValidCryptoRevisionString(out[0], 8, 2)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto index = std::stoul(out[0].substr(8, 2), nullptr, 16);
|
const auto index = std::stoul(out[0].substr(8, 2), nullptr, 16);
|
||||||
keyblobs[index] = Common::HexStringToArray<0x90>(out[1]);
|
keyblobs[index] = Common::HexStringToArray<0x90>(out[1]);
|
||||||
} else if (out[0].compare(0, 18, "encrypted_keyblob_") == 0) {
|
} else if (out[0].compare(0, 18, "encrypted_keyblob_") == 0) {
|
||||||
if (!ValidCryptoRevisionString(out[0], 18, 2))
|
if (!ValidCryptoRevisionString(out[0], 18, 2)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto index = std::stoul(out[0].substr(18, 2), nullptr, 16);
|
const auto index = std::stoul(out[0].substr(18, 2), nullptr, 16);
|
||||||
encrypted_keyblobs[index] = Common::HexStringToArray<0xB0>(out[1]);
|
encrypted_keyblobs[index] = Common::HexStringToArray<0xB0>(out[1]);
|
||||||
|
@ -568,8 +591,9 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
||||||
eticket_extended_kek = Common::HexStringToArray<576>(out[1]);
|
eticket_extended_kek = Common::HexStringToArray<576>(out[1]);
|
||||||
} else {
|
} else {
|
||||||
for (const auto& kv : KEYS_VARIABLE_LENGTH) {
|
for (const auto& kv : KEYS_VARIABLE_LENGTH) {
|
||||||
if (!ValidCryptoRevisionString(out[0], kv.second.size(), 2))
|
if (!ValidCryptoRevisionString(out[0], kv.second.size(), 2)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (out[0].compare(0, kv.second.size(), kv.second) == 0) {
|
if (out[0].compare(0, kv.second.size(), kv.second) == 0) {
|
||||||
const auto index =
|
const auto index =
|
||||||
std::stoul(out[0].substr(kv.second.size(), 2), nullptr, 16);
|
std::stoul(out[0].substr(kv.second.size(), 2), nullptr, 16);
|
||||||
|
@ -604,19 +628,21 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
|
||||||
|
|
||||||
void KeyManager::AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
|
void KeyManager::AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
|
||||||
const std::string& filename, bool title) {
|
const std::string& filename, bool title) {
|
||||||
if (FileUtil::Exists(dir1 + DIR_SEP + filename))
|
if (Common::FS::Exists(dir1 + DIR_SEP + filename)) {
|
||||||
LoadFromFile(dir1 + DIR_SEP + filename, title);
|
LoadFromFile(dir1 + DIR_SEP + filename, title);
|
||||||
else if (FileUtil::Exists(dir2 + DIR_SEP + filename))
|
} else if (Common::FS::Exists(dir2 + DIR_SEP + filename)) {
|
||||||
LoadFromFile(dir2 + DIR_SEP + filename, title);
|
LoadFromFile(dir2 + DIR_SEP + filename, title);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool KeyManager::BaseDeriveNecessary() const {
|
bool KeyManager::BaseDeriveNecessary() const {
|
||||||
const auto check_key_existence = [this](auto key_type, u64 index1 = 0, u64 index2 = 0) {
|
const auto check_key_existence = [this](auto key_type, u64 index1 = 0, u64 index2 = 0) {
|
||||||
return !HasKey(key_type, index1, index2);
|
return !HasKey(key_type, index1, index2);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (check_key_existence(S256KeyType::Header))
|
if (check_key_existence(S256KeyType::Header)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < CURRENT_CRYPTO_REVISION; ++i) {
|
for (size_t i = 0; i < CURRENT_CRYPTO_REVISION; ++i) {
|
||||||
if (check_key_existence(S128KeyType::Master, i) ||
|
if (check_key_existence(S128KeyType::Master, i) ||
|
||||||
|
@ -641,14 +667,16 @@ bool KeyManager::HasKey(S256KeyType id, u64 field1, u64 field2) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Key128 KeyManager::GetKey(S128KeyType id, u64 field1, u64 field2) const {
|
Key128 KeyManager::GetKey(S128KeyType id, u64 field1, u64 field2) const {
|
||||||
if (!HasKey(id, field1, field2))
|
if (!HasKey(id, field1, field2)) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
return s128_keys.at({id, field1, field2});
|
return s128_keys.at({id, field1, field2});
|
||||||
}
|
}
|
||||||
|
|
||||||
Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const {
|
Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const {
|
||||||
if (!HasKey(id, field1, field2))
|
if (!HasKey(id, field1, field2)) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
return s256_keys.at({id, field1, field2});
|
return s256_keys.at({id, field1, field2});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +698,7 @@ Key256 KeyManager::GetBISKey(u8 partition_id) const {
|
||||||
template <size_t Size>
|
template <size_t Size>
|
||||||
void KeyManager::WriteKeyToFile(KeyCategory category, std::string_view keyname,
|
void KeyManager::WriteKeyToFile(KeyCategory category, std::string_view keyname,
|
||||||
const std::array<u8, Size>& key) {
|
const std::array<u8, Size>& key) {
|
||||||
const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
|
const std::string yuzu_keys_dir = Common::FS::GetUserPath(Common::FS::UserPath::KeysDir);
|
||||||
std::string filename = "title.keys_autogenerated";
|
std::string filename = "title.keys_autogenerated";
|
||||||
if (category == KeyCategory::Standard) {
|
if (category == KeyCategory::Standard) {
|
||||||
filename = dev_mode ? "dev.keys_autogenerated" : "prod.keys_autogenerated";
|
filename = dev_mode ? "dev.keys_autogenerated" : "prod.keys_autogenerated";
|
||||||
|
@ -679,9 +707,9 @@ void KeyManager::WriteKeyToFile(KeyCategory category, std::string_view keyname,
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto path = yuzu_keys_dir + DIR_SEP + filename;
|
const auto path = yuzu_keys_dir + DIR_SEP + filename;
|
||||||
const auto add_info_text = !FileUtil::Exists(path);
|
const auto add_info_text = !Common::FS::Exists(path);
|
||||||
FileUtil::CreateFullPath(path);
|
Common::FS::CreateFullPath(path);
|
||||||
FileUtil::IOFile file{path, "a"};
|
Common::FS::IOFile file{path, "a"};
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -765,30 +793,32 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyManager::KeyFileExists(bool title) {
|
bool KeyManager::KeyFileExists(bool title) {
|
||||||
const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
|
const std::string hactool_keys_dir = Common::FS::GetHactoolConfigurationPath();
|
||||||
const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
|
const std::string yuzu_keys_dir = Common::FS::GetUserPath(Common::FS::UserPath::KeysDir);
|
||||||
if (title) {
|
if (title) {
|
||||||
return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "title.keys") ||
|
return Common::FS::Exists(hactool_keys_dir + DIR_SEP + "title.keys") ||
|
||||||
FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "title.keys");
|
Common::FS::Exists(yuzu_keys_dir + DIR_SEP + "title.keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::values.use_dev_keys) {
|
if (Settings::values.use_dev_keys) {
|
||||||
return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "dev.keys") ||
|
return Common::FS::Exists(hactool_keys_dir + DIR_SEP + "dev.keys") ||
|
||||||
FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "dev.keys");
|
Common::FS::Exists(yuzu_keys_dir + DIR_SEP + "dev.keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "prod.keys") ||
|
return Common::FS::Exists(hactool_keys_dir + DIR_SEP + "prod.keys") ||
|
||||||
FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "prod.keys");
|
Common::FS::Exists(yuzu_keys_dir + DIR_SEP + "prod.keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::DeriveSDSeedLazy() {
|
void KeyManager::DeriveSDSeedLazy() {
|
||||||
if (HasKey(S128KeyType::SDSeed))
|
if (HasKey(S128KeyType::SDSeed)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto res = DeriveSDSeed();
|
const auto res = DeriveSDSeed();
|
||||||
if (res)
|
if (res) {
|
||||||
SetKey(S128KeyType::SDSeed, *res);
|
SetKey(S128KeyType::SDSeed, *res);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Key128 CalculateCMAC(const u8* source, size_t size, const Key128& key) {
|
static Key128 CalculateCMAC(const u8* source, size_t size, const Key128& key) {
|
||||||
Key128 out{};
|
Key128 out{};
|
||||||
|
@ -799,11 +829,13 @@ static Key128 CalculateCMAC(const u8* source, size_t size, const Key128& key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::DeriveBase() {
|
void KeyManager::DeriveBase() {
|
||||||
if (!BaseDeriveNecessary())
|
if (!BaseDeriveNecessary()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!HasKey(S128KeyType::SecureBoot) || !HasKey(S128KeyType::TSEC))
|
if (!HasKey(S128KeyType::SecureBoot) || !HasKey(S128KeyType::TSEC)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto has_bis = [this](u64 id) {
|
const auto has_bis = [this](u64 id) {
|
||||||
return HasKey(S128KeyType::BIS, id, static_cast<u64>(BISKeyType::Crypto)) &&
|
return HasKey(S128KeyType::BIS, id, static_cast<u64>(BISKeyType::Crypto)) &&
|
||||||
|
@ -820,10 +852,11 @@ void KeyManager::DeriveBase() {
|
||||||
static_cast<u64>(BISKeyType::Tweak));
|
static_cast<u64>(BISKeyType::Tweak));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (has_bis(2) && !has_bis(3))
|
if (has_bis(2) && !has_bis(3)) {
|
||||||
copy_bis(2, 3);
|
copy_bis(2, 3);
|
||||||
else if (has_bis(3) && !has_bis(2))
|
} else if (has_bis(3) && !has_bis(2)) {
|
||||||
copy_bis(3, 2);
|
copy_bis(3, 2);
|
||||||
|
}
|
||||||
|
|
||||||
std::bitset<32> revisions(0xFFFFFFFF);
|
std::bitset<32> revisions(0xFFFFFFFF);
|
||||||
for (size_t i = 0; i < revisions.size(); ++i) {
|
for (size_t i = 0; i < revisions.size(); ++i) {
|
||||||
|
@ -833,15 +866,17 @@ void KeyManager::DeriveBase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!revisions.any())
|
if (!revisions.any()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto sbk = GetKey(S128KeyType::SecureBoot);
|
const auto sbk = GetKey(S128KeyType::SecureBoot);
|
||||||
const auto tsec = GetKey(S128KeyType::TSEC);
|
const auto tsec = GetKey(S128KeyType::TSEC);
|
||||||
|
|
||||||
for (size_t i = 0; i < revisions.size(); ++i) {
|
for (size_t i = 0; i < revisions.size(); ++i) {
|
||||||
if (!revisions[i])
|
if (!revisions[i]) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Derive keyblob key
|
// Derive keyblob key
|
||||||
const auto key = DeriveKeyblobKey(
|
const auto key = DeriveKeyblobKey(
|
||||||
|
@ -850,16 +885,18 @@ void KeyManager::DeriveBase() {
|
||||||
SetKey(S128KeyType::Keyblob, key, i);
|
SetKey(S128KeyType::Keyblob, key, i);
|
||||||
|
|
||||||
// Derive keyblob MAC key
|
// Derive keyblob MAC key
|
||||||
if (!HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::KeyblobMAC)))
|
if (!HasKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::KeyblobMAC))) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto mac_key = DeriveKeyblobMACKey(
|
const auto mac_key = DeriveKeyblobMACKey(
|
||||||
key, GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::KeyblobMAC)));
|
key, GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::KeyblobMAC)));
|
||||||
SetKey(S128KeyType::KeyblobMAC, mac_key, i);
|
SetKey(S128KeyType::KeyblobMAC, mac_key, i);
|
||||||
|
|
||||||
Key128 cmac = CalculateCMAC(encrypted_keyblobs[i].data() + 0x10, 0xA0, mac_key);
|
Key128 cmac = CalculateCMAC(encrypted_keyblobs[i].data() + 0x10, 0xA0, mac_key);
|
||||||
if (std::memcmp(cmac.data(), encrypted_keyblobs[i].data(), cmac.size()) != 0)
|
if (std::memcmp(cmac.data(), encrypted_keyblobs[i].data(), cmac.size()) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Decrypt keyblob
|
// Decrypt keyblob
|
||||||
if (keyblobs[i] == std::array<u8, 0x90>{}) {
|
if (keyblobs[i] == std::array<u8, 0x90>{}) {
|
||||||
|
@ -883,16 +920,19 @@ void KeyManager::DeriveBase() {
|
||||||
|
|
||||||
revisions.set();
|
revisions.set();
|
||||||
for (size_t i = 0; i < revisions.size(); ++i) {
|
for (size_t i = 0; i < revisions.size(); ++i) {
|
||||||
if (!HasKey(S128KeyType::Master, i))
|
if (!HasKey(S128KeyType::Master, i)) {
|
||||||
revisions.reset(i);
|
revisions.reset(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!revisions.any())
|
if (!revisions.any()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < revisions.size(); ++i) {
|
for (size_t i = 0; i < revisions.size(); ++i) {
|
||||||
if (!revisions[i])
|
if (!revisions[i]) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Derive general purpose keys
|
// Derive general purpose keys
|
||||||
DeriveGeneralPurposeKeys(i);
|
DeriveGeneralPurposeKeys(i);
|
||||||
|
@ -922,16 +962,19 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
|
||||||
const auto es = Core::System::GetInstance().GetContentProvider().GetEntry(
|
const auto es = Core::System::GetInstance().GetContentProvider().GetEntry(
|
||||||
0x0100000000000033, FileSys::ContentRecordType::Program);
|
0x0100000000000033, FileSys::ContentRecordType::Program);
|
||||||
|
|
||||||
if (es == nullptr)
|
if (es == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto exefs = es->GetExeFS();
|
const auto exefs = es->GetExeFS();
|
||||||
if (exefs == nullptr)
|
if (exefs == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto main = exefs->GetFile("main");
|
const auto main = exefs->GetFile("main");
|
||||||
if (main == nullptr)
|
if (main == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto bytes = main->ReadAllBytes();
|
const auto bytes = main->ReadAllBytes();
|
||||||
|
|
||||||
|
@ -941,16 +984,19 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
|
||||||
const auto seed3 = data.GetRSAKekSeed3();
|
const auto seed3 = data.GetRSAKekSeed3();
|
||||||
const auto mask0 = data.GetRSAKekMask0();
|
const auto mask0 = data.GetRSAKekMask0();
|
||||||
|
|
||||||
if (eticket_kek != Key128{})
|
if (eticket_kek != Key128{}) {
|
||||||
SetKey(S128KeyType::Source, eticket_kek, static_cast<size_t>(SourceKeyType::ETicketKek));
|
SetKey(S128KeyType::Source, eticket_kek, static_cast<size_t>(SourceKeyType::ETicketKek));
|
||||||
|
}
|
||||||
if (eticket_kekek != Key128{}) {
|
if (eticket_kekek != Key128{}) {
|
||||||
SetKey(S128KeyType::Source, eticket_kekek,
|
SetKey(S128KeyType::Source, eticket_kekek,
|
||||||
static_cast<size_t>(SourceKeyType::ETicketKekek));
|
static_cast<size_t>(SourceKeyType::ETicketKekek));
|
||||||
}
|
}
|
||||||
if (seed3 != Key128{})
|
if (seed3 != Key128{}) {
|
||||||
SetKey(S128KeyType::RSAKek, seed3, static_cast<size_t>(RSAKekType::Seed3));
|
SetKey(S128KeyType::RSAKek, seed3, static_cast<size_t>(RSAKekType::Seed3));
|
||||||
if (mask0 != Key128{})
|
}
|
||||||
|
if (mask0 != Key128{}) {
|
||||||
SetKey(S128KeyType::RSAKek, mask0, static_cast<size_t>(RSAKekType::Mask0));
|
SetKey(S128KeyType::RSAKek, mask0, static_cast<size_t>(RSAKekType::Mask0));
|
||||||
|
}
|
||||||
if (eticket_kek == Key128{} || eticket_kekek == Key128{} || seed3 == Key128{} ||
|
if (eticket_kek == Key128{} || eticket_kekek == Key128{} || seed3 == Key128{} ||
|
||||||
mask0 == Key128{}) {
|
mask0 == Key128{}) {
|
||||||
return;
|
return;
|
||||||
|
@ -976,8 +1022,9 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
|
||||||
AESCipher<Key128> es_kek(temp_kekek, Mode::ECB);
|
AESCipher<Key128> es_kek(temp_kekek, Mode::ECB);
|
||||||
es_kek.Transcode(eticket_kek.data(), eticket_kek.size(), eticket_final.data(), Op::Decrypt);
|
es_kek.Transcode(eticket_kek.data(), eticket_kek.size(), eticket_final.data(), Op::Decrypt);
|
||||||
|
|
||||||
if (eticket_final == Key128{})
|
if (eticket_final == Key128{}) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetKey(S128KeyType::ETicketRSAKek, eticket_final);
|
SetKey(S128KeyType::ETicketRSAKek, eticket_final);
|
||||||
|
|
||||||
|
@ -992,16 +1039,18 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
|
||||||
void KeyManager::PopulateTickets() {
|
void KeyManager::PopulateTickets() {
|
||||||
const auto rsa_key = GetETicketRSAKey();
|
const auto rsa_key = GetETicketRSAKey();
|
||||||
|
|
||||||
if (rsa_key == RSAKeyPair<2048>{})
|
if (rsa_key == RSAKeyPair<2048>{}) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!common_tickets.empty() && !personal_tickets.empty())
|
if (!common_tickets.empty() && !personal_tickets.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const FileUtil::IOFile save1(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const Common::FS::IOFile save1(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/80000000000000e1",
|
"/system/save/80000000000000e1",
|
||||||
"rb+");
|
"rb+");
|
||||||
const FileUtil::IOFile save2(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const Common::FS::IOFile save2(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/80000000000000e2",
|
"/system/save/80000000000000e2",
|
||||||
"rb+");
|
"rb+");
|
||||||
|
|
||||||
|
@ -1013,8 +1062,10 @@ void KeyManager::PopulateTickets() {
|
||||||
for (std::size_t i = 0; i < res.size(); ++i) {
|
for (std::size_t i = 0; i < res.size(); ++i) {
|
||||||
const auto common = i < idx;
|
const auto common = i < idx;
|
||||||
const auto pair = ParseTicket(res[i], rsa_key);
|
const auto pair = ParseTicket(res[i], rsa_key);
|
||||||
if (!pair)
|
if (!pair) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& [rid, key] = *pair;
|
const auto& [rid, key] = *pair;
|
||||||
u128 rights_id;
|
u128 rights_id;
|
||||||
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
||||||
|
@ -1043,27 +1094,33 @@ void KeyManager::SynthesizeTickets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::SetKeyWrapped(S128KeyType id, Key128 key, u64 field1, u64 field2) {
|
void KeyManager::SetKeyWrapped(S128KeyType id, Key128 key, u64 field1, u64 field2) {
|
||||||
if (key == Key128{})
|
if (key == Key128{}) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
SetKey(id, key, field1, field2);
|
SetKey(id, key, field1, field2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::SetKeyWrapped(S256KeyType id, Key256 key, u64 field1, u64 field2) {
|
void KeyManager::SetKeyWrapped(S256KeyType id, Key256 key, u64 field1, u64 field2) {
|
||||||
if (key == Key256{})
|
if (key == Key256{}) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetKey(id, key, field1, field2);
|
SetKey(id, key, field1, field2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyManager::PopulateFromPartitionData(PartitionDataManager& data) {
|
void KeyManager::PopulateFromPartitionData(PartitionDataManager& data) {
|
||||||
if (!BaseDeriveNecessary())
|
if (!BaseDeriveNecessary()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data.HasBoot0())
|
if (!data.HasBoot0()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < encrypted_keyblobs.size(); ++i) {
|
for (size_t i = 0; i < encrypted_keyblobs.size(); ++i) {
|
||||||
if (encrypted_keyblobs[i] != std::array<u8, 0xB0>{})
|
if (encrypted_keyblobs[i] != std::array<u8, 0xB0>{}) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
encrypted_keyblobs[i] = data.GetEncryptedKeyblob(i);
|
encrypted_keyblobs[i] = data.GetEncryptedKeyblob(i);
|
||||||
WriteKeyToFile<0xB0>(KeyCategory::Console, fmt::format("encrypted_keyblob_{:02X}", i),
|
WriteKeyToFile<0xB0>(KeyCategory::Console, fmt::format("encrypted_keyblob_{:02X}", i),
|
||||||
encrypted_keyblobs[i]);
|
encrypted_keyblobs[i]);
|
||||||
|
@ -1085,8 +1142,9 @@ void KeyManager::PopulateFromPartitionData(PartitionDataManager& data) {
|
||||||
static_cast<u64>(SourceKeyType::Keyblob), i);
|
static_cast<u64>(SourceKeyType::Keyblob), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.HasFuses())
|
if (data.HasFuses()) {
|
||||||
SetKeyWrapped(S128KeyType::SecureBoot, data.GetSecureBootKey());
|
SetKeyWrapped(S128KeyType::SecureBoot, data.GetSecureBootKey());
|
||||||
|
}
|
||||||
|
|
||||||
DeriveBase();
|
DeriveBase();
|
||||||
|
|
||||||
|
@ -1100,9 +1158,10 @@ void KeyManager::PopulateFromPartitionData(PartitionDataManager& data) {
|
||||||
|
|
||||||
const auto masters = data.GetTZMasterKeys(latest_master);
|
const auto masters = data.GetTZMasterKeys(latest_master);
|
||||||
for (size_t i = 0; i < masters.size(); ++i) {
|
for (size_t i = 0; i < masters.size(); ++i) {
|
||||||
if (masters[i] != Key128{} && !HasKey(S128KeyType::Master, i))
|
if (masters[i] != Key128{} && !HasKey(S128KeyType::Master, i)) {
|
||||||
SetKey(S128KeyType::Master, masters[i], i);
|
SetKey(S128KeyType::Master, masters[i], i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DeriveBase();
|
DeriveBase();
|
||||||
|
|
||||||
|
@ -1111,9 +1170,10 @@ void KeyManager::PopulateFromPartitionData(PartitionDataManager& data) {
|
||||||
|
|
||||||
std::array<Key128, 0x20> package2_keys{};
|
std::array<Key128, 0x20> package2_keys{};
|
||||||
for (size_t i = 0; i < package2_keys.size(); ++i) {
|
for (size_t i = 0; i < package2_keys.size(); ++i) {
|
||||||
if (HasKey(S128KeyType::Package2, i))
|
if (HasKey(S128KeyType::Package2, i)) {
|
||||||
package2_keys[i] = GetKey(S128KeyType::Package2, i);
|
package2_keys[i] = GetKey(S128KeyType::Package2, i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
data.DecryptPackage2(package2_keys, Package2Type::NormalMain);
|
data.DecryptPackage2(package2_keys, Package2Type::NormalMain);
|
||||||
|
|
||||||
SetKeyWrapped(S128KeyType::Source, data.GetKeyAreaKeyApplicationSource(),
|
SetKeyWrapped(S128KeyType::Source, data.GetKeyAreaKeyApplicationSource(),
|
||||||
|
@ -1150,12 +1210,15 @@ const std::map<u128, Ticket>& KeyManager::GetPersonalizedTickets() const {
|
||||||
|
|
||||||
bool KeyManager::AddTicketCommon(Ticket raw) {
|
bool KeyManager::AddTicketCommon(Ticket raw) {
|
||||||
const auto rsa_key = GetETicketRSAKey();
|
const auto rsa_key = GetETicketRSAKey();
|
||||||
if (rsa_key == RSAKeyPair<2048>{})
|
if (rsa_key == RSAKeyPair<2048>{}) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto pair = ParseTicket(raw, rsa_key);
|
const auto pair = ParseTicket(raw, rsa_key);
|
||||||
if (!pair)
|
if (!pair) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& [rid, key] = *pair;
|
const auto& [rid, key] = *pair;
|
||||||
u128 rights_id;
|
u128 rights_id;
|
||||||
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
||||||
|
@ -1166,12 +1229,15 @@ bool KeyManager::AddTicketCommon(Ticket raw) {
|
||||||
|
|
||||||
bool KeyManager::AddTicketPersonalized(Ticket raw) {
|
bool KeyManager::AddTicketPersonalized(Ticket raw) {
|
||||||
const auto rsa_key = GetETicketRSAKey();
|
const auto rsa_key = GetETicketRSAKey();
|
||||||
if (rsa_key == RSAKeyPair<2048>{})
|
if (rsa_key == RSAKeyPair<2048>{}) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto pair = ParseTicket(raw, rsa_key);
|
const auto pair = ParseTicket(raw, rsa_key);
|
||||||
if (!pair)
|
if (!pair) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& [rid, key] = *pair;
|
const auto& [rid, key] = *pair;
|
||||||
u128 rights_id;
|
u128 rights_id;
|
||||||
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
std::memcpy(rights_id.data(), rid.data(), rid.size());
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "core/crypto/partition_data_manager.h"
|
#include "core/crypto/partition_data_manager.h"
|
||||||
#include "core/file_sys/vfs_types.h"
|
#include "core/file_sys/vfs_types.h"
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace Common::FS {
|
||||||
class IOFile;
|
class IOFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ std::array<u8, 0x90> DecryptKeyblob(const std::array<u8, 0xB0>& encrypted_keyblo
|
||||||
std::optional<Key128> DeriveSDSeed();
|
std::optional<Key128> DeriveSDSeed();
|
||||||
Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys);
|
Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys);
|
||||||
|
|
||||||
std::vector<Ticket> GetTicketblob(const FileUtil::IOFile& ticket_save);
|
std::vector<Ticket> GetTicketblob(const Common::FS::IOFile& ticket_save);
|
||||||
|
|
||||||
// Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority
|
// Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority
|
||||||
// (offset 0x140-0x144 is zero)
|
// (offset 0x140-0x144 is zero)
|
||||||
|
|
|
@ -86,7 +86,7 @@ VirtualFile BISFactory::OpenPartitionStorage(BisPartitionId id) const {
|
||||||
auto& keys = Core::Crypto::KeyManager::Instance();
|
auto& keys = Core::Crypto::KeyManager::Instance();
|
||||||
Core::Crypto::PartitionDataManager pdm{
|
Core::Crypto::PartitionDataManager pdm{
|
||||||
Core::System::GetInstance().GetFilesystem()->OpenDirectory(
|
Core::System::GetInstance().GetFilesystem()->OpenDirectory(
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), Mode::Read)};
|
Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir), Mode::Read)};
|
||||||
keys.PopulateFromPartitionData(pdm);
|
keys.PopulateFromPartitionData(pdm);
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
|
|
@ -728,7 +728,7 @@ InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFuncti
|
||||||
LOG_WARNING(Loader, "Overwriting existing NCA...");
|
LOG_WARNING(Loader, "Overwriting existing NCA...");
|
||||||
VirtualDir c_dir;
|
VirtualDir c_dir;
|
||||||
{ c_dir = dir->GetFileRelative(path)->GetContainingDirectory(); }
|
{ c_dir = dir->GetFileRelative(path)->GetContainingDirectory(); }
|
||||||
c_dir->DeleteFile(FileUtil::GetFilename(path));
|
c_dir->DeleteFile(Common::FS::GetFilename(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out = dir->CreateFileRelative(path);
|
auto out = dir->CreateFileRelative(path);
|
||||||
|
|
|
@ -30,7 +30,7 @@ bool VfsFilesystem::IsWritable() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) 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)
|
if (root->GetFileRelative(path) != nullptr)
|
||||||
return VfsEntryType::File;
|
return VfsEntryType::File;
|
||||||
if (root->GetDirectoryRelative(path) != nullptr)
|
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) {
|
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);
|
return root->GetFileRelative(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) {
|
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);
|
return root->CreateFileRelative(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) {
|
VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) {
|
||||||
const auto old_path = FileUtil::SanitizePath(old_path_);
|
const auto old_path = Common::FS::SanitizePath(old_path_);
|
||||||
const auto new_path = FileUtil::SanitizePath(new_path_);
|
const auto new_path = Common::FS::SanitizePath(new_path_);
|
||||||
|
|
||||||
// VfsDirectory impls are only required to implement copy across the current directory.
|
// VfsDirectory impls are only required to implement copy across the current directory.
|
||||||
if (FileUtil::GetParentPath(old_path) == FileUtil::GetParentPath(new_path)) {
|
if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) {
|
||||||
if (!root->Copy(FileUtil::GetFilename(old_path), FileUtil::GetFilename(new_path)))
|
if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return OpenFile(new_path, Mode::ReadWrite);
|
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) {
|
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_old_path = Common::FS::SanitizePath(old_path);
|
||||||
const auto sanitized_new_path = FileUtil::SanitizePath(new_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.
|
// Again, non-default impls are highly encouraged to provide a more optimized version of this.
|
||||||
auto out = CopyFile(sanitized_old_path, sanitized_new_path);
|
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_) {
|
bool VfsFilesystem::DeleteFile(std::string_view path_) {
|
||||||
const auto path = FileUtil::SanitizePath(path_);
|
const auto path = Common::FS::SanitizePath(path_);
|
||||||
auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write);
|
auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write);
|
||||||
if (parent == nullptr)
|
if (parent == nullptr)
|
||||||
return false;
|
return false;
|
||||||
return parent->DeleteFile(FileUtil::GetFilename(path));
|
return parent->DeleteFile(Common::FS::GetFilename(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) {
|
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);
|
return root->GetDirectoryRelative(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) {
|
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);
|
return root->CreateDirectoryRelative(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_view new_path_) {
|
VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_view new_path_) {
|
||||||
const auto old_path = FileUtil::SanitizePath(old_path_);
|
const auto old_path = Common::FS::SanitizePath(old_path_);
|
||||||
const auto new_path = FileUtil::SanitizePath(new_path_);
|
const auto new_path = Common::FS::SanitizePath(new_path_);
|
||||||
|
|
||||||
// Non-default impls are highly encouraged to provide a more optimized version of this.
|
// Non-default impls are highly encouraged to provide a more optimized version of this.
|
||||||
auto old_dir = OpenDirectory(old_path, Mode::Read);
|
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) {
|
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_old_path = Common::FS::SanitizePath(old_path);
|
||||||
const auto sanitized_new_path = FileUtil::SanitizePath(new_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.
|
// Non-default impls are highly encouraged to provide a more optimized version of this.
|
||||||
auto out = CopyDirectory(sanitized_old_path, sanitized_new_path);
|
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_) {
|
bool VfsFilesystem::DeleteDirectory(std::string_view path_) {
|
||||||
const auto path = FileUtil::SanitizePath(path_);
|
const auto path = Common::FS::SanitizePath(path_);
|
||||||
auto parent = OpenDirectory(FileUtil::GetParentPath(path), Mode::Write);
|
auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write);
|
||||||
if (parent == nullptr)
|
if (parent == nullptr)
|
||||||
return false;
|
return false;
|
||||||
return parent->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path));
|
return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsFile::~VfsFile() = default;
|
VfsFile::~VfsFile() = default;
|
||||||
|
|
||||||
std::string VfsFile::GetExtension() const {
|
std::string VfsFile::GetExtension() const {
|
||||||
return std::string(FileUtil::GetExtensionFromFilename(GetName()));
|
return std::string(Common::FS::GetExtensionFromFilename(GetName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsDirectory::~VfsDirectory() = default;
|
VfsDirectory::~VfsDirectory() = default;
|
||||||
|
@ -203,7 +203,7 @@ std::string VfsFile::GetFullPath() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) const {
|
std::shared_ptr<VfsFile> 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.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||||
vec.end());
|
vec.end());
|
||||||
if (vec.empty()) {
|
if (vec.empty()) {
|
||||||
|
@ -239,7 +239,7 @@ std::shared_ptr<VfsFile> VfsDirectory::GetFileAbsolute(std::string_view path) co
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> VfsDirectory::GetDirectoryRelative(std::string_view path) const {
|
std::shared_ptr<VfsDirectory> 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.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||||
vec.end());
|
vec.end());
|
||||||
if (vec.empty()) {
|
if (vec.empty()) {
|
||||||
|
@ -301,7 +301,7 @@ std::size_t VfsDirectory::GetSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsFile> VfsDirectory::CreateFileRelative(std::string_view path) {
|
std::shared_ptr<VfsFile> 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.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||||
vec.end());
|
vec.end());
|
||||||
if (vec.empty()) {
|
if (vec.empty()) {
|
||||||
|
@ -320,7 +320,7 @@ std::shared_ptr<VfsFile> VfsDirectory::CreateFileRelative(std::string_view path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir->CreateFileRelative(FileUtil::GetPathWithoutTop(path));
|
return dir->CreateFileRelative(Common::FS::GetPathWithoutTop(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path) {
|
std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path) {
|
||||||
|
@ -332,7 +332,7 @@ std::shared_ptr<VfsFile> VfsDirectory::CreateFileAbsolute(std::string_view path)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryRelative(std::string_view path) {
|
std::shared_ptr<VfsDirectory> 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.erase(std::remove_if(vec.begin(), vec.end(), [](const auto& str) { return str.empty(); }),
|
||||||
vec.end());
|
vec.end());
|
||||||
if (vec.empty()) {
|
if (vec.empty()) {
|
||||||
|
@ -351,7 +351,7 @@ std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryRelative(std::string_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir->CreateDirectoryRelative(FileUtil::GetPathWithoutTop(path));
|
return dir->CreateDirectoryRelative(Common::FS::GetPathWithoutTop(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryAbsolute(std::string_view path) {
|
std::shared_ptr<VfsDirectory> VfsDirectory::CreateDirectoryAbsolute(std::string_view path) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ VirtualDir ExtractZIP(VirtualFile file) {
|
||||||
if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size()))
|
if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const auto parts = FileUtil::SplitPathComponents(stat.name);
|
const auto parts = Common::FS::SplitPathComponents(stat.name);
|
||||||
const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back());
|
const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back());
|
||||||
|
|
||||||
std::shared_ptr<VectorVfsDirectory> dtrv = out;
|
std::shared_ptr<VectorVfsDirectory> dtrv = out;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
|
namespace FS = Common::FS;
|
||||||
|
|
||||||
static std::string ModeFlagsToString(Mode mode) {
|
static std::string ModeFlagsToString(Mode mode) {
|
||||||
std::string mode_str;
|
std::string mode_str;
|
||||||
|
|
||||||
|
@ -57,17 +59,19 @@ bool RealVfsFilesystem::IsWritable() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const {
|
VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
if (!FileUtil::Exists(path))
|
if (!FS::Exists(path)) {
|
||||||
return VfsEntryType::None;
|
return VfsEntryType::None;
|
||||||
if (FileUtil::IsDirectory(path))
|
}
|
||||||
|
if (FS::IsDirectory(path)) {
|
||||||
return VfsEntryType::Directory;
|
return VfsEntryType::Directory;
|
||||||
|
}
|
||||||
|
|
||||||
return VfsEntryType::File;
|
return VfsEntryType::File;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
|
VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
if (cache.find(path) != cache.end()) {
|
if (cache.find(path) != cache.end()) {
|
||||||
auto weak = cache[path];
|
auto weak = cache[path];
|
||||||
if (!weak.expired()) {
|
if (!weak.expired()) {
|
||||||
|
@ -75,11 +79,11 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) {
|
if (!FS::Exists(path) && True(perms & Mode::WriteAppend)) {
|
||||||
FileUtil::CreateEmptyFile(path);
|
FS::CreateEmptyFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto backing = std::make_shared<FileUtil::IOFile>(path, ModeFlagsToString(perms).c_str());
|
auto backing = std::make_shared<FS::IOFile>(path, ModeFlagsToString(perms).c_str());
|
||||||
cache[path] = backing;
|
cache[path] = backing;
|
||||||
|
|
||||||
// Cannot use make_shared as RealVfsFile constructor is private
|
// Cannot use make_shared as RealVfsFile constructor is private
|
||||||
|
@ -87,33 +91,31 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) {
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) {
|
VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash);
|
const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash);
|
||||||
if (!FileUtil::Exists(path)) {
|
if (!FS::Exists(path)) {
|
||||||
FileUtil::CreateFullPath(path_fwd);
|
FS::CreateFullPath(path_fwd);
|
||||||
if (!FileUtil::CreateEmptyFile(path))
|
if (!FS::CreateEmptyFile(path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return OpenFile(path, perms);
|
return OpenFile(path, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) {
|
VirtualFile RealVfsFilesystem::CopyFile(std::string_view old_path_, std::string_view new_path_) {
|
||||||
const auto old_path =
|
const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto new_path =
|
|
||||||
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
|
||||||
|
|
||||||
if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
|
if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) ||
|
||||||
FileUtil::IsDirectory(old_path) || !FileUtil::Copy(old_path, new_path))
|
!FS::Copy(old_path, new_path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return OpenFile(new_path, Mode::ReadWrite);
|
return OpenFile(new_path, Mode::ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) {
|
VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_view new_path_) {
|
||||||
const auto old_path =
|
const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto new_path =
|
|
||||||
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
|
||||||
|
|
||||||
if (cache.find(old_path) != cache.end()) {
|
if (cache.find(old_path) != cache.end()) {
|
||||||
auto file = cache[old_path].lock();
|
auto file = cache[old_path].lock();
|
||||||
|
@ -122,8 +124,8 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_
|
||||||
file->Close();
|
file->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
|
if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) ||
|
||||||
FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) {
|
!FS::Rename(old_path, new_path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,64 +141,64 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RealVfsFilesystem::DeleteFile(std::string_view path_) {
|
bool RealVfsFilesystem::DeleteFile(std::string_view path_) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
if (cache.find(path) != cache.end()) {
|
if (cache.find(path) != cache.end()) {
|
||||||
if (!cache[path].expired())
|
if (!cache[path].expired()) {
|
||||||
cache[path].lock()->Close();
|
cache[path].lock()->Close();
|
||||||
|
}
|
||||||
cache.erase(path);
|
cache.erase(path);
|
||||||
}
|
}
|
||||||
return FileUtil::Delete(path);
|
return FS::Delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) {
|
VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
// Cannot use make_shared as RealVfsDirectory constructor is private
|
// Cannot use make_shared as RealVfsDirectory constructor is private
|
||||||
return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));
|
return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) {
|
VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto path_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash);
|
const auto path_fwd = FS::SanitizePath(path, FS::DirectorySeparator::ForwardSlash);
|
||||||
if (!FileUtil::Exists(path)) {
|
if (!FS::Exists(path)) {
|
||||||
FileUtil::CreateFullPath(path_fwd);
|
FS::CreateFullPath(path_fwd);
|
||||||
if (!FileUtil::CreateDir(path))
|
if (!FS::CreateDir(path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Cannot use make_shared as RealVfsDirectory constructor is private
|
// Cannot use make_shared as RealVfsDirectory constructor is private
|
||||||
return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));
|
return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_,
|
VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_,
|
||||||
std::string_view new_path_) {
|
std::string_view new_path_) {
|
||||||
const auto old_path =
|
const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto new_path =
|
if (!FS::Exists(old_path) || FS::Exists(new_path) || !FS::IsDirectory(old_path)) {
|
||||||
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
|
||||||
if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
|
|
||||||
!FileUtil::IsDirectory(old_path))
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
FileUtil::CopyDir(old_path, new_path);
|
}
|
||||||
|
FS::CopyDir(old_path, new_path);
|
||||||
return OpenDirectory(new_path, Mode::ReadWrite);
|
return OpenDirectory(new_path, Mode::ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_,
|
VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_,
|
||||||
std::string_view new_path_) {
|
std::string_view new_path_) {
|
||||||
const auto old_path =
|
const auto old_path = FS::SanitizePath(old_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
FileUtil::SanitizePath(old_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto new_path = FS::SanitizePath(new_path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto new_path =
|
|
||||||
FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault);
|
if (!FS::Exists(old_path) || FS::Exists(new_path) || FS::IsDirectory(old_path) ||
|
||||||
if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) ||
|
!FS::Rename(old_path, new_path)) {
|
||||||
FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path))
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& kv : cache) {
|
for (auto& kv : cache) {
|
||||||
// Path in cache starts with old_path
|
// Path in cache starts with old_path
|
||||||
if (kv.first.rfind(old_path, 0) == 0) {
|
if (kv.first.rfind(old_path, 0) == 0) {
|
||||||
const auto file_old_path =
|
const auto file_old_path =
|
||||||
FileUtil::SanitizePath(kv.first, FileUtil::DirectorySeparator::PlatformDefault);
|
FS::SanitizePath(kv.first, FS::DirectorySeparator::PlatformDefault);
|
||||||
const auto file_new_path =
|
const auto file_new_path =
|
||||||
FileUtil::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()),
|
FS::SanitizePath(new_path + DIR_SEP + kv.first.substr(old_path.size()),
|
||||||
FileUtil::DirectorySeparator::PlatformDefault);
|
FS::DirectorySeparator::PlatformDefault);
|
||||||
auto cached = cache[file_old_path];
|
auto cached = cache[file_old_path];
|
||||||
if (!cached.expired()) {
|
if (!cached.expired()) {
|
||||||
auto file = cached.lock();
|
auto file = cached.lock();
|
||||||
|
@ -211,24 +213,24 @@ VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) {
|
bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) {
|
||||||
const auto path = FileUtil::SanitizePath(path_, FileUtil::DirectorySeparator::PlatformDefault);
|
const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
|
||||||
for (auto& kv : cache) {
|
for (auto& kv : cache) {
|
||||||
// Path in cache starts with old_path
|
// Path in cache starts with old_path
|
||||||
if (kv.first.rfind(path, 0) == 0) {
|
if (kv.first.rfind(path, 0) == 0) {
|
||||||
if (!cache[kv.first].expired())
|
if (!cache[kv.first].expired()) {
|
||||||
cache[kv.first].lock()->Close();
|
cache[kv.first].lock()->Close();
|
||||||
|
}
|
||||||
cache.erase(kv.first);
|
cache.erase(kv.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FileUtil::DeleteDirRecursively(path);
|
return FS::DeleteDirRecursively(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::shared_ptr<FileUtil::IOFile> backing_,
|
RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::shared_ptr<FS::IOFile> backing_,
|
||||||
const std::string& path_, Mode perms_)
|
const std::string& path_, Mode perms_)
|
||||||
: base(base_), backing(std::move(backing_)), path(path_),
|
: base(base_), backing(std::move(backing_)), path(path_), parent_path(FS::GetParentPath(path_)),
|
||||||
parent_path(FileUtil::GetParentPath(path_)),
|
path_components(FS::SplitPathComponents(path_)),
|
||||||
path_components(FileUtil::SplitPathComponents(path_)),
|
parent_components(FS::SliceVector(path_components, 0, path_components.size() - 1)),
|
||||||
parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)),
|
|
||||||
perms(perms_) {}
|
perms(perms_) {}
|
||||||
|
|
||||||
RealVfsFile::~RealVfsFile() = default;
|
RealVfsFile::~RealVfsFile() = default;
|
||||||
|
@ -258,14 +260,16 @@ bool RealVfsFile::IsReadable() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
|
std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
|
||||||
if (!backing->Seek(offset, SEEK_SET))
|
if (!backing->Seek(offset, SEEK_SET)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return backing->ReadBytes(data, length);
|
return backing->ReadBytes(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
|
std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
|
||||||
if (!backing->Seek(offset, SEEK_SET))
|
if (!backing->Seek(offset, SEEK_SET)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return backing->WriteBytes(data, length);
|
return backing->WriteBytes(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,16 +286,18 @@ bool RealVfsFile::Close() {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const {
|
std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const {
|
||||||
if (perms == Mode::Append)
|
if (perms == Mode::Append) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<VirtualFile> out;
|
std::vector<VirtualFile> out;
|
||||||
FileUtil::ForeachDirectoryEntry(
|
FS::ForeachDirectoryEntry(
|
||||||
nullptr, path,
|
nullptr, path,
|
||||||
[&out, this](u64* entries_out, const std::string& directory, const std::string& filename) {
|
[&out, this](u64* entries_out, const std::string& directory, const std::string& filename) {
|
||||||
const std::string full_path = directory + DIR_SEP + filename;
|
const std::string full_path = directory + DIR_SEP + filename;
|
||||||
if (!FileUtil::IsDirectory(full_path))
|
if (!FS::IsDirectory(full_path)) {
|
||||||
out.emplace_back(base.OpenFile(full_path, perms));
|
out.emplace_back(base.OpenFile(full_path, perms));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -300,16 +306,18 @@ std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>(
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const {
|
std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const {
|
||||||
if (perms == Mode::Append)
|
if (perms == Mode::Append) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<VirtualDir> out;
|
std::vector<VirtualDir> out;
|
||||||
FileUtil::ForeachDirectoryEntry(
|
FS::ForeachDirectoryEntry(
|
||||||
nullptr, path,
|
nullptr, path,
|
||||||
[&out, this](u64* entries_out, const std::string& directory, const std::string& filename) {
|
[&out, this](u64* entries_out, const std::string& directory, const std::string& filename) {
|
||||||
const std::string full_path = directory + DIR_SEP + filename;
|
const std::string full_path = directory + DIR_SEP + filename;
|
||||||
if (FileUtil::IsDirectory(full_path))
|
if (FS::IsDirectory(full_path)) {
|
||||||
out.emplace_back(base.OpenDirectory(full_path, perms));
|
out.emplace_back(base.OpenDirectory(full_path, perms));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -317,29 +325,30 @@ std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDi
|
||||||
}
|
}
|
||||||
|
|
||||||
RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_)
|
RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_)
|
||||||
: base(base_), path(FileUtil::RemoveTrailingSlash(path_)),
|
: base(base_), path(FS::RemoveTrailingSlash(path_)), parent_path(FS::GetParentPath(path)),
|
||||||
parent_path(FileUtil::GetParentPath(path)),
|
path_components(FS::SplitPathComponents(path)),
|
||||||
path_components(FileUtil::SplitPathComponents(path)),
|
parent_components(FS::SliceVector(path_components, 0, path_components.size() - 1)),
|
||||||
parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)),
|
|
||||||
perms(perms_) {
|
perms(perms_) {
|
||||||
if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) {
|
if (!FS::Exists(path) && True(perms & Mode::WriteAppend)) {
|
||||||
FileUtil::CreateDir(path);
|
FS::CreateDir(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RealVfsDirectory::~RealVfsDirectory() = default;
|
RealVfsDirectory::~RealVfsDirectory() = default;
|
||||||
|
|
||||||
std::shared_ptr<VfsFile> RealVfsDirectory::GetFileRelative(std::string_view path) const {
|
std::shared_ptr<VfsFile> RealVfsDirectory::GetFileRelative(std::string_view path) const {
|
||||||
const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path));
|
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path));
|
||||||
if (!FileUtil::Exists(full_path) || FileUtil::IsDirectory(full_path))
|
if (!FS::Exists(full_path) || FS::IsDirectory(full_path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return base.OpenFile(full_path, perms);
|
return base.OpenFile(full_path, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> RealVfsDirectory::GetDirectoryRelative(std::string_view path) const {
|
std::shared_ptr<VfsDirectory> RealVfsDirectory::GetDirectoryRelative(std::string_view path) const {
|
||||||
const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path));
|
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path));
|
||||||
if (!FileUtil::Exists(full_path) || !FileUtil::IsDirectory(full_path))
|
if (!FS::Exists(full_path) || !FS::IsDirectory(full_path)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
return base.OpenDirectory(full_path, perms);
|
return base.OpenDirectory(full_path, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,17 +361,17 @@ std::shared_ptr<VfsDirectory> RealVfsDirectory::GetSubdirectory(std::string_view
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsFile> RealVfsDirectory::CreateFileRelative(std::string_view path) {
|
std::shared_ptr<VfsFile> RealVfsDirectory::CreateFileRelative(std::string_view path) {
|
||||||
const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path));
|
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path));
|
||||||
return base.CreateFile(full_path, perms);
|
return base.CreateFile(full_path, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> RealVfsDirectory::CreateDirectoryRelative(std::string_view path) {
|
std::shared_ptr<VfsDirectory> RealVfsDirectory::CreateDirectoryRelative(std::string_view path) {
|
||||||
const auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(path));
|
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(path));
|
||||||
return base.CreateDirectory(full_path, perms);
|
return base.CreateDirectory(full_path, perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RealVfsDirectory::DeleteSubdirectoryRecursive(std::string_view name) {
|
bool RealVfsDirectory::DeleteSubdirectoryRecursive(std::string_view name) {
|
||||||
auto full_path = FileUtil::SanitizePath(this->path + DIR_SEP + std::string(name));
|
const auto full_path = FS::SanitizePath(this->path + DIR_SEP + std::string(name));
|
||||||
return base.DeleteDirectory(full_path);
|
return base.DeleteDirectory(full_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,8 +396,9 @@ std::string RealVfsDirectory::GetName() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<VfsDirectory> RealVfsDirectory::GetParentDirectory() const {
|
std::shared_ptr<VfsDirectory> RealVfsDirectory::GetParentDirectory() const {
|
||||||
if (path_components.size() <= 1)
|
if (path_components.size() <= 1) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return base.OpenDirectory(parent_path, perms);
|
return base.OpenDirectory(parent_path, perms);
|
||||||
}
|
}
|
||||||
|
@ -425,16 +435,17 @@ std::string RealVfsDirectory::GetFullPath() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const {
|
std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const {
|
||||||
if (perms == Mode::Append)
|
if (perms == Mode::Append) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::map<std::string, VfsEntryType, std::less<>> out;
|
std::map<std::string, VfsEntryType, std::less<>> out;
|
||||||
FileUtil::ForeachDirectoryEntry(
|
FS::ForeachDirectoryEntry(
|
||||||
nullptr, path,
|
nullptr, path,
|
||||||
[&out](u64* entries_out, const std::string& directory, const std::string& filename) {
|
[&out](u64* entries_out, const std::string& directory, const std::string& filename) {
|
||||||
const std::string full_path = directory + DIR_SEP + filename;
|
const std::string full_path = directory + DIR_SEP + filename;
|
||||||
out.emplace(filename, FileUtil::IsDirectory(full_path) ? VfsEntryType::Directory
|
out.emplace(filename,
|
||||||
: VfsEntryType::File);
|
FS::IsDirectory(full_path) ? VfsEntryType::Directory : VfsEntryType::File);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "core/file_sys/mode.h"
|
#include "core/file_sys/mode.h"
|
||||||
#include "core/file_sys/vfs.h"
|
#include "core/file_sys/vfs.h"
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace Common::FS {
|
||||||
class IOFile;
|
class IOFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
bool DeleteDirectory(std::string_view path) override;
|
bool DeleteDirectory(std::string_view path) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::container::flat_map<std::string, std::weak_ptr<FileUtil::IOFile>> cache;
|
boost::container::flat_map<std::string, std::weak_ptr<Common::FS::IOFile>> cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
// An implmentation of VfsFile that represents a file on the user's computer.
|
// An implmentation of VfsFile that represents a file on the user's computer.
|
||||||
|
@ -58,13 +58,13 @@ public:
|
||||||
bool Rename(std::string_view name) override;
|
bool Rename(std::string_view name) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<FileUtil::IOFile> backing,
|
RealVfsFile(RealVfsFilesystem& base, std::shared_ptr<Common::FS::IOFile> backing,
|
||||||
const std::string& path, Mode perms = Mode::Read);
|
const std::string& path, Mode perms = Mode::Read);
|
||||||
|
|
||||||
bool Close();
|
bool Close();
|
||||||
|
|
||||||
RealVfsFilesystem& base;
|
RealVfsFilesystem& base;
|
||||||
std::shared_ptr<FileUtil::IOFile> backing;
|
std::shared_ptr<Common::FS::IOFile> backing;
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string parent_path;
|
std::string parent_path;
|
||||||
std::vector<std::string> path_components;
|
std::vector<std::string> path_components;
|
||||||
|
|
|
@ -44,7 +44,7 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) {
|
NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) {
|
||||||
std::string path = FileUtil::SanitizePath(file->GetFullPath());
|
std::string path = Common::FS::SanitizePath(file->GetFullPath());
|
||||||
static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca",
|
static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca",
|
||||||
std::regex_constants::ECMAScript |
|
std::regex_constants::ECMAScript |
|
||||||
std::regex_constants::icase);
|
std::regex_constants::icase);
|
||||||
|
|
|
@ -35,7 +35,7 @@ constexpr ResultCode ERR_INVALID_BUFFER_SIZE{ErrorModule::Account, 30};
|
||||||
constexpr ResultCode ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100};
|
constexpr ResultCode ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100};
|
||||||
|
|
||||||
static std::string GetImagePath(Common::UUID uuid) {
|
static std::string GetImagePath(Common::UUID uuid) {
|
||||||
return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
return Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ protected:
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
|
||||||
const FileUtil::IOFile image(GetImagePath(user_id), "rb");
|
const Common::FS::IOFile image(GetImagePath(user_id), "rb");
|
||||||
if (!image.IsOpen()) {
|
if (!image.IsOpen()) {
|
||||||
LOG_WARNING(Service_ACC,
|
LOG_WARNING(Service_ACC,
|
||||||
"Failed to load user provided image! Falling back to built-in backup...");
|
"Failed to load user provided image! Falling back to built-in backup...");
|
||||||
|
@ -340,7 +340,7 @@ protected:
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
|
||||||
const FileUtil::IOFile image(GetImagePath(user_id), "rb");
|
const Common::FS::IOFile image(GetImagePath(user_id), "rb");
|
||||||
|
|
||||||
if (!image.IsOpen()) {
|
if (!image.IsOpen()) {
|
||||||
LOG_WARNING(Service_ACC,
|
LOG_WARNING(Service_ACC,
|
||||||
|
@ -405,7 +405,7 @@ protected:
|
||||||
ProfileData data;
|
ProfileData data;
|
||||||
std::memcpy(&data, user_data.data(), sizeof(ProfileData));
|
std::memcpy(&data, user_data.data(), sizeof(ProfileData));
|
||||||
|
|
||||||
FileUtil::IOFile image(GetImagePath(user_id), "wb");
|
Common::FS::IOFile image(GetImagePath(user_id), "wb");
|
||||||
|
|
||||||
if (!image.IsOpen() || !image.Resize(image_data.size()) ||
|
if (!image.IsOpen() || !image.Resize(image_data.size()) ||
|
||||||
image.WriteBytes(image_data.data(), image_data.size()) != image_data.size() ||
|
image.WriteBytes(image_data.data(), image_data.size()) != image_data.size() ||
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
namespace Service::Account {
|
namespace Service::Account {
|
||||||
|
|
||||||
|
namespace FS = Common::FS;
|
||||||
using Common::UUID;
|
using Common::UUID;
|
||||||
|
|
||||||
struct UserRaw {
|
struct UserRaw {
|
||||||
|
@ -318,9 +319,8 @@ bool ProfileManager::SetProfileBaseAndData(Common::UUID uuid, const ProfileBase&
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::ParseUserSaveFile() {
|
void ProfileManager::ParseUserSaveFile() {
|
||||||
FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const FS::IOFile save(
|
||||||
ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
|
FS::GetUserPath(FS::UserPath::NANDDir) + ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", "rb");
|
||||||
"rb");
|
|
||||||
|
|
||||||
if (!save.IsOpen()) {
|
if (!save.IsOpen()) {
|
||||||
LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
|
LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
|
||||||
|
@ -366,22 +366,22 @@ void ProfileManager::WriteUserSaveFile() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto raw_path =
|
const auto raw_path = FS::GetUserPath(FS::UserPath::NANDDir) + "/system/save/8000000000000010";
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010";
|
if (FS::Exists(raw_path) && !FS::IsDirectory(raw_path)) {
|
||||||
if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path))
|
FS::Delete(raw_path);
|
||||||
FileUtil::Delete(raw_path);
|
}
|
||||||
|
|
||||||
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const auto path =
|
||||||
ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat";
|
FS::GetUserPath(FS::UserPath::NANDDir) + ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat";
|
||||||
|
|
||||||
if (!FileUtil::CreateFullPath(path)) {
|
if (!FS::CreateFullPath(path)) {
|
||||||
LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory "
|
LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory "
|
||||||
"nand/system/save/8000000000000010/su/avators to mitigate this "
|
"nand/system/save/8000000000000010/su/avators to mitigate this "
|
||||||
"issue.");
|
"issue.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile save(path, "wb");
|
FS::IOFile save(path, "wb");
|
||||||
|
|
||||||
if (!save.IsOpen()) {
|
if (!save.IsOpen()) {
|
||||||
LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
|
LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
|
||||||
|
|
|
@ -293,8 +293,8 @@ void WebBrowser::Finalize() {
|
||||||
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(std::move(data)));
|
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(std::move(data)));
|
||||||
broker.SignalStateChanged();
|
broker.SignalStateChanged();
|
||||||
|
|
||||||
if (!temporary_dir.empty() && FileUtil::IsDirectory(temporary_dir)) {
|
if (!temporary_dir.empty() && Common::FS::IsDirectory(temporary_dir)) {
|
||||||
FileUtil::DeleteDirRecursively(temporary_dir);
|
Common::FS::DeleteDirRecursively(temporary_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,10 +452,10 @@ void WebBrowser::InitializeOffline() {
|
||||||
};
|
};
|
||||||
|
|
||||||
temporary_dir =
|
temporary_dir =
|
||||||
FileUtil::SanitizePath(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + "web_applet_" +
|
Common::FS::SanitizePath(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
|
||||||
WEB_SOURCE_NAMES[static_cast<u32>(source) - 1],
|
"web_applet_" + WEB_SOURCE_NAMES[static_cast<u32>(source) - 1],
|
||||||
FileUtil::DirectorySeparator::PlatformDefault);
|
Common::FS::DirectorySeparator::PlatformDefault);
|
||||||
FileUtil::DeleteDirRecursively(temporary_dir);
|
Common::FS::DeleteDirRecursively(temporary_dir);
|
||||||
|
|
||||||
u64 title_id = 0; // 0 corresponds to current process
|
u64 title_id = 0; // 0 corresponds to current process
|
||||||
ASSERT(args[WebArgTLVType::ApplicationID].size() >= 0x8);
|
ASSERT(args[WebArgTLVType::ApplicationID].size() >= 0x8);
|
||||||
|
@ -492,8 +492,8 @@ void WebBrowser::InitializeOffline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
filename =
|
filename =
|
||||||
FileUtil::SanitizePath(temporary_dir + path_additional_directory + DIR_SEP + filename,
|
Common::FS::SanitizePath(temporary_dir + path_additional_directory + DIR_SEP + filename,
|
||||||
FileUtil::DirectorySeparator::PlatformDefault);
|
Common::FS::DirectorySeparator::PlatformDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::ExecuteShop() {
|
void WebBrowser::ExecuteShop() {
|
||||||
|
|
|
@ -89,12 +89,12 @@ constexpr u32 TIMEOUT_SECONDS = 30;
|
||||||
|
|
||||||
std::string GetBINFilePath(u64 title_id) {
|
std::string GetBINFilePath(u64 title_id) {
|
||||||
return fmt::format("{}bcat/{:016X}/launchparam.bin",
|
return fmt::format("{}bcat/{:016X}/launchparam.bin",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir), title_id);
|
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir), title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetZIPFilePath(u64 title_id) {
|
std::string GetZIPFilePath(u64 title_id) {
|
||||||
return fmt::format("{}bcat/{:016X}/data.zip",
|
return fmt::format("{}bcat/{:016X}/data.zip",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir), title_id);
|
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir), title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the error is something the user should know about (build ID mismatch, bad client version),
|
// If the error is something the user should know about (build ID mismatch, bad client version),
|
||||||
|
@ -205,8 +205,8 @@ private:
|
||||||
{std::string("Game-Build-Id"), fmt::format("{:016X}", build_id)},
|
{std::string("Game-Build-Id"), fmt::format("{:016X}", build_id)},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (FileUtil::Exists(path)) {
|
if (Common::FS::Exists(path)) {
|
||||||
FileUtil::IOFile file{path, "rb"};
|
Common::FS::IOFile file{path, "rb"};
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
std::vector<u8> bytes(file.GetSize());
|
std::vector<u8> bytes(file.GetSize());
|
||||||
file.ReadBytes(bytes.data(), bytes.size());
|
file.ReadBytes(bytes.data(), bytes.size());
|
||||||
|
@ -236,8 +236,8 @@ private:
|
||||||
return DownloadResult::InvalidContentType;
|
return DownloadResult::InvalidContentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::CreateFullPath(path);
|
Common::FS::CreateFullPath(path);
|
||||||
FileUtil::IOFile file{path, "wb"};
|
Common::FS::IOFile file{path, "wb"};
|
||||||
if (!file.IsOpen())
|
if (!file.IsOpen())
|
||||||
return DownloadResult::GeneralFSError;
|
return DownloadResult::GeneralFSError;
|
||||||
if (!file.Resize(response->body.size()))
|
if (!file.Resize(response->body.size()))
|
||||||
|
@ -290,7 +290,7 @@ void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGe
|
||||||
LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
|
LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
|
||||||
|
|
||||||
if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
|
if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
|
||||||
FileUtil::Delete(zip_path);
|
Common::FS::Delete(zip_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleDownloadDisplayResult(applet_manager, res);
|
HandleDownloadDisplayResult(applet_manager, res);
|
||||||
|
@ -300,7 +300,7 @@ void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGe
|
||||||
|
|
||||||
progress.StartProcessingDataList();
|
progress.StartProcessingDataList();
|
||||||
|
|
||||||
FileUtil::IOFile zip{zip_path, "rb"};
|
Common::FS::IOFile zip{zip_path, "rb"};
|
||||||
const auto size = zip.GetSize();
|
const auto size = zip.GetSize();
|
||||||
std::vector<u8> bytes(size);
|
std::vector<u8> bytes(size);
|
||||||
if (!zip.IsOpen() || size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
if (!zip.IsOpen() || size == 0 || zip.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||||
|
@ -420,7 +420,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title)
|
||||||
LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
|
LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
|
||||||
|
|
||||||
if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
|
if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
|
||||||
FileUtil::Delete(path);
|
Common::FS::Delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleDownloadDisplayResult(applet_manager, res);
|
HandleDownloadDisplayResult(applet_manager, res);
|
||||||
|
@ -428,7 +428,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile bin{path, "rb"};
|
Common::FS::IOFile bin{path, "rb"};
|
||||||
const auto size = bin.GetSize();
|
const auto size = bin.GetSize();
|
||||||
std::vector<u8> bytes(size);
|
std::vector<u8> bytes(size);
|
||||||
if (!bin.IsOpen() || size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
if (!bin.IsOpen() || size == 0 || bin.ReadBytes(bytes.data(), bytes.size()) != bytes.size()) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ constexpr u64 SUFFICIENT_SAVE_DATA_SIZE = 0xF0000000;
|
||||||
|
|
||||||
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base,
|
||||||
std::string_view dir_name_) {
|
std::string_view dir_name_) {
|
||||||
std::string dir_name(FileUtil::SanitizePath(dir_name_));
|
std::string dir_name(Common::FS::SanitizePath(dir_name_));
|
||||||
if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
|
if (dir_name.empty() || dir_name == "." || dir_name == "/" || dir_name == "\\")
|
||||||
return base;
|
return base;
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ std::string VfsDirectoryServiceWrapper::GetName() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const {
|
ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
// dir can be nullptr if path contains subdirectories, create those prior to creating the file.
|
// dir can be nullptr if path contains subdirectories, create those prior to creating the file.
|
||||||
if (dir == nullptr) {
|
if (dir == nullptr) {
|
||||||
dir = backing->CreateSubdirectory(FileUtil::GetParentPath(path));
|
dir = backing->CreateSubdirectory(Common::FS::GetParentPath(path));
|
||||||
}
|
}
|
||||||
auto file = dir->CreateFile(FileUtil::GetFilename(path));
|
auto file = dir->CreateFile(Common::FS::GetFilename(path));
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
|
@ -72,17 +72,17 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
|
ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
if (path.empty()) {
|
if (path.empty()) {
|
||||||
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
|
// TODO(DarkLordZach): Why do games call this and what should it do? Works as is but...
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
if (dir->GetFile(FileUtil::GetFilename(path)) == nullptr) {
|
if (dir->GetFile(Common::FS::GetFilename(path)) == nullptr) {
|
||||||
return FileSys::ERROR_PATH_NOT_FOUND;
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
||||||
}
|
}
|
||||||
if (!dir->DeleteFile(FileUtil::GetFilename(path))) {
|
if (!dir->DeleteFile(Common::FS::GetFilename(path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -91,11 +91,11 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) cons
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
|
ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
if (dir == nullptr && FileUtil::GetFilename(FileUtil::GetParentPath(path)).empty())
|
if (dir == nullptr && Common::FS::GetFilename(Common::FS::GetParentPath(path)).empty())
|
||||||
dir = backing;
|
dir = backing;
|
||||||
auto new_dir = dir->CreateSubdirectory(FileUtil::GetFilename(path));
|
auto new_dir = dir->CreateSubdirectory(Common::FS::GetFilename(path));
|
||||||
if (new_dir == nullptr) {
|
if (new_dir == nullptr) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
|
@ -104,9 +104,9 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_)
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const {
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) {
|
if (!dir->DeleteSubdirectory(Common::FS::GetFilename(path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_)
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const {
|
ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::string& path_) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) {
|
if (!dir->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -124,10 +124,10 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::string& path) const {
|
ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::string& path) const {
|
||||||
const std::string sanitized_path(FileUtil::SanitizePath(path));
|
const std::string sanitized_path(Common::FS::SanitizePath(path));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(sanitized_path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(sanitized_path));
|
||||||
|
|
||||||
if (!dir->CleanSubdirectoryRecursive(FileUtil::GetFilename(sanitized_path))) {
|
if (!dir->CleanSubdirectoryRecursive(Common::FS::GetFilename(sanitized_path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -137,14 +137,14 @@ ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::stri
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
||||||
const std::string& dest_path_) const {
|
const std::string& dest_path_) const {
|
||||||
std::string src_path(FileUtil::SanitizePath(src_path_));
|
std::string src_path(Common::FS::SanitizePath(src_path_));
|
||||||
std::string dest_path(FileUtil::SanitizePath(dest_path_));
|
std::string dest_path(Common::FS::SanitizePath(dest_path_));
|
||||||
auto src = backing->GetFileRelative(src_path);
|
auto src = backing->GetFileRelative(src_path);
|
||||||
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
|
if (Common::FS::GetParentPath(src_path) == Common::FS::GetParentPath(dest_path)) {
|
||||||
// Use more-optimized vfs implementation rename.
|
// Use more-optimized vfs implementation rename.
|
||||||
if (src == nullptr)
|
if (src == nullptr)
|
||||||
return FileSys::ERROR_PATH_NOT_FOUND;
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
||||||
if (!src->Rename(FileUtil::GetFilename(dest_path))) {
|
if (!src->Rename(Common::FS::GetFilename(dest_path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
||||||
ASSERT_MSG(dest->WriteBytes(src->ReadAllBytes()) == src->GetSize(),
|
ASSERT_MSG(dest->WriteBytes(src->ReadAllBytes()) == src->GetSize(),
|
||||||
"Could not write all of the bytes but everything else has succeded.");
|
"Could not write all of the bytes but everything else has succeded.");
|
||||||
|
|
||||||
if (!src->GetContainingDirectory()->DeleteFile(FileUtil::GetFilename(src_path))) {
|
if (!src->GetContainingDirectory()->DeleteFile(Common::FS::GetFilename(src_path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -172,14 +172,14 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
|
||||||
|
|
||||||
ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_,
|
ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_,
|
||||||
const std::string& dest_path_) const {
|
const std::string& dest_path_) const {
|
||||||
std::string src_path(FileUtil::SanitizePath(src_path_));
|
std::string src_path(Common::FS::SanitizePath(src_path_));
|
||||||
std::string dest_path(FileUtil::SanitizePath(dest_path_));
|
std::string dest_path(Common::FS::SanitizePath(dest_path_));
|
||||||
auto src = GetDirectoryRelativeWrapped(backing, src_path);
|
auto src = GetDirectoryRelativeWrapped(backing, src_path);
|
||||||
if (FileUtil::GetParentPath(src_path) == FileUtil::GetParentPath(dest_path)) {
|
if (Common::FS::GetParentPath(src_path) == Common::FS::GetParentPath(dest_path)) {
|
||||||
// Use more-optimized vfs implementation rename.
|
// Use more-optimized vfs implementation rename.
|
||||||
if (src == nullptr)
|
if (src == nullptr)
|
||||||
return FileSys::ERROR_PATH_NOT_FOUND;
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
||||||
if (!src->Rename(FileUtil::GetFilename(dest_path))) {
|
if (!src->Rename(Common::FS::GetFilename(dest_path))) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
||||||
FileSys::Mode mode) const {
|
FileSys::Mode mode) const {
|
||||||
const std::string path(FileUtil::SanitizePath(path_));
|
const std::string path(Common::FS::SanitizePath(path_));
|
||||||
std::string_view npath = path;
|
std::string_view npath = path;
|
||||||
while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) {
|
while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) {
|
||||||
npath.remove_prefix(1);
|
npath.remove_prefix(1);
|
||||||
|
@ -218,7 +218,7 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) {
|
ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, path);
|
auto dir = GetDirectoryRelativeWrapped(backing, path);
|
||||||
if (dir == nullptr) {
|
if (dir == nullptr) {
|
||||||
// TODO(DarkLordZach): Find a better error code for this
|
// TODO(DarkLordZach): Find a better error code for this
|
||||||
|
@ -229,11 +229,11 @@ ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const s
|
||||||
|
|
||||||
ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
|
ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
|
||||||
const std::string& path_) const {
|
const std::string& path_) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
std::string path(Common::FS::SanitizePath(path_));
|
||||||
auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
|
auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
|
||||||
if (dir == nullptr)
|
if (dir == nullptr)
|
||||||
return FileSys::ERROR_PATH_NOT_FOUND;
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
||||||
auto filename = FileUtil::GetFilename(path);
|
auto filename = Common::FS::GetFilename(path);
|
||||||
// TODO(Subv): Some games use the '/' path, find out what this means.
|
// TODO(Subv): Some games use the '/' path, find out what this means.
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
return MakeResult(FileSys::EntryType::Directory);
|
return MakeResult(FileSys::EntryType::Directory);
|
||||||
|
@ -695,13 +695,13 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
|
||||||
sdmc_factory = nullptr;
|
sdmc_factory = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nand_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir),
|
auto nand_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir),
|
||||||
FileSys::Mode::ReadWrite);
|
FileSys::Mode::ReadWrite);
|
||||||
auto sd_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir),
|
auto sd_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir),
|
||||||
FileSys::Mode::ReadWrite);
|
FileSys::Mode::ReadWrite);
|
||||||
auto load_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
auto load_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
|
||||||
FileSys::Mode::ReadWrite);
|
FileSys::Mode::ReadWrite);
|
||||||
auto dump_directory = vfs.OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
|
auto dump_directory = vfs.OpenDirectory(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir),
|
||||||
FileSys::Mode::ReadWrite);
|
FileSys::Mode::ReadWrite);
|
||||||
|
|
||||||
if (bis_factory == nullptr) {
|
if (bis_factory == nullptr) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ FileType GuessFromFilename(const std::string& name) {
|
||||||
return FileType::NCA;
|
return FileType::NCA;
|
||||||
|
|
||||||
const std::string extension =
|
const std::string extension =
|
||||||
Common::ToLower(std::string(FileUtil::GetExtensionFromFilename(name)));
|
Common::ToLower(std::string(Common::FS::GetExtensionFromFilename(name)));
|
||||||
|
|
||||||
if (extension == "elf")
|
if (extension == "elf")
|
||||||
return FileType::ELF;
|
return FileType::ELF;
|
||||||
|
|
|
@ -38,11 +38,11 @@ PerfStats::~PerfStats() {
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index,
|
std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index,
|
||||||
std::ostream_iterator<double>(stream, "\n"));
|
std::ostream_iterator<double>(stream, "\n"));
|
||||||
const std::string& path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& path = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
|
||||||
// %F Date format expanded is "%Y-%m-%d"
|
// %F Date format expanded is "%Y-%m-%d"
|
||||||
const std::string filename =
|
const std::string filename =
|
||||||
fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id);
|
fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id);
|
||||||
FileUtil::IOFile file(filename, "w");
|
Common::FS::IOFile file(filename, "w");
|
||||||
file.WriteString(stream.str());
|
file.WriteString(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string GetPath(std::string_view type, u64 title_id, std::string_view timestamp) {
|
std::string GetPath(std::string_view type, u64 title_id, std::string_view timestamp) {
|
||||||
return fmt::format("{}{}/{:016X}_{}.json", FileUtil::GetUserPath(FileUtil::UserPath::LogDir),
|
return fmt::format("{}{}/{:016X}_{}.json",
|
||||||
type, title_id, timestamp);
|
Common::FS::GetUserPath(Common::FS::UserPath::LogDir), type, title_id,
|
||||||
|
timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetTimestamp() {
|
std::string GetTimestamp() {
|
||||||
|
@ -40,13 +41,13 @@ std::string GetTimestamp() {
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
void SaveToFile(json json, const std::string& filename) {
|
void SaveToFile(json json, const std::string& filename) {
|
||||||
if (!FileUtil::CreateFullPath(filename)) {
|
if (!Common::FS::CreateFullPath(filename)) {
|
||||||
LOG_ERROR(Core, "Failed to create path for '{}' to save report!", filename);
|
LOG_ERROR(Core, "Failed to create path for '{}' to save report!", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream file(
|
std::ofstream file(
|
||||||
FileUtil::SanitizePath(filename, FileUtil::DirectorySeparator::PlatformDefault));
|
Common::FS::SanitizePath(filename, Common::FS::DirectorySeparator::PlatformDefault));
|
||||||
file << std::setw(4) << json << std::endl;
|
file << std::setw(4) << json << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ void LogSettings() {
|
||||||
log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue());
|
log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue());
|
||||||
log_setting("Audio_OutputDevice", values.audio_device_id);
|
log_setting("Audio_OutputDevice", values.audio_device_id);
|
||||||
log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd);
|
log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd);
|
||||||
log_setting("DataStorage_NandDir", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
|
log_setting("DataStorage_NandDir", Common::FS::GetUserPath(Common::FS::UserPath::NANDDir));
|
||||||
log_setting("DataStorage_SdmcDir", FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
|
log_setting("DataStorage_SdmcDir", Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir));
|
||||||
log_setting("Debugging_UseGdbstub", values.use_gdbstub);
|
log_setting("Debugging_UseGdbstub", values.use_gdbstub);
|
||||||
log_setting("Debugging_GdbstubPort", values.gdbstub_port);
|
log_setting("Debugging_GdbstubPort", values.gdbstub_port);
|
||||||
log_setting("Debugging_ProgramArgs", values.program_args);
|
log_setting("Debugging_ProgramArgs", values.program_args);
|
||||||
|
|
|
@ -70,12 +70,12 @@ static const char* TranslateGPUAccuracyLevel(Settings::GPUAccuracy backend) {
|
||||||
|
|
||||||
u64 GetTelemetryId() {
|
u64 GetTelemetryId() {
|
||||||
u64 telemetry_id{};
|
u64 telemetry_id{};
|
||||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) +
|
||||||
"telemetry_id"};
|
"telemetry_id"};
|
||||||
|
|
||||||
bool generate_new_id = !FileUtil::Exists(filename);
|
bool generate_new_id = !Common::FS::Exists(filename);
|
||||||
if (!generate_new_id) {
|
if (!generate_new_id) {
|
||||||
FileUtil::IOFile file(filename, "rb");
|
Common::FS::IOFile file(filename, "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
||||||
return {};
|
return {};
|
||||||
|
@ -88,7 +88,7 @@ u64 GetTelemetryId() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generate_new_id) {
|
if (generate_new_id) {
|
||||||
FileUtil::IOFile file(filename, "wb");
|
Common::FS::IOFile file(filename, "wb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
||||||
return {};
|
return {};
|
||||||
|
@ -102,10 +102,10 @@ u64 GetTelemetryId() {
|
||||||
|
|
||||||
u64 RegenerateTelemetryId() {
|
u64 RegenerateTelemetryId() {
|
||||||
const u64 new_telemetry_id{GenerateTelemetryId()};
|
const u64 new_telemetry_id{GenerateTelemetryId()};
|
||||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) +
|
||||||
"telemetry_id"};
|
"telemetry_id"};
|
||||||
|
|
||||||
FileUtil::IOFile file(filename, "wb");
|
Common::FS::IOFile file(filename, "wb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -73,7 +73,7 @@ ShaderDiskCacheEntry::ShaderDiskCacheEntry() = default;
|
||||||
|
|
||||||
ShaderDiskCacheEntry::~ShaderDiskCacheEntry() = default;
|
ShaderDiskCacheEntry::~ShaderDiskCacheEntry() = default;
|
||||||
|
|
||||||
bool ShaderDiskCacheEntry::Load(FileUtil::IOFile& file) {
|
bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) {
|
||||||
if (file.ReadBytes(&type, sizeof(u32)) != sizeof(u32)) {
|
if (file.ReadBytes(&type, sizeof(u32)) != sizeof(u32)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ bool ShaderDiskCacheEntry::Load(FileUtil::IOFile& file) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderDiskCacheEntry::Save(FileUtil::IOFile& file) const {
|
bool ShaderDiskCacheEntry::Save(Common::FS::IOFile& file) const {
|
||||||
if (file.WriteObject(static_cast<u32>(type)) != 1 ||
|
if (file.WriteObject(static_cast<u32>(type)) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(code.size())) != 1 ||
|
file.WriteObject(static_cast<u32>(code.size())) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(code_b.size())) != 1) {
|
file.WriteObject(static_cast<u32>(code_b.size())) != 1) {
|
||||||
|
@ -217,7 +217,7 @@ std::optional<std::vector<ShaderDiskCacheEntry>> ShaderDiskCacheOpenGL::LoadTran
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file(GetTransferablePath(), "rb");
|
Common::FS::IOFile file(GetTransferablePath(), "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_INFO(Render_OpenGL, "No transferable shader cache found");
|
LOG_INFO(Render_OpenGL, "No transferable shader cache found");
|
||||||
is_usable = true;
|
is_usable = true;
|
||||||
|
@ -262,7 +262,7 @@ std::vector<ShaderDiskCachePrecompiled> ShaderDiskCacheOpenGL::LoadPrecompiled()
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file(GetPrecompiledPath(), "rb");
|
Common::FS::IOFile file(GetPrecompiledPath(), "rb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_INFO(Render_OpenGL, "No precompiled shader cache found");
|
LOG_INFO(Render_OpenGL, "No precompiled shader cache found");
|
||||||
return {};
|
return {};
|
||||||
|
@ -279,7 +279,7 @@ std::vector<ShaderDiskCachePrecompiled> ShaderDiskCacheOpenGL::LoadPrecompiled()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::LoadPrecompiledFile(
|
std::optional<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::LoadPrecompiledFile(
|
||||||
FileUtil::IOFile& file) {
|
Common::FS::IOFile& file) {
|
||||||
// Read compressed file from disk and decompress to virtual precompiled cache file
|
// Read compressed file from disk and decompress to virtual precompiled cache file
|
||||||
std::vector<u8> compressed(file.GetSize());
|
std::vector<u8> compressed(file.GetSize());
|
||||||
file.ReadBytes(compressed.data(), compressed.size());
|
file.ReadBytes(compressed.data(), compressed.size());
|
||||||
|
@ -317,7 +317,7 @@ std::optional<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::Lo
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderDiskCacheOpenGL::InvalidateTransferable() {
|
void ShaderDiskCacheOpenGL::InvalidateTransferable() {
|
||||||
if (!FileUtil::Delete(GetTransferablePath())) {
|
if (!Common::FS::Delete(GetTransferablePath())) {
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}",
|
LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}",
|
||||||
GetTransferablePath());
|
GetTransferablePath());
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ void ShaderDiskCacheOpenGL::InvalidatePrecompiled() {
|
||||||
// Clear virtaul precompiled cache file
|
// Clear virtaul precompiled cache file
|
||||||
precompiled_cache_virtual_file.Resize(0);
|
precompiled_cache_virtual_file.Resize(0);
|
||||||
|
|
||||||
if (!FileUtil::Delete(GetPrecompiledPath())) {
|
if (!Common::FS::Delete(GetPrecompiledPath())) {
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
|
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ void ShaderDiskCacheOpenGL::SaveEntry(const ShaderDiskCacheEntry& entry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file = AppendTransferableFile();
|
Common::FS::IOFile file = AppendTransferableFile();
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -386,15 +386,15 @@ void ShaderDiskCacheOpenGL::SavePrecompiled(u64 unique_identifier, GLuint progra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const {
|
Common::FS::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const {
|
||||||
if (!EnsureDirectories()) {
|
if (!EnsureDirectories()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto transferable_path{GetTransferablePath()};
|
const auto transferable_path{GetTransferablePath()};
|
||||||
const bool existed = FileUtil::Exists(transferable_path);
|
const bool existed = Common::FS::Exists(transferable_path);
|
||||||
|
|
||||||
FileUtil::IOFile file(transferable_path, "ab");
|
Common::FS::IOFile file(transferable_path, "ab");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path);
|
LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path);
|
||||||
return {};
|
return {};
|
||||||
|
@ -426,7 +426,7 @@ void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() {
|
||||||
Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size());
|
Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size());
|
||||||
|
|
||||||
const auto precompiled_path{GetPrecompiledPath()};
|
const auto precompiled_path{GetPrecompiledPath()};
|
||||||
FileUtil::IOFile file(precompiled_path, "wb");
|
Common::FS::IOFile file(precompiled_path, "wb");
|
||||||
|
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
|
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
|
||||||
|
@ -440,24 +440,24 @@ void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() {
|
||||||
|
|
||||||
bool ShaderDiskCacheOpenGL::EnsureDirectories() const {
|
bool ShaderDiskCacheOpenGL::EnsureDirectories() const {
|
||||||
const auto CreateDir = [](const std::string& dir) {
|
const auto CreateDir = [](const std::string& dir) {
|
||||||
if (!FileUtil::CreateDir(dir)) {
|
if (!Common::FS::CreateDir(dir)) {
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir);
|
LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
return CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) &&
|
return CreateDir(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir)) &&
|
||||||
CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) &&
|
CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) &&
|
||||||
CreateDir(GetPrecompiledDir());
|
CreateDir(GetPrecompiledDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderDiskCacheOpenGL::GetTransferablePath() const {
|
std::string ShaderDiskCacheOpenGL::GetTransferablePath() const {
|
||||||
return FileUtil::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
|
return Common::FS::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const {
|
std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const {
|
||||||
return FileUtil::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
|
return Common::FS::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderDiskCacheOpenGL::GetTransferableDir() const {
|
std::string ShaderDiskCacheOpenGL::GetTransferableDir() const {
|
||||||
|
@ -469,7 +469,7 @@ std::string ShaderDiskCacheOpenGL::GetPrecompiledDir() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderDiskCacheOpenGL::GetBaseDir() const {
|
std::string ShaderDiskCacheOpenGL::GetBaseDir() const {
|
||||||
return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
|
return Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir) + DIR_SEP "opengl";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ShaderDiskCacheOpenGL::GetTitleID() const {
|
std::string ShaderDiskCacheOpenGL::GetTitleID() const {
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Core {
|
||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace Common::FS {
|
||||||
class IOFile;
|
class IOFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ struct ShaderDiskCacheEntry {
|
||||||
ShaderDiskCacheEntry();
|
ShaderDiskCacheEntry();
|
||||||
~ShaderDiskCacheEntry();
|
~ShaderDiskCacheEntry();
|
||||||
|
|
||||||
bool Load(FileUtil::IOFile& file);
|
bool Load(Common::FS::IOFile& file);
|
||||||
|
|
||||||
bool Save(FileUtil::IOFile& file) const;
|
bool Save(Common::FS::IOFile& file) const;
|
||||||
|
|
||||||
bool HasProgramA() const {
|
bool HasProgramA() const {
|
||||||
return !code.empty() && !code_b.empty();
|
return !code.empty() && !code_b.empty();
|
||||||
|
@ -97,10 +97,10 @@ public:
|
||||||
private:
|
private:
|
||||||
/// Loads the transferable cache. Returns empty on failure.
|
/// Loads the transferable cache. Returns empty on failure.
|
||||||
std::optional<std::vector<ShaderDiskCachePrecompiled>> LoadPrecompiledFile(
|
std::optional<std::vector<ShaderDiskCachePrecompiled>> LoadPrecompiledFile(
|
||||||
FileUtil::IOFile& file);
|
Common::FS::IOFile& file);
|
||||||
|
|
||||||
/// Opens current game's transferable file and write it's header if it doesn't exist
|
/// Opens current game's transferable file and write it's header if it doesn't exist
|
||||||
FileUtil::IOFile AppendTransferableFile() const;
|
Common::FS::IOFile AppendTransferableFile() const;
|
||||||
|
|
||||||
/// Save precompiled header to precompiled_cache_in_memory
|
/// Save precompiled header to precompiled_cache_in_memory
|
||||||
void SavePrecompiledHeaderToVirtualPrecompiledCache();
|
void SavePrecompiledHeaderToVirtualPrecompiledCache();
|
||||||
|
|
|
@ -65,10 +65,10 @@ bool NsightAftermathTracker::Initialize() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir) + "gpucrash";
|
dump_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir) + "gpucrash";
|
||||||
|
|
||||||
(void)FileUtil::DeleteDirRecursively(dump_dir);
|
(void)Common::FS::DeleteDirRecursively(dump_dir);
|
||||||
if (!FileUtil::CreateDir(dump_dir)) {
|
if (!Common::FS::CreateDir(dump_dir)) {
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to create Nsight Aftermath dump directory");
|
LOG_ERROR(Render_Vulkan, "Failed to create Nsight Aftermath dump directory");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ void NsightAftermathTracker::SaveShader(const std::vector<u32>& spirv) const {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil::IOFile file(fmt::format("{}/source_{:016x}.spv", dump_dir, hash.hash), "wb");
|
Common::FS::IOFile file(fmt::format("{}/source_{:016x}.spv", dump_dir, hash.hash), "wb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to dump SPIR-V module with hash={:016x}", hash.hash);
|
LOG_ERROR(Render_Vulkan, "Failed to dump SPIR-V module with hash={:016x}", hash.hash);
|
||||||
return;
|
return;
|
||||||
|
@ -156,12 +156,12 @@ void NsightAftermathTracker::OnGpuCrashDumpCallback(const void* gpu_crash_dump,
|
||||||
}();
|
}();
|
||||||
|
|
||||||
std::string_view dump_view(static_cast<const char*>(gpu_crash_dump), gpu_crash_dump_size);
|
std::string_view dump_view(static_cast<const char*>(gpu_crash_dump), gpu_crash_dump_size);
|
||||||
if (FileUtil::WriteStringToFile(false, base_name, dump_view) != gpu_crash_dump_size) {
|
if (Common::FS::WriteStringToFile(false, base_name, dump_view) != gpu_crash_dump_size) {
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to write dump file");
|
LOG_ERROR(Render_Vulkan, "Failed to write dump file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const std::string_view json_view(json.data(), json.size());
|
const std::string_view json_view(json.data(), json.size());
|
||||||
if (FileUtil::WriteStringToFile(true, base_name + ".json", json_view) != json.size()) {
|
if (Common::FS::WriteStringToFile(true, base_name + ".json", json_view) != json.size()) {
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to write JSON");
|
LOG_ERROR(Render_Vulkan, "Failed to write JSON");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ void NsightAftermathTracker::OnShaderDebugInfoCallback(const void* shader_debug_
|
||||||
|
|
||||||
const std::string path =
|
const std::string path =
|
||||||
fmt::format("{}/shader_{:016x}{:016x}.nvdbg", dump_dir, identifier.id[0], identifier.id[1]);
|
fmt::format("{}/shader_{:016x}{:016x}.nvdbg", dump_dir, identifier.id[0], identifier.id[1]);
|
||||||
FileUtil::IOFile file(path, "wb");
|
Common::FS::IOFile file(path, "wb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
LOG_ERROR(Render_Vulkan, "Failed to create file {}", path);
|
LOG_ERROR(Render_Vulkan, "Failed to create file {}", path);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -78,7 +78,7 @@ Common::DynamicLibrary OpenVulkanLibrary() {
|
||||||
if (!libvulkan_env || !library.Open(libvulkan_env)) {
|
if (!libvulkan_env || !library.Open(libvulkan_env)) {
|
||||||
// Use the libvulkan.dylib from the application bundle.
|
// Use the libvulkan.dylib from the application bundle.
|
||||||
const std::string filename =
|
const std::string filename =
|
||||||
FileUtil::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib";
|
Common::FS::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib";
|
||||||
library.Open(filename.c_str());
|
library.Open(filename.c_str());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -26,7 +26,7 @@ QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetImagePath(Common::UUID uuid) {
|
QString GetImagePath(Common::UUID uuid) {
|
||||||
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
||||||
return QString::fromStdString(path);
|
return QString::fromStdString(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,12 @@
|
||||||
#include "input_common/udp/client.h"
|
#include "input_common/udp/client.h"
|
||||||
#include "yuzu/configuration/config.h"
|
#include "yuzu/configuration/config.h"
|
||||||
|
|
||||||
|
namespace FS = Common::FS;
|
||||||
|
|
||||||
Config::Config(const std::string& config_file, bool is_global) {
|
Config::Config(const std::string& config_file, bool is_global) {
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||||
qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + config_file;
|
qt_config_loc = FS::GetUserPath(FS::UserPath::ConfigDir) + config_file;
|
||||||
FileUtil::CreateFullPath(qt_config_loc);
|
FS::CreateFullPath(qt_config_loc);
|
||||||
qt_config =
|
qt_config =
|
||||||
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
|
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
|
||||||
global = is_global;
|
global = is_global;
|
||||||
|
@ -464,39 +466,34 @@ void Config::ReadDataStorageValues() {
|
||||||
qt_config->beginGroup(QStringLiteral("Data Storage"));
|
qt_config->beginGroup(QStringLiteral("Data Storage"));
|
||||||
|
|
||||||
Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool();
|
Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool();
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(FS::UserPath::NANDDir,
|
||||||
FileUtil::UserPath::NANDDir,
|
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("nand_directory"),
|
->value(QStringLiteral("nand_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(FS::UserPath::SDMCDir,
|
||||||
FileUtil::UserPath::SDMCDir,
|
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("sdmc_directory"),
|
->value(QStringLiteral("sdmc_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(FS::UserPath::LoadDir,
|
||||||
FileUtil::UserPath::LoadDir,
|
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("load_directory"),
|
->value(QStringLiteral("load_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(FS::UserPath::DumpDir,
|
||||||
FileUtil::UserPath::DumpDir,
|
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("dump_directory"),
|
->value(QStringLiteral("dump_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(FS::UserPath::CacheDir,
|
||||||
FileUtil::UserPath::CacheDir,
|
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("cache_directory"),
|
->value(QStringLiteral("cache_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
Settings::values.gamecard_inserted =
|
Settings::values.gamecard_inserted =
|
||||||
|
@ -677,11 +674,11 @@ void Config::ReadScreenshotValues() {
|
||||||
|
|
||||||
UISettings::values.enable_screenshot_save_as =
|
UISettings::values.enable_screenshot_save_as =
|
||||||
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
|
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
|
||||||
FileUtil::GetUserPath(
|
FS::GetUserPath(
|
||||||
FileUtil::UserPath::ScreenshotsDir,
|
FS::UserPath::ScreenshotsDir,
|
||||||
qt_config
|
qt_config
|
||||||
->value(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath(
|
->value(QStringLiteral("screenshot_path"),
|
||||||
FileUtil::UserPath::ScreenshotsDir)))
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString());
|
.toStdString());
|
||||||
|
|
||||||
|
@ -1016,20 +1013,20 @@ void Config::SaveDataStorageValues() {
|
||||||
|
|
||||||
WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true);
|
WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true);
|
||||||
WriteSetting(QStringLiteral("nand_directory"),
|
WriteSetting(QStringLiteral("nand_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)));
|
||||||
WriteSetting(QStringLiteral("sdmc_directory"),
|
WriteSetting(QStringLiteral("sdmc_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)));
|
||||||
WriteSetting(QStringLiteral("load_directory"),
|
WriteSetting(QStringLiteral("load_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)),
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)));
|
||||||
WriteSetting(QStringLiteral("dump_directory"),
|
WriteSetting(QStringLiteral("dump_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)),
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)));
|
||||||
WriteSetting(QStringLiteral("cache_directory"),
|
WriteSetting(QStringLiteral("cache_directory"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)),
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)));
|
||||||
WriteSetting(QStringLiteral("gamecard_inserted"), Settings::values.gamecard_inserted, false);
|
WriteSetting(QStringLiteral("gamecard_inserted"), Settings::values.gamecard_inserted, false);
|
||||||
WriteSetting(QStringLiteral("gamecard_current_game"), Settings::values.gamecard_current_game,
|
WriteSetting(QStringLiteral("gamecard_current_game"), Settings::values.gamecard_current_game,
|
||||||
false);
|
false);
|
||||||
|
@ -1180,7 +1177,7 @@ void Config::SaveScreenshotValues() {
|
||||||
WriteSetting(QStringLiteral("enable_screenshot_save_as"),
|
WriteSetting(QStringLiteral("enable_screenshot_save_as"),
|
||||||
UISettings::values.enable_screenshot_save_as);
|
UISettings::values.enable_screenshot_save_as);
|
||||||
WriteSetting(QStringLiteral("screenshot_path"),
|
WriteSetting(QStringLiteral("screenshot_path"),
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
|
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)));
|
||||||
|
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@ ConfigureDebug::ConfigureDebug(QWidget* parent) : QWidget(parent), ui(new Ui::Co
|
||||||
SetConfiguration();
|
SetConfiguration();
|
||||||
|
|
||||||
connect(ui->open_log_button, &QPushButton::clicked, []() {
|
connect(ui->open_log_button, &QPushButton::clicked, []() {
|
||||||
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LogDir));
|
const auto path =
|
||||||
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LogDir));
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,16 +42,16 @@ ConfigureFilesystem::~ConfigureFilesystem() = default;
|
||||||
|
|
||||||
void ConfigureFilesystem::setConfiguration() {
|
void ConfigureFilesystem::setConfiguration() {
|
||||||
ui->nand_directory_edit->setText(
|
ui->nand_directory_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)));
|
||||||
ui->sdmc_directory_edit->setText(
|
ui->sdmc_directory_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)));
|
||||||
ui->gamecard_path_edit->setText(QString::fromStdString(Settings::values.gamecard_path));
|
ui->gamecard_path_edit->setText(QString::fromStdString(Settings::values.gamecard_path));
|
||||||
ui->dump_path_edit->setText(
|
ui->dump_path_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir)));
|
||||||
ui->load_path_edit->setText(
|
ui->load_path_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir)));
|
||||||
ui->cache_directory_edit->setText(
|
ui->cache_directory_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)));
|
||||||
|
|
||||||
ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted);
|
ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted);
|
||||||
ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game);
|
ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game);
|
||||||
|
@ -64,13 +64,15 @@ void ConfigureFilesystem::setConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureFilesystem::applyConfiguration() {
|
void ConfigureFilesystem::applyConfiguration() {
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir,
|
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir,
|
||||||
ui->nand_directory_edit->text().toStdString());
|
ui->nand_directory_edit->text().toStdString());
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir,
|
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir,
|
||||||
ui->sdmc_directory_edit->text().toStdString());
|
ui->sdmc_directory_edit->text().toStdString());
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir, ui->dump_path_edit->text().toStdString());
|
Common::FS::GetUserPath(Common::FS::UserPath::DumpDir,
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir, ui->load_path_edit->text().toStdString());
|
ui->dump_path_edit->text().toStdString());
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir,
|
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir,
|
||||||
|
ui->load_path_edit->text().toStdString());
|
||||||
|
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir,
|
||||||
ui->cache_directory_edit->text().toStdString());
|
ui->cache_directory_edit->text().toStdString());
|
||||||
Settings::values.gamecard_path = ui->gamecard_path_edit->text().toStdString();
|
Settings::values.gamecard_path = ui->gamecard_path_edit->text().toStdString();
|
||||||
|
|
||||||
|
@ -121,12 +123,13 @@ void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureFilesystem::ResetMetadata() {
|
void ConfigureFilesystem::ResetMetadata() {
|
||||||
if (!FileUtil::Exists(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
|
if (!Common::FS::Exists(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
"game_list")) {
|
"game_list")) {
|
||||||
QMessageBox::information(this, tr("Reset Metadata Cache"),
|
QMessageBox::information(this, tr("Reset Metadata Cache"),
|
||||||
tr("The metadata cache is already empty."));
|
tr("The metadata cache is already empty."));
|
||||||
} else if (FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) +
|
} else if (Common::FS::DeleteDirRecursively(
|
||||||
DIR_SEP + "game_list")) {
|
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
|
"game_list")) {
|
||||||
QMessageBox::information(this, tr("Reset Metadata Cache"),
|
QMessageBox::information(this, tr("Reset Metadata Cache"),
|
||||||
tr("The operation completed successfully."));
|
tr("The operation completed successfully."));
|
||||||
UISettings::values.is_game_list_reload_pending.exchange(true);
|
UISettings::values.is_game_list_reload_pending.exchange(true);
|
||||||
|
|
|
@ -79,7 +79,7 @@ void ConfigurePerGameAddons::ApplyConfiguration() {
|
||||||
std::sort(disabled_addons.begin(), disabled_addons.end());
|
std::sort(disabled_addons.begin(), disabled_addons.end());
|
||||||
std::sort(current.begin(), current.end());
|
std::sort(current.begin(), current.end());
|
||||||
if (disabled_addons != current) {
|
if (disabled_addons != current) {
|
||||||
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
|
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
|
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ constexpr std::array<u8, 107> backup_jpeg{
|
||||||
};
|
};
|
||||||
|
|
||||||
QString GetImagePath(Common::UUID uuid) {
|
QString GetImagePath(Common::UUID uuid) {
|
||||||
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
|
||||||
return QString::fromStdString(path);
|
return QString::fromStdString(path);
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ void ConfigureProfileManager::SetUserImage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto raw_path = QString::fromStdString(
|
const auto raw_path = QString::fromStdString(
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010");
|
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) + "/system/save/8000000000000010");
|
||||||
const QFileInfo raw_info{raw_path};
|
const QFileInfo raw_info{raw_path};
|
||||||
if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
|
if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
|
||||||
QMessageBox::warning(this, tr("Error deleting file"),
|
QMessageBox::warning(this, tr("Error deleting file"),
|
||||||
|
|
|
@ -61,9 +61,9 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur
|
||||||
// Set screenshot path to user specification.
|
// Set screenshot path to user specification.
|
||||||
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
|
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
|
||||||
const QString& filename =
|
const QString& filename =
|
||||||
QFileDialog::getExistingDirectory(
|
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
|
||||||
this, tr("Select Screenshots Path..."),
|
QString::fromStdString(Common::FS::GetUserPath(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))) +
|
Common::FS::UserPath::ScreenshotsDir))) +
|
||||||
QDir::separator();
|
QDir::separator();
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
ui->screenshot_path_edit->setText(filename);
|
ui->screenshot_path_edit->setText(filename);
|
||||||
|
@ -82,7 +82,7 @@ void ConfigureUi::ApplyConfiguration() {
|
||||||
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
|
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
|
||||||
|
|
||||||
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
|
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir,
|
Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir,
|
||||||
ui->screenshot_path_edit->text().toStdString());
|
ui->screenshot_path_edit->text().toStdString());
|
||||||
Settings::Apply();
|
Settings::Apply();
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ void ConfigureUi::SetConfiguration() {
|
||||||
|
|
||||||
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
|
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
|
||||||
ui->screenshot_path_edit->setText(
|
ui->screenshot_path_edit->setText(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureUi::changeEvent(QEvent* event) {
|
void ConfigureUi::changeEvent(QEvent* event) {
|
||||||
|
|
|
@ -39,12 +39,12 @@ QString GetGameListCachedObject(const std::string& filename, const std::string&
|
||||||
return generator();
|
return generator();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" +
|
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
DIR_SEP + filename + '.' + ext;
|
"game_list" + DIR_SEP + filename + '.' + ext;
|
||||||
|
|
||||||
FileUtil::CreateFullPath(path);
|
Common::FS::CreateFullPath(path);
|
||||||
|
|
||||||
if (!FileUtil::Exists(path)) {
|
if (!Common::FS::Exists(path)) {
|
||||||
const auto str = generator();
|
const auto str = generator();
|
||||||
|
|
||||||
QFile file{QString::fromStdString(path)};
|
QFile file{QString::fromStdString(path)};
|
||||||
|
@ -70,14 +70,14 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject(
|
||||||
return generator();
|
return generator();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto path1 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" +
|
const auto path1 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
DIR_SEP + filename + ".jpeg";
|
"game_list" + DIR_SEP + filename + ".jpeg";
|
||||||
const auto path2 = FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list" +
|
const auto path2 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||||
DIR_SEP + filename + ".appname.txt";
|
"game_list" + DIR_SEP + filename + ".appname.txt";
|
||||||
|
|
||||||
FileUtil::CreateFullPath(path1);
|
Common::FS::CreateFullPath(path1);
|
||||||
|
|
||||||
if (!FileUtil::Exists(path1) || !FileUtil::Exists(path2)) {
|
if (!Common::FS::Exists(path1) || !Common::FS::Exists(path2)) {
|
||||||
const auto [icon, nacp] = generator();
|
const auto [icon, nacp] = generator();
|
||||||
|
|
||||||
QFile file1{QString::fromStdString(path1)};
|
QFile file1{QString::fromStdString(path1)};
|
||||||
|
@ -208,7 +208,7 @@ QList<QStandardItem*> MakeGameListEntry(const std::string& path, const std::stri
|
||||||
file_type_string, program_id),
|
file_type_string, program_id),
|
||||||
new GameListItemCompat(compatibility),
|
new GameListItemCompat(compatibility),
|
||||||
new GameListItem(file_type_string),
|
new GameListItem(file_type_string),
|
||||||
new GameListItemSize(FileUtil::GetSize(path)),
|
new GameListItemSize(Common::FS::GetSize(path)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (UISettings::values.show_add_ons) {
|
if (UISettings::values.show_add_ons) {
|
||||||
|
@ -289,7 +289,7 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string physical_name = directory + DIR_SEP + virtual_name;
|
const std::string physical_name = directory + DIR_SEP + virtual_name;
|
||||||
const bool is_dir = FileUtil::IsDirectory(physical_name);
|
const bool is_dir = Common::FS::IsDirectory(physical_name);
|
||||||
if (!is_dir &&
|
if (!is_dir &&
|
||||||
(HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
|
(HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
|
||||||
const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read);
|
const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read);
|
||||||
|
@ -345,7 +345,7 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
FileUtil::ForeachDirectoryEntry(nullptr, dir_path, callback);
|
Common::FS::ForeachDirectoryEntry(nullptr, dir_path, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameListWorker::run() {
|
void GameListWorker::run() {
|
||||||
|
|
|
@ -177,8 +177,8 @@ static void InitializeLogging() {
|
||||||
log_filter.ParseFilterString(Settings::values.log_filter);
|
log_filter.ParseFilterString(Settings::values.log_filter);
|
||||||
Log::SetGlobalFilter(log_filter);
|
Log::SetGlobalFilter(log_filter);
|
||||||
|
|
||||||
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
|
||||||
FileUtil::CreateFullPath(log_dir);
|
Common::FS::CreateFullPath(log_dir);
|
||||||
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
||||||
|
@ -1121,7 +1121,7 @@ void GMainWindow::BootGame(const QString& filename) {
|
||||||
title_name = metadata.first->GetApplicationName();
|
title_name = metadata.first->GetApplicationName();
|
||||||
}
|
}
|
||||||
if (res != Loader::ResultStatus::Success || title_name.empty()) {
|
if (res != Loader::ResultStatus::Success || title_name.empty()) {
|
||||||
title_name = FileUtil::GetFilename(filename.toStdString());
|
title_name = Common::FS::GetFilename(filename.toStdString());
|
||||||
}
|
}
|
||||||
LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version);
|
LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version);
|
||||||
UpdateWindowTitle(title_name, title_version);
|
UpdateWindowTitle(title_name, title_version);
|
||||||
|
@ -1259,7 +1259,7 @@ void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::str
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case GameListOpenTarget::SaveData: {
|
case GameListOpenTarget::SaveData: {
|
||||||
open_target = tr("Save Data");
|
open_target = tr("Save Data");
|
||||||
const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
const std::string nand_dir = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
|
||||||
|
|
||||||
if (has_user_save) {
|
if (has_user_save) {
|
||||||
// User save data
|
// User save data
|
||||||
|
@ -1294,16 +1294,16 @@ void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::str
|
||||||
FileSys::SaveDataType::SaveData, program_id, {}, 0);
|
FileSys::SaveDataType::SaveData, program_id, {}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileUtil::Exists(path)) {
|
if (!Common::FS::Exists(path)) {
|
||||||
FileUtil::CreateFullPath(path);
|
Common::FS::CreateFullPath(path);
|
||||||
FileUtil::CreateDir(path);
|
Common::FS::CreateDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GameListOpenTarget::ModData: {
|
case GameListOpenTarget::ModData: {
|
||||||
open_target = tr("Mod Data");
|
open_target = tr("Mod Data");
|
||||||
const auto load_dir = FileUtil::GetUserPath(FileUtil::UserPath::LoadDir);
|
const auto load_dir = Common::FS::GetUserPath(Common::FS::UserPath::LoadDir);
|
||||||
path = fmt::format("{}{:016X}", load_dir, program_id);
|
path = fmt::format("{}{:016X}", load_dir, program_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1325,7 +1325,7 @@ void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::str
|
||||||
|
|
||||||
void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) {
|
void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) {
|
||||||
const QString shader_dir =
|
const QString shader_dir =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir));
|
||||||
const QString transferable_shader_cache_folder_path =
|
const QString transferable_shader_cache_folder_path =
|
||||||
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
|
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
|
||||||
const QString transferable_shader_cache_file_path =
|
const QString transferable_shader_cache_file_path =
|
||||||
|
@ -1428,8 +1428,8 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
|
||||||
RemoveAddOnContent(program_id, entry_type);
|
RemoveAddOnContent(program_id, entry_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
|
Common::FS::DeleteDirRecursively(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
|
||||||
"game_list");
|
DIR_SEP + "game_list");
|
||||||
game_list->PopulateAsync(UISettings::values.game_dirs);
|
game_list->PopulateAsync(UISettings::values.game_dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1519,7 +1519,7 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
|
||||||
|
|
||||||
void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
|
void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
|
||||||
const QString shader_dir =
|
const QString shader_dir =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir));
|
||||||
const QString transferable_shader_cache_folder_path =
|
const QString transferable_shader_cache_folder_path =
|
||||||
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
|
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
|
||||||
const QString transferable_shader_cache_file_path =
|
const QString transferable_shader_cache_file_path =
|
||||||
|
@ -1543,7 +1543,7 @@ void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
|
||||||
|
|
||||||
void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
|
void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
|
||||||
const QString config_dir =
|
const QString config_dir =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir));
|
||||||
const QString custom_config_file_path =
|
const QString custom_config_file_path =
|
||||||
config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
|
config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
|
||||||
|
|
||||||
|
@ -1590,7 +1590,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto path = fmt::format(
|
const auto path = fmt::format(
|
||||||
"{}{:016X}/romfs", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), *romfs_title_id);
|
"{}{:016X}/romfs", Common::FS::GetUserPath(Common::FS::UserPath::DumpDir), *romfs_title_id);
|
||||||
|
|
||||||
FileSys::VirtualFile romfs;
|
FileSys::VirtualFile romfs;
|
||||||
|
|
||||||
|
@ -1670,13 +1670,13 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
|
||||||
void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
|
void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
|
||||||
QString path;
|
QString path;
|
||||||
if (directory == QStringLiteral("SDMC")) {
|
if (directory == QStringLiteral("SDMC")) {
|
||||||
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) +
|
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir) +
|
||||||
"Nintendo/Contents/registered");
|
"Nintendo/Contents/registered");
|
||||||
} else if (directory == QStringLiteral("UserNAND")) {
|
} else if (directory == QStringLiteral("UserNAND")) {
|
||||||
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"user/Contents/registered");
|
"user/Contents/registered");
|
||||||
} else if (directory == QStringLiteral("SysNAND")) {
|
} else if (directory == QStringLiteral("SysNAND")) {
|
||||||
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
|
||||||
"system/Contents/registered");
|
"system/Contents/registered");
|
||||||
} else {
|
} else {
|
||||||
path = directory;
|
path = directory;
|
||||||
|
@ -1690,8 +1690,10 @@ void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
|
||||||
|
|
||||||
void GMainWindow::OnGameListAddDirectory() {
|
void GMainWindow::OnGameListAddDirectory() {
|
||||||
const QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
|
const QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
|
||||||
if (dir_path.isEmpty())
|
if (dir_path.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UISettings::GameDir game_dir{dir_path, false, true};
|
UISettings::GameDir game_dir{dir_path, false, true};
|
||||||
if (!UISettings::values.game_dirs.contains(game_dir)) {
|
if (!UISettings::values.game_dirs.contains(game_dir)) {
|
||||||
UISettings::values.game_dirs.append(game_dir);
|
UISettings::values.game_dirs.append(game_dir);
|
||||||
|
@ -1882,8 +1884,8 @@ void GMainWindow::OnMenuInstallToNAND() {
|
||||||
: tr("%n file(s) failed to install\n", "", failed_files.size()));
|
: tr("%n file(s) failed to install\n", "", failed_files.size()));
|
||||||
|
|
||||||
QMessageBox::information(this, tr("Install Results"), install_results);
|
QMessageBox::information(this, tr("Install Results"), install_results);
|
||||||
FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
|
Common::FS::DeleteDirRecursively(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
|
||||||
"game_list");
|
DIR_SEP + "game_list");
|
||||||
game_list->PopulateAsync(UISettings::values.game_dirs);
|
game_list->PopulateAsync(UISettings::values.game_dirs);
|
||||||
ui.action_Install_File_NAND->setEnabled(true);
|
ui.action_Install_File_NAND->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -2302,7 +2304,7 @@ void GMainWindow::LoadAmiibo(const QString& filename) {
|
||||||
|
|
||||||
void GMainWindow::OnOpenYuzuFolder() {
|
void GMainWindow::OnOpenYuzuFolder() {
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(
|
QDesktopServices::openUrl(QUrl::fromLocalFile(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir))));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::UserDir))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMainWindow::OnAbout() {
|
void GMainWindow::OnAbout() {
|
||||||
|
@ -2324,7 +2326,7 @@ void GMainWindow::OnCaptureScreenshot() {
|
||||||
|
|
||||||
const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
|
const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
|
||||||
const auto screenshot_path =
|
const auto screenshot_path =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir));
|
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir));
|
||||||
const auto date =
|
const auto date =
|
||||||
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz"));
|
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz"));
|
||||||
QString filename = QStringLiteral("%1%2_%3.png")
|
QString filename = QStringLiteral("%1%2_%3.png")
|
||||||
|
@ -2527,18 +2529,18 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
|
||||||
if (res == QMessageBox::Cancel)
|
if (res == QMessageBox::Cancel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
|
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
|
||||||
"prod.keys_autogenerated");
|
"prod.keys_autogenerated");
|
||||||
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
|
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
|
||||||
"console.keys_autogenerated");
|
"console.keys_autogenerated");
|
||||||
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
|
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
|
||||||
"title.keys_autogenerated");
|
"title.keys_autogenerated");
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance();
|
Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance();
|
||||||
if (keys.BaseDeriveNecessary()) {
|
if (keys.BaseDeriveNecessary()) {
|
||||||
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
|
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), FileSys::Mode::Read)};
|
Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir), FileSys::Mode::Read)};
|
||||||
|
|
||||||
const auto function = [this, &keys, &pdm] {
|
const auto function = [this, &keys, &pdm] {
|
||||||
keys.PopulateFromPartitionData(pdm);
|
keys.PopulateFromPartitionData(pdm);
|
||||||
|
@ -2870,7 +2872,7 @@ int main(int argc, char* argv[]) {
|
||||||
// If you start a bundle (binary) on OSX without the Terminal, the working directory is "/".
|
// If you start a bundle (binary) on OSX without the Terminal, the working directory is "/".
|
||||||
// But since we require the working directory to be the executable path for the location of
|
// But since we require the working directory to be the executable path for the location of
|
||||||
// the user folder in the Qt Frontend, we need to cd into that working directory
|
// the user folder in the Qt Frontend, we need to cd into that working directory
|
||||||
const std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
|
const std::string bin_path = Common::FS::GetBundleDirectory() + DIR_SEP + "..";
|
||||||
chdir(bin_path.c_str());
|
chdir(bin_path.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@
|
||||||
#include "yuzu_cmd/config.h"
|
#include "yuzu_cmd/config.h"
|
||||||
#include "yuzu_cmd/default_ini.h"
|
#include "yuzu_cmd/default_ini.h"
|
||||||
|
|
||||||
|
namespace FS = Common::FS;
|
||||||
|
|
||||||
Config::Config() {
|
Config::Config() {
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||||
sdl2_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-config.ini";
|
sdl2_config_loc = FS::GetUserPath(FS::UserPath::ConfigDir) + "sdl2-config.ini";
|
||||||
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
||||||
|
|
||||||
Reload();
|
Reload();
|
||||||
|
@ -31,8 +33,8 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
|
||||||
if (sdl2_config->ParseError() < 0) {
|
if (sdl2_config->ParseError() < 0) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
|
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
|
||||||
FileUtil::CreateFullPath(location);
|
FS::CreateFullPath(location);
|
||||||
FileUtil::WriteStringToFile(true, location, default_contents);
|
FS::WriteStringToFile(true, location, default_contents);
|
||||||
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
|
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
|
||||||
|
|
||||||
return LoadINI(default_contents, false);
|
return LoadINI(default_contents, false);
|
||||||
|
@ -315,21 +317,21 @@ void Config::ReadValues() {
|
||||||
// Data Storage
|
// Data Storage
|
||||||
Settings::values.use_virtual_sd =
|
Settings::values.use_virtual_sd =
|
||||||
sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
|
sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir,
|
FS::GetUserPath(
|
||||||
sdl2_config->Get("Data Storage", "nand_directory",
|
FS::UserPath::NANDDir,
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
|
sdl2_config->Get("Data Storage", "nand_directory", FS::GetUserPath(FS::UserPath::NANDDir)));
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir,
|
FS::GetUserPath(
|
||||||
sdl2_config->Get("Data Storage", "sdmc_directory",
|
FS::UserPath::SDMCDir,
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
|
sdl2_config->Get("Data Storage", "sdmc_directory", FS::GetUserPath(FS::UserPath::SDMCDir)));
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir,
|
FS::GetUserPath(
|
||||||
sdl2_config->Get("Data Storage", "load_directory",
|
FS::UserPath::LoadDir,
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)));
|
sdl2_config->Get("Data Storage", "load_directory", FS::GetUserPath(FS::UserPath::LoadDir)));
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir,
|
FS::GetUserPath(
|
||||||
sdl2_config->Get("Data Storage", "dump_directory",
|
FS::UserPath::DumpDir,
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)));
|
sdl2_config->Get("Data Storage", "dump_directory", FS::GetUserPath(FS::UserPath::DumpDir)));
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir,
|
FS::GetUserPath(FS::UserPath::CacheDir,
|
||||||
sdl2_config->Get("Data Storage", "cache_directory",
|
sdl2_config->Get("Data Storage", "cache_directory",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)));
|
FS::GetUserPath(FS::UserPath::CacheDir)));
|
||||||
Settings::values.gamecard_inserted =
|
Settings::values.gamecard_inserted =
|
||||||
sdl2_config->GetBoolean("Data Storage", "gamecard_inserted", false);
|
sdl2_config->GetBoolean("Data Storage", "gamecard_inserted", false);
|
||||||
Settings::values.gamecard_current_game =
|
Settings::values.gamecard_current_game =
|
||||||
|
|
|
@ -82,8 +82,8 @@ static void InitializeLogging() {
|
||||||
|
|
||||||
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
||||||
|
|
||||||
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
|
||||||
FileUtil::CreateFullPath(log_dir);
|
Common::FS::CreateFullPath(log_dir);
|
||||||
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
||||||
|
|
|
@ -15,10 +15,11 @@
|
||||||
#include "yuzu_tester/config.h"
|
#include "yuzu_tester/config.h"
|
||||||
#include "yuzu_tester/default_ini.h"
|
#include "yuzu_tester/default_ini.h"
|
||||||
|
|
||||||
|
namespace FS = Common::FS;
|
||||||
|
|
||||||
Config::Config() {
|
Config::Config() {
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||||
sdl2_config_loc =
|
sdl2_config_loc = FS::GetUserPath(FS::UserPath::ConfigDir) + "sdl2-tester-config.ini";
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-tester-config.ini";
|
|
||||||
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
||||||
|
|
||||||
Reload();
|
Reload();
|
||||||
|
@ -31,8 +32,8 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
|
||||||
if (sdl2_config->ParseError() < 0) {
|
if (sdl2_config->ParseError() < 0) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
|
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
|
||||||
FileUtil::CreateFullPath(location);
|
FS::CreateFullPath(location);
|
||||||
FileUtil::WriteStringToFile(true, default_contents, location);
|
FS::WriteStringToFile(true, default_contents, location);
|
||||||
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
|
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
|
||||||
|
|
||||||
return LoadINI(default_contents, false);
|
return LoadINI(default_contents, false);
|
||||||
|
@ -87,12 +88,12 @@ void Config::ReadValues() {
|
||||||
// Data Storage
|
// Data Storage
|
||||||
Settings::values.use_virtual_sd =
|
Settings::values.use_virtual_sd =
|
||||||
sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
|
sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir,
|
FS::GetUserPath(Common::FS::UserPath::NANDDir,
|
||||||
sdl2_config->Get("Data Storage", "nand_directory",
|
sdl2_config->Get("Data Storage", "nand_directory",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
|
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)));
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir,
|
FS::GetUserPath(Common::FS::UserPath::SDMCDir,
|
||||||
sdl2_config->Get("Data Storage", "sdmc_directory",
|
sdl2_config->Get("Data Storage", "sdmc_directory",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
|
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)));
|
||||||
|
|
||||||
// System
|
// System
|
||||||
Settings::values.current_user = std::clamp<int>(
|
Settings::values.current_user = std::clamp<int>(
|
||||||
|
|
|
@ -79,8 +79,8 @@ static void InitializeLogging(bool console) {
|
||||||
if (console)
|
if (console)
|
||||||
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
||||||
|
|
||||||
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
|
||||||
FileUtil::CreateFullPath(log_dir);
|
Common::FS::CreateFullPath(log_dir);
|
||||||
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
||||||
|
|
Loading…
Reference in a new issue