[XAM] Fixed issues with reading savefiles that are loaded via: XamContentAggregate
This commit is contained in:
parent
e85a59ca90
commit
85458c811f
|
@ -103,7 +103,10 @@ std::filesystem::path ContentManager::ResolvePackagePath(
|
||||||
// Content path:
|
// Content path:
|
||||||
// content_root/title_id/content_type/data_file_name/
|
// content_root/title_id/content_type/data_file_name/
|
||||||
auto get_package_path = [&, data, disc_number](const uint32_t title_id) {
|
auto get_package_path = [&, data, disc_number](const uint32_t title_id) {
|
||||||
auto package_root = ResolvePackageRoot(xuid, title_id, data.content_type);
|
uint64_t used_xuid = (data.xuid != -1 && data.xuid != 0) ? data.xuid : xuid;
|
||||||
|
|
||||||
|
auto package_root =
|
||||||
|
ResolvePackageRoot(used_xuid, title_id, data.content_type);
|
||||||
std::string final_name = xe::string_util::trim(data.file_name());
|
std::string final_name = xe::string_util::trim(data.file_name());
|
||||||
std::filesystem::path package_path = package_root / xe::to_path(final_name);
|
std::filesystem::path package_path = package_root / xe::to_path(final_name);
|
||||||
|
|
||||||
|
@ -252,10 +255,17 @@ bool ContentManager::ContentExists(const uint64_t xuid,
|
||||||
return std::filesystem::exists(path);
|
return std::filesystem::exists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
X_RESULT ContentManager::WriteContentHeaderFile(
|
X_RESULT ContentManager::WriteContentHeaderFile(const uint64_t xuid,
|
||||||
const uint64_t xuid, const XCONTENT_AGGREGATE_DATA* data) {
|
XCONTENT_AGGREGATE_DATA data) {
|
||||||
auto header_path = ResolvePackageHeaderPath(
|
if (data.title_id == -1) {
|
||||||
data->file_name(), xuid, data->title_id, data->content_type);
|
data.title_id = kernel_state_->title_id();
|
||||||
|
}
|
||||||
|
if (data.xuid == -1) {
|
||||||
|
data.xuid = xuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto header_path = ResolvePackageHeaderPath(data.file_name(), xuid,
|
||||||
|
data.title_id, data.content_type);
|
||||||
auto parent_path = header_path.parent_path();
|
auto parent_path = header_path.parent_path();
|
||||||
|
|
||||||
if (!std::filesystem::exists(parent_path)) {
|
if (!std::filesystem::exists(parent_path)) {
|
||||||
|
@ -268,7 +278,7 @@ X_RESULT ContentManager::WriteContentHeaderFile(
|
||||||
|
|
||||||
if (std::filesystem::exists(header_path)) {
|
if (std::filesystem::exists(header_path)) {
|
||||||
auto file = xe::filesystem::OpenFile(header_path, "wb");
|
auto file = xe::filesystem::OpenFile(header_path, "wb");
|
||||||
fwrite(data, 1, sizeof(XCONTENT_AGGREGATE_DATA), file);
|
fwrite(&data, 1, sizeof(XCONTENT_AGGREGATE_DATA), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -302,12 +312,6 @@ X_RESULT ContentManager::ReadContentHeaderFile(
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
std::memcpy(&data, buffer.data(), buffer.size());
|
std::memcpy(&data, buffer.data(), buffer.size());
|
||||||
// It only reads basic info, however importing savefiles
|
|
||||||
// usually requires title_id to be provided
|
|
||||||
// Kinda simple workaround for that, but still assumption
|
|
||||||
data.title_id = title_id;
|
|
||||||
data.xuid = xuid;
|
|
||||||
|
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
return X_STATUS_NO_SUCH_FILE;
|
return X_STATUS_NO_SUCH_FILE;
|
||||||
|
|
|
@ -157,7 +157,7 @@ class ContentManager {
|
||||||
|
|
||||||
bool ContentExists(const uint64_t xuid, const XCONTENT_AGGREGATE_DATA& data);
|
bool ContentExists(const uint64_t xuid, const XCONTENT_AGGREGATE_DATA& data);
|
||||||
X_RESULT WriteContentHeaderFile(const uint64_t xuid,
|
X_RESULT WriteContentHeaderFile(const uint64_t xuid,
|
||||||
const XCONTENT_AGGREGATE_DATA* data_raw);
|
XCONTENT_AGGREGATE_DATA data);
|
||||||
X_RESULT ReadContentHeaderFile(const std::string_view file_name,
|
X_RESULT ReadContentHeaderFile(const std::string_view file_name,
|
||||||
const uint64_t xuid, const uint32_t title_id,
|
const uint64_t xuid, const uint32_t title_id,
|
||||||
XContentType content_type,
|
XContentType content_type,
|
||||||
|
|
|
@ -273,7 +273,7 @@ dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
|
||||||
if (disposition == kDispositionState::Create) {
|
if (disposition == kDispositionState::Create) {
|
||||||
result = content_manager->CreateContent(root_name, xuid, content_data);
|
result = content_manager->CreateContent(root_name, xuid, content_data);
|
||||||
if (XSUCCEEDED(result)) {
|
if (XSUCCEEDED(result)) {
|
||||||
content_manager->WriteContentHeaderFile(xuid, &content_data);
|
content_manager->WriteContentHeaderFile(xuid, content_data);
|
||||||
}
|
}
|
||||||
} else if (disposition == kDispositionState::Open) {
|
} else if (disposition == kDispositionState::Open) {
|
||||||
result = content_manager->OpenContent(root_name, xuid, content_data,
|
result = content_manager->OpenContent(root_name, xuid, content_data,
|
||||||
|
|
Loading…
Reference in New Issue