diff --git a/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs b/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs index 7064cc1f..4ac99dba 100644 --- a/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs +++ b/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; using System; namespace BetterGenshinImpact.Core.Config; @@ -44,4 +44,7 @@ public partial class GenshinStartConfig : ObservableObject /// [ObservableProperty] private bool _recordGameTimeEnabled = false; + + [ObservableProperty] + private bool _startGameWithCmd = false; } diff --git a/BetterGenshinImpact/GameTask/SystemControl.cs b/BetterGenshinImpact/GameTask/SystemControl.cs index 2505ba6f..d87b8f50 100644 --- a/BetterGenshinImpact/GameTask/SystemControl.cs +++ b/BetterGenshinImpact/GameTask/SystemControl.cs @@ -1,4 +1,4 @@ -using BetterGenshinImpact.View.Windows; +using BetterGenshinImpact.View.Windows; using System; using System.Diagnostics; using System.IO; @@ -24,13 +24,30 @@ public class SystemControl return IntPtr.Zero; } - // 直接exe启动 - Process.Start(new ProcessStartInfo(path) + var cfg = TaskContext.Instance().Config.GenshinStartConfig; + var workdir = Path.GetDirectoryName(path) ?? ""; + var arg = cfg.GenshinStartArgs; + + if (cfg.StartGameWithCmd) { - UseShellExecute = true, - Arguments = TaskContext.Instance().Config.GenshinStartConfig.GenshinStartArgs, - WorkingDirectory = Path.GetDirectoryName(path) - }); + var psi = new ProcessStartInfo + { + FileName = "cmd.exe", + Arguments = $"/c start \"\" /d \"{workdir}\" \"{path}\" {arg}", + UseShellExecute = false, + CreateNoWindow = true + }; + Process.Start(psi); + } + else + { + Process.Start(new ProcessStartInfo(path) + { + UseShellExecute = true, + Arguments = arg, + WorkingDirectory = workdir + }); + } for (var i = 0; i < 5; i++) { diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml index e1914ef5..fb31c5a2 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml @@ -462,6 +462,32 @@ IsChecked="{Binding Config.GenshinStartConfig.AutoEnterGameEnabled, Mode=TwoWay}" /> + + + + + + + + + + + + + + @@ -522,4 +548,4 @@ - \ No newline at end of file +