Merge pull request #456 from Sergio0694/dev/remove-uwp-startup-reflection

Remove reflection from UWP sample startup path
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-12-24 13:59:17 +01:00
コミット aa655ce8c1
4ファイル変更
+25 -54

検索条件に一致するファイルはありません

+22 -2
ファイルの表示
@@ -6,9 +6,29 @@ if(!(Test-Path -Path $TOKENS_FOLDER_RELATIVE_PATH)) {
$TOKENS_FOLDER_PATH = Resolve-Path -Path $TOKENS_FOLDER_RELATIVE_PATH
# AppCenter tokens
$APPCENTER_TOKENS_NAME = "AppCenter.txt"
$APPCENTER_TOKENS_NAME = "App.AppCenter.cs"
$APPCENTER_TOKENS_PATH = Join-Path -Path $TOKENS_FOLDER_PATH -ChildPath $APPCENTER_TOKENS_NAME
if (!(Test-Path -Path $APPCENTER_TOKENS_PATH))
{
echo "<APP_CENTER_SECRET>" > $APPCENTER_TOKENS_PATH
# Prepare the generated source
$APP_APPCENTER_TEXT =
@"
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ComputeSharp.SwapChain.Uwp;
/// <inheritdoc/>
partial class App
{
/// <summary>
/// The secret token for the AppService connection.
/// </summary>
private const string AppServiceSecret = "";
}
"@.Trim()
# Output the source to the target file
Add-Content $APP_APPCENTER_TEXT -Path $APPCENTER_TOKENS_PATH -NoNewline
}
+2 -6
ファイルの表示
@@ -1,13 +1,11 @@
#if !DEBUG
using System;
using System.Diagnostics;
using System.Reflection;
#endif
using CommunityToolkit.Mvvm.DependencyInjection;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.ViewModels;
#if !DEBUG
using ComputeSharp.SwapChain.Uwp.Extensions;
using ComputeSharp.SwapChain.Uwp.Services;
#endif
using ComputeSharp.SwapChain.Uwp.Views;
@@ -62,11 +60,9 @@ sealed partial class App : Application
ServiceCollection services = new();
#if !DEBUG
if (!Debugger.IsAttached &&
Assembly.GetExecutingAssembly().TryReadAllTextFromManifestFile("Assets/ServiceTokens/AppCenter.txt", out string? secret) &&
Guid.TryParse(secret, out _))
if (Guid.TryParse(AppServiceSecret, out _) && !Debugger.IsAttached)
{
services.AddSingleton<IAnalyticsService>(new AppCenterService(secret!));
services.AddSingleton<IAnalyticsService>(new AppCenterService(AppServiceSecret));
}
else
{
+1 -2
ファイルの表示
@@ -78,7 +78,7 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\AssemblyExtensions.cs" />
<Compile Include="Assets\ServiceTokens\App.AppCenter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\SkipLocalsInitAttribute.cs" />
<Compile Include="Services\AppCenterService.cs" />
@@ -104,7 +104,6 @@
<Link>Assets\Textures\RustyMetal.png</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Assets\ServiceTokens\AppCenter.txt" />
<Content Include="Assets\SmallTile.scale-100.png" />
<Content Include="Assets\SmallTile.scale-125.png" />
<Content Include="Assets\SmallTile.scale-150.png" />
-44
ファイルの表示
@@ -1,44 +0,0 @@
using System.IO;
using System.Reflection;
using CommunityToolkit.Diagnostics;
#nullable enable
namespace ComputeSharp.SwapChain.Uwp.Extensions;
/// <summary>
/// Helpers for the <see cref="Assembly"/> type.
/// </summary>
public static class AssemblyExtensions
{
/// <summary>
/// Tries to read a <see cref="string"/> from a specified file in the target <see cref="Assembly"/>.
/// </summary>
/// <param name="assembly">The target <see cref="Assembly"/> to read data from.</param>
/// <param name="filename">The target filename to read from.</param>
/// <param name="text">The resulting text, if the read was successful.</param>
/// <returns>The contents of the specified file.</returns>
public static bool TryReadAllTextFromManifestFile(this Assembly assembly, string filename, out string? text)
{
Guard.IsNotNull(assembly);
Guard.IsNotNull(filename);
try
{
string manifestFilename = $"{assembly.GetName().Name}.{filename.Replace('/', '.').Replace('\\', '.')}";
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestFilename);
using StreamReader reader = new(stream);
text = reader.ReadToEnd().Trim();
return true;
}
catch
{
text = null;
return false;
}
}
}