[XAM] Added iterating over publisher type content.

Importing savefiles this way still doesn't work
This commit is contained in:
Gliniak 2024-02-10 10:23:53 +01:00
parent c847987c27
commit 7e7784347b
1 changed files with 41 additions and 21 deletions

View File

@ -11,6 +11,7 @@
#include <array>
#include <string>
#include <set>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/filesystem.h"
@ -96,28 +97,47 @@ std::vector<XCONTENT_AGGREGATE_DATA> ContentManager::ListContent(
title_id = kernel_state_->title_id();
}
// Search path:
// content_root/title_id/type_name/*
auto package_root = ResolvePackageRoot(content_type, title_id);
auto file_infos = xe::filesystem::ListFiles(package_root);
for (const auto& file_info : file_infos) {
if (file_info.type != xe::filesystem::FileInfo::Type::kDirectory) {
// Directories only.
continue;
}
std::set<uint32_t> title_ids = {title_id};
XCONTENT_AGGREGATE_DATA content_data;
if (XSUCCEEDED(
ReadContentHeaderFile(xe::path_to_utf8(file_info.name) + ".header",
content_type, content_data, title_id))) {
result.emplace_back(std::move(content_data));
} else {
content_data.device_id = device_id;
content_data.content_type = content_type;
content_data.set_display_name(xe::path_to_utf16(file_info.name));
content_data.set_file_name(xe::path_to_utf8(file_info.name));
content_data.title_id = title_id;
result.emplace_back(std::move(content_data));
if (content_type == XContentType::kPublisher) {
std::string publisher_id_regex =
fmt::format("^{:04X}.*", static_cast<uint16_t>(title_id >> 16));
// Get all publisher entries
auto publisher_entries = xe::filesystem::FilterByName(
xe::filesystem::ListDirectories(root_path_),
std::regex(publisher_id_regex));
for (const auto& entry : publisher_entries) {
title_ids.insert(xe::string_util::from_string<uint32_t>(
xe::path_to_utf8(entry.name), true));
}
}
for (const uint32_t& title_id : title_ids) {
// Search path:
// content_root/title_id/type_name/*
auto package_root = ResolvePackageRoot(content_type, title_id);
auto file_infos = xe::filesystem::ListFiles(package_root);
for (const auto& file_info : file_infos) {
if (file_info.type != xe::filesystem::FileInfo::Type::kDirectory) {
// Directories only.
continue;
}
XCONTENT_AGGREGATE_DATA content_data;
if (XSUCCEEDED(ReadContentHeaderFile(
xe::path_to_utf8(file_info.name) + ".header", content_type,
content_data, title_id))) {
result.emplace_back(std::move(content_data));
} else {
content_data.device_id = device_id;
content_data.content_type = content_type;
content_data.set_display_name(xe::path_to_utf16(file_info.name));
content_data.set_file_name(xe::path_to_utf8(file_info.name));
content_data.title_id = title_id;
result.emplace_back(std::move(content_data));
}
}
}
return result;