diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 97eba84154..224776dcaf 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -419,12 +419,13 @@ SharedContentMap::SharedContentMap(Common::FromWhichRoot root) : m_root(root) SharedContentMap::~SharedContentMap() = default; -std::string SharedContentMap::GetFilenameFromSHA1(const std::array& sha1) const +std::optional +SharedContentMap::GetFilenameFromSHA1(const std::array& sha1) const { const auto it = std::find_if(m_entries.begin(), m_entries.end(), [&sha1](const auto& entry) { return entry.sha1 == sha1; }); if (it == m_entries.end()) - return "unk"; + return {}; const std::string id_string(it->id.begin(), it->id.end()); return Common::RootUserPath(m_root) + StringFromFormat("/shared1/%s.app", id_string.c_str()); @@ -442,9 +443,9 @@ std::vector> SharedContentMap::GetHashes() const std::string SharedContentMap::AddSharedContent(const std::array& sha1) { - std::string filename = GetFilenameFromSHA1(sha1); - if (filename != "unk") - return filename; + auto filename = GetFilenameFromSHA1(sha1); + if (filename) + return *filename; const std::string id = StringFromFormat("%08x", m_last_id); Entry entry; @@ -455,7 +456,7 @@ std::string SharedContentMap::AddSharedContent(const std::array& sha1) WriteEntries(); filename = Common::RootUserPath(m_root) + StringFromFormat("/shared1/%s.app", id.c_str()); m_last_id++; - return filename; + return *filename; } bool SharedContentMap::DeleteSharedContent(const std::array& sha1) diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index e90cb089b4..6d53baf1fc 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -217,7 +218,7 @@ public: explicit SharedContentMap(Common::FromWhichRoot root); ~SharedContentMap(); - std::string GetFilenameFromSHA1(const std::array& sha1) const; + std::optional GetFilenameFromSHA1(const std::array& sha1) const; std::string AddSharedContent(const std::array& sha1); bool DeleteSharedContent(const std::array& sha1); std::vector> GetHashes() const; diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index fd586010e5..70c03bbb05 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -152,8 +152,8 @@ std::vector GetStoredContentsFromTMD(const TMDReader& tmd) [&tmd, &shared](const auto& content) { if (content.IsShared()) { - const std::string path = shared.GetFilenameFromSHA1(content.sha1); - return path != "unk" && File::Exists(path); + const auto path = shared.GetFilenameFromSHA1(content.sha1); + return path && File::Exists(*path); } return File::Exists( Common::GetTitleContentPath(tmd.GetTitleId(), Common::FROM_SESSION_ROOT) + diff --git a/Source/Core/Core/IOS/ES/TitleManagement.cpp b/Source/Core/Core/IOS/ES/TitleManagement.cpp index 487b799d99..1bfd229a96 100644 --- a/Source/Core/Core/IOS/ES/TitleManagement.cpp +++ b/Source/Core/Core/IOS/ES/TitleManagement.cpp @@ -665,8 +665,8 @@ IPCCommandResult ES::ExportTitleDone(Context& context, const IOCtlVRequest& requ ReturnCode ES::DeleteSharedContent(const std::array& sha1) const { IOS::ES::SharedContentMap map{Common::FromWhichRoot::FROM_SESSION_ROOT}; - const std::string content_path = map.GetFilenameFromSHA1(sha1); - if (content_path == "unk") + const auto content_path = map.GetFilenameFromSHA1(sha1); + if (!content_path) return ES_EINVAL; // Check whether the shared content is used by a system title. @@ -689,7 +689,7 @@ ReturnCode ES::DeleteSharedContent(const std::array& sha1) const return ES_EINVAL; // Delete the shared content and update the content map. - if (!File::Delete(content_path)) + if (!File::Delete(*content_path)) return FS_ENOENT; if (!map.DeleteSharedContent(sha1)) diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index e6aca0ce79..b55efc413b 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -208,7 +208,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector& data_ap { std::string filename; if (content.IsShared()) - filename = shared_content.GetFilenameFromSHA1(content.sha1); + filename = *shared_content.GetFilenameFromSHA1(content.sha1); else filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), content.id);