mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-25 10:05:49 +08:00
fixed
This commit is contained in:
@@ -23,6 +23,7 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.Helpers.Device;
|
||||
using BetterGenshinImpact.Service.Singletons;
|
||||
using BetterGenshinImpact.View.Pages.View;
|
||||
using BetterGenshinImpact.ViewModel.Pages.OneDragon;
|
||||
using BetterGenshinImpact.ViewModel.Pages.View;
|
||||
@@ -155,8 +156,7 @@ public partial class App : Application
|
||||
/// </summary>
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
var homePageViewModel = GetService<HomePageViewModel>();
|
||||
homePageViewModel?.ChangeResolution();
|
||||
StartEndSingleton.Instance.OnStartup();
|
||||
|
||||
base.OnStartup(e);
|
||||
|
||||
@@ -183,12 +183,7 @@ public partial class App : Application
|
||||
/// </summary>
|
||||
protected override async void OnExit(ExitEventArgs e)
|
||||
{
|
||||
TouchpadSoft.Instance.RestoreTouchpadByHotKey();
|
||||
|
||||
var homePageViewModel = GetService<HomePageViewModel>();
|
||||
homePageViewModel?.ResetResolution();
|
||||
SysDpi.Instance.ResetDpi();
|
||||
|
||||
StartEndSingleton.Instance.OnExit();
|
||||
base.OnExit(e);
|
||||
|
||||
await _host.StopAsync();
|
||||
|
||||
@@ -34,4 +34,12 @@ public partial class CommonConfig : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string _ffmpegCommand = " -f gdigrab -framerate 60 -use_wallclock_as_timestamps 1 -i title=原神 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -f segment -segment_time 1800 -reset_timestamps 1 -strftime 1 ";
|
||||
|
||||
// 启动时修改分辨率
|
||||
[ObservableProperty]
|
||||
private bool _changeResolutionOnStart = true;
|
||||
|
||||
// 关闭时还原分辨率
|
||||
[ObservableProperty]
|
||||
private bool _restoreResolutionOnExit;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
|
||||
namespace BetterGenshinImpact.Helpers.Device;
|
||||
|
||||
public class Resolution
|
||||
{
|
||||
public int autoWidth = Screen.PrimaryScreen.Bounds.Width;
|
||||
public int autoHeight = Screen.PrimaryScreen.Bounds.Height;
|
||||
public int autoWidth = PrimaryScreen.WorkingArea.Width;
|
||||
public int autoHeight = PrimaryScreen.WorkingArea.Height;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct DEVMODE
|
||||
@@ -113,7 +115,7 @@ public class Resolution
|
||||
}
|
||||
default:
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("改变屏幕分辨率失败,错误码:" + iRet, "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
System.Windows.Forms.MessageBox.Show($"改变屏幕分辨率失败,目标{width}x{height},错误码:{iRet}", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
62
BetterGenshinImpact/Service/Singletons/StartEndSingleton.cs
Normal file
62
BetterGenshinImpact/Service/Singletons/StartEndSingleton.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.Helpers.Device;
|
||||
using BetterGenshinImpact.Model;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Singletons;
|
||||
|
||||
public class StartEndSingleton: Singleton<StartEndSingleton>
|
||||
{
|
||||
private Resolution? _resolution;
|
||||
|
||||
public void OnStartup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnMainWindowLoad()
|
||||
{
|
||||
|
||||
TouchpadSoft.Instance.CheckAndRecordStatus();
|
||||
TouchpadSoft.Instance.DisableTouchpadWhenEnabledByHotKey();
|
||||
|
||||
|
||||
if (TaskContext.Instance().Config.CommonConfig.ChangeResolutionOnStart)
|
||||
{
|
||||
ChangeResolution();
|
||||
// 设置DPI
|
||||
SysDpi.Instance.SetDpi();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
{
|
||||
TouchpadSoft.Instance.RestoreTouchpadByHotKey();
|
||||
|
||||
if (TaskContext.Instance().Config.CommonConfig.RestoreResolutionOnExit)
|
||||
{
|
||||
ResetResolution();
|
||||
SysDpi.Instance.ResetDpi();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ChangeResolution()
|
||||
{
|
||||
_resolution = new Resolution();
|
||||
_resolution.ChangeResolution(1920, 1080);
|
||||
}
|
||||
|
||||
public void ResetResolution()
|
||||
{
|
||||
_resolution?.ChangeResolution(_resolution.autoWidth, _resolution.autoHeight);
|
||||
}
|
||||
}
|
||||
@@ -424,6 +424,86 @@
|
||||
<ui:ToggleSwitch Margin="0,0,36,0" IsChecked="{Binding Config.CommonConfig.ExitToTray, Mode=TwoWay}" />
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12"
|
||||
ContentPadding="0"
|
||||
Icon="{ui:SymbolIcon Settings24}">
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="通用设置"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="通用设置"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="启动时修改显示器分辨率"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="1920x1080 100%"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.CommonConfig.ChangeResolutionOnStart, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="关闭时还原显示器分辨率"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="关闭时还原显示器分辨率"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.CommonConfig.RestoreResolutionOnExit, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<!--<ui:TextBlock Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="通知设置" />-->
|
||||
|
||||
@@ -22,6 +22,7 @@ using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
using BetterGenshinImpact.Helpers.Device;
|
||||
using BetterGenshinImpact.Service.Singletons;
|
||||
using Wpf.Ui;
|
||||
using Application = System.Windows.Application;
|
||||
|
||||
@@ -129,25 +130,8 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
|
||||
EnvironmentUtil.PrintMouseSettings();
|
||||
|
||||
|
||||
TouchpadSoft.Instance.CheckAndRecordStatus();
|
||||
TouchpadSoft.Instance.DisableTouchpadWhenEnabledByHotKey();
|
||||
|
||||
try
|
||||
{
|
||||
var json = GetPCInfo.GetJson();
|
||||
// 保存
|
||||
File.WriteAllText(Global.Absolute("User\\pc.json"), json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError("获取PC信息失败:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置DPI
|
||||
SysDpi.Instance.SetDpi();
|
||||
StartEndSingleton.Instance.OnMainWindowLoad();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -63,8 +63,6 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi
|
||||
[ObservableProperty]
|
||||
private string[] _inferenceDeviceTypes = BgiSessionOption.InferenceDeviceTypes;
|
||||
|
||||
Resolution? resolution;
|
||||
|
||||
public HomePageViewModel(IConfigService configService, TaskTriggerDispatcher taskTriggerDispatcher)
|
||||
{
|
||||
_taskDispatcher = taskTriggerDispatcher;
|
||||
@@ -380,15 +378,4 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi
|
||||
win.NavigateToHtml(html);
|
||||
win.ShowDialog();
|
||||
}
|
||||
|
||||
public void ChangeResolution()
|
||||
{
|
||||
resolution = new Resolution();
|
||||
resolution.ChangeResolution(1920, 1080);
|
||||
}
|
||||
|
||||
public void ResetResolution()
|
||||
{
|
||||
resolution?.ChangeResolution(resolution.autoWidth, resolution.autoHeight);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using BetterGenshinImpact.Core.Recorder.Model;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
@@ -54,31 +55,31 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
private void InitScriptListViewData()
|
||||
{
|
||||
_scriptItems.Clear();
|
||||
var fileInfos = LoadScriptFiles(scriptPath)
|
||||
.OrderByDescending(f => f.CreationTime)
|
||||
var directoryInfos = LoadScriptDirectories(scriptPath)
|
||||
.OrderByDescending(d => d.CreationTime)
|
||||
.ToList();
|
||||
foreach (var f in fileInfos)
|
||||
foreach (var d in directoryInfos)
|
||||
{
|
||||
_scriptItems.Add(new KeyMouseScriptItem
|
||||
{
|
||||
Name = f.Name,
|
||||
Path = f.FullName,
|
||||
CreateTime = f.CreationTime,
|
||||
CreateTimeStr = f.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
Name = d.Name,
|
||||
Path = d.FullName,
|
||||
CreateTime = d.CreationTime,
|
||||
CreateTimeStr = d.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<FileInfo> LoadScriptFiles(string folder)
|
||||
private List<DirectoryInfo> LoadScriptDirectories(string folder)
|
||||
{
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(folder, "*.json", SearchOption.AllDirectories);
|
||||
var directories = Directory.GetDirectories(folder);
|
||||
|
||||
return files.Select(file => new FileInfo(file)).ToList();
|
||||
return directories.Select(dir => new DirectoryInfo(dir)).ToList();
|
||||
}
|
||||
|
||||
public void OnNavigatedTo()
|
||||
@@ -120,21 +121,36 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await MessageBox.ShowAsync(e.Message, "校验错误", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
// await MessageBox.ShowAsync(e.Message, "校验错误", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
// SystemControl.ActivateWindow(new WindowInteropHelper(UIDispatcherHelper.MainWindow).Handle);
|
||||
Toast.Error(e.Message);
|
||||
_logger.LogError(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fileName = $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}";
|
||||
|
||||
try
|
||||
{
|
||||
var json = GetPCInfo.GetJson();
|
||||
// 保存
|
||||
await File.WriteAllTextAsync(Global.Absolute(@$"User/KeyMouseScript/{fileName}/pc.json"), json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TaskControl.Logger.LogDebug("获取PC信息失败:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
|
||||
}
|
||||
|
||||
|
||||
if (!IsRecording)
|
||||
{
|
||||
IsRecording = true;
|
||||
SystemSettingsManager.GetSystemSettings();
|
||||
SystemSettingsManager.SetSystemSettings();
|
||||
|
||||
|
||||
fileName = $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}";
|
||||
|
||||
await GlobalKeyMouseRecord.Instance.StartRecord(fileName);
|
||||
}
|
||||
}
|
||||
@@ -165,13 +181,13 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
[RelayCommand]
|
||||
public async Task OnStartPlay(string path)
|
||||
{
|
||||
var file = new FileInfo(path);
|
||||
var name = file.Name;
|
||||
var file = new FileInfo(Path.Combine(path, "systemInfo.json"));
|
||||
var name = file.Directory?.Name;
|
||||
_logger.LogInformation("重放开始:{Name}", name);
|
||||
try
|
||||
{
|
||||
await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage)
|
||||
.RunAsync(async () => await KeyMouseMacroPlayerJsonLine.PlayMacro(path, CancellationContext.Instance.Cts.Token));
|
||||
.RunAsync(async () => await KeyMouseMacroPlayerJsonLine.PlayMacro(file.FullName, CancellationContext.Instance.Cts.Token));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -244,7 +260,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
|
||||
try
|
||||
{
|
||||
var path = new FileInfo(item.Path).Directory!.FullName;
|
||||
var path = item.Path;
|
||||
// 校验文件夹是否在 scriptPath 下
|
||||
if (!path.StartsWith(scriptPath))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user