Skip to content

Commit 159bcc8

Browse files
committed
1.8.4
[Bug fixes] - Lost data of UWP apps after updates - Icons of UWP apps are missing after update
1 parent 2887b09 commit 159bcc8

File tree

4 files changed

+87
-21
lines changed

4 files changed

+87
-21
lines changed

Source/AutoHDR/Applications/ApplicationItem.cs

+50-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodectoryCore.UI.Wpf;
1+
using AutoHDR.UWP;
2+
using CodectoryCore.UI.Wpf;
23
using CodectoryCore.Windows;
34
using CodectoryCore.Windows.FileSystem;
45
using CodectoryCore.Windows.Icons;
@@ -28,6 +29,7 @@ public class ApplicationItem : BaseViewModel, IEquatable<ApplicationItem>
2829
private string _applicationName;
2930
private System.Drawing.Bitmap icon = null;
3031
//private bool _restartProcess = false;
32+
private string _uwpFullPackageName = string.Empty;
3133
private string _uwpFamilyPackageName = string.Empty;
3234
private string _uwpApplicationID = string.Empty;
3335
private string _uwpIconPath = string.Empty;
@@ -38,22 +40,37 @@ public class ApplicationItem : BaseViewModel, IEquatable<ApplicationItem>
3840
public string DisplayName { get => displayName; set { displayName = value; OnPropertyChanged(); } }
3941
[JsonProperty]
4042
public string ApplicationName { get => _applicationName; set { _applicationName = value; OnPropertyChanged(); } }
41-
[JsonProperty]
42-
public string ApplicationFilePath { get => _applicationFilePath; set { _applicationFilePath = value; try { Icon = IconHelper.GetFileIcon(value); } catch { } OnPropertyChanged(); } }
43+
[JsonProperty(Order = 1)]
44+
public string ApplicationFilePath {
45+
get => _applicationFilePath;
46+
set { _applicationFilePath = value; try { if (!IsUWP && !IsUWPWepApp) Icon = IconHelper.GetFileIcon(value); } catch { } OnPropertyChanged(); } }
4347
// public bool RestartProcess { get => _restartProcess; set { _restartProcess = value; OnPropertyChanged(); } }
44-
[JsonProperty]
48+
[JsonProperty(Order =0)]
4549
public bool IsUWP { get => _isUWP; set { _isUWP = value; OnPropertyChanged(); } }
46-
[JsonProperty]
50+
[JsonProperty(Order = 0)]
4751
public bool IsUWPWepApp { get => _isUWPWebApp; set { _isUWPWebApp = value; OnPropertyChanged(); } }
4852
public Bitmap Icon { get => icon; set { icon = value; OnPropertyChanged(); } }
49-
[JsonProperty]
50-
public string UWPFamilyPackageName { get => _uwpFamilyPackageName; set { _uwpFamilyPackageName = value; OnPropertyChanged(); } }
51-
[JsonProperty]
52-
public string UWPApplicationID { get => _uwpApplicationID; set { _uwpApplicationID = value; OnPropertyChanged(); } }
53-
[JsonProperty]
54-
public string UWPIconPath { get => _uwpIconPath; set { _uwpIconPath = value; try { Icon = new Bitmap(Bitmap.FromFile(value)); } catch { }OnPropertyChanged(); } }
53+
[JsonProperty(Order = 1)]
54+
public string UWPFullPackageName {
55+
get => _uwpFullPackageName;
56+
set { _uwpFullPackageName = value; OnPropertyChanged(); LoadUWPData(); }
57+
}
58+
59+
[JsonProperty(Order = 0)]
60+
public string UWPFamilyPackageName
61+
{
62+
get => _uwpFamilyPackageName;
63+
set { _uwpFamilyPackageName = value; OnPropertyChanged(); }
64+
}
65+
66+
[JsonProperty(Order = 2)]
67+
public string UWPApplicationID {
68+
get => _uwpApplicationID;
69+
set { _uwpApplicationID = value; OnPropertyChanged(); if (string.IsNullOrEmpty(UWPFullPackageName)) LoadUWPData(); } }
70+
public string UWPIconPath {
71+
get => _uwpIconPath;
72+
set { _uwpIconPath = value; try { if (IsUWP ||IsUWPWepApp) Icon = new Bitmap(Bitmap.FromFile(value)); } catch { }OnPropertyChanged(); } }
5573

56-
[JsonProperty]
5774
public string UWPIdentity { get => _uwpIdentity; set { _uwpIdentity = value; OnPropertyChanged(); } }
5875

5976
private ApplicationItem()
@@ -67,12 +84,31 @@ public ApplicationItem(string displayName, string applicationFilePath)
6784
ApplicationName = new FileInfo(ApplicationFilePath).Name.Replace(".exe", "");
6885
}
6986

