Merge branch 'babalae:main' into main

This commit is contained in:
mfkvfhpdx
2025-01-26 18:42:50 +08:00
committed by GitHub
2 changed files with 22 additions and 13 deletions

View File

@@ -10,7 +10,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationIcon>Assets\Images\logo.ico</ApplicationIcon>
<AssemblyName>BetterGI</AssemblyName>
<AssemblyVersion>0.39.7</AssemblyVersion>
<AssemblyVersion>0.40.0</AssemblyVersion>
<Platforms>x64</Platforms>
<DebugType>embedded</DebugType>
</PropertyGroup>

View File

@@ -102,12 +102,12 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
{
// 预热OCR
await OcrPreheating();
if (Environment.GetCommandLineArgs().Length > 1)
{
return;
}
// 自动处理目录配置
await Patch1();
@@ -158,19 +158,28 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
*/
private async Task Patch1()
{
if (Directory.Exists(Global.Absolute("BetterGI"))
// && File.Exists(Global.Absolute("BetterGI/BetterGI.exe"))
&& Directory.Exists(Global.Absolute("BetterGI/User"))
var embeddedPath = Global.Absolute("BetterGI");
var embeddedUserPath = Global.Absolute("BetterGI/User");
var exePath = Global.Absolute("BetterGI/BetterGI.exe");
if (Directory.Exists(embeddedPath)
&& File.Exists(exePath)
&& Directory.Exists(embeddedUserPath)
)
{
var res = await MessageBox.ShowAsync("检测到旧的 BetterGI 配置,是否迁移配置并清理旧目录?", "BetterGI", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
if (res == System.Windows.MessageBoxResult.Yes)
var fileVersionInfo = FileVersionInfo.GetVersionInfo(exePath);
// 低版本才需要迁移
if (fileVersionInfo.FileVersion != null && !Global.IsNewVersion(fileVersionInfo.FileVersion))
{
var dir = Global.Absolute("BetterGI/User");
// 迁移配置,拷贝整个目录并覆盖
DirectoryHelper.CopyDirectory(dir, Global.Absolute("User"));
// 删除旧目录
DirectoryHelper.DeleteDirectoryRecursively(Global.Absolute("BetterGI"));
var res = await MessageBox.ShowAsync("检测到旧的 BetterGI 配置,是否迁移配置并清理旧目录?", "BetterGI", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
if (res == System.Windows.MessageBoxResult.Yes)
{
// 迁移配置,拷贝整个目录并覆盖
DirectoryHelper.CopyDirectory(embeddedUserPath, Global.Absolute("User"));
// 删除旧目录
DirectoryHelper.DeleteReadOnlyDirectory(embeddedPath);
await MessageBox.InformationAsync("迁移配置成功, 软件将自动退出,请手动重新启动 BetterGI");
Application.Current.Shutdown();
}
}
}
}