Skip to content

Commit

Permalink
Fix store app check and update bug
Browse files Browse the repository at this point in the history
Fix store app check and update bug
  • Loading branch information
Gaoyifei1011 committed Nov 13, 2024
1 parent 909204d commit d7a47b0
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Description/README_EN-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ All the content of the program has been developed
> * Complete the translation steps described above to ensure that all steps run smoothly.
> * Open the GetStoreAppPackage packaging project, find the Package.appxmanifest file, right-click the file, click View Code, find the Sources tab, and add the corresponding language according to the template, such as "<Resource Language="EN-US"/>".
> * Open the Strings folder of the GetStoreApp project and create the language you are using, for example ( English (United States) folder name is en-us , you can refer to the Table of Indicating Language (Culture) Codes and Countries and Regions)
> * Open the resw file under the subfolder and translate each name.
> * Open the resjson file under the subfolder and translate each name.
> * Compile and run the code and test your language, when the application is first opened if there is no language you use to display English (United States) by default, it needs to be dynamically adjusted in the settings.
> * Create a PR after completing the above steps, then submit the modified content to this project and wait for the merge.
Expand Down
2 changes: 1 addition & 1 deletion Description/README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
> * 完成上面所述的翻译步骤,确保所有步骤能够顺利运行。
> * 打开 GetStoreAppPackage 打包项目,找到 Package.appxmanifest 文件,右键该文件,点击查看代码,找到 Resources 标签,根据模板添加相对应的语言,例如“<Resource Language="EN-US"/>”。
> * 打开 GetStoreApp 项目的 Strings 文件夹,并创建您使用的语言,比如(English(United States))文件夹名称为 en-us,具体可以参考表示语言(文化)代码与国家地区对照表)。
> * 打开子文件夹下的 resw 文件,对每一个名称进行翻译。
> * 打开子文件夹下的 resjson 文件,对每一个名称进行翻译。
> * 编译运行代码并测试您的语言,应用在初次打开的时候如果没有您使用的语言默认显示 English(United States),需要在设置中动态调整。
> * 完成上述步骤后创建 PR,然后将修改的内容提交到本项目,等待合并即可。
Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/GetStoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<DesktopCompatible>true</DesktopCompatible>
<DisableXbfLineInfo>false</DisableXbfLineInfo>
<EnableDefaultPriItems>false</EnableDefaultPriItems>
<ForceAotCompile>true</ForceAotCompile>
<ForceAotCompile>false</ForceAotCompile>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<ImplicitUsings>disable</ImplicitUsings>
<IncludeAllContentForSelfExtract>false</IncludeAllContentForSelfExtract>
<IncludeSymbols>false</IncludeSymbols>
<IsAotCompatible>true</IsAotCompatible>
<LangVersion>preview</LangVersion>
<LangVersion>latest</LangVersion>
<MetadataUpdaterSupport>false</MetadataUpdaterSupport>
<MetricsSupport>false</MetricsSupport>
<OptimizationPreference>Size</OptimizationPreference>
Expand Down Expand Up @@ -233,7 +233,7 @@

<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2849.39" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241106002" />

<Page Update="Styles\WinUI\AppBarButton.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
<Page Update="Styles\WinUI\HyperlinkButton.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
Expand Down
Binary file modified GetStoreApp/GetStoreApp.res
Binary file not shown.
6 changes: 3 additions & 3 deletions GetStoreApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用")]
[assembly: AssemblyFileVersion("5.1.1106.0")]
[assembly: AssemblyInformationalVersion("5.1.1106.0")]
[assembly: AssemblyFileVersion("5.1.1113.0")]
[assembly: AssemblyInformationalVersion("5.1.1113.0")]
[assembly: AssemblyProduct("获取商店应用")]
[assembly: AssemblyTitle("获取商店应用")]
[assembly: AssemblyVersion("5.1.1106.0")]
[assembly: AssemblyVersion("5.1.1113.0")]

// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
153 changes: 117 additions & 36 deletions GetStoreApp/Views/Pages/AppUpdatePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.InteropServices.Marshalling;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Store.Preview.InstallControl;
Expand Down Expand Up @@ -42,6 +44,7 @@ public sealed partial class AppUpdatePage : Page, INotifyPropertyChanged
private readonly AppInstallManager appInstallManager = new();
private readonly PackageManager packageManager = new();

private readonly Lock appinstallingLock = new();
private readonly Dictionary<string, AppInstallItem> AppInstallingDict = [];

private string AppUpdateCountInfo { get; } = ResourceService.GetLocalized("AppUpdate/AppUpdateCountInfo");
Expand Down Expand Up @@ -134,12 +137,25 @@ await Task.Run(async () =>
LogService.WriteLog(LoggingLevel.Error, string.Format("Update app failed: package family name {0}", appUpdateItem.PackageFamilyName), e);
}

if (appInstallItem is not null)
appinstallingLock.Enter();

try
{
appInstallItem.StatusChanged += OnAppInstallItemStatausChanged;
appInstallItem.Completed += OnAppInstallItemCompleted;
if (appInstallItem is not null && !AppInstallingDict.ContainsKey(appInstallItem.PackageFamilyName))
{
appInstallItem.StatusChanged += OnAppInstallItemStatausChanged;
appInstallItem.Completed += OnAppInstallItemCompleted;

AppInstallingDict.TryAdd(appInstallItem.PackageFamilyName, appInstallItem);
AppInstallingDict.TryAdd(appInstallItem.PackageFamilyName, appInstallItem);
}
}
catch (Exception e)
{
ExceptionAsVoidMarshaller.ConvertToUnmanaged(e);
}
finally
{
appinstallingLock.Exit();
}
});

