diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-08-12 21:55:44 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-08-12 21:55:44 +0200 |
commit | 35e4a47be0c4ef25f860d51851d2c02c02dff53d (patch) | |
tree | e1ef42bdd5e4e2bdfc7bd3a0abf0e35cbc912dbd /src | |
parent | registration: Add support for force overwrite of installed (diff) | |
download | yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.gz yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.bz2 yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.lz yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.xz yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.tar.zst yuzu-35e4a47be0c4ef25f860d51851d2c02c02dff53d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/core/file_sys/nca_metadata.cpp | 11 | ||||
-rw-r--r-- | src/core/file_sys/registered_cache.cpp | 13 | ||||
-rw-r--r-- | src/core/file_sys/vfs_real.cpp | 16 |
3 files changed, 22 insertions, 18 deletions
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp index 234d70199..449244444 100644 --- a/src/core/file_sys/nca_metadata.cpp +++ b/src/core/file_sys/nca_metadata.cpp @@ -103,7 +103,10 @@ bool CNMT::UnionRecords(const CNMT& other) { std::vector<u8> CNMT::Serialize() const { const bool has_opt_header = header.type >= TitleType::Application && header.type <= TitleType::AOC; - std::vector<u8> out(sizeof(CNMTHeader) + (has_opt_header ? sizeof(OptionalHeader) : 0)); + const auto dead_zone = header.table_offset + sizeof(CNMTHeader); + std::vector<u8> out( + std::max(sizeof(CNMTHeader) + (has_opt_header ? sizeof(OptionalHeader) : 0), dead_zone) + + content_records.size() * sizeof(ContentRecord) + meta_records.size() * sizeof(MetaRecord)); memcpy(out.data(), &header, sizeof(CNMTHeader)); // Optional Header @@ -113,17 +116,11 @@ std::vector<u8> CNMT::Serialize() const { auto offset = header.table_offset; - const auto dead_zone = offset + sizeof(CNMTHeader) - out.size(); - if (dead_zone > 0) - out.resize(offset + sizeof(CNMTHeader)); - - out.resize(out.size() + content_records.size() * sizeof(ContentRecord)); for (const auto& rec : content_records) { memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(ContentRecord)); offset += sizeof(ContentRecord); } - out.resize(out.size() + content_records.size() * sizeof(MetaRecord)); for (const auto& rec : meta_records) { memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(MetaRecord)); offset += sizeof(MetaRecord); diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index e916d5610..a5e935f64 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -29,8 +29,8 @@ static bool FollowsTwoDigitDirFormat(std::string_view name) { } static bool FollowsNcaIdFormat(std::string_view name) { - static const std::regex nca_id_regex("[0-9A-F]{32}.nca", std::regex_constants::ECMAScript | - std::regex_constants::icase); + static const std::regex nca_id_regex("[0-9A-F]{32}\\.nca", std::regex_constants::ECMAScript | + std::regex_constants::icase); return name.size() == 36 && std::regex_match(name.begin(), name.end(), nca_id_regex); } @@ -59,8 +59,10 @@ static std::string GetCNMTName(TitleType type, u64 title_id) { auto index = static_cast<size_t>(type); // If the index is after the jump in TitleType, subtract it out. - if (index >= static_cast<size_t>(TitleType::Application)) - index -= 0x7B; + if (index >= static_cast<size_t>(TitleType::Application)) { + index -= static_cast<size_t>(TitleType::Application) - + static_cast<size_t>(TitleType::FirmwarePackageB); + } return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id); } @@ -96,7 +98,8 @@ VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir, file = files[0]; } else { std::vector<VirtualFile> concat; - for (u8 i = 0; i < 0x10; ++i) { + // Since the files are a two-digit hex number, max is FF. + for (size_t i = 0; i < 0x100; ++i) { auto next = nca_dir->GetFile(fmt::format("{:02X}", i)); if (next != nullptr) { concat.push_back(std::move(next)); diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 02cdb039a..0afe515f0 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -84,9 +84,11 @@ VirtualFile RealVfsFilesystem::OpenFile(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_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); - if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) && - !FileUtil::CreateEmptyFile(path)) - return nullptr; + if (!FileUtil::Exists(path)) { + FileUtil::CreateFullPath(path_fwd); + if (!FileUtil::CreateEmptyFile(path)) + return nullptr; + } return OpenFile(path, perms); } @@ -143,9 +145,11 @@ VirtualDir RealVfsFilesystem::OpenDirectory(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_fwd = FileUtil::SanitizePath(path, FileUtil::DirectorySeparator::ForwardSlash); - if (!FileUtil::Exists(path) && !FileUtil::CreateFullPath(path_fwd) && - !FileUtil::CreateEmptyFile(path)) - return nullptr; + if (!FileUtil::Exists(path)) { + FileUtil::CreateFullPath(path_fwd); + if (!FileUtil::CreateDir(path)) + return nullptr; + } // Cannot use make_shared as RealVfsDirectory constructor is private return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); } |