diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp index 6102ef476..76a2b7e86 100644 --- a/src/core/file_sys/bis_factory.cpp +++ b/src/core/file_sys/bis_factory.cpp @@ -10,19 +10,19 @@ namespace FileSys { BISFactory::BISFactory(VirtualDir nand_root_, VirtualDir load_root_) : nand_root(std::move(nand_root_)), load_root(std::move(load_root_)), - sysnand_cache(std::make_shared( + sysnand_cache(std::make_unique( GetOrCreateDirectoryRelative(nand_root, "/system/Contents/registered"))), - usrnand_cache(std::make_shared( + usrnand_cache(std::make_unique( GetOrCreateDirectoryRelative(nand_root, "/user/Contents/registered"))) {} BISFactory::~BISFactory() = default; -std::shared_ptr BISFactory::GetSystemNANDContents() const { - return sysnand_cache; +RegisteredCache* BISFactory::GetSystemNANDContents() const { + return sysnand_cache.get(); } -std::shared_ptr BISFactory::GetUserNANDContents() const { - return usrnand_cache; +RegisteredCache* BISFactory::GetUserNANDContents() const { + return usrnand_cache.get(); } VirtualDir BISFactory::GetModificationLoadRoot(u64 title_id) const { diff --git a/src/core/file_sys/bis_factory.h b/src/core/file_sys/bis_factory.h index c352e0925..364d309bd 100644 --- a/src/core/file_sys/bis_factory.h +++ b/src/core/file_sys/bis_factory.h @@ -20,8 +20,8 @@ public: explicit BISFactory(VirtualDir nand_root, VirtualDir load_root); ~BISFactory(); - std::shared_ptr GetSystemNANDContents() const; - std::shared_ptr GetUserNANDContents() const; + RegisteredCache* GetSystemNANDContents() const; + RegisteredCache* GetUserNANDContents() const; VirtualDir GetModificationLoadRoot(u64 title_id) const; @@ -29,8 +29,8 @@ private: VirtualDir nand_root; VirtualDir load_root; - std::shared_ptr sysnand_cache; - std::shared_ptr usrnand_cache; + std::unique_ptr sysnand_cache; + std::unique_ptr usrnand_cache; }; } // namespace FileSys diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 019caebe9..c15ac8e19 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -346,7 +346,7 @@ std::map> PatchManager::GetPatchVersionNam } std::pair, VirtualFile> PatchManager::GetControlMetadata() const { - const auto& installed{Service::FileSystem::GetUnionContents()}; + const auto installed{Service::FileSystem::GetUnionContents()}; const auto base_control_nca = installed->GetEntry(title_id, ContentRecordType::Control); if (base_control_nca == nullptr) diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index e9b040689..1febb398e 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp @@ -308,14 +308,14 @@ VirtualFile RegisteredCache::GetEntryRaw(RegisteredCacheEntry entry) const { return GetEntryRaw(entry.title_id, entry.type); } -std::shared_ptr RegisteredCache::GetEntry(u64 title_id, ContentRecordType type) const { +std::unique_ptr RegisteredCache::GetEntry(u64 title_id, ContentRecordType type) const { const auto raw = GetEntryRaw(title_id, type); if (raw == nullptr) return nullptr; - return std::make_shared(raw); + return std::make_unique(raw); } -std::shared_ptr RegisteredCache::GetEntry(RegisteredCacheEntry entry) const { +std::unique_ptr RegisteredCache::GetEntry(RegisteredCacheEntry entry) const { return GetEntry(entry.title_id, entry.type); } @@ -516,7 +516,7 @@ bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) { }) != yuzu_meta.end(); } -RegisteredCacheUnion::RegisteredCacheUnion(std::vector> caches) +RegisteredCacheUnion::RegisteredCacheUnion(std::vector caches) : caches(std::move(caches)) {} void RegisteredCacheUnion::Refresh() { @@ -572,14 +572,14 @@ VirtualFile RegisteredCacheUnion::GetEntryRaw(RegisteredCacheEntry entry) const return GetEntryRaw(entry.title_id, entry.type); } -std::shared_ptr RegisteredCacheUnion::GetEntry(u64 title_id, ContentRecordType type) const { +std::unique_ptr RegisteredCacheUnion::GetEntry(u64 title_id, ContentRecordType type) const { const auto raw = GetEntryRaw(title_id, type); if (raw == nullptr) return nullptr; - return std::make_shared(raw); + return std::make_unique(raw); } -std::shared_ptr RegisteredCacheUnion::GetEntry(RegisteredCacheEntry entry) const { +std::unique_ptr RegisteredCacheUnion::GetEntry(RegisteredCacheEntry entry) const { return GetEntry(entry.title_id, entry.type); } diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h index c0cd59fc5..5ddacba47 100644 --- a/src/core/file_sys/registered_cache.h +++ b/src/core/file_sys/registered_cache.h @@ -88,8 +88,8 @@ public: VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const; VirtualFile GetEntryRaw(RegisteredCacheEntry entry) const; - std::shared_ptr GetEntry(u64 title_id, ContentRecordType type) const; - std::shared_ptr GetEntry(RegisteredCacheEntry entry) const; + std::unique_ptr GetEntry(u64 title_id, ContentRecordType type) const; + std::unique_ptr GetEntry(RegisteredCacheEntry entry) const; std::vector ListEntries() const; // If a parameter is not boost::none, it will be filtered for from all entries. @@ -142,7 +142,7 @@ private: // Combines multiple RegisteredCaches (i.e. SysNAND, UserNAND, SDMC) into one interface. class RegisteredCacheUnion { public: - explicit RegisteredCacheUnion(std::vector> caches); + explicit RegisteredCacheUnion(std::vector caches); void Refresh(); @@ -157,8 +157,8 @@ public: VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const; VirtualFile GetEntryRaw(RegisteredCacheEntry entry) const; - std::shared_ptr GetEntry(u64 title_id, ContentRecordType type) const; - std::shared_ptr GetEntry(RegisteredCacheEntry entry) const; + std::unique_ptr GetEntry(u64 title_id, ContentRecordType type) const; + std::unique_ptr GetEntry(RegisteredCacheEntry entry) const; std::vector ListEntries() const; // If a parameter is not boost::none, it will be filtered for from all entries. @@ -168,7 +168,7 @@ public: boost::optional title_id = boost::none) const; private: - std::vector> caches; + std::vector caches; }; } // namespace FileSys diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp index d66a9c9a4..bd3a57058 100644 --- a/src/core/file_sys/sdmc_factory.cpp +++ b/src/core/file_sys/sdmc_factory.cpp @@ -10,10 +10,10 @@ namespace FileSys { SDMCFactory::SDMCFactory(VirtualDir dir_) - : dir(std::move(dir_)), contents(std::make_shared( + : dir(std::move(dir_)), contents(std::make_unique( GetOrCreateDirectoryRelative(dir, "/Nintendo/Contents/registered"), [](const VirtualFile& file, const NcaID& id) { - return std::make_shared(file, id)->GetDecrypted(); + return NAX{file, id}.GetDecrypted(); })) {} SDMCFactory::~SDMCFactory() = default; @@ -22,8 +22,8 @@ ResultVal SDMCFactory::Open() { return MakeResult(dir); } -std::shared_ptr SDMCFactory::GetSDMCContents() const { - return contents; +RegisteredCache* SDMCFactory::GetSDMCContents() const { + return contents.get(); } } // namespace FileSys diff --git a/src/core/file_sys/sdmc_factory.h b/src/core/file_sys/sdmc_factory.h index ea12149de..42794ba5b 100644 --- a/src/core/file_sys/sdmc_factory.h +++ b/src/core/file_sys/sdmc_factory.h @@ -19,12 +19,12 @@ public: ~SDMCFactory(); ResultVal Open(); - std::shared_ptr GetSDMCContents() const; + RegisteredCache* GetSDMCContents() const; private: VirtualDir dir; - std::shared_ptr contents; + std::unique_ptr contents; }; } // namespace FileSys diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index e06712603..e32a7c48e 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -319,13 +319,12 @@ ResultVal OpenSDMC() { return sdmc_factory->Open(); } -std::shared_ptr GetUnionContents() { - return std::make_shared( - std::vector>{ - GetSystemNANDContents(), GetUserNANDContents(), GetSDMCContents()}); +std::unique_ptr GetUnionContents() { + return std::make_unique(std::vector{ + GetSystemNANDContents(), GetUserNANDContents(), GetSDMCContents()}); } -std::shared_ptr GetSystemNANDContents() { +FileSys::RegisteredCache* GetSystemNANDContents() { LOG_TRACE(Service_FS, "Opening System NAND Contents"); if (bis_factory == nullptr) @@ -334,7 +333,7 @@ std::shared_ptr GetSystemNANDContents() { return bis_factory->GetSystemNANDContents(); } -std::shared_ptr GetUserNANDContents() { +FileSys::RegisteredCache* GetUserNANDContents() { LOG_TRACE(Service_FS, "Opening User NAND Contents"); if (bis_factory == nullptr) @@ -343,7 +342,7 @@ std::shared_ptr GetUserNANDContents() { return bis_factory->GetUserNANDContents(); } -std::shared_ptr GetSDMCContents() { +FileSys::RegisteredCache* GetSDMCContents() { LOG_TRACE(Service_FS, "Opening SDMC Contents"); if (sdmc_factory == nullptr) diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 2df1faeb0..6ca5c5636 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -47,11 +47,11 @@ ResultVal OpenSaveData(FileSys::SaveDataSpaceId space, FileSys::SaveDataDescriptor save_struct); ResultVal OpenSDMC(); -std::shared_ptr GetUnionContents(); +std::unique_ptr GetUnionContents(); -std::shared_ptr GetSystemNANDContents(); -std::shared_ptr GetUserNANDContents(); -std::shared_ptr GetSDMCContents(); +FileSys::RegisteredCache* GetSystemNANDContents(); +FileSys::RegisteredCache* GetUserNANDContents(); +FileSys::RegisteredCache* GetSDMCContents(); FileSys::VirtualDir GetModificationLoadRoot(u64 title_id); diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index 4b2f758a8..44accecb7 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp @@ -161,7 +161,7 @@ PL_U::PL_U() : ServiceFramework("pl:u"), impl{std::make_unique()} { }; RegisterHandlers(functions); // Attempt to load shared font data from disk - const auto nand = FileSystem::GetSystemNANDContents(); + const auto* nand = FileSystem::GetSystemNANDContents(); std::size_t offset = 0; // Rebuild shared fonts from data ncas if (nand->HasEntry(static_cast(FontArchives::Standard), diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 8f99a1c78..3881aba5f 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -96,7 +96,7 @@ void GameListWorker::AddInstalledTitlesToGameList() { FileSys::ContentRecordType::Program); for (const auto& game : installed_games) { - const auto& file = cache->GetEntryUnparsed(game); + const auto file = cache->GetEntryUnparsed(game); std::unique_ptr loader = Loader::GetLoader(file); if (!loader) continue; @@ -107,7 +107,7 @@ void GameListWorker::AddInstalledTitlesToGameList() { loader->ReadProgramId(program_id); const FileSys::PatchManager patch{program_id}; - const auto& control = cache->GetEntry(game.title_id, FileSys::ContentRecordType::Control); + const auto control = cache->GetEntry(game.title_id, FileSys::ContentRecordType::Control); if (control != nullptr) GetMetadataFromControlNCA(patch, *control, icon, name); @@ -135,9 +135,10 @@ void GameListWorker::AddInstalledTitlesToGameList() { FileSys::ContentRecordType::Control); for (const auto& entry : control_data) { - const auto nca = cache->GetEntry(entry); - if (nca != nullptr) - nca_control_map.insert_or_assign(entry.title_id, nca); + auto nca = cache->GetEntry(entry); + if (nca != nullptr) { + nca_control_map.insert_or_assign(entry.title_id, std::move(nca)); + } } } @@ -153,9 +154,11 @@ void GameListWorker::FillControlMap(const std::string& dir_path) { QFileInfo file_info(physical_name.c_str()); if (!is_dir && file_info.suffix().toStdString() == "nca") { auto nca = - std::make_shared(vfs->OpenFile(physical_name, FileSys::Mode::Read)); - if (nca->GetType() == FileSys::NCAContentType::Control) - nca_control_map.insert_or_assign(nca->GetTitleId(), nca); + std::make_unique(vfs->OpenFile(physical_name, FileSys::Mode::Read)); + if (nca->GetType() == FileSys::NCAContentType::Control) { + const u64 title_id = nca->GetTitleId(); + nca_control_map.insert_or_assign(title_id, std::move(nca)); + } } return true; }; diff --git a/src/yuzu/game_list_worker.h b/src/yuzu/game_list_worker.h index 09d20c42f..0e42d0bde 100644 --- a/src/yuzu/game_list_worker.h +++ b/src/yuzu/game_list_worker.h @@ -63,7 +63,7 @@ private: void AddFstEntriesToGameList(const std::string& dir_path, unsigned int recursion = 0); std::shared_ptr vfs; - std::map> nca_control_map; + std::map> nca_control_map; QStringList watch_list; QString dir_path; bool deep_scan;