IOS/ES: Add a helper function to get a content path

This commit is contained in:
Léo Lam 2017-10-01 17:02:01 +02:00
parent 44fc6d878a
commit a7e21bca13
2 changed files with 18 additions and 10 deletions

View File

@ -339,6 +339,10 @@ private:
void FinishStaleImport(u64 title_id);
void FinishAllStaleImports();
std::string GetContentPath(u64 title_id, const IOS::ES::Content& content,
const IOS::ES::SharedContentMap& map = IOS::ES::SharedContentMap{
Common::FROM_SESSION_ROOT}) const;
// TODO: remove these
const DiscIO::NANDContentLoader& AccessContentDevice(u64 title_id);

View File

@ -168,21 +168,15 @@ std::vector<IOS::ES::Content> ES::GetStoredContentsFromTMD(const IOS::ES::TMDRea
if (!tmd.IsValid())
return {};
const IOS::ES::SharedContentMap shared{Common::FROM_SESSION_ROOT};
const IOS::ES::SharedContentMap map{Common::FROM_SESSION_ROOT};
const std::vector<IOS::ES::Content> contents = tmd.GetContents();
std::vector<IOS::ES::Content> stored_contents;
std::copy_if(contents.begin(), contents.end(), std::back_inserter(stored_contents),
[&tmd, &shared](const auto& content) {
if (content.IsShared())
{
const auto path = shared.GetFilenameFromSHA1(content.sha1);
return path && File::Exists(*path);
}
return File::Exists(
Common::GetTitleContentPath(tmd.GetTitleId(), Common::FROM_SESSION_ROOT) +
StringFromFormat("%08x.app", content.id));
[this, &tmd, &map](const IOS::ES::Content& content) {
const std::string path = GetContentPath(tmd.GetTitleId(), content, map);
return !path.empty() && File::Exists(path);
});
return stored_contents;
@ -303,6 +297,16 @@ void ES::FinishAllStaleImports()
File::DeleteDirRecursively(import_dir);
File::CreateDir(import_dir);
}
std::string ES::GetContentPath(const u64 title_id, const IOS::ES::Content& content,
const IOS::ES::SharedContentMap& content_map) const
{
if (content.IsShared())
return content_map.GetFilenameFromSHA1(content.sha1).value_or("");
return Common::GetTitleContentPath(title_id, Common::FROM_SESSION_ROOT) +
StringFromFormat("%08x.app", content.id);
}
} // namespace Device
} // namespace HLE
} // namespace IOS