Skip to content

Open-source Xbox-inspired desktop launcher for Xodus on Linux

TypeScript
5.8 KB
Raw Blame
--- a/dlls/xgameruntime/xpackage.c
+++ b/dlls/xgameruntime/xpackage.c
@@ -465,49 +465,13 @@
 } 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;
+    char version[32];
+    xmlDocPtr doc = NULL;
+    xmlNodePtr root, visuals;
     WCHAR *sep;
-    HANDLE file;
 
     if (package_fields_loaded) return;
     package_fields_loaded = TRUE;
@@ -516,33 +480,17 @@
     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 (GetFileAttributesW( config_path ) != INVALID_FILE_ATTRIBUTES)
         {
-            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 );
+            doc = content_read_xml( config_path );
             break;
         }
         if (GetLastError() != ERROR_FILE_NOT_FOUND && GetLastError() != ERROR_PATH_NOT_FOUND) break;
@@ -550,31 +498,27 @@
         *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) );
+    if (!doc) return;
+    root = xmlDocGetRootElement( doc );
+    if (!root || strcmp( (char *)root->name, "Game" )) { xmlFreeDoc( doc ); return; }
+
+    /* Share the bounded, DTD-free XML reader with content packages. Only active
+     * direct elements can supply metadata, never commented examples, CDATA
+     * markup, similarly named attributes or unrelated nested elements. */
+    if (content_text( content_child( root, "Identity" ), "Version", version, sizeof(version) ))
+        content_version( version, &package_fields.version );
+    visuals = content_child( root, "ShellVisuals" );
+    content_text( visuals, "DefaultDisplayName", package_fields.displayName, sizeof(package_fields.displayName) );
+    content_text( visuals, "Description", package_fields.description, sizeof(package_fields.description) );
+    content_text( visuals, "PublisherDisplayName", package_fields.publisher, sizeof(package_fields.publisher) );
+    content_text( content_child( root, "TitleId" ), NULL, package_fields.titleID, sizeof(package_fields.titleID) );
+    content_text( content_child( root, "StoreId" ), NULL, 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,
+           package_fields.version.major, package_fields.version.minor,
+           package_fields.version.build, package_fields.version.revision,
            debugstr_a( package_fields.titleID ), debugstr_a( package_fields.storeId ),
            debugstr_a( package_fields.displayName ) );
-    free( text );
+    xmlFreeDoc( doc );
 }
 
 static HRESULT enumerate_current_package( XPackageKind kind, XPackageEnumerationScope scope, void *context, XPackageEnumerationCallback *callback )