diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index ac39296fed..3e004af57d 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -604,12 +604,7 @@ namespace MaaWpfGui.Main } } - bool buy_wine = false; - if (_latestTaskId.ContainsKey(TaskType.Mall) && Instances.SettingsViewModel.DidYouBuyWine()) - { - buy_wine = true; - } - + bool buy_wine = _latestTaskId.ContainsKey(TaskType.Mall) && Instances.SettingsViewModel.DidYouBuyWine(); _latestTaskId.Clear(); Instances.TaskQueueViewModel.ResetFightVariables(); @@ -1253,29 +1248,27 @@ namespace MaaWpfGui.Main string host = address_[0].Equals("emulator") ? "127.0.0.1" : address_[0]; int port = int.Parse(address_[1]); - using (var client = new TcpClient()) + using var client = new TcpClient(); + try { - try - { - IAsyncResult result = client.BeginConnect(host, port, null, null); - bool success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(.5)); + IAsyncResult result = client.BeginConnect(host, port, null, null); + bool success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(.5)); - if (success) - { - client.EndConnect(result); - return true; - } - else - { - client.Close(); - return false; - } - } - catch (Exception) + if (success) { + client.EndConnect(result); + return true; + } + else + { + client.Close(); return false; } } + catch (Exception) + { + return false; + } } /// diff --git a/src/MaaWpfGui/Services/Web/HttpService.cs b/src/MaaWpfGui/Services/Web/HttpService.cs index e8adae7b66..1ebd9d0330 100644 --- a/src/MaaWpfGui/Services/Web/HttpService.cs +++ b/src/MaaWpfGui/Services/Web/HttpService.cs @@ -108,7 +108,7 @@ namespace MaaWpfGui.Services.Web { var response = await GetAsync(uri, extraHeader); - if (response == null || response.StatusCode != HttpStatusCode.OK) + if (response?.StatusCode != HttpStatusCode.OK) { return null; } @@ -120,7 +120,7 @@ namespace MaaWpfGui.Services.Web { var response = await GetAsync(uri, extraHeader); - if (response == null || response.StatusCode != HttpStatusCode.OK) + if (response?.StatusCode != HttpStatusCode.OK) { return null; } @@ -183,7 +183,7 @@ namespace MaaWpfGui.Services.Web var response = await GetAsync(uri, extraHeader: new Dictionary { { "Accept", contentType } }, httpCompletionOption: HttpCompletionOption.ResponseHeadersRead); - if (response == null || response.StatusCode != HttpStatusCode.OK) + if (response?.StatusCode != HttpStatusCode.OK) { return false; } @@ -264,7 +264,6 @@ namespace MaaWpfGui.Services.Web } HttpClient client = new HttpClient(handler); - client = new HttpClient(handler); client.DefaultRequestHeaders.Add("User-Agent", UserAgent); client.Timeout = TimeSpan.FromSeconds(15); return client;