From a7e8d10969f280cd5a869b3525c3339357a958a6 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 18 Aug 2018 21:16:20 -0400 Subject: file_sys: Cut down on includes and copies --- src/core/crypto/key_manager.cpp | 22 +++++++++++----------- src/core/crypto/key_manager.h | 6 ++---- src/core/file_sys/registered_cache.cpp | 2 ++ src/core/file_sys/registered_cache.h | 1 + src/core/file_sys/sdmc_factory.h | 3 +++ src/core/loader/nax.cpp | 2 ++ src/core/loader/nax.h | 13 +++++++++---- 7 files changed, 30 insertions(+), 19 deletions(-) (limited to 'src/core') diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index acf635a65..1cb3fce00 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -199,7 +199,7 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const { template void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, - std::array key) { + const std::array& key) { const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); std::string filename = "title.keys_autogenerated"; if (!title_key) @@ -209,11 +209,10 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, if (!file.is_open()) return; if (add_info_text) { - file << "# This file is autogenerated by Yuzu" << std::endl - << "# It serves to store keys that were automatically generated from the normal keys" - << std::endl - << "# If you are experiencing issues involving keys, it may help to delete this file" - << std::endl; + file + << "# This file is autogenerated by Yuzu\n" + << "# It serves to store keys that were automatically generated from the normal keys\n" + << "# If you are experiencing issues involving keys, it may help to delete this file\n"; } file << std::endl @@ -263,11 +262,12 @@ bool KeyManager::KeyFileExists(bool title) { } void KeyManager::DeriveSDSeedLazy() { - if (!HasKey(S128KeyType::SDSeed)) { - const auto res = DeriveSDSeed(); - if (res != boost::none) - SetKey(S128KeyType::SDSeed, res.get()); - } + if (HasKey(S128KeyType::SDSeed)) + return; + + const auto res = DeriveSDSeed(); + if (res != boost::none) + SetKey(S128KeyType::SDSeed, res.get()); } const boost::container::flat_map> KeyManager::s128_file_id = { diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index 78d0b64e0..7a8728f76 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -74,9 +74,7 @@ struct KeyIndex { // boost flat_map requires operator< for O(log(n)) lookups. template bool operator<(const KeyIndex& lhs, const KeyIndex& rhs) { - return (static_cast(lhs.type) < static_cast(rhs.type)) || - (lhs.type == rhs.type && lhs.field1 < rhs.field1) || - (lhs.type == rhs.type && lhs.field1 == rhs.field1 && lhs.field2 < rhs.field2); + return std::tie(lhs.type, lhs.field1, lhs.field2) < std::tie(rhs.type, rhs.field1, rhs.field2); } class KeyManager { @@ -107,7 +105,7 @@ private: void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2, const std::string& filename, bool title); template - void WriteKeyToFile(bool title_key, std::string_view keyname, std::array key); + void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array& key); static const boost::container::flat_map> s128_file_id; static const boost::container::flat_map> s256_file_id; diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index a128fa33d..a02efc71e 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -254,6 +254,8 @@ RegisteredCache::RegisteredCache(VirtualDir dir_, RegisteredCacheParsingFunction Refresh(); } +RegisteredCache::~RegisteredCache() = default; + bool RegisteredCache::HasEntry(u64 title_id, ContentRecordType type) const { return GetEntryRaw(title_id, type) != nullptr; } diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h index f48cf3146..7b8955dfa 100644 --- a/src/core/file_sys/registered_cache.h +++ b/src/core/file_sys/registered_cache.h @@ -63,6 +63,7 @@ public: explicit RegisteredCache(VirtualDir dir, RegisteredCacheParsingFunction parsing_function = [](const VirtualFile& file, const NcaID& id) { return file; }); + ~RegisteredCache(); void Refresh(); diff --git a/src/core/file_sys/sdmc_factory.h b/src/core/file_sys/sdmc_factory.h index bb579472c..4eac92621 100644 --- a/src/core/file_sys/sdmc_factory.h +++ b/src/core/file_sys/sdmc_factory.h @@ -4,11 +4,14 @@ #pragma once +#include #include "core/file_sys/vfs.h" #include "core/hle/result.h" namespace FileSys { +class RegisteredCache; + /// File system interface to the SDCard archive class SDMCFactory { public: diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 76390bf46..b35fdc3f8 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp @@ -6,8 +6,10 @@ #include "core/core.h" #include "core/file_sys/content_archive.h" #include "core/file_sys/romfs.h" +#include "core/file_sys/xts_archive.h" #include "core/hle/kernel/process.h" #include "core/loader/nax.h" +#include "core/loader/nca.h" namespace Loader { diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index 08d6ef346..4dbae2918 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -6,18 +6,23 @@ #include #include "common/common_types.h" -#include "core/file_sys/card_image.h" -#include "core/file_sys/xts_archive.h" #include "core/loader/loader.h" -#include "core/loader/nca.h" + +namespace FileSys { + +class NAX; + +} // namespace FileSys namespace Loader { +class AppLoader_NCA; + /// Loads a NAX file class AppLoader_NAX final : public AppLoader { public: explicit AppLoader_NAX(FileSys::VirtualFile file); - ~AppLoader_NAX(); + ~AppLoader_NAX() override; /** * Returns the type of the file -- cgit v1.2.3