Skip to content

Commit

Permalink
[XAM] Added iterating over publisher type content.
Browse files Browse the repository at this point in the history
Importing savefiles this way still doesn't work
  • Loading branch information
Gliniak committed Feb 10, 2024
1 parent c847987 commit 7e77843
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/xenia/kernel/xam/content_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <array>
#include <string>
#include <set>

#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/filesystem.h"
Expand Down Expand Up @@ -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};

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));
}
}

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));
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;
Expand Down

0 comments on commit 7e77843

Please sign in to comment.