diff options
| author | 2019-06-12 17:27:06 -0400 | |
|---|---|---|
| committer | 2019-06-12 17:54:05 -0400 | |
| commit | a62088539ed02a8569814601b3b99b713c5d8a34 (patch) | |
| tree | 03fe279e7651c55291f702f5a8b518cb07e35812 /src/core/file_sys | |
| parent | Merge pull request #2578 from lioncash/cnmt (diff) | |
| download | yuzu-a62088539ed02a8569814601b3b99b713c5d8a34.tar.gz yuzu-a62088539ed02a8569814601b3b99b713c5d8a34.tar.xz yuzu-a62088539ed02a8569814601b3b99b713c5d8a34.zip | |
common/hex_util: Combine HexVectorToString() and HexArrayToString()
These can be generified together by using a concept type to designate
them. This also has the benefit of not making copies of potentially very
large arrays.
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/ips_layer.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 8 | ||||
| -rw-r--r-- | src/core/file_sys/registered_cache.cpp | 14 | ||||
| -rw-r--r-- | src/core/file_sys/submission_package.cpp | 13 | ||||
| -rw-r--r-- | src/core/file_sys/xts_archive.cpp | 2 |
5 files changed, 22 insertions, 17 deletions
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index 485c4913a..fcf8dc49b 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -295,7 +295,7 @@ void IPSwitchCompiler::Parse() { | |||
| 295 | LOG_INFO(Loader, | 295 | LOG_INFO(Loader, |
| 296 | "[IPSwitchCompiler ('{}')] - Patching value at offset 0x{:08X} " | 296 | "[IPSwitchCompiler ('{}')] - Patching value at offset 0x{:08X} " |
| 297 | "with byte string '{}'", | 297 | "with byte string '{}'", |
| 298 | patch_text->GetName(), offset, Common::HexVectorToString(replace)); | 298 | patch_text->GetName(), offset, Common::HexToString(replace)); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | patch.records.insert_or_assign(offset, std::move(replace)); | 301 | patch.records.insert_or_assign(offset, std::move(replace)); |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 78dbadee3..da823c37b 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -142,7 +142,7 @@ std::vector<VirtualFile> PatchManager::CollectPatches(const std::vector<VirtualD | |||
| 142 | if (!compiler.IsValid()) | 142 | if (!compiler.IsValid()) |
| 143 | continue; | 143 | continue; |
| 144 | 144 | ||
| 145 | auto this_build_id = Common::HexArrayToString(compiler.GetBuildID()); | 145 | auto this_build_id = Common::HexToString(compiler.GetBuildID()); |
| 146 | this_build_id = | 146 | this_build_id = |
| 147 | this_build_id.substr(0, this_build_id.find_last_not_of('0') + 1); | 147 | this_build_id.substr(0, this_build_id.find_last_not_of('0') + 1); |
| 148 | 148 | ||
| @@ -168,7 +168,7 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso, const std::st | |||
| 168 | return nso; | 168 | return nso; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | const auto build_id_raw = Common::HexArrayToString(header.build_id); | 171 | const auto build_id_raw = Common::HexToString(header.build_id); |
| 172 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | 172 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); |
| 173 | 173 | ||
| 174 | if (Settings::values.dump_nso) { | 174 | if (Settings::values.dump_nso) { |
| @@ -219,7 +219,7 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso, const std::st | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | 221 | bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { |
| 222 | const auto build_id_raw = Common::HexArrayToString(build_id_); | 222 | const auto build_id_raw = Common::HexToString(build_id_); |
| 223 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | 223 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); |
| 224 | 224 | ||
| 225 | LOG_INFO(Loader, "Querying NSO patch existence for build_id={}", build_id); | 225 | LOG_INFO(Loader, "Querying NSO patch existence for build_id={}", build_id); |
| @@ -235,7 +235,7 @@ bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | |||
| 235 | static std::optional<CheatList> ReadCheatFileFromFolder(const Core::System& system, u64 title_id, | 235 | static std::optional<CheatList> ReadCheatFileFromFolder(const Core::System& system, u64 title_id, |
| 236 | const std::array<u8, 0x20>& build_id_, | 236 | const std::array<u8, 0x20>& build_id_, |
| 237 | const VirtualDir& base_path, bool upper) { | 237 | const VirtualDir& base_path, bool upper) { |
| 238 | const auto build_id_raw = Common::HexArrayToString(build_id_, upper); | 238 | const auto build_id_raw = Common::HexToString(build_id_, upper); |
| 239 | const auto build_id = build_id_raw.substr(0, sizeof(u64) * 2); | 239 | const auto build_id = build_id_raw.substr(0, sizeof(u64) * 2); |
| 240 | const auto file = base_path->GetFile(fmt::format("{}.txt", build_id)); | 240 | const auto file = base_path->GetFile(fmt::format("{}.txt", build_id)); |
| 241 | 241 | ||
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 3946ff871..58917e094 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -53,13 +53,14 @@ static bool FollowsNcaIdFormat(std::string_view name) { | |||
| 53 | 53 | ||
| 54 | static std::string GetRelativePathFromNcaID(const std::array<u8, 16>& nca_id, bool second_hex_upper, | 54 | static std::string GetRelativePathFromNcaID(const std::array<u8, 16>& nca_id, bool second_hex_upper, |
| 55 | bool within_two_digit) { | 55 | bool within_two_digit) { |
| 56 | if (!within_two_digit) | 56 | if (!within_two_digit) { |
| 57 | return fmt::format("/{}.nca", Common::HexArrayToString(nca_id, second_hex_upper)); | 57 | return fmt::format("/{}.nca", Common::HexToString(nca_id, second_hex_upper)); |
| 58 | } | ||
| 58 | 59 | ||
| 59 | Core::Crypto::SHA256Hash hash{}; | 60 | Core::Crypto::SHA256Hash hash{}; |
| 60 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); | 61 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); |
| 61 | return fmt::format("/000000{:02X}/{}.nca", hash[0], | 62 | return fmt::format("/000000{:02X}/{}.nca", hash[0], |
| 62 | Common::HexArrayToString(nca_id, second_hex_upper)); | 63 | Common::HexToString(nca_id, second_hex_upper)); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | static std::string GetCNMTName(TitleType type, u64 title_id) { | 66 | static std::string GetCNMTName(TitleType type, u64 title_id) { |
| @@ -376,10 +377,11 @@ std::vector<ContentProviderEntry> RegisteredCache::ListEntriesFilter( | |||
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | static std::shared_ptr<NCA> GetNCAFromNSPForID(const NSP& nsp, const NcaID& id) { | 379 | static std::shared_ptr<NCA> GetNCAFromNSPForID(const NSP& nsp, const NcaID& id) { |
| 379 | const auto file = nsp.GetFile(fmt::format("{}.nca", Common::HexArrayToString(id, false))); | 380 | auto file = nsp.GetFile(fmt::format("{}.nca", Common::HexToString(id, false))); |
| 380 | if (file == nullptr) | 381 | if (file == nullptr) { |
| 381 | return nullptr; | 382 | return nullptr; |
| 382 | return std::make_shared<NCA>(file); | 383 | } |
| 384 | return std::make_shared<NCA>(std::move(file)); | ||
| 383 | } | 385 | } |
| 384 | 386 | ||
| 385 | InstallResult RegisteredCache::InstallEntry(const XCI& xci, bool overwrite_if_exists, | 387 | InstallResult RegisteredCache::InstallEntry(const XCI& xci, bool overwrite_if_exists, |
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index c69caae0f..d0428a457 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -235,16 +235,18 @@ void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { | |||
| 235 | const auto section0 = nca->GetSubdirectories()[0]; | 235 | const auto section0 = nca->GetSubdirectories()[0]; |
| 236 | 236 | ||
| 237 | for (const auto& inner_file : section0->GetFiles()) { | 237 | for (const auto& inner_file : section0->GetFiles()) { |
| 238 | if (inner_file->GetExtension() != "cnmt") | 238 | if (inner_file->GetExtension() != "cnmt") { |
| 239 | continue; | 239 | continue; |
| 240 | } | ||
| 240 | 241 | ||
| 241 | const CNMT cnmt(inner_file); | 242 | const CNMT cnmt(inner_file); |
| 242 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | 243 | auto& ncas_title = ncas[cnmt.GetTitleID()]; |
| 243 | 244 | ||
| 244 | ncas_title[{cnmt.GetType(), ContentRecordType::Meta}] = nca; | 245 | ncas_title[{cnmt.GetType(), ContentRecordType::Meta}] = nca; |
| 245 | for (const auto& rec : cnmt.GetContentRecords()) { | 246 | for (const auto& rec : cnmt.GetContentRecords()) { |
| 246 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | 247 | const auto id_string = Common::HexToString(rec.nca_id, false); |
| 247 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | 248 | auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); |
| 249 | |||
| 248 | if (next_file == nullptr) { | 250 | if (next_file == nullptr) { |
| 249 | LOG_WARNING(Service_FS, | 251 | LOG_WARNING(Service_FS, |
| 250 | "NCA with ID {}.nca is listed in content metadata, but cannot " | 252 | "NCA with ID {}.nca is listed in content metadata, but cannot " |
| @@ -253,9 +255,10 @@ void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { | |||
| 253 | continue; | 255 | continue; |
| 254 | } | 256 | } |
| 255 | 257 | ||
| 256 | auto next_nca = std::make_shared<NCA>(next_file, nullptr, 0, keys); | 258 | auto next_nca = std::make_shared<NCA>(std::move(next_file), nullptr, 0, keys); |
| 257 | if (next_nca->GetType() == NCAContentType::Program) | 259 | if (next_nca->GetType() == NCAContentType::Program) { |
| 258 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | 260 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); |
| 261 | } | ||
| 259 | if (next_nca->GetStatus() == Loader::ResultStatus::Success || | 262 | if (next_nca->GetStatus() == Loader::ResultStatus::Success || |
| 260 | (next_nca->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS && | 263 | (next_nca->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS && |
| 261 | (cnmt.GetTitleID() & 0x800) != 0)) { | 264 | (cnmt.GetTitleID() & 0x800) != 0)) { |
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index eec51c64e..4bc5cb2ee 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp | |||
| @@ -66,7 +66,7 @@ NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id) | |||
| 66 | Core::Crypto::SHA256Hash hash{}; | 66 | Core::Crypto::SHA256Hash hash{}; |
| 67 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); | 67 | mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); |
| 68 | status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0], | 68 | status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0], |
| 69 | Common::HexArrayToString(nca_id, false))); | 69 | Common::HexToString(nca_id, false))); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | NAX::~NAX() = default; | 72 | NAX::~NAX() = default; |