mirror of
https://github.com/yuzu-mirror/yuzu
synced 2024-12-19 11:43:04 +00:00
file_sys: Create ContentProvider interface and default implementations
This commit is contained in:
parent
595511876e
commit
a6c7ae6fe8
2 changed files with 277 additions and 150 deletions
|
@ -23,19 +23,19 @@ namespace FileSys {
|
||||||
// The size of blocks to use when vfs raw copying into nand.
|
// The size of blocks to use when vfs raw copying into nand.
|
||||||
constexpr size_t VFS_RC_LARGE_COPY_BLOCK = 0x400000;
|
constexpr size_t VFS_RC_LARGE_COPY_BLOCK = 0x400000;
|
||||||
|
|
||||||
std::string RegisteredCacheEntry::DebugInfo() const {
|
std::string ContentProviderEntry::DebugInfo() const {
|
||||||
return fmt::format("title_id={:016X}, content_type={:02X}", title_id, static_cast<u8>(type));
|
return fmt::format("title_id={:016X}, content_type={:02X}", title_id, static_cast<u8>(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
|
bool operator<(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
|
||||||
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
|
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
|
bool operator==(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
|
||||||
return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type);
|
return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
|
bool operator!=(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
|
||||||
return !operator==(lhs, rhs);
|
return !operator==(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ static std::string GetCNMTName(TitleType type, u64 title_id) {
|
||||||
return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id);
|
return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ContentRecordType GetCRTypeFromNCAType(NCAContentType type) {
|
ContentRecordType GetCRTypeFromNCAType(NCAContentType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NCAContentType::Program:
|
case NCAContentType::Program:
|
||||||
// TODO(DarkLordZach): Differentiate between Program and Patch
|
// TODO(DarkLordZach): Differentiate between Program and Patch
|
||||||
|
@ -104,6 +104,28 @@ static ContentRecordType GetCRTypeFromNCAType(NCAContentType type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentProvider::~ContentProvider() = default;
|
||||||
|
|
||||||
|
bool ContentProvider::HasEntry(ContentProviderEntry entry) const {
|
||||||
|
return HasEntry(entry.title_id, entry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
VirtualFile ContentProvider::GetEntryUnparsed(ContentProviderEntry entry) const {
|
||||||
|
return GetEntryUnparsed(entry.title_id, entry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
VirtualFile ContentProvider::GetEntryRaw(ContentProviderEntry entry) const {
|
||||||
|
return GetEntryRaw(entry.title_id, entry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<NCA> ContentProvider::GetEntry(ContentProviderEntry entry) const {
|
||||||
|
return GetEntry(entry.title_id, entry.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ContentProviderEntry> ContentProvider::ListEntries() const {
|
||||||
|
return ListEntriesFilter(std::nullopt, std::nullopt, std::nullopt);
|
||||||
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir,
|
VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir,
|
||||||
std::string_view path) const {
|
std::string_view path) const {
|
||||||
const auto file = dir->GetFileRelative(path);
|
const auto file = dir->GetFileRelative(path);
|
||||||
|
@ -161,8 +183,8 @@ VirtualFile RegisteredCache::GetFileAtID(NcaID id) const {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<NcaID> CheckMapForContentRecord(
|
static std::optional<NcaID> CheckMapForContentRecord(const std::map<u64, CNMT>& map, u64 title_id,
|
||||||
const boost::container::flat_map<u64, CNMT>& map, u64 title_id, ContentRecordType type) {
|
ContentRecordType type) {
|
||||||
if (map.find(title_id) == map.end())
|
if (map.find(title_id) == map.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -268,7 +290,7 @@ void RegisteredCache::Refresh() {
|
||||||
AccumulateYuzuMeta();
|
AccumulateYuzuMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredCache::RegisteredCache(VirtualDir dir_, RegisteredCacheParsingFunction parsing_function)
|
RegisteredCache::RegisteredCache(VirtualDir dir_, ContentProviderParsingFunction parsing_function)
|
||||||
: dir(std::move(dir_)), parser(std::move(parsing_function)) {
|
: dir(std::move(dir_)), parser(std::move(parsing_function)) {
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
@ -279,19 +301,11 @@ bool RegisteredCache::HasEntry(u64 title_id, ContentRecordType type) const {
|
||||||
return GetEntryRaw(title_id, type) != nullptr;
|
return GetEntryRaw(title_id, type) != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCache::HasEntry(RegisteredCacheEntry entry) const {
|
|
||||||
return GetEntryRaw(entry) != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
|
VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
|
||||||
const auto id = GetNcaIDFromMetadata(title_id, type);
|
const auto id = GetNcaIDFromMetadata(title_id, type);
|
||||||
return id ? GetFileAtID(*id) : nullptr;
|
return id ? GetFileAtID(*id) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCache::GetEntryUnparsed(RegisteredCacheEntry entry) const {
|
|
||||||
return GetEntryUnparsed(entry.title_id, entry.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const {
|
std::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const {
|
||||||
const auto meta_iter = meta.find(title_id);
|
const auto meta_iter = meta.find(title_id);
|
||||||
if (meta_iter != meta.end())
|
if (meta_iter != meta.end())
|
||||||
|
@ -309,10 +323,6 @@ VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) c
|
||||||
return id ? parser(GetFileAtID(*id), *id) : nullptr;
|
return id ? parser(GetFileAtID(*id), *id) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCache::GetEntryRaw(RegisteredCacheEntry entry) const {
|
|
||||||
return GetEntryRaw(entry.title_id, entry.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<NCA> RegisteredCache::GetEntry(u64 title_id, ContentRecordType type) const {
|
std::unique_ptr<NCA> RegisteredCache::GetEntry(u64 title_id, ContentRecordType type) const {
|
||||||
const auto raw = GetEntryRaw(title_id, type);
|
const auto raw = GetEntryRaw(title_id, type);
|
||||||
if (raw == nullptr)
|
if (raw == nullptr)
|
||||||
|
@ -320,10 +330,6 @@ std::unique_ptr<NCA> RegisteredCache::GetEntry(u64 title_id, ContentRecordType t
|
||||||
return std::make_unique<NCA>(raw, nullptr, 0, keys);
|
return std::make_unique<NCA>(raw, nullptr, 0, keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<NCA> RegisteredCache::GetEntry(RegisteredCacheEntry entry) const {
|
|
||||||
return GetEntry(entry.title_id, entry.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void RegisteredCache::IterateAllMetadata(
|
void RegisteredCache::IterateAllMetadata(
|
||||||
std::vector<T>& out, std::function<T(const CNMT&, const ContentRecord&)> proc,
|
std::vector<T>& out, std::function<T(const CNMT&, const ContentRecord&)> proc,
|
||||||
|
@ -348,25 +354,14 @@ void RegisteredCache::IterateAllMetadata(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> RegisteredCache::ListEntries() const {
|
std::vector<ContentProviderEntry> RegisteredCache::ListEntriesFilter(
|
||||||
std::vector<RegisteredCacheEntry> out;
|
|
||||||
IterateAllMetadata<RegisteredCacheEntry>(
|
|
||||||
out,
|
|
||||||
[](const CNMT& c, const ContentRecord& r) {
|
|
||||||
return RegisteredCacheEntry{c.GetTitleID(), r.type};
|
|
||||||
},
|
|
||||||
[](const CNMT& c, const ContentRecord& r) { return true; });
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
|
|
||||||
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
||||||
std::optional<u64> title_id) const {
|
std::optional<u64> title_id) const {
|
||||||
std::vector<RegisteredCacheEntry> out;
|
std::vector<ContentProviderEntry> out;
|
||||||
IterateAllMetadata<RegisteredCacheEntry>(
|
IterateAllMetadata<ContentProviderEntry>(
|
||||||
out,
|
out,
|
||||||
[](const CNMT& c, const ContentRecord& r) {
|
[](const CNMT& c, const ContentRecord& r) {
|
||||||
return RegisteredCacheEntry{c.GetTitleID(), r.type};
|
return ContentProviderEntry{c.GetTitleID(), r.type};
|
||||||
},
|
},
|
||||||
[&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) {
|
[&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) {
|
||||||
if (title_type && *title_type != c.GetType())
|
if (title_type && *title_type != c.GetType())
|
||||||
|
@ -521,37 +516,56 @@ bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) {
|
||||||
}) != yuzu_meta.end();
|
}) != yuzu_meta.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredCacheUnion::RegisteredCacheUnion(std::vector<RegisteredCache*> caches)
|
ContentProviderUnion::~ContentProviderUnion() = default;
|
||||||
: caches(std::move(caches)) {}
|
|
||||||
|
|
||||||
void RegisteredCacheUnion::Refresh() {
|
void ContentProviderUnion::SetSlot(ContentProviderUnionSlot slot, ContentProvider* provider) {
|
||||||
for (const auto& c : caches)
|
providers[slot] = provider;
|
||||||
c->Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCacheUnion::HasEntry(u64 title_id, ContentRecordType type) const {
|
void ContentProviderUnion::ClearSlot(ContentProviderUnionSlot slot) {
|
||||||
return std::any_of(caches.begin(), caches.end(), [title_id, type](const auto& cache) {
|
providers[slot] = nullptr;
|
||||||
return cache->HasEntry(title_id, type);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCacheUnion::HasEntry(RegisteredCacheEntry entry) const {
|
void ContentProviderUnion::Refresh() {
|
||||||
return HasEntry(entry.title_id, entry.type);
|
for (auto& provider : providers) {
|
||||||
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
provider.second->Refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u32> RegisteredCacheUnion::GetEntryVersion(u64 title_id) const {
|
bool ContentProviderUnion::HasEntry(u64 title_id, ContentRecordType type) const {
|
||||||
for (const auto& c : caches) {
|
for (const auto& provider : providers) {
|
||||||
const auto res = c->GetEntryVersion(title_id);
|
if (provider.second == nullptr)
|
||||||
if (res)
|
continue;
|
||||||
|
|
||||||
|
if (provider.second->HasEntry(title_id, type))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<u32> ContentProviderUnion::GetEntryVersion(u64 title_id) const {
|
||||||
|
for (const auto& provider : providers) {
|
||||||
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto res = provider.second->GetEntryVersion(title_id);
|
||||||
|
if (res != std::nullopt)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCacheUnion::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
|
VirtualFile ContentProviderUnion::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
|
||||||
for (const auto& c : caches) {
|
for (const auto& provider : providers) {
|
||||||
const auto res = c->GetEntryUnparsed(title_id, type);
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto res = provider.second->GetEntryUnparsed(title_id, type);
|
||||||
if (res != nullptr)
|
if (res != nullptr)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -559,13 +573,12 @@ VirtualFile RegisteredCacheUnion::GetEntryUnparsed(u64 title_id, ContentRecordTy
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCacheUnion::GetEntryUnparsed(RegisteredCacheEntry entry) const {
|
VirtualFile ContentProviderUnion::GetEntryRaw(u64 title_id, ContentRecordType type) const {
|
||||||
return GetEntryUnparsed(entry.title_id, entry.type);
|
for (const auto& provider : providers) {
|
||||||
}
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
VirtualFile RegisteredCacheUnion::GetEntryRaw(u64 title_id, ContentRecordType type) const {
|
const auto res = provider.second->GetEntryRaw(title_id, type);
|
||||||
for (const auto& c : caches) {
|
|
||||||
const auto res = c->GetEntryRaw(title_id, type);
|
|
||||||
if (res != nullptr)
|
if (res != nullptr)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -573,30 +586,30 @@ VirtualFile RegisteredCacheUnion::GetEntryRaw(u64 title_id, ContentRecordType ty
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFile RegisteredCacheUnion::GetEntryRaw(RegisteredCacheEntry entry) const {
|
std::unique_ptr<NCA> ContentProviderUnion::GetEntry(u64 title_id, ContentRecordType type) const {
|
||||||
return GetEntryRaw(entry.title_id, entry.type);
|
for (const auto& provider : providers) {
|
||||||
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto res = provider.second->GetEntry(title_id, type);
|
||||||
|
if (res != nullptr)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<NCA> RegisteredCacheUnion::GetEntry(u64 title_id, ContentRecordType type) const {
|
std::vector<ContentProviderEntry> ContentProviderUnion::ListEntriesFilter(
|
||||||
const auto raw = GetEntryRaw(title_id, type);
|
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
||||||
if (raw == nullptr)
|
std::optional<u64> title_id) const {
|
||||||
return nullptr;
|
std::vector<ContentProviderEntry> out;
|
||||||
return std::make_unique<NCA>(raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<NCA> RegisteredCacheUnion::GetEntry(RegisteredCacheEntry entry) const {
|
for (const auto& provider : providers) {
|
||||||
return GetEntry(entry.title_id, entry.type);
|
if (provider.second == nullptr)
|
||||||
}
|
continue;
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const {
|
const auto vec = provider.second->ListEntriesFilter(title_type, record_type, title_id);
|
||||||
std::vector<RegisteredCacheEntry> out;
|
std::copy(vec.begin(), vec.end(), std::back_inserter(out));
|
||||||
for (const auto& c : caches) {
|
|
||||||
c->IterateAllMetadata<RegisteredCacheEntry>(
|
|
||||||
out,
|
|
||||||
[](const CNMT& c, const ContentRecord& r) {
|
|
||||||
return RegisteredCacheEntry{c.GetTitleID(), r.type};
|
|
||||||
},
|
|
||||||
[](const CNMT& c, const ContentRecord& r) { return true; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(out.begin(), out.end());
|
std::sort(out.begin(), out.end());
|
||||||
|
@ -604,25 +617,87 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter(
|
std::vector<std::pair<ContentProviderUnionSlot, ContentProviderEntry>>
|
||||||
|
ContentProviderUnion::ListEntriesFilterOrigin(std::optional<ContentProviderUnionSlot> origin,
|
||||||
|
std::optional<TitleType> title_type,
|
||||||
|
std::optional<ContentRecordType> record_type,
|
||||||
|
std::optional<u64> title_id) const {
|
||||||
|
std::vector<std::pair<ContentProviderUnionSlot, ContentProviderEntry>> out;
|
||||||
|
|
||||||
|
for (const auto& provider : providers) {
|
||||||
|
if (provider.second == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (origin.has_value() && *origin != provider.first)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto vec = provider.second->ListEntriesFilter(title_type, record_type, title_id);
|
||||||
|
std::transform(vec.begin(), vec.end(), std::back_inserter(out),
|
||||||
|
[&provider](const ContentProviderEntry& entry) {
|
||||||
|
return std::make_pair(provider.first, entry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(out.begin(), out.end());
|
||||||
|
out.erase(std::unique(out.begin(), out.end()), out.end());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ManualContentProvider::~ManualContentProvider() = default;
|
||||||
|
|
||||||
|
void ManualContentProvider::AddEntry(TitleType title_type, ContentRecordType content_type,
|
||||||
|
u64 title_id, VirtualFile file) {
|
||||||
|
entries.insert_or_assign({title_type, content_type, title_id}, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualContentProvider::ClearAllEntries() {
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ManualContentProvider::Refresh() {}
|
||||||
|
|
||||||
|
bool ManualContentProvider::HasEntry(u64 title_id, ContentRecordType type) const {
|
||||||
|
return GetEntryRaw(title_id, type) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<u32> ManualContentProvider::GetEntryVersion(u64 title_id) const {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
VirtualFile ManualContentProvider::GetEntryUnparsed(u64 title_id, ContentRecordType type) const {
|
||||||
|
return GetEntryRaw(title_id, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
VirtualFile ManualContentProvider::GetEntryRaw(u64 title_id, ContentRecordType type) const {
|
||||||
|
const auto iter =
|
||||||
|
std::find_if(entries.begin(), entries.end(), [title_id, type](const auto& entry) {
|
||||||
|
const auto [title_type, content_type, e_title_id] = entry.first;
|
||||||
|
return content_type == type && e_title_id == title_id;
|
||||||
|
});
|
||||||
|
if (iter == entries.end())
|
||||||
|
return nullptr;
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<NCA> ManualContentProvider::GetEntry(u64 title_id, ContentRecordType type) const {
|
||||||
|
const auto res = GetEntryRaw(title_id, type);
|
||||||
|
if (res == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
return std::make_unique<NCA>(res, nullptr, 0, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ContentProviderEntry> ManualContentProvider::ListEntriesFilter(
|
||||||
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
||||||
std::optional<u64> title_id) const {
|
std::optional<u64> title_id) const {
|
||||||
std::vector<RegisteredCacheEntry> out;
|
std::vector<ContentProviderEntry> out;
|
||||||
for (const auto& c : caches) {
|
|
||||||
c->IterateAllMetadata<RegisteredCacheEntry>(
|
for (const auto& entry : entries) {
|
||||||
out,
|
const auto [e_title_type, e_content_type, e_title_id] = entry.first;
|
||||||
[](const CNMT& c, const ContentRecord& r) {
|
if ((title_type == std::nullopt || e_title_type == *title_type) &&
|
||||||
return RegisteredCacheEntry{c.GetTitleID(), r.type};
|
(record_type == std::nullopt || e_content_type == *record_type) &&
|
||||||
},
|
(title_id == std::nullopt || e_title_id == *title_id)) {
|
||||||
[&title_type, &record_type, &title_id](const CNMT& c, const ContentRecord& r) {
|
out.emplace_back(ContentProviderEntry{e_title_id, e_content_type});
|
||||||
if (title_type && *title_type != c.GetType())
|
}
|
||||||
return false;
|
|
||||||
if (record_type && *record_type != r.type)
|
|
||||||
return false;
|
|
||||||
if (title_id && *title_id != c.GetTitleID())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(out.begin(), out.end());
|
std::sort(out.begin(), out.end());
|
||||||
|
|
|
@ -21,12 +21,13 @@ class NSP;
|
||||||
class XCI;
|
class XCI;
|
||||||
|
|
||||||
enum class ContentRecordType : u8;
|
enum class ContentRecordType : u8;
|
||||||
|
enum class NCAContentType : u8;
|
||||||
enum class TitleType : u8;
|
enum class TitleType : u8;
|
||||||
|
|
||||||
struct ContentRecord;
|
struct ContentRecord;
|
||||||
|
|
||||||
using NcaID = std::array<u8, 0x10>;
|
using NcaID = std::array<u8, 0x10>;
|
||||||
using RegisteredCacheParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>;
|
using ContentProviderParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>;
|
||||||
using VfsCopyFunction = std::function<bool(const VirtualFile&, const VirtualFile&, size_t)>;
|
using VfsCopyFunction = std::function<bool(const VirtualFile&, const VirtualFile&, size_t)>;
|
||||||
|
|
||||||
enum class InstallResult {
|
enum class InstallResult {
|
||||||
|
@ -36,7 +37,7 @@ enum class InstallResult {
|
||||||
ErrorMetaFailed,
|
ErrorMetaFailed,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RegisteredCacheEntry {
|
struct ContentProviderEntry {
|
||||||
u64 title_id;
|
u64 title_id;
|
||||||
ContentRecordType type;
|
ContentRecordType type;
|
||||||
|
|
||||||
|
@ -47,12 +48,46 @@ constexpr u64 GetUpdateTitleID(u64 base_title_id) {
|
||||||
return base_title_id | 0x800;
|
return base_title_id | 0x800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentRecordType GetCRTypeFromNCAType(NCAContentType type);
|
||||||
|
|
||||||
// boost flat_map requires operator< for O(log(n)) lookups.
|
// boost flat_map requires operator< for O(log(n)) lookups.
|
||||||
bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
bool operator<(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs);
|
||||||
|
|
||||||
// std unique requires operator== to identify duplicates.
|
// std unique requires operator== to identify duplicates.
|
||||||
bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
bool operator==(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs);
|
||||||
bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
bool operator!=(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs);
|
||||||
|
|
||||||
|
class ContentProvider {
|
||||||
|
public:
|
||||||
|
virtual ~ContentProvider();
|
||||||
|
|
||||||
|
virtual void Refresh() = 0;
|
||||||
|
|
||||||
|
virtual bool HasEntry(u64 title_id, ContentRecordType type) const = 0;
|
||||||
|
virtual bool HasEntry(ContentProviderEntry entry) const;
|
||||||
|
|
||||||
|
virtual std::optional<u32> GetEntryVersion(u64 title_id) const = 0;
|
||||||
|
|
||||||
|
virtual VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const = 0;
|
||||||
|
virtual VirtualFile GetEntryUnparsed(ContentProviderEntry entry) const;
|
||||||
|
|
||||||
|
virtual VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const = 0;
|
||||||
|
virtual VirtualFile GetEntryRaw(ContentProviderEntry entry) const;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const = 0;
|
||||||
|
virtual std::unique_ptr<NCA> GetEntry(ContentProviderEntry entry) const;
|
||||||
|
|
||||||
|
virtual std::vector<ContentProviderEntry> ListEntries() const;
|
||||||
|
|
||||||
|
// If a parameter is not std::nullopt, it will be filtered for from all entries.
|
||||||
|
virtual std::vector<ContentProviderEntry> ListEntriesFilter(
|
||||||
|
std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
|
||||||
|
std::optional<u64> title_id = {}) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// A single instance of KeyManager to be used by GetEntry()
|
||||||
|
Core::Crypto::KeyManager keys;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A class that catalogues NCAs in the registered directory structure.
|
* A class that catalogues NCAs in the registered directory structure.
|
||||||
|
@ -67,39 +102,32 @@ bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs
|
||||||
* (This impl also supports substituting the nca dir for an nca file, as that's more convenient
|
* (This impl also supports substituting the nca dir for an nca file, as that's more convenient
|
||||||
* when 4GB splitting can be ignored.)
|
* when 4GB splitting can be ignored.)
|
||||||
*/
|
*/
|
||||||
class RegisteredCache {
|
class RegisteredCache : public ContentProvider {
|
||||||
friend class RegisteredCacheUnion;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Parsing function defines the conversion from raw file to NCA. If there are other steps
|
// Parsing function defines the conversion from raw file to NCA. If there are other steps
|
||||||
// besides creating the NCA from the file (e.g. NAX0 on SD Card), that should go in a custom
|
// besides creating the NCA from the file (e.g. NAX0 on SD Card), that should go in a custom
|
||||||
// parsing function.
|
// parsing function.
|
||||||
explicit RegisteredCache(VirtualDir dir,
|
explicit RegisteredCache(VirtualDir dir,
|
||||||
RegisteredCacheParsingFunction parsing_function =
|
ContentProviderParsingFunction parsing_function =
|
||||||
[](const VirtualFile& file, const NcaID& id) { return file; });
|
[](const VirtualFile& file, const NcaID& id) { return file; });
|
||||||
~RegisteredCache();
|
~RegisteredCache() override;
|
||||||
|
|
||||||
void Refresh();
|
void Refresh() override;
|
||||||
|
|
||||||
bool HasEntry(u64 title_id, ContentRecordType type) const;
|
bool HasEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
bool HasEntry(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
std::optional<u32> GetEntryVersion(u64 title_id) const;
|
std::optional<u32> GetEntryVersion(u64 title_id) const override;
|
||||||
|
|
||||||
VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const;
|
VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const override;
|
||||||
VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const;
|
VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const override;
|
||||||
VirtualFile GetEntryRaw(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const;
|
std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> ListEntries() const;
|
|
||||||
// If a parameter is not std::nullopt, it will be filtered for from all entries.
|
// If a parameter is not std::nullopt, it will be filtered for from all entries.
|
||||||
std::vector<RegisteredCacheEntry> ListEntriesFilter(
|
std::vector<ContentProviderEntry> ListEntriesFilter(
|
||||||
std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
|
std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
|
||||||
std::optional<u64> title_id = {}) const;
|
std::optional<u64> title_id = {}) const override;
|
||||||
|
|
||||||
// Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
|
// Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
|
||||||
// there is a meta NCA and all of them are accessible.
|
// there is a meta NCA and all of them are accessible.
|
||||||
|
@ -131,46 +159,70 @@ private:
|
||||||
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
||||||
|
|
||||||
VirtualDir dir;
|
VirtualDir dir;
|
||||||
RegisteredCacheParsingFunction parser;
|
ContentProviderParsingFunction parser;
|
||||||
Core::Crypto::KeyManager keys;
|
|
||||||
|
|
||||||
// maps tid -> NcaID of meta
|
// maps tid -> NcaID of meta
|
||||||
boost::container::flat_map<u64, NcaID> meta_id;
|
std::map<u64, NcaID> meta_id;
|
||||||
// maps tid -> meta
|
// maps tid -> meta
|
||||||
boost::container::flat_map<u64, CNMT> meta;
|
std::map<u64, CNMT> meta;
|
||||||
// maps tid -> meta for CNMT in yuzu_meta
|
// maps tid -> meta for CNMT in yuzu_meta
|
||||||
boost::container::flat_map<u64, CNMT> yuzu_meta;
|
std::map<u64, CNMT> yuzu_meta;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Combines multiple RegisteredCaches (i.e. SysNAND, UserNAND, SDMC) into one interface.
|
enum class ContentProviderUnionSlot {
|
||||||
class RegisteredCacheUnion {
|
SysNAND, ///< System NAND
|
||||||
|
UserNAND, ///< User NAND
|
||||||
|
SDMC, ///< SD Card
|
||||||
|
FrontendManual, ///< Frontend-defined game list or similar
|
||||||
|
};
|
||||||
|
|
||||||
|
// Combines multiple ContentProvider(s) (i.e. SysNAND, UserNAND, SDMC) into one interface.
|
||||||
|
class ContentProviderUnion : public ContentProvider {
|
||||||
public:
|
public:
|
||||||
explicit RegisteredCacheUnion(std::vector<RegisteredCache*> caches);
|
~ContentProviderUnion() override;
|
||||||
|
|
||||||
void Refresh();
|
void SetSlot(ContentProviderUnionSlot slot, ContentProvider* provider);
|
||||||
|
void ClearSlot(ContentProviderUnionSlot slot);
|
||||||
|
|
||||||
bool HasEntry(u64 title_id, ContentRecordType type) const;
|
void Refresh() override;
|
||||||
bool HasEntry(RegisteredCacheEntry entry) const;
|
bool HasEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::optional<u32> GetEntryVersion(u64 title_id) const override;
|
||||||
|
VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const override;
|
||||||
|
VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::vector<ContentProviderEntry> ListEntriesFilter(
|
||||||
|
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
||||||
|
std::optional<u64> title_id) const override;
|
||||||
|
|
||||||
std::optional<u32> GetEntryVersion(u64 title_id) const;
|
std::vector<std::pair<ContentProviderUnionSlot, ContentProviderEntry>> ListEntriesFilterOrigin(
|
||||||
|
std::optional<ContentProviderUnionSlot> origin = {},
|
||||||
VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const;
|
|
||||||
VirtualFile GetEntryUnparsed(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const;
|
|
||||||
VirtualFile GetEntryRaw(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const;
|
|
||||||
std::unique_ptr<NCA> GetEntry(RegisteredCacheEntry entry) const;
|
|
||||||
|
|
||||||
std::vector<RegisteredCacheEntry> ListEntries() const;
|
|
||||||
// If a parameter is not std::nullopt, it will be filtered for from all entries.
|
|
||||||
std::vector<RegisteredCacheEntry> ListEntriesFilter(
|
|
||||||
std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
|
std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {},
|
||||||
std::optional<u64> title_id = {}) const;
|
std::optional<u64> title_id = {}) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<RegisteredCache*> caches;
|
std::map<ContentProviderUnionSlot, ContentProvider*> providers;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ManualContentProvider : public ContentProvider {
|
||||||
|
public:
|
||||||
|
~ManualContentProvider() override;
|
||||||
|
|
||||||
|
void AddEntry(TitleType title_type, ContentRecordType content_type, u64 title_id,
|
||||||
|
VirtualFile file);
|
||||||
|
void ClearAllEntries();
|
||||||
|
|
||||||
|
void Refresh() override;
|
||||||
|
bool HasEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::optional<u32> GetEntryVersion(u64 title_id) const override;
|
||||||
|
VirtualFile GetEntryUnparsed(u64 title_id, ContentRecordType type) const override;
|
||||||
|
VirtualFile GetEntryRaw(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::unique_ptr<NCA> GetEntry(u64 title_id, ContentRecordType type) const override;
|
||||||
|
std::vector<ContentProviderEntry> ListEntriesFilter(
|
||||||
|
std::optional<TitleType> title_type, std::optional<ContentRecordType> record_type,
|
||||||
|
std::optional<u64> title_id) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::tuple<TitleType, ContentRecordType, u64>, VirtualFile> entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
|
Loading…
Reference in a new issue