Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
Merge pull request #36 from Drommedhar/xbox_fix
Browse files Browse the repository at this point in the history
Xbox fix
  • Loading branch information
Drommedhar authored Dec 11, 2024
2 parents 3d50262 + 3c36351 commit 4989e2c
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 57 deletions.
9 changes: 5 additions & 4 deletions DlssUpdater/DLSSUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>icon.ico</ApplicationIcon>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>x64</Platforms>
<FileVersion>2.0.5.4</FileVersion>
<FileVersion>2.0.5.5</FileVersion>
<SelfContained>true</SelfContained>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<SignAssembly>False</SignAssembly>
<AssemblyVersion>2.0.5.4</AssemblyVersion>
<AssemblyVersion>2.0.5.5</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -36,7 +36,8 @@
<PackageReference Include="Octokit" Version="13.0.1"/>
<PackageReference Include="System.Drawing.Common" Version="8.0.8"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.1"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="System.Management" Version="9.0.0"/>
<PackageReference Include="WpfBindingErrors" Version="1.1.0"/>
</ItemGroup>

Expand Down
102 changes: 50 additions & 52 deletions DlssUpdater/GameLibrary/XboxLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using System.Xml.Linq;
using DLSSUpdater.Defines;
using DlssUpdater.Helpers;
using DLSSUpdater.Helpers;
using NLog;
using GameInfo = DlssUpdater.Defines.GameInfo;

Expand Down Expand Up @@ -46,6 +46,8 @@ private async Task<List<GameInfo>> getGames()
var amount = 0;
var current = 0;

List<ApplicationInfo> windowsStoreApps = WindowsAppHelper.GetInstalledAppsFromWindowsStore();

