Use std::optional for ESFormats/SharedContentMap
This commit is contained in:
parent
b08653d69d
commit
545006f666
|
@ -419,12 +419,13 @@ SharedContentMap::SharedContentMap(Common::FromWhichRoot root) : m_root(root)
|
|||
|
||||
SharedContentMap::~SharedContentMap() = default;
|
||||
|
||||
std::string SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const
|
||||
std::optional<std::string>
|
||||
SharedContentMap::GetFilenameFromSHA1(const std::array<u8, 20>& 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<std::array<u8, 20>> SharedContentMap::GetHashes() const
|
|||
|
||||
std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& 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<u8, 20>& 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<u8, 20>& sha1)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -217,7 +218,7 @@ public:
|
|||
explicit SharedContentMap(Common::FromWhichRoot root);
|
||||
~SharedContentMap();
|
||||
|
||||
std::string GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const;
|
||||
std::optional<std::string> GetFilenameFromSHA1(const std::array<u8, 20>& sha1) const;
|
||||
std::string AddSharedContent(const std::array<u8, 20>& sha1);
|
||||
bool DeleteSharedContent(const std::array<u8, 20>& sha1);
|
||||
std::vector<std::array<u8, 20>> GetHashes() const;
|
||||
|
|
|
@ -152,8 +152,8 @@ std::vector<Content> 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) +
|
||||
|
|
|
@ -665,8 +665,8 @@ IPCCommandResult ES::ExportTitleDone(Context& context, const IOCtlVRequest& requ
|
|||
ReturnCode ES::DeleteSharedContent(const std::array<u8, 20>& 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<u8, 20>& 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))
|
||||
|
|
|
@ -208,7 +208,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector<u8>& 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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue