From 2b18e03098ace94e95b33c21f2086c501ecc6454 Mon Sep 17 00:00:00 2001 From: "john.jiang" <572164008@qq.com> Date: Fri, 10 Nov 2023 18:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20fixs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiSteamFarmServiceImpl.cs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) 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 c10b0f61b67..9af5d87d651 100644 --- a/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs +++ b/src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Services.Implementation/ArchiSteamFarmServiceImpl.cs @@ -15,25 +15,26 @@ public partial class ArchiSteamFarmServiceImpl : ReactiveObject, IArchiSteamFarm { const string TAG = "ArchiSteamFarmS"; + private readonly AsyncLock @lock = new AsyncLock(); + + private bool isFirstStart = true; + + private bool _IsReadPasswordLine; + + private HttpClient _httpClient = new(); + protected readonly IArchiSteamFarmWebApiService webApiService = IArchiSteamFarmWebApiService.Instance; public ArchiSteamFarmServiceImpl() { - } public Process? ASFProcess { get; set; } - private Process? MainProcess; - public event Action? OnConsoleWirteLine; public TaskCompletionSource? ReadLineTask { get; set; } - private readonly AsyncLock @lock = new AsyncLock(); - - bool _IsReadPasswordLine; - public bool IsReadPasswordLine { get => _IsReadPasswordLine; @@ -44,8 +45,6 @@ public bool IsReadPasswordLine public Version CurrentVersion => SharedInfo.Version; - private bool isFirstStart = true; - public async Task StartAsync(string[]? args = null) { try @@ -194,25 +193,22 @@ string CalculateFileHash(string filePath) async Task DownloadASFRelease(string downloadUrl, string savePath) { - using (HttpClient httpClient = new HttpClient()) + try { - try - { - HttpResponseMessage response = await httpClient.GetAsync(downloadUrl); + HttpResponseMessage response = await _httpClient.GetAsync(downloadUrl); - // Ensure a successful response before proceeding - response.EnsureSuccessStatusCode(); + // Ensure a successful response before proceeding + response.EnsureSuccessStatusCode(); - using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None)) - { - await response.Content.CopyToAsync(fileStream); - } - } - catch (Exception ex) + using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None)) { - return false; + await response.Content.CopyToAsync(fileStream); } } + catch (Exception ex) + { + return false; + } return true; } }