From a69d97fcdb578a0180e48b5e4f706462133f0285 Mon Sep 17 00:00:00 2001 From: "john.jiang" <572164008@qq.com> Date: Tue, 14 Nov 2023 19:09:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20ASF=20fixs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ref/SteamClient | 2 +- .../ArchiSteamFarmServiceImpl.cs | 75 +++++++++++++++++-- .../Services/IArchiSteamFarmService.cs | 6 ++ .../Services/Mvvm/ASFService.cs | 17 +++++ .../ArchiSteamFarmPlusPageViewModel.cs | 4 + .../ArchiSteamFarmPlusPageViewModel.props.cs | 2 + .../UI/Views/Pages/ArchiSteamFarmPage.axaml | 13 ++++ 7 files changed, 111 insertions(+), 8 deletions(-) diff --git a/ref/SteamClient b/ref/SteamClient index 660ec83a6c2..3d84c89221c 160000 --- a/ref/SteamClient +++ b/ref/SteamClient @@ -1 +1 @@ -Subproject commit 660ec83a6c23e842692f69b70152f0b23f163cdb +Subproject commit 3d84c89221c40aa36700ecd3d31e5486219066a5 diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs index 9af5d87d651..cada44eeab7 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs @@ -45,6 +45,15 @@ public bool IsReadPasswordLine public Version CurrentVersion => SharedInfo.Version; + public void ShellMessageInput(string data) + { + using (var sw = ASFProcess.StandardInput) + { + sw.WriteLine(data); + sw.Flush(); + } + } + public async Task StartAsync(string[]? args = null) { try @@ -111,16 +120,10 @@ private async Task StartProcess() options.ArgumentList.Add(EncryptionKey); } ASFProcess = Process.Start(options); + ThreadPool.QueueUserWorkItem(ReadOutPutData); AppDomain.CurrentDomain.ProcessExit += ExitHandler; AppDomain.CurrentDomain.UnhandledException += ExitHandler; ASFProcess!.ErrorDataReceived += new DataReceivedEventHandler(ExitHandler); - ASFProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) => - { - if (!string.IsNullOrEmpty(e.Data)) - OnConsoleWirteLine?.Invoke(e.Data); - }); - - ASFProcess.BeginOutputReadLine(); ASFProcess.BeginErrorReadLine(); while (!SocketHelper.IsUsePort(CurrentIPCPortValue)) { @@ -217,6 +220,64 @@ private void ExitHandler(object? sender, EventArgs eventArgs) { ASFService.Current.StopASFAsync().GetAwaiter().GetResult(); } + + private async void ReadOutPutData(object? obj) + { + using (StreamReader sr = ASFProcess.StandardOutput) + { + int readResult; + char ch; + var len = string.Empty; + StringBuilder sb = new(); + while (true) + { + Task readAsync = Task.Run(sr.Read); + + await Task.WhenAny(readAsync, Task.Delay(TimeSpan.FromSeconds(3))); + + if (!readAsync.IsCompleted) + { + if (sb.Length > 0) + { + len = sb.ToString(); + OnConsoleWirteLine?.Invoke(len); + sb.Clear(); + } + } + + if ((readResult = await readAsync) != -1) + { + ch = (char)readResult; + sb.Append(ch); + + // Note the following common line feed chars: + // \n - UNIX \r\n - DOS \r - Mac + if (ch == '\r' || ch == '\n') + { + readResult = sr.Read(); + if (readResult != -1) + { + ch = (char)readResult; + if (ch == '\n') + { + sb.Append(ch); + len = sb.ToString(); + OnConsoleWirteLine?.Invoke(len); + sb.Clear(); + } + else + { + len = sb.ToString(); + OnConsoleWirteLine?.Invoke(len); + sb.Clear(); + sb.Append(ch); + } + } + } + } + } + } + } #endregion public async Task StopAsync() diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/IArchiSteamFarmService.cs b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/IArchiSteamFarmService.cs index a25f6521610..8d12671313f 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/IArchiSteamFarmService.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/IArchiSteamFarmService.cs @@ -26,6 +26,12 @@ public partial interface IArchiSteamFarmService Version CurrentVersion { get; } + /// + /// 控制台输入 + /// + /// + void ShellMessageInput(string data); + /// /// 启动 ArchiSteamFarm /// diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/Mvvm/ASFService.cs b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/Mvvm/ASFService.cs index 7732f9c5885..786c2b2e372 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/Mvvm/ASFService.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services/Mvvm/ASFService.cs @@ -33,6 +33,14 @@ public string? ConsoleLogText set => this.RaiseAndSetIfChanged(ref _ConsoleLogText, value); } + string? _ConsoleLogInput; + + public string? ConsoleLogInput + { + get => _ConsoleLogInput; + set => this.RaiseAndSetIfChanged(ref _ConsoleLogInput, value); + } + public IConsoleBuilder ConsoleLogBuilder { get; } = new ConsoleBuilder(); public SourceCache SteamBotsSourceList; @@ -74,6 +82,15 @@ void OnConsoleWirteLine(string message) }); } + public void ShellMessageInput() + { + if (string.IsNullOrEmpty(ConsoleLogInput)) + { + return; + } + archiSteamFarmService.ShellMessageInput(ConsoleLogInput); + } + /// /// 是否正在启动或停止中 /// diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.cs b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.cs index a6db11a99e2..11819b82eb2 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.cs @@ -30,6 +30,8 @@ public ArchiSteamFarmPlusPageViewModel() OpenASFBrowser = ReactiveCommand.Create(OpenBrowser); + ShellMessageInput = ReactiveCommand.Create(ShellMessageInput_Click); + RunOrStop = ReactiveCommand.Create(RunOrStopASF); AddBot = ReactiveCommand.Create(ShowAddBotWindow); @@ -284,6 +286,8 @@ public void OpenBrowser(string? tag) public async void SetEncryptionKey_Click() => await asfService.SetEncryptionKeyAsync(); + public void ShellMessageInput_Click() => ASFService.Current.ShellMessageInput(); + public string IPCUrl => asfService.GetIPCUrl(); } #endif \ No newline at end of file diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.props.cs b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.props.cs index 6f12dcdfee8..406934e007f 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.props.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/ViewModels/ArchiSteamFarmPlusPageViewModel.props.cs @@ -70,6 +70,8 @@ public sealed partial class ArchiSteamFarmPlusPageViewModel /// public ICommand OpenASFBrowser { get; } + public ICommand ShellMessageInput { get; } + private bool _IsRedeemKeyDialogOpen; public bool IsRedeemKeyDialogOpen diff --git a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/Views/Pages/ArchiSteamFarmPage.axaml b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/Views/Pages/ArchiSteamFarmPage.axaml index 4d5e966cc42..fc75069be02 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/Views/Pages/ArchiSteamFarmPage.axaml +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/UI/Views/Pages/ArchiSteamFarmPage.axaml @@ -276,6 +276,19 @@ CommandParameter="www" Content="WEBUI 文件夹" /> + +