diff --git a/GetStoreApp/Extensions/Console/CharExtension.cs b/GetStoreApp/Extensions/Console/CharExtension.cs index 550e98cc1..b21437d27 100644 --- a/GetStoreApp/Extensions/Console/CharExtension.cs +++ b/GetStoreApp/Extensions/Console/CharExtension.cs @@ -1,5 +1,4 @@ using GetStoreApp.Services.Root; -using System.Threading.Tasks; namespace GetStoreApp.Extensions.Console { @@ -10,9 +9,9 @@ public static class CharExtension { private static byte[] lengths; - public static async Task InitializeAsync() + public static void Initialize() { - lengths = await ResourceService.GetEmbeddedDataAsync("Files/EmbedAssets/Lengths.bin"); + lengths = ResourceService.GetEmbeddedData("Files/EmbedAssets/Lengths.bin"); } /// diff --git a/GetStoreApp/GetStoreApp.csproj b/GetStoreApp/GetStoreApp.csproj index 38a3e6336..590f65d4c 100644 --- a/GetStoreApp/GetStoreApp.csproj +++ b/GetStoreApp/GetStoreApp.csproj @@ -111,7 +111,7 @@ - + @@ -157,6 +157,7 @@ + diff --git a/GetStoreApp/GetStoreApp.res b/GetStoreApp/GetStoreApp.res index 075453686..e665058f5 100644 Binary files a/GetStoreApp/GetStoreApp.res and b/GetStoreApp/GetStoreApp.res differ diff --git a/GetStoreApp/Helpers/Controls/Store/QueryLinksHelper.cs b/GetStoreApp/Helpers/Controls/Store/QueryLinksHelper.cs index dc6b933e6..341c62612 100644 --- a/GetStoreApp/Helpers/Controls/Store/QueryLinksHelper.cs +++ b/GetStoreApp/Helpers/Controls/Store/QueryLinksHelper.cs @@ -55,7 +55,7 @@ public static async Task GetCookieAsync() try { - byte[] contentBytes = await ResourceService.GetEmbeddedDataAsync("Files/EmbedAssets/cookie.xml"); + byte[] contentBytes = ResourceService.GetEmbeddedData("Files/EmbedAssets/cookie.xml"); HttpStringContent httpStringContent = new(Encoding.UTF8.GetString(contentBytes)); httpStringContent.Headers.Expires = DateTime.Now; @@ -234,7 +234,7 @@ public static async Task GetFileListXmlAsync(string cookie, string categ try { - byte[] wubytesArray = await ResourceService.GetEmbeddedDataAsync("Files/EmbedAssets/wu.xml"); + byte[] wubytesArray = ResourceService.GetEmbeddedData("Files/EmbedAssets/wu.xml"); string fileListXml = Encoding.UTF8.GetString(wubytesArray).Replace("{1}", cookie).Replace("{2}", categoryId).Replace("{3}", ring); byte[] contentBytes = Encoding.UTF8.GetBytes(fileListXml); @@ -406,7 +406,7 @@ private static async Task GetAppxUrlAsync(string updateID, string revisi try { - byte[] urlbytesArray = await ResourceService.GetEmbeddedDataAsync("Files/EmbedAssets/url.xml"); + byte[] urlbytesArray = ResourceService.GetEmbeddedData("Files/EmbedAssets/url.xml"); string url = Encoding.UTF8.GetString(urlbytesArray).Replace("{1}", updateID).Replace("{2}", revisionNumber).Replace("{3}", ring); byte[] contentBytes = Encoding.UTF8.GetBytes(url); diff --git a/GetStoreApp/Properties/AssemblyInfo.cs b/GetStoreApp/Properties/AssemblyInfo.cs index bb6f9d09d..af646a6fb 100644 --- a/GetStoreApp/Properties/AssemblyInfo.cs +++ b/GetStoreApp/Properties/AssemblyInfo.cs @@ -6,11 +6,11 @@ [assembly: AssemblyCompany("高怡飞")] [assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")] [assembly: AssemblyDescription("获取商店应用")] -[assembly: AssemblyFileVersion("4.1.630.0")] -[assembly: AssemblyInformationalVersion("4.1.630.0")] +[assembly: AssemblyFileVersion("4.1.703.0")] +[assembly: AssemblyInformationalVersion("4.1.703.0")] [assembly: AssemblyProduct("获取商店应用")] [assembly: AssemblyTitle("获取商店应用")] -[assembly: AssemblyVersion("4.1.630.0")] +[assembly: AssemblyVersion("4.1.703.0")] // 应用程序默认区域性的资源控制器设置 [assembly: NeutralResourcesLanguage("en-us")] diff --git a/GetStoreApp/Services/Controls/Settings/LanguageService.cs b/GetStoreApp/Services/Controls/Settings/LanguageService.cs index 5c7c913f7..de97740cc 100644 --- a/GetStoreApp/Services/Controls/Settings/LanguageService.cs +++ b/GetStoreApp/Services/Controls/Settings/LanguageService.cs @@ -1,9 +1,9 @@ using GetStoreApp.Extensions.DataType.Constant; using GetStoreApp.Services.Root; +using Microsoft.Windows.Globalization; using System; using System.Collections; using System.Collections.Generic; -using Windows.Globalization; namespace GetStoreApp.Services.Controls.Settings { @@ -29,7 +29,7 @@ private static void InitializeLanguageList() { foreach (string applanguage in AppLanguagesList) { - LanguageList.Add(new DictionaryEntry(new Language(applanguage).NativeName, applanguage)); + LanguageList.Add(new DictionaryEntry(new Windows.Globalization.Language(applanguage).NativeName, applanguage)); } } @@ -100,8 +100,8 @@ private static DictionaryEntry GetLanguage() public static void SetLanguage(DictionaryEntry language) { AppLanguage = language; - LocalSettingsService.SaveSetting(settingsKey, language.Value); + ApplicationLanguages.PrimaryLanguageOverride = language.Value.ToString(); } } } diff --git a/GetStoreApp/Services/Root/ConsoleLaunchService.cs b/GetStoreApp/Services/Root/ConsoleLaunchService.cs index c9e3227a7..c18382ee7 100644 --- a/GetStoreApp/Services/Root/ConsoleLaunchService.cs +++ b/GetStoreApp/Services/Root/ConsoleLaunchService.cs @@ -54,7 +54,7 @@ public static async Task InitializeLaunchAsync(string[] args) InitializeIntroduction(); InitializeRequestContent(); - await CharExtension.InitializeAsync(); + CharExtension.Initialize(); await RequestService.GetLinksAsync(); DownloadSchedulerService.CloseDownloadScheduler(false); diff --git a/GetStoreApp/Services/Root/ResourceService.cs b/GetStoreApp/Services/Root/ResourceService.cs index 0f244d188..85bdf719b 100644 --- a/GetStoreApp/Services/Root/ResourceService.cs +++ b/GetStoreApp/Services/Root/ResourceService.cs @@ -5,13 +5,11 @@ using Microsoft.UI.Composition.SystemBackdrops; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.Windows.ApplicationModel.Resources; using System; using System.Collections; using System.Collections.Generic; -using System.Threading.Tasks; -using Windows.ApplicationModel.Resources.Core; using Windows.Foundation.Diagnostics; -using Windows.Storage.Streams; namespace GetStoreApp.Services.Root { @@ -25,9 +23,10 @@ public static class ResourceService private static DictionaryEntry _defaultAppLanguage; private static DictionaryEntry _currentAppLanguage; - private static readonly ResourceContext defaultResourceContext = new(); - private static readonly ResourceContext currentResourceContext = new(); - private static readonly ResourceMap resourceMap = ResourceManager.Current.MainResourceMap; + private static readonly ResourceManager resourceManager = new(); + private static readonly ResourceContext defaultResourceContext; + private static readonly ResourceContext currentResourceContext; + private static readonly ResourceMap resourceMap = new ResourceManager().MainResourceMap; public static List TypeList { get; } = []; @@ -53,6 +52,45 @@ public static class ResourceService public static List DoEngineModeList { get; } = []; + static ResourceService() + { + defaultResourceContext = resourceManager.CreateResourceContext(); + currentResourceContext = resourceManager.CreateResourceContext(); + resourceMap = resourceManager.MainResourceMap; + GlobalNotificationService.ApplicationExit += OnApplicationExit; + resourceManager.ResourceNotFound += OnResourceNotFound; + } + + /// + /// 应用程序退出时触发的事件 + /// + private static void OnApplicationExit(object sender, EventArgs args) + { + try + { + GlobalNotificationService.ApplicationExit -= OnApplicationExit; + resourceManager.ResourceNotFound -= OnResourceNotFound; + } + catch (Exception e) + { + LogService.WriteLog(LoggingLevel.Error, "Unregister resource service event failed", e); + } + } + + /// + /// 找不到指定的资源而尝试获取资源失败时发生的事件 + /// + private static void OnResourceNotFound(ResourceManager sender, ResourceNotFoundEventArgs args) + { + Dictionary loggingInformationDict = new() + { + { "ResourceName", args.Name }, + { "ResourceContext", args.Context.QualifierValues["language"] } + }; + + LogService.WriteLog(LoggingLevel.Warning, string.Format("No value for resource {0} could be found.", args.Name), loggingInformationDict); + } + /// /// 初始化应用本地化资源 /// @@ -320,20 +358,26 @@ public static string GetLocalized(string resource) { try { - return resourceMap.GetValue(resource, currentResourceContext).ValueAsString; - } - catch (Exception currentResourceException) - { - LogService.WriteLog(LoggingLevel.Warning, string.Format("Get resource context with langauge {0} failed.", _currentAppLanguage.Value), currentResourceException); - try + string currentResourceString = resourceMap.GetValue(resource, currentResourceContext).ValueAsString; + + if (!string.IsNullOrEmpty(currentResourceString)) { - return resourceMap.GetValue(resource, defaultResourceContext).ValueAsString; + return currentResourceString; } - catch (Exception defaultResourceException) + + string defaultResourceString = resourceMap.GetValue(resource, defaultResourceContext).ValueAsString; + + if (!string.IsNullOrEmpty(defaultResourceString)) { - LogService.WriteLog(LoggingLevel.Warning, string.Format("Get resource context string with langauge {0} failed.", _defaultAppLanguage.Value), defaultResourceException); - return resource; + return defaultResourceString; } + + return resource; + } + catch (Exception e) + { + LogService.WriteLog(LoggingLevel.Warning, string.Format("Get resource context with resource {0} failed.", resource), e); + return resource; } } else @@ -346,17 +390,11 @@ public static string GetLocalized(string resource) /// /// 获取嵌入的数据 /// - public static async Task GetEmbeddedDataAsync(string resource) + public static byte[] GetEmbeddedData(string resource) { try { - IRandomAccessStream randomAccessStream = await resourceMap.GetValue(resource).GetValueAsStreamAsync(); - DataReader dataReader = new(randomAccessStream); - await dataReader.LoadAsync((uint)randomAccessStream.Size); - byte[] bytesArray = new byte[randomAccessStream.Size]; - dataReader.ReadBytes(bytesArray); - dataReader.Dispose(); - return bytesArray; + return resourceMap.GetValue(resource).ValueAsBytes; } catch (Exception e) { diff --git a/GetStoreApp/UI/Controls/Download/CompletedControl.xaml.cs b/GetStoreApp/UI/Controls/Download/CompletedControl.xaml.cs index 2fe581a81..f568eee4e 100644 --- a/GetStoreApp/UI/Controls/Download/CompletedControl.xaml.cs +++ b/GetStoreApp/UI/Controls/Download/CompletedControl.xaml.cs @@ -673,10 +673,10 @@ private void OnApplicationExit(object sender, EventArgs args) { try { + GlobalNotificationService.ApplicationExit -= OnApplicationExit; DownloadStorageService.StorageDataAdded -= OnStorageDataAdded; DownloadStorageService.StorageDataDeleted -= OnStorageDataDeleted; DownloadStorageService.StorageDataCleared -= OnStorageDataCleared; - GlobalNotificationService.ApplicationExit -= OnApplicationExit; } catch (Exception e) { diff --git a/GetStoreApp/UI/Controls/Download/DownloadingControl.xaml.cs b/GetStoreApp/UI/Controls/Download/DownloadingControl.xaml.cs index 94fd3ee2d..560c03b71 100644 --- a/GetStoreApp/UI/Controls/Download/DownloadingControl.xaml.cs +++ b/GetStoreApp/UI/Controls/Download/DownloadingControl.xaml.cs @@ -351,13 +351,13 @@ private void OnApplicationExit(object sender, EventArgs args) { try { + GlobalNotificationService.ApplicationExit -= OnApplicationExit; DownloadSchedulerService.DownloadCreated -= OnDownloadCreated; DownloadSchedulerService.DownloadContinued -= OnDownloadContinued; DownloadSchedulerService.DownloadPaused -= OnDownloadPaused; DownloadSchedulerService.DownloadDeleted -= OnDownloadDeleted; DownloadSchedulerService.DownloadProgressing -= OnDownloadProgressing; DownloadSchedulerService.DownloadCompleted -= OnDownloadCompleted; - GlobalNotificationService.ApplicationExit -= OnApplicationExit; } catch (Exception e) { diff --git a/GetStoreApp/UI/Dialogs/About/LicenseDialog.xaml.cs b/GetStoreApp/UI/Dialogs/About/LicenseDialog.xaml.cs index a5a6514cd..ec5929c3c 100644 --- a/GetStoreApp/UI/Dialogs/About/LicenseDialog.xaml.cs +++ b/GetStoreApp/UI/Dialogs/About/LicenseDialog.xaml.cs @@ -40,9 +40,9 @@ public LicenseDialog() /// /// 初始化许可证对话框时加载的内容 /// - private async void OnLoaded(object sender, RoutedEventArgs args) + private void OnLoaded(object sender, RoutedEventArgs args) { - LicenseText = Encoding.UTF8.GetString(await ResourceService.GetEmbeddedDataAsync("Files/EmbedAssets/LICENSE")); + LicenseText = Encoding.UTF8.GetString(ResourceService.GetEmbeddedData("Files/EmbedAssets/LICENSE")); } } } diff --git a/GetStoreAppPackage/GetStoreAppPackage.wapproj b/GetStoreAppPackage/GetStoreAppPackage.wapproj index c565d36e3..0a1ca45cf 100644 --- a/GetStoreAppPackage/GetStoreAppPackage.wapproj +++ b/GetStoreAppPackage/GetStoreAppPackage.wapproj @@ -107,6 +107,7 @@ + \ No newline at end of file diff --git a/GetStoreAppPackage/Package.appxmanifest b/GetStoreAppPackage/Package.appxmanifest index ffb0c088c..efd91fe01 100644 --- a/GetStoreAppPackage/Package.appxmanifest +++ b/GetStoreAppPackage/Package.appxmanifest @@ -11,7 +11,7 @@ + Version="4.1.703.0" /> ms-resource:PackageDisplayName diff --git a/GetStoreAppWebView/GetStoreAppWebView.csproj b/GetStoreAppWebView/GetStoreAppWebView.csproj index 5c5d43a85..c84b414d4 100644 --- a/GetStoreAppWebView/GetStoreAppWebView.csproj +++ b/GetStoreAppWebView/GetStoreAppWebView.csproj @@ -63,15 +63,16 @@ - + - + + diff --git a/GetStoreAppWebView/GetStoreAppWebView.res b/GetStoreAppWebView/GetStoreAppWebView.res index 54c5fccba..591c21c76 100644 Binary files a/GetStoreAppWebView/GetStoreAppWebView.res and b/GetStoreAppWebView/GetStoreAppWebView.res differ diff --git a/GetStoreAppWebView/Properties/AssemblyInfo.cs b/GetStoreAppWebView/Properties/AssemblyInfo.cs index eece53a0a..d551e9951 100644 --- a/GetStoreAppWebView/Properties/AssemblyInfo.cs +++ b/GetStoreAppWebView/Properties/AssemblyInfo.cs @@ -6,11 +6,11 @@ [assembly: AssemblyCompany("高怡飞")] [assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")] [assembly: AssemblyDescription("网页浏览器")] -[assembly: AssemblyFileVersion("4.1.630.0")] -[assembly: AssemblyInformationalVersion("4.1.630.0")] +[assembly: AssemblyFileVersion("4.1.703.0")] +[assembly: AssemblyInformationalVersion("4.1.703.0")] [assembly: AssemblyProduct("网页浏览器")] [assembly: AssemblyTitle("网页浏览器")] -[assembly: AssemblyVersion("4.1.630.0")] +[assembly: AssemblyVersion("4.1.703.0")] // 应用程序默认区域性的资源控制器设置 [assembly: NeutralResourcesLanguage("en-us")] diff --git a/GetStoreAppWebView/Services/Controls/Settings/LanguageService.cs b/GetStoreAppWebView/Services/Controls/Settings/LanguageService.cs index acf30f7db..8a41f2fdf 100644 --- a/GetStoreAppWebView/Services/Controls/Settings/LanguageService.cs +++ b/GetStoreAppWebView/Services/Controls/Settings/LanguageService.cs @@ -1,8 +1,8 @@ using GetStoreAppWebView.Extensions.DataType.Constant; using GetStoreAppWebView.Services.Root; +using Microsoft.Windows.Globalization; using System; using System.Collections.Generic; -using Windows.Globalization; namespace GetStoreAppWebView.Services.Controls.Settings { diff --git a/GetStoreAppWebView/Services/Root/ResourceService.cs b/GetStoreAppWebView/Services/Root/ResourceService.cs index 0b9828149..b246ece15 100644 --- a/GetStoreAppWebView/Services/Root/ResourceService.cs +++ b/GetStoreAppWebView/Services/Root/ResourceService.cs @@ -1,5 +1,5 @@ -using System; -using Windows.ApplicationModel.Resources.Core; +using Microsoft.Windows.ApplicationModel.Resources; +using System; using Windows.Foundation.Diagnostics; namespace GetStoreAppWebView.Services.Root @@ -14,9 +14,17 @@ public static class ResourceService private static string _defaultAppLanguage; private static string _currentAppLanguage; - private static readonly ResourceContext defaultResourceContext = new(); - private static readonly ResourceContext currentResourceContext = new(); - private static readonly ResourceMap resourceMap = ResourceManager.Current.MainResourceMap; + private static readonly ResourceManager resourceManager = new ResourceManager(); + private static readonly ResourceContext defaultResourceContext; + private static readonly ResourceContext currentResourceContext; + private static readonly ResourceMap resourceMap; + + static ResourceService() + { + defaultResourceContext = resourceManager.CreateResourceContext(); + currentResourceContext = resourceManager.CreateResourceContext(); + resourceMap = resourceManager.MainResourceMap; + } /// /// 初始化应用本地化资源 diff --git a/Microsoft.Management.Deployment.Projection/Microsoft.Management.Deployment.Projection.csproj b/Microsoft.Management.Deployment.Projection/Microsoft.Management.Deployment.Projection.csproj index e2d2d8691..5cbaacb59 100644 --- a/Microsoft.Management.Deployment.Projection/Microsoft.Management.Deployment.Projection.csproj +++ b/Microsoft.Management.Deployment.Projection/Microsoft.Management.Deployment.Projection.csproj @@ -34,7 +34,7 @@ - + diff --git a/Microsoft.Management.Deployment.Projection/Properties/AssemblyInfo.cs b/Microsoft.Management.Deployment.Projection/Properties/AssemblyInfo.cs index 99fa6f11d..601d56ac6 100644 --- a/Microsoft.Management.Deployment.Projection/Properties/AssemblyInfo.cs +++ b/Microsoft.Management.Deployment.Projection/Properties/AssemblyInfo.cs @@ -4,10 +4,10 @@ // 程序集信息设置 [assembly: AssemblyCompany("高怡飞")] [assembly: AssemblyCopyright("©Copyright ©2022-2024 高怡飞, All Rights Reserved.")] -[assembly: AssemblyFileVersion("4.1.630.0")] -[assembly: AssemblyInformationalVersion("4.1.630.0")] +[assembly: AssemblyFileVersion("4.1.703.0")] +[assembly: AssemblyInformationalVersion("4.1.703.0")] [assembly: AssemblyProduct("获取商店应用 WinGet WinRT 扩展")] -[assembly: AssemblyVersion("4.1.630.0")] +[assembly: AssemblyVersion("4.1.703.0")] // 设置程序集仅允许在Windows平台上可用 [assembly: SupportedOSPlatform("windows10.0.26100")] \ No newline at end of file