Minor code refactoring
このコミットが含まれているのは:
1 親
cb9c0d9b7b
コミット
c06594c0d0
3ファイル変更
+59
-18
検索条件に一致するファイルはありません
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
#if !DEBUG
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
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;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
@@ -14,6 +18,8 @@ using Windows.UI;
|
||||
using Windows.UI.ViewManagement;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Uwp;
|
||||
|
||||
/// <summary>
|
||||
@@ -55,26 +61,16 @@ sealed partial class App : Application
|
||||
{
|
||||
ServiceCollection services = new();
|
||||
|
||||
#if RELEASE
|
||||
if (Debugger.IsAttached)
|
||||
#if !DEBUG
|
||||
if (!Debugger.IsAttached &&
|
||||
Assembly.GetExecutingAssembly().TryReadAllTextFromManifestFile("Assets/ServiceTokens/AppCenter.txt", out string? secret) &&
|
||||
Guid.TryParse(secret, out _))
|
||||
{
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
services.AddSingleton<IAnalyticsService>(new AppCenterService(secret!));
|
||||
}
|
||||
else
|
||||
{
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ComputeSharp.SwapChain.Uwp.Assets.ServiceTokens.AppCenter.txt");
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
string appCenterSecret = reader.ReadToEnd().Trim();
|
||||
|
||||
if (Guid.TryParse(appCenterSecret, out _))
|
||||
{
|
||||
services.AddSingleton<IAnalyticsService>(new AppCenterService(appCenterSecret));
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
}
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
}
|
||||
#else
|
||||
services.AddSingleton<IAnalyticsService, DebugAnalyticsService>();
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\AssemblyExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\SkipLocalsInitAttribute.cs" />
|
||||
<Compile Include="Services\AppCenterService.cs" />
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Toolkit.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, nameof(assembly));
|
||||
Guard.IsNotNull(filename, nameof(filename));
|
||||
|
||||
try
|
||||
{
|
||||
string manifestFilename = $"{assembly.FullName}.{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;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする