mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Use std::optional for ESFormats/SharedContentMap
This commit is contained in:
@ -419,12 +419,13 @@ SharedContentMap::SharedContentMap(Common::FromWhichRoot root) : m_root(root)
|
|||||||
|
|
||||||
SharedContentMap::~SharedContentMap() = default;
|
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(),
|
const auto it = std::find_if(m_entries.begin(), m_entries.end(),
|
||||||
[&sha1](const auto& entry) { return entry.sha1 == sha1; });
|
[&sha1](const auto& entry) { return entry.sha1 == sha1; });
|
||||||
if (it == m_entries.end())
|
if (it == m_entries.end())
|
||||||
return "unk";
|
return {};
|
||||||
|
|
||||||
const std::string id_string(it->id.begin(), it->id.end());
|
const std::string id_string(it->id.begin(), it->id.end());
|
||||||
return Common::RootUserPath(m_root) + StringFromFormat("/shared1/%s.app", id_string.c_str());
|
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 SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
||||||
{
|
{
|
||||||
std::string filename = GetFilenameFromSHA1(sha1);
|
auto filename = GetFilenameFromSHA1(sha1);
|
||||||
if (filename != "unk")
|
if (filename)
|
||||||
return filename;
|
return *filename;
|
||||||
|
|
||||||
const std::string id = StringFromFormat("%08x", m_last_id);
|
const std::string id = StringFromFormat("%08x", m_last_id);
|
||||||
Entry entry;
|
Entry entry;
|
||||||
@ -455,7 +456,7 @@ std::string SharedContentMap::AddSharedContent(const std::array<u8, 20>& sha1)
|
|||||||
WriteEntries();
|
WriteEntries();
|
||||||
filename = Common::RootUserPath(m_root) + StringFromFormat("/shared1/%s.app", id.c_str());
|
filename = Common::RootUserPath(m_root) + StringFromFormat("/shared1/%s.app", id.c_str());
|
||||||
m_last_id++;
|
m_last_id++;
|
||||||
return filename;
|
return *filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
bool SharedContentMap::DeleteSharedContent(const std::array<u8, 20>& sha1)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -217,7 +218,7 @@ public:
|
|||||||
explicit SharedContentMap(Common::FromWhichRoot root);
|
explicit SharedContentMap(Common::FromWhichRoot root);
|
||||||
~SharedContentMap();
|
~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);
|
std::string AddSharedContent(const std::array<u8, 20>& sha1);
|
||||||
bool DeleteSharedContent(const std::array<u8, 20>& sha1);
|
bool DeleteSharedContent(const std::array<u8, 20>& sha1);
|
||||||
std::vector<std::array<u8, 20>> GetHashes() const;
|
std::vector<std::array<u8, 20>> GetHashes() const;
|
||||||
|
@ -152,8 +152,8 @@ std::vector<Content> GetStoredContentsFromTMD(const TMDReader& tmd)
|
|||||||
[&tmd, &shared](const auto& content) {
|
[&tmd, &shared](const auto& content) {
|
||||||
if (content.IsShared())
|
if (content.IsShared())
|
||||||
{
|
{
|
||||||
const std::string path = shared.GetFilenameFromSHA1(content.sha1);
|
const auto path = shared.GetFilenameFromSHA1(content.sha1);
|
||||||
return path != "unk" && File::Exists(path);
|
return path && File::Exists(*path);
|
||||||
}
|
}
|
||||||
return File::Exists(
|
return File::Exists(
|
||||||
Common::GetTitleContentPath(tmd.GetTitleId(), Common::FROM_SESSION_ROOT) +
|
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
|
ReturnCode ES::DeleteSharedContent(const std::array<u8, 20>& sha1) const
|
||||||
{
|
{
|
||||||
IOS::ES::SharedContentMap map{Common::FromWhichRoot::FROM_SESSION_ROOT};
|
IOS::ES::SharedContentMap map{Common::FromWhichRoot::FROM_SESSION_ROOT};
|
||||||
const std::string content_path = map.GetFilenameFromSHA1(sha1);
|
const auto content_path = map.GetFilenameFromSHA1(sha1);
|
||||||
if (content_path == "unk")
|
if (!content_path)
|
||||||
return ES_EINVAL;
|
return ES_EINVAL;
|
||||||
|
|
||||||
// Check whether the shared content is used by a system title.
|
// 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;
|
return ES_EINVAL;
|
||||||
|
|
||||||
// Delete the shared content and update the content map.
|
// Delete the shared content and update the content map.
|
||||||
if (!File::Delete(content_path))
|
if (!File::Delete(*content_path))
|
||||||
return FS_ENOENT;
|
return FS_ENOENT;
|
||||||
|
|
||||||
if (!map.DeleteSharedContent(sha1))
|
if (!map.DeleteSharedContent(sha1))
|
||||||
|
@ -208,7 +208,7 @@ void CNANDContentLoader::InitializeContentEntries(const std::vector<u8>& data_ap
|
|||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
if (content.IsShared())
|
if (content.IsShared())
|
||||||
filename = shared_content.GetFilenameFromSHA1(content.sha1);
|
filename = *shared_content.GetFilenameFromSHA1(content.sha1);
|
||||||
else
|
else
|
||||||
filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), content.id);
|
filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), content.id);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user