[XAM] xeXamContentCreate - Disposition cleanup

This commit is contained in:
Gliniak 2023-02-20 13:33:50 +01:00 committed by Rick Gibbed
parent e110527bfe
commit 858af5ae75
1 changed files with 16 additions and 22 deletions

View File

@ -116,6 +116,8 @@ dword_result_t XamContentCreateEnumerator_entry(
} }
DECLARE_XAM_EXPORT1(XamContentCreateEnumerator, kContent, kImplemented); DECLARE_XAM_EXPORT1(XamContentCreateEnumerator, kContent, kImplemented);
enum class kDispositionState : uint32_t { Unknown = 0, Create = 1, Open = 2 };
dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name, dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
lpvoid_t content_data_ptr, lpvoid_t content_data_ptr,
dword_t content_data_size, dword_t flags, dword_t content_data_size, dword_t flags,
@ -143,40 +145,37 @@ dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
content_data, disposition_ptr, license_mask_ptr]( content_data, disposition_ptr, license_mask_ptr](
uint32_t& extended_error, uint32_t& length) -> X_RESULT { uint32_t& extended_error, uint32_t& length) -> X_RESULT {
X_RESULT result = X_ERROR_INVALID_PARAMETER; X_RESULT result = X_ERROR_INVALID_PARAMETER;
bool create = false; kDispositionState disposition = kDispositionState::Unknown;
bool open = false;
switch (flags & 0xF) { switch (flags & 0xF) {
case 1: // CREATE_NEW case 1: // CREATE_NEW
// Fail if exists. // Fail if exists.
if (content_manager->ContentExists(content_data)) { if (content_manager->ContentExists(content_data)) {
result = X_ERROR_ALREADY_EXISTS; result = X_ERROR_ALREADY_EXISTS;
} else { } else {
create = true; disposition = kDispositionState::Create;
} }
break; break;
case 2: // CREATE_ALWAYS case 2: // CREATE_ALWAYS
// Overwrite existing, if any. // Overwrite existing, if any.
if (content_manager->ContentExists(content_data)) { if (content_manager->ContentExists(content_data)) {
content_manager->DeleteContent(content_data); content_manager->DeleteContent(content_data);
create = true;
} else {
create = true;
} }
disposition = kDispositionState::Create;
break; break;
case 3: // OPEN_EXISTING case 3: // OPEN_EXISTING
// Open only if exists. // Open only if exists.
if (!content_manager->ContentExists(content_data)) { if (!content_manager->ContentExists(content_data)) {
result = X_ERROR_PATH_NOT_FOUND; result = X_ERROR_PATH_NOT_FOUND;
} else { } else {
open = true; disposition = kDispositionState::Open;
} }
break; break;
case 4: // OPEN_ALWAYS case 4: // OPEN_ALWAYS
// Create if needed. // Create if needed.
if (!content_manager->ContentExists(content_data)) { if (!content_manager->ContentExists(content_data)) {
create = true; disposition = kDispositionState::Create;
} else { } else {
open = true; disposition = kDispositionState::Open;
} }
break; break;
case 5: // TRUNCATE_EXISTING case 5: // TRUNCATE_EXISTING
@ -185,7 +184,7 @@ dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
result = X_ERROR_PATH_NOT_FOUND; result = X_ERROR_PATH_NOT_FOUND;
} else { } else {
content_manager->DeleteContent(content_data); content_manager->DeleteContent(content_data);
create = true; disposition = kDispositionState::Create;
} }
break; break;
default: default:
@ -193,19 +192,14 @@ dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
break; break;
} }
// creation result if (disposition == kDispositionState::Create) {
// 0 = ? result = content_manager->CreateContent(root_name, content_data);
// 1 = created } else if (disposition == kDispositionState::Open) {
// 2 = opened result = content_manager->OpenContent(root_name, content_data);
uint32_t disposition = create ? 1 : 2;
if (disposition_ptr) {
*disposition_ptr = disposition;
} }
if (create) { if (disposition_ptr) {
result = content_manager->CreateContent(root_name, content_data); *disposition_ptr = static_cast<uint32_t>(disposition);
} else if (open) {
result = content_manager->OpenContent(root_name, content_data);
} }
if (license_mask_ptr && XSUCCEEDED(result)) { if (license_mask_ptr && XSUCCEEDED(result)) {
@ -213,7 +207,7 @@ dword_result_t xeXamContentCreate(dword_t user_index, lpstring_t root_name,
} }
extended_error = X_HRESULT_FROM_WIN32(result); extended_error = X_HRESULT_FROM_WIN32(result);
length = disposition; length = static_cast<uint32_t>(disposition);
return result; return result;
}; };