70-
public ApplicationItem(UWP.UWPApp uwpApp) : this(uwpApp.Name, uwpApp.ExecutablePath)
87+
public ApplicationItem(UWPApp uwpApp) : this(uwpApp.Name, uwpApp.ExecutablePath)
7188
{
7289
IsUWP = true;
7390
IsUWPWepApp = true;
7491
UWPFamilyPackageName = uwpApp.FamilyPackageName;
75-
UWPApplicationID = uwpApp.ApplicationID;
92+
_uwpFullPackageName = uwpApp.FullPackageName;
93+
_uwpApplicationID = uwpApp.ApplicationID;
94+
UWPIconPath = uwpApp.IconPath;
95+
UWPIdentity = uwpApp.Identity;
96+
}
97+
98+
private void LoadUWPData()
99+
{
100+
if (!IsUWP && !IsUWPWepApp)
101+
return;
102+
UWPApp uwpApp;
103+
//Compatibility for old UWP handling
104+
if (string.IsNullOrEmpty(UWPFullPackageName))
105+
uwpApp = UWPAppsManager.GetUWPApp(UWPFamilyPackageName, UWPApplicationID);
106+
else
107+
uwpApp = UWPAppsManager.GetUWPApp(UWPFullPackageName);
108+
109+
UWPFamilyPackageName = uwpApp.FamilyPackageName;
110+
_uwpFullPackageName = uwpApp.FullPackageName;
111+
_uwpApplicationID = uwpApp.ApplicationID;
76112
UWPIconPath = uwpApp.IconPath;
77113
UWPIdentity = uwpApp.Identity;
78114
}

Source/AutoHDR/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5353
// indem Sie "*" wie unten gezeigt eingeben:
5454
// [assembly: AssemblyVersion("1.0.*")]
55-
[assembly: AssemblyVersion("1.8.2.0")]
56-
[assembly: AssemblyFileVersion("1.8.2.0")]
55+
[assembly: AssemblyVersion("1.8.4.0")]
56+
[assembly: AssemblyFileVersion("1.8.4.0")]

Source/AutoHDR/UWP/UWPApp.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public string ExecutablePath
3434
public bool IsWebApp { get; private set; } = false;
3535
public string InstallLocation { get; private set; } = string.Empty;
3636
public string FamilyPackageName { get; private set; } = string.Empty;
37+
public string FullPackageName { get; private set; } = string.Empty;
38+
3739
public string ApplicationID { get; private set; } = string.Empty;
3840
public string Identity { get; private set; } = string.Empty;
39-
4041
public string IconPath { get; private set; } = string.Empty;
4142

4243

@@ -70,6 +71,7 @@ private void ReadAppxManifest(Package package)
7071
{
7172
XmlSerializer serializer = new XmlSerializer(typeof(AppxManifest));
7273
AppxManifest appxManifest = (AppxManifest)serializer.Deserialize(reader);
74+
if (appxManifest.Applications==null)
7375
Name = ((XmlNode[])appxManifest.Properties.DisplayName)[0].Value;
7476
if (Name.Contains("ms-resource:"))
7577
{
@@ -81,7 +83,8 @@ private void ReadAppxManifest(Package package)
8183
if (Executable == null)
8284
IsWebApp = true;
8385
FamilyPackageName = package.Id.FamilyName;
84-
ApplicationID = appxManifest.Applications.Application.Id;
86+
FullPackageName = package.Id.FullName;
87+
ApplicationID = appxManifest.Applications?.Application.Id;
8588
Identity = appxManifest.Identity.Name;
8689
IconPath = GetIconPath(Path.Combine(InstallLocation, ((XmlNode[])(appxManifest.Properties.Logo))[0].Value));
8790
}

Source/AutoHDR/UWP/UWPAppsManager.cs

+30-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,42 @@ namespace AutoHDR.UWP
1515
{
1616
public static class UWPAppsManager
1717
{
18+
static PackageManager manager = new PackageManager();
19+
1820

1921
private const string xboxPassAppFN = "Microsoft.GamingApp_8wekyb3d8bbwe";
2022

2123

24+
public static UWPApp GetUWPApp(string packageNameOrFamilyPackageName, string applicationID = "")
25+
{
26+
var package = manager.FindPackageForUser(WindowsIdentity.GetCurrent().User.Value, packageNameOrFamilyPackageName);
27+
if (package == null)
28+
return GetUWPAppCompatible(packageNameOrFamilyPackageName, applicationID);
29+
return new UWPApp(package);
30+
}
31+
32+
private static UWPApp GetUWPAppCompatible(string familyPackageName, string applicationID)
33+
{
34+
foreach (var package in manager.FindPackagesForUser(WindowsIdentity.GetCurrent().User.Value))
35+
{
36+
try
37+
{
38+
UWPApp uwpApp = new UWPApp(package);
39+
if (uwpApp.FamilyPackageName.Equals(familyPackageName) && uwpApp.ApplicationID.Equals(applicationID))
40+
return uwpApp;
41+
}
42+
catch {}
43+
}
44+
return null;
45+
}
46+
47+
2248
public static List<ApplicationItem> GetUWPApps()
2349
{
2450

2551
Globals.Logs.Add($"Retrieving UWP apps...", false);
2652

2753
List<ApplicationItem> uwpApps = new List<ApplicationItem>();
28-
var manager = new PackageManager();
2954
IEnumerable<Package> packages = manager.FindPackagesForUser(WindowsIdentity.GetCurrent().User.Value);
3055
try
3156
{
@@ -51,8 +76,10 @@ public static List<ApplicationItem> GetUWPApps()
5176

5277
try
5378
{
54-
uwpApps.Add(new ApplicationItem(new UWPApp(package)));
55-
}
79+
UWPApp uwpApp = new UWPApp(package);
80+
if (!string.IsNullOrEmpty(uwpApp.ApplicationID))
81+
uwpApps.Add(new ApplicationItem(uwpApp));
82+
}
5683
catch
5784
{
5885
continue;

0 commit comments

Comments
 (0)