Expand All @@ -158,20 +174,33 @@ private async void OnCancelExecuteRequested(XamlUICommand sender, ExecuteRequest
{
await Task.Run(() =>
{
if (AppInstallingDict.TryGetValue(packageFamilyName, out AppInstallItem appInstallItem))
appinstallingLock.Enter();

try
{
try
{
appInstallItem.Completed -= OnAppInstallItemCompleted;
appInstallItem.StatusChanged -= OnAppInstallItemStatausChanged;
appInstallItem.Cancel();
}
catch (Exception e)
if (AppInstallingDict.TryGetValue(packageFamilyName, out AppInstallItem appInstallItem))
{
LogService.WriteLog(LoggingLevel.Error, "Store app cancel install failed", e);
}
try
{
appInstallItem.Completed -= OnAppInstallItemCompleted;
appInstallItem.StatusChanged -= OnAppInstallItemStatausChanged;
appInstallItem.Cancel();
}
catch (Exception e)
{
LogService.WriteLog(LoggingLevel.Error, "Store app cancel install failed", e);
}

AppInstallingDict.Remove(packageFamilyName);
AppInstallingDict.Remove(packageFamilyName);
}
}
catch (Exception e)
{
ExceptionAsVoidMarshaller.ConvertToUnmanaged(e);
}
finally
{
appinstallingLock.Exit();
}
});

Expand Down Expand Up @@ -230,13 +259,13 @@ await Task.Run(async () =>
};
IReadOnlyList<AppInstallItem> upgradableAppsList = await appInstallManager.SearchForAllUpdatesAsync(string.Empty, string.Empty, updateOptions);

foreach (AppInstallItem upgradableApps in upgradableAppsList)
foreach (AppInstallItem upgradableAppItem in upgradableAppsList)
{
// 判断是否已经添加到 AppUpdateCollection 中,没有则添加
bool isExisted = false;
foreach (AppUpdateModel appUpdateItem in AppUpdateCollection)
{
if (appUpdateItem.PackageFamilyName.Equals(upgradableApps.PackageFamilyName))
if (appUpdateItem.PackageFamilyName.Equals(upgradableAppItem.PackageFamilyName))
{
isExisted = true;
}
Expand All @@ -246,9 +275,9 @@ await Task.Run(async () =>
{
foreach (Package packageItem in packageManager.FindPackagesForUser(string.Empty))
{
if (packageItem.Id.FamilyName.Equals(upgradableApps.PackageFamilyName, StringComparison.OrdinalIgnoreCase))
if (packageItem.Id.FamilyName.Equals(upgradableAppItem.PackageFamilyName, StringComparison.OrdinalIgnoreCase))
{
AppInstallStatus appInstallStatus = upgradableApps.GetCurrentStatus();
AppInstallStatus appInstallStatus = upgradableAppItem.GetCurrentStatus();
string installInformation = GetInstallInformation(appInstallStatus.InstallState, appInstallStatus);
string installSubInformation = string.Format(InstallingSubInformation, FileSizeHelper.ConvertFileSizeToString(appInstallStatus.DownloadSizeInBytes), FileSizeHelper.ConvertFileSizeToString(appInstallStatus.BytesDownloaded));

Expand All @@ -261,13 +290,35 @@ await Task.Run(async () =>
InstallSubInformation = installSubInformation,
IsUpdating = appInstallStatus.InstallState is AppInstallState.Pending ||
appInstallStatus.InstallState is AppInstallState.Starting ||
appInstallStatus.InstallState is AppInstallState.AcquiringLicense ||
appInstallStatus.InstallState is AppInstallState.Downloading ||
appInstallStatus.InstallState is AppInstallState.RestoringData ||
appInstallStatus.InstallState is AppInstallState.Installing,
PackageFamilyName = upgradableApps.PackageFamilyName,
PackageFamilyName = upgradableAppItem.PackageFamilyName,
PercentComplete = appInstallStatus.PercentComplete,
ProductId = upgradableApps.ProductId
ProductId = upgradableAppItem.ProductId
});

appinstallingLock.Enter();

try
{
if (upgradableAppItem is not null && !AppInstallingDict.ContainsKey(upgradableAppItem.PackageFamilyName))
{
upgradableAppItem.StatusChanged += OnAppInstallItemStatausChanged;
upgradableAppItem.Completed += OnAppInstallItemCompleted;

AppInstallingDict.TryAdd(upgradableAppItem.PackageFamilyName, upgradableAppItem);
}
}
catch (Exception e)
{
ExceptionAsVoidMarshaller.ConvertToUnmanaged(e);
}
finally
{
appinstallingLock.Exit();
}
break;
}
}
Expand Down Expand Up @@ -311,12 +362,25 @@ private void OnUpdateAllClicked(object sender, RoutedEventArgs args)
{
AppInstallItem appInstallItem = await appInstallManager.UpdateAppByPackageFamilyNameAsync(appUpdateItem.PackageFamilyName);

if (appInstallItem is not null && !AppInstallingDict.ContainsKey(appInstallItem.PackageFamilyName))
appinstallingLock.Enter();

try
{
appInstallItem.Completed += OnAppInstallItemCompleted;
appInstallItem.StatusChanged += OnAppInstallItemStatausChanged;
if (appInstallItem is not null && !AppInstallingDict.ContainsKey(appInstallItem.PackageFamilyName))
{
appInstallItem.StatusChanged += OnAppInstallItemStatausChanged;
appInstallItem.Completed += OnAppInstallItemCompleted;

AppInstallingDict.TryAdd(appInstallItem.PackageFamilyName, appInstallItem);
AppInstallingDict.TryAdd(appInstallItem.PackageFamilyName, appInstallItem);
}
}
catch (Exception e)
{
ExceptionAsVoidMarshaller.ConvertToUnmanaged(e);
}
finally
{
appinstallingLock.Exit();
}
}
});
Expand All @@ -334,13 +398,30 @@ private void OnAppInstallItemCompleted(AppInstallItem sender, object args)
sender.Completed -= OnAppInstallItemCompleted;
sender.StatusChanged -= OnAppInstallItemStatausChanged;

AppInstallingDict.Remove(appUpdateItem.PackageFamilyName);
appinstallingLock.Enter();

try
{
AppInstallingDict.Remove(appUpdateItem.PackageFamilyName);
}
catch (Exception e)
{
ExceptionAsVoidMarshaller.ConvertToUnmanaged(e);
}
finally
{
appinstallingLock.Exit();
}

// 显示商店应用更新成功通知
AppNotificationBuilder appNotificationBuilder = new();
appNotificationBuilder.AddArgument("action", "OpenApp");
appNotificationBuilder.AddText(string.Format(ResourceService.GetLocalized("Notification/AppUpdateSuccessfully"), appUpdateItem.DisplayName));
ToastNotificationService.Show(appNotificationBuilder.BuildNotification());
if (appUpdateItem.AppInstallState is AppInstallState.Completed)
{
AppNotificationBuilder appNotificationBuilder = new();
appNotificationBuilder.AddArgument("action", "OpenApp");
appNotificationBuilder.AddText(string.Format(ResourceService.GetLocalized("Notification/AppUpdateSuccessfully"), appUpdateItem.DisplayName));
ToastNotificationService.Show(appNotificationBuilder.BuildNotification());
}

break;
}
}
Expand Down Expand Up @@ -404,12 +485,12 @@ await Task.Run(() =>
appUpdateItem.PercentComplete = appInstallStatus.PercentComplete;
appUpdateItem.InstallInformation = installInformation;
appUpdateItem.InstallSubInformation = installSubInformation;
appUpdateItem.IsUpdating = !(appInstallStatus.InstallState is AppInstallState.Canceled ||
appInstallStatus.InstallState is AppInstallState.Error ||
appInstallStatus.InstallState is AppInstallState.Paused ||
appInstallStatus.InstallState is AppInstallState.PausedLowBattery ||
appInstallStatus.InstallState is AppInstallState.PausedWiFiRecommended ||
appInstallStatus.InstallState is AppInstallState.PausedWiFiRequired);
appUpdateItem.IsUpdating = appInstallStatus.InstallState is AppInstallState.Pending ||
appInstallStatus.InstallState is AppInstallState.Starting ||
appInstallStatus.InstallState is AppInstallState.AcquiringLicense ||
appInstallStatus.InstallState is AppInstallState.Downloading ||
appInstallStatus.InstallState is AppInstallState.RestoringData ||
appInstallStatus.InstallState is AppInstallState.Installing;
}
}
}
Expand Down
Binary file modified GetStoreAppInstaller/GetStoreAppInstaller.res
Binary file not shown.
6 changes: 3 additions & 3 deletions GetStoreAppInstaller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用 应用安装器")]
[assembly: AssemblyFileVersion("5.1.1106.0")]
[assembly: AssemblyInformationalVersion("5.1.1106.0")]
[assembly: AssemblyFileVersion("5.1.1113.0")]
[assembly: AssemblyInformationalVersion("5.1.1113.0")]
[assembly: AssemblyProduct("获取商店应用 应用安装器")]
[assembly: AssemblyTitle("获取商店应用 应用安装器")]
[assembly: AssemblyVersion("5.1.1106.0")]
[assembly: AssemblyVersion("5.1.1113.0")]

// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
2 changes: 1 addition & 1 deletion GetStoreAppPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Identity
Name="Gaoyifei1011.GetStoreApp"
Publisher="CN=高怡飞"
Version="5.1.1106.0" />
Version="5.1.1113.0" />

<Properties>
<DisplayName>ms-resource:PackageDisplayName</DisplayName>
Expand Down
6 changes: 3 additions & 3 deletions GetStoreAppShellExtension/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用 右键菜单扩展")]
[assembly: AssemblyFileVersion("5.1.1106.0")]
[assembly: AssemblyInformationalVersion("5.1.1106.0")]
[assembly: AssemblyFileVersion("5.1.1113.0")]
[assembly: AssemblyInformationalVersion("5.1.1113.0")]
[assembly: AssemblyProduct("获取商店应用 右键菜单扩展")]
[assembly: AssemblyTitle("获取商店应用 右键菜单扩展")]
[assembly: AssemblyVersion("5.1.1106.0")]
[assembly: AssemblyVersion("5.1.1113.0")]

// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
Binary file modified GetStoreAppWebView/GetStoreAppWebView.res
Binary file not shown.
Loading

0 comments on commit d7a47b0

Please sign in to comment.