Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
--- a/dlls/xgameruntime/xpackage.c
+++ b/dlls/xgameruntime/xpackage.c
@@ -377,6 +377,137 @@
* caller asks for its kind) or visits nothing. Fields we have no data for
* are empty rather than invented; installing is FALSE because there is
* nothing left to install. */
+
+/* Titles read their own record out of XPackageDetails -- Forza prints the
+ * package version on its title screen and gates initialization steps on it.
+ * The layout file carries no version, but MicrosoftGame.Config -- the GDK
+ * standard file shipped beside the executable -- carries Identity/Version,
+ * the display metadata and TitleId/StoreId. It is read once, on demand, by
+ * walking up from the executable directory the same way the layout file is
+ * found; nothing here knows which title is running. */
+static struct
+{
+ XVersion version;
+ char displayName[128];
+ char description[256];
+ char publisher[128];
+ char titleID[16];
+ char storeId[64];
+} package_fields;
+static BOOL package_fields_loaded;
+
+static BOOL copy_xml_attribute( const char *text, const char *attribute, char *out, SIZE_T size )
+{
+ const char *p, *q;
+ SIZE_T length;
+
+ if (!(p = strstr( text, attribute ))) return FALSE;
+ p += strlen( attribute );
+ while (*p == ' ' || *p == '\t') p++;
+ if (*p != '=') return FALSE;
+ p++;
+ while (*p == ' ' || *p == '\t') p++;
+ if (*p != '"') return FALSE;
+ p++;
+ if (!(q = strchr( p, '"' ))) return FALSE;
+ length = min( q - p, size - 1 );
+ memcpy( out, p, length );
+ out[length] = 0;
+ return TRUE;
+}
+
+static BOOL copy_xml_element( const char *text, const char *tag, char *out, SIZE_T size )
+{
+ char open[32];
+ const char *p, *q;
+ SIZE_T length;
+
+ snprintf( open, sizeof(open), "<%s>", tag );
+ if (!(p = strstr( text, open ))) return FALSE;
+ p += strlen( open );
+ if (!(q = strchr( p, '<' ))) return FALSE;
+ length = min( q - p, size - 1 );
+ memcpy( out, p, length );
+ out[length] = 0;
+ return TRUE;
+}
+
+static void load_package_fields( void )
+{
+ WCHAR path[MAX_PATH];
+ char *text, version[32];
+ unsigned int major = 0, minor = 0, build = 0, revision = 0;
+ WCHAR *sep;
+ HANDLE file;
+
+ if (package_fields_loaded) return;
+ package_fields_loaded = TRUE;
+
+ if (!GetModuleFileNameW( NULL, path, ARRAY_SIZE(path) )) return;
+ if (!(sep = wcsrchr( path, '\\' ))) return;
+ *sep = 0;
+
+ text = NULL;
+ for (;;)
+ {
+ WCHAR config_path[MAX_PATH];
+ LARGE_INTEGER size;
+ DWORD read;
+
+ if (wcslen( path ) + ARRAY_SIZE(L"\\MicrosoftGame.Config") > ARRAY_SIZE(config_path)) break;
+ wcscpy( config_path, path );
+ wcscat( config_path, L"\\MicrosoftGame.Config" );
+
+ if ((file = CreateFileW( config_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL )) != INVALID_HANDLE_VALUE)
+ {
+ if (GetFileSizeEx( file, &size ) && size.QuadPart && size.QuadPart <= 64 * 1024)
+ {
+ if ((text = malloc( size.QuadPart + 1 )))
+ {
+ if (ReadFile( file, text, size.QuadPart, &read, NULL ) && read == size.QuadPart)
+ text[read] = 0;
+ else
+ {
+ free( text );
+ text = NULL;
+ }
+ }
+ }
+ CloseHandle( file );
+ break;
+ }
+ if (GetLastError() != ERROR_FILE_NOT_FOUND && GetLastError() != ERROR_PATH_NOT_FOUND) break;
+ if (!(sep = wcsrchr( path, '\\' ))) break;
+ *sep = 0;
+ }
+
+ if (!text) return;
+
+ /* configVersion="1" also matches "Version"; the package version is the
+ * one on the Identity element. */
+ {
+ const char *identity = strstr( text, "<Identity" );
+ if (identity && copy_xml_attribute( identity, "Version", version, sizeof(version) ))
+ {
+ sscanf( version, "%u.%u.%u.%u", &major, &minor, &build, &revision );
+ package_fields.version.major = major;
+ package_fields.version.minor = minor;
+ package_fields.version.build = build;
+ package_fields.version.revision = revision;
+ }
+ }
+ copy_xml_attribute( text, "DefaultDisplayName", package_fields.displayName, sizeof(package_fields.displayName) );
+ copy_xml_attribute( text, "Description", package_fields.description, sizeof(package_fields.description) );
+ copy_xml_attribute( text, "PublisherDisplayName", package_fields.publisher, sizeof(package_fields.publisher) );
+ copy_xml_element( text, "TitleId", package_fields.titleID, sizeof(package_fields.titleID) );
+ copy_xml_element( text, "StoreId", package_fields.storeId, sizeof(package_fields.storeId) );
+ TRACE( "package version %u.%u.%u.%u, titleId %s, storeId %s, displayName %s.\n",
+ major, minor, build, revision,
+ debugstr_a( package_fields.titleID ), debugstr_a( package_fields.storeId ),
+ debugstr_a( package_fields.displayName ) );
+ free( text );
+}
+
static HRESULT enumerate_current_package( XPackageKind kind, XPackageEnumerationScope scope, void *context, XPackageEnumerationCallback *callback )
{
char identifier[33]; /* 32 characters and a terminator, as titles ask for. */
@@ -387,12 +518,20 @@
if (kind != XPackageKind_Game) return S_OK;
if (FAILED(hr = package_identifier( identifier, sizeof(identifier) ))) return hr;
+ load_package_fields();
+
memset( &details, 0, sizeof(details) );
details.packageIdentifier = identifier;
details.kind = XPackageKind_Game;
details.installing = FALSE;
details.index = 0;
details.count = 1;
+ details.version = package_fields.version;
+ details.displayName = package_fields.displayName[0] ? package_fields.displayName : NULL;
+ details.description = package_fields.description[0] ? package_fields.description : NULL;
+ details.publisher = package_fields.publisher[0] ? package_fields.publisher : NULL;
+ details.storeId = package_fields.storeId[0] ? package_fields.storeId : NULL;
+ details.titleID = package_fields.titleID[0] ? package_fields.titleID : NULL;
callback( context, &details );
return S_OK;
}