check integration #468

This commit is contained in:
qhy040404 2024-08-14 16:03:43 +08:00
parent b62e87f36f
commit 78ec9d31e8
No known key found for this signature in database
GPG Key ID: B1E14E493E9BB96C
2 changed files with 24 additions and 0 deletions

View File

@ -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(

View File

@ -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;
}
}