Skip to content

Commit

Permalink
Migrate MRT to MRT Core
Browse files Browse the repository at this point in the history
1.Migrate MRT to MRT Core
2.Update Windows App SDK to 1.6.240701003-experimental2
3.Update Microsoft.WindowsPackageManager.ComInterop to 1.8.1791
  • Loading branch information
Gaoyifei1011 committed Jul 3, 2024
1 parent d7ee6ca commit e5fe1c1
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 58 deletions.
5 changes: 2 additions & 3 deletions GetStoreApp/Extensions/Console/CharExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GetStoreApp.Services.Root;
using System.Threading.Tasks;

namespace GetStoreApp.Extensions.Console
{
Expand All @@ -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");
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion GetStoreApp/GetStoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<None Remove="WinUIApp.xaml" />

<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240602.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240531000-experimental1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" />

<Page Update="Styles\AppBarButton.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
<Page Update="Styles\Flyout.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
Expand Down Expand Up @@ -157,6 +157,7 @@

<TrimmableAssembly Include="Microsoft.InteractiveExperiences.Projection" />
<TrimmableAssembly Include="Microsoft.Management.Deployment.Projection" />
<TrimmableAssembly Include="Microsoft.Web.WebView2.Core.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.DynamicDependency.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.Resources.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection" />
Expand Down
Binary file modified GetStoreApp/GetStoreApp.res
Binary file not shown.
6 changes: 3 additions & 3 deletions GetStoreApp/Helpers/Controls/Store/QueryLinksHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static async Task<string> 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;
Expand Down Expand Up @@ -234,7 +234,7 @@ public static async Task<string> 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);

Expand Down Expand Up @@ -406,7 +406,7 @@ private static async Task<string> 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);

Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
6 changes: 3 additions & 3 deletions GetStoreApp/Services/Controls/Settings/LanguageService.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion GetStoreApp/Services/Root/ConsoleLaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static async Task InitializeLaunchAsync(string[] args)

InitializeIntroduction();
InitializeRequestContent();
await CharExtension.InitializeAsync();
CharExtension.Initialize();
await RequestService.GetLinksAsync();

DownloadSchedulerService.CloseDownloadScheduler(false);
Expand Down
86 changes: 62 additions & 24 deletions GetStoreApp/Services/Root/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<TypeModel> TypeList { get; } = [];

Expand All @@ -53,6 +52,45 @@ public static class ResourceService

public static List<DictionaryEntry> DoEngineModeList { get; } = [];

static ResourceService()
{
defaultResourceContext = resourceManager.CreateResourceContext();
currentResourceContext = resourceManager.CreateResourceContext();
resourceMap = resourceManager.MainResourceMap;
GlobalNotificationService.ApplicationExit += OnApplicationExit;
resourceManager.ResourceNotFound += OnResourceNotFound;
}

/// <summary>
/// 应用程序退出时触发的事件
/// </summary>
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);
}
}

/// <summary>
/// 找不到指定的资源而尝试获取资源失败时发生的事件
/// </summary>
private static void OnResourceNotFound(ResourceManager sender, ResourceNotFoundEventArgs args)
{
Dictionary<string, string> 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);
}

/// <summary>
/// 初始化应用本地化资源
/// </summary>
Expand Down Expand Up @@ -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
Expand All @@ -346,17 +390,11 @@ public static string GetLocalized(string resource)
/// <summary>
/// 获取嵌入的数据
/// </summary>
public static async Task<byte[]> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion GetStoreApp/UI/Controls/Download/CompletedControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions GetStoreApp/UI/Dialogs/About/LicenseDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public LicenseDialog()
/// <summary>
/// 初始化许可证对话框时加载的内容
/// </summary>
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"));
}
}
}
1 change: 1 addition & 0 deletions GetStoreAppPackage/GetStoreAppPackage.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<Target Name="_RemoveFilesFromPayload" AfterTargets="_CalculateInputsForGenerateAppxPackageRecipe" Condition="'$(MSBuildProjectExtension)' == '.wapproj' and '$(_IsGeneratingAppxPackage)' == 'true'">
<ItemGroup>
<AppxPackagePayload Remove="@(AppxPackagePayload)" Condition="'%(FileName)%(Extension)'=='Microsoft.WindowsAppRuntime.Bootstrap.dll'" />
<AppxPackagePayload Remove="@(AppxPackagePayload)" Condition="'%(FileName)%(Extension)'=='WebView2Loader.dll'" />
</ItemGroup>
</Target>
</Project>
2 changes: 1 addition & 1 deletion GetStoreAppPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Identity
Name="Gaoyifei1011.GetStoreApp"
Publisher="CN=高怡飞"
Version="4.1.630.0" />
Version="4.1.703.0" />

<Properties>
<DisplayName>ms-resource:PackageDisplayName</DisplayName>
Expand Down
5 changes: 3 additions & 2 deletions GetStoreAppWebView/GetStoreAppWebView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@
<None Remove="WebWindow.xaml" />

<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240602.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240531000-experimental1" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" GeneratePathProperty="true" />

<Page Remove="WebApp.xaml" />

<Page Update="UI\Dialogs\ProcessFailedDialog.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
<Page Update="WebWindow.xaml" XamlRuntime="$(DefaultXamlRuntime)" />

<TrimmableAssembly Include="Microsoft.InteractiveExperiences.Projection" />
<TrimmableAssembly Include="Microsoft.Management.Deployment.Projection" />
<TrimmableAssembly Include="Microsoft.Web.WebView2.Core.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.DynamicDependency.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.Resources.Projection" />
<TrimmableAssembly Include="Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection" />
Expand Down
Binary file modified GetStoreAppWebView/GetStoreAppWebView.res
Binary file not shown.
6 changes: 3 additions & 3 deletions GetStoreAppWebView/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
18 changes: 13 additions & 5 deletions GetStoreAppWebView/Services/Root/ResourceService.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}

/// <summary>
/// 初始化应用本地化资源
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Content Include="$(TargetDir)\Microsoft.Management.Deployment.winmd" ExcludeFromSingleFile="true" Link="Microsoft.Management.Deployment.winmd" CopyToOutputDirectory="Always" />
<Content Include="$(TargetDir)\winrtact.dll" ExcludeFromSingleFile="true" Link="winrtact.dll" CopyToOutputDirectory="Always" />

<PackageReference Include="Microsoft.WindowsPackageManager.ComInterop" Version="1.7.11261" GeneratePathProperty="true" IncludeAssets="none" />
<PackageReference Include="Microsoft.WindowsPackageManager.ComInterop" Version="1.8.1791" GeneratePathProperty="true" IncludeAssets="none" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240602.1" />

<WindowsSdkSupportedTargetPlatformVersion Include="10.0.26100.0" WindowsSdkPackageVersion="10.0.26100.1" MinimumNETVersion="6.0" />
Expand Down
Loading

0 comments on commit e5fe1c1

Please sign in to comment.