var drive = DriveInfo.GetDrives();
foreach (var driveItem in drive)
{
Expand Down Expand Up @@ -82,7 +84,7 @@ private async Task<List<GameInfo>> getGames()
{
return;
}

var gameDirs = Directory.GetDirectories(gamePath);
amount += gameDirs.Length;
foreach (var gameDir in gameDirs)
Expand All @@ -91,69 +93,65 @@ private async Task<List<GameInfo>> getGames()
LoadingProgress?.Invoke(this,
new Tuple<int, int, LibraryType>(current, amount, GetLibraryType()));

var manifestPath = Path.Combine(gameDir, "Content", "appxmanifest.xml");
if (!File.Exists(manifestPath))
string? identityName = null;
string? displayName = null;
var xmlDoc = WindowsAppHelper.InitXDocumentFromManifest(Path.Combine(gameDir, "Content", "appxmanifest.xml"), out var uap);
if (xmlDoc != null)
{
identityName = WindowsAppHelper.GetIdentityNameFromXml(xmlDoc, uap!);
}
else
{
continue;
}

// Load the XML file
var xmlDoc = XDocument.Load(manifestPath);

// Extract the "uap" namespace dynamically from the XML
var uap = xmlDoc.Root?.GetNamespaceOfPrefix("uap")!;

// Query the SplashScreen element and get the Image attribute
var splashScreenImage = xmlDoc
.Descendants(uap + "SplashScreen")
.FirstOrDefault()?.Attribute("Image")?.Value;

// Query the DisplayName inside uap:VisualElements
var displayName = xmlDoc
.Descendants(uap + "VisualElements")
.FirstOrDefault()?.Attribute("DisplayName")?.Value;

if (displayName is not null && displayName.Contains("AppDisplayName") || displayName is null)
if (identityName != null)
{
displayName = xmlDoc.Descendants("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}DisplayName")
.FirstOrDefault()?.Value;
}
// Query the SplashScreen element and get the Image attribute
var splashScreenImage = xmlDoc
.Descendants(uap! + "SplashScreen")
.FirstOrDefault()?.Attribute("Image")?.Value;

ApplicationInfo? windowsStoreApp = windowsStoreApps.Find(f => f.identityName.Equals(identityName));

// Extract the namespace (if any is necessary)
var ns = xmlDoc.Root!.Name.Namespace;
displayName = windowsStoreApp?.displayName ?? WindowsAppHelper.GetDisplayNameFromXml(xmlDoc, uap!);

// Query all Application elements and get their Id attributes
var id = xmlDoc
.Descendants(ns + "Application") // Include the namespace for the Application element
.Select(app => app.Attribute("Id")?.Value).FirstOrDefault();
// Extract the namespace (if any is necessary)
var ns = xmlDoc.Root!.Name.Namespace;

var imagePathFinal = "";
if (splashScreenImage != null)
{
imagePathFinal = Path.Combine(gameDir, "Content", splashScreenImage);
}
// Query all Application elements and get their Id attributes
var id = xmlDoc
.Descendants(ns + "Application") // Include the namespace for the Application element
.Select(app => app.Attribute("Id")?.Value).FirstOrDefault();

if (!string.IsNullOrEmpty(displayName))
{
var info = new GameInfo(displayName, gameDir, GetLibraryType())
var imagePathFinal = "";
if (splashScreenImage != null)
{
UniqueId = "xbox_" + id
};
if (!string.IsNullOrEmpty(imagePathFinal))
{
info.SetGameImageUri(imagePathFinal);
imagePathFinal = Path.Combine(gameDir, "Content", splashScreenImage);
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
_logger.Debug($"Xbox: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
if (!string.IsNullOrEmpty(displayName))
{
_logger.Debug(
$"Xbox: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
var info = new GameInfo(displayName, gameDir, GetLibraryType())
{
UniqueId = "xbox_" + id
};
if (!string.IsNullOrEmpty(imagePathFinal))
{
info.SetGameImageUri(imagePathFinal);
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
_logger.Debug($"Xbox: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
{
_logger.Debug(
$"Xbox: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
}
}
}
}
Expand Down
109 changes: 109 additions & 0 deletions DlssUpdater/Helpers/WindowsAppHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.IO;
using System.Xml.Linq;
using Windows.Management.Deployment;

namespace DLSSUpdater.Helpers
{
public static class WindowsAppHelper
{
public static XDocument? InitXDocumentFromManifest(string manifestPath, out XNamespace? uap)
{
XDocument? xmlDoc = null;
if (!File.Exists(manifestPath))
{
uap = null;
return null;
}

// Load the XML file
xmlDoc = XDocument.Load(manifestPath);

// Extract the "uap" namespace dynamically from the XML
uap = xmlDoc.Root?.GetNamespaceOfPrefix("uap");

return xmlDoc;
}

public static string? GetIdentityNameFromXml(XDocument xmlDoc, XNamespace ns)
{
// Find the package element
var packageElement = xmlDoc
.Descendants("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Package")
.FirstOrDefault();

// Get the identity name from the Identity element
string? name = packageElement?
.Descendants("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Identity")
.FirstOrDefault()?.Attribute("Name")?.Value;

return name;
}

public static string? GetDisplayNameFromXml(XDocument xmlDoc, XNamespace uap)
{
string? displayName = null;

// Query the DisplayName inside uap:VisualElements
displayName = xmlDoc
.Descendants(uap + "VisualElements")
.FirstOrDefault()?.Attribute("DisplayName")?.Value;

if (displayName is not null && displayName.Contains("AppDisplayName") || displayName is null)
{
displayName = xmlDoc.Descendants("{http://schemas.microsoft.com/appx/manifest/foundation/windows10}DisplayName")
.FirstOrDefault()?.Value;
}

return displayName;
}

public static List<ApplicationInfo> GetInstalledAppsFromWindowsStore()
{
List<ApplicationInfo> apps = new List<ApplicationInfo>();
PackageManager packageManager = new PackageManager();

// Query the package manager to get every packages installed.
var packages = packageManager.FindPackagesForUserWithPackageTypes(
string.Empty,
PackageTypes.Main
);

foreach (var package in packages)
{
try
{
if (package.InstalledLocation?.Path != null)
{
var manifestPath = Path.Combine(package.InstalledLocation?.Path!, "appxmanifest.xml");
var xmlDoc = InitXDocumentFromManifest(manifestPath, out var uap);
if (xmlDoc is not null && uap is not null)
{
var identityName = GetIdentityNameFromXml(xmlDoc, uap);
if(identityName is not null)
{
// Associate the correct name to the one found in the manifest
apps.Add(new ApplicationInfo
{
displayName = package.DisplayName,
identityName = identityName
});
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

return apps;
}
}

public class ApplicationInfo
{
public string displayName { get; set; }

Check warning on line 106 in DlssUpdater/Helpers/WindowsAppHelper.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'displayName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string identityName { get; set; }

Check warning on line 107 in DlssUpdater/Helpers/WindowsAppHelper.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Non-nullable property 'identityName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
3 changes: 3 additions & 0 deletions DlssUpdater/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.0.5.5
* Fix Xbox games showing wrong name finally (thanks to SilyNoMeta)

# 2.0.5.4
* Fix Xbox games showing wrong name

Expand Down
2 changes: 1 addition & 1 deletion DlssUpdater/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2.0.5.4"
"version": "2.0.5.5"
}

0 comments on commit 4989e2c

Please sign in to comment.