From 78ec9d31e810b8b782d6823d9f8a8ae4592689fe Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Wed, 14 Aug 2024 16:03:43 +0800 Subject: [PATCH] check integration #468 --- BetterGenshinImpact/App.xaml.cs | 1 + BetterGenshinImpact/Helpers/RuntimeHelper.cs | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/BetterGenshinImpact/App.xaml.cs b/BetterGenshinImpact/App.xaml.cs index 56cee9a0..2baa0b1e 100644 --- a/BetterGenshinImpact/App.xaml.cs +++ b/BetterGenshinImpact/App.xaml.cs @@ -33,6 +33,7 @@ public partial class App : Application // https://docs.microsoft.com/dotnet/core/extensions/configuration // https://docs.microsoft.com/dotnet/core/extensions/logging private static readonly IHost _host = Host.CreateDefaultBuilder() + .CheckIntegration() .UseElevated() .UseSingleInstance("BetterGI") .ConfigureServices( diff --git a/BetterGenshinImpact/Helpers/RuntimeHelper.cs b/BetterGenshinImpact/Helpers/RuntimeHelper.cs index e887d3ad..6e9fd47f 100644 --- a/BetterGenshinImpact/Helpers/RuntimeHelper.cs +++ b/BetterGenshinImpact/Helpers/RuntimeHelper.cs @@ -3,8 +3,10 @@ using Microsoft.Extensions.Hosting; using System; using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Security.Principal; +using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -130,6 +132,21 @@ internal static class RuntimeHelper } }, TaskCreationOptions.LongRunning); } + + public static void CheckIntegration() + { + if (!Directory.Exists("Assets") || !Directory.Exists("GameTask") || !Directory.Exists("User")) + { + StringBuilder stringBuilder = new("发现有关键文件缺失,"); + stringBuilder.Append(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) == Global.StartUpPath + ? "请不要把主程序exe文件剪切到桌面" + : "请重新安装软件"); + + MessageBox.Show(stringBuilder.ToString(), + "警告", MessageBoxButton.OK, MessageBoxImage.Warning); + Environment.Exit(0xFFFF); + } + } } internal static class RuntimeExtension @@ -145,4 +162,10 @@ internal static class RuntimeExtension RuntimeHelper.CheckSingleInstance(instanceName, callback); return self; } + + public static IHostBuilder CheckIntegration(this IHostBuilder app) + { + RuntimeHelper.CheckIntegration(); + return app; + } }