From 47d8b0f60418e01034d46845c053bd9ff732d2fa Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:44:20 +0800 Subject: [PATCH] chore: format & nullable [skip changelog] --- src/MaaWpfGui/Configuration/GUI.cs | 1 - .../Helper/Notification/NotificationHint.cs | 1 - .../Notification/NotificationImplWinRT.cs | 3 ++- src/MaaWpfGui/Main/AsstProxy.cs | 24 +++++++++---------- src/MaaWpfGui/Utilities/PowerManagement.cs | 4 ++-- .../ViewModels/UI/SettingsViewModel.cs | 2 +- .../ViewModels/UI/TaskQueueViewModel.cs | 4 ++-- .../Settings/GameSettingsUserControlModel.cs | 13 ++++++++++ .../WineCompat/MaaDesktopIntegration.cs | 2 +- .../WineCompat/WineBridgeAvailability.cs | 10 +++++++- 10 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/MaaWpfGui/Configuration/GUI.cs b/src/MaaWpfGui/Configuration/GUI.cs index 4e168891fc..70a8e3f856 100644 --- a/src/MaaWpfGui/Configuration/GUI.cs +++ b/src/MaaWpfGui/Configuration/GUI.cs @@ -1,5 +1,4 @@ // -// // MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors // diff --git a/src/MaaWpfGui/Helper/Notification/NotificationHint.cs b/src/MaaWpfGui/Helper/Notification/NotificationHint.cs index a562a735a0..666ac73982 100644 --- a/src/MaaWpfGui/Helper/Notification/NotificationHint.cs +++ b/src/MaaWpfGui/Helper/Notification/NotificationHint.cs @@ -48,5 +48,4 @@ public class NotificationHint public static NotificationHint RowCount(int rowCount) => new NotificationHintRowCount(rowCount); public static NotificationHint ExpirationTime(TimeSpan value) => new NotificationHintExpirationTime(value); - } diff --git a/src/MaaWpfGui/Helper/Notification/NotificationImplWinRT.cs b/src/MaaWpfGui/Helper/Notification/NotificationImplWinRT.cs index 62ad0b1396..5ed6037da5 100644 --- a/src/MaaWpfGui/Helper/Notification/NotificationImplWinRT.cs +++ b/src/MaaWpfGui/Helper/Notification/NotificationImplWinRT.cs @@ -30,7 +30,8 @@ internal class NotificationImplWinRT : INotificationPoster, IDisposable public void Dispose() { ToastNotificationManagerCompat.OnActivated -= OnWinRTActivated; - //ToastNotificationManagerCompat.History.Clear(); + + // ToastNotificationManagerCompat.History.Clear(); } private void OnWinRTActivated(ToastNotificationActivatedEventArgsCompat args) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 2e258932d9..abebda1268 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -389,7 +389,7 @@ namespace MaaWpfGui.Main var jsonStr = PtrToStringCustom(jsonBuffer, Encoding.UTF8); // Console.WriteLine(json_str); - var json = (JObject?)JsonConvert.DeserializeObject(jsonStr); + var json = (JObject?)JsonConvert.DeserializeObject(jsonStr ?? string.Empty); MaaService.ProcCallbackMsg dlg = ProcMsg; Execute.OnUIThread( () => @@ -458,8 +458,8 @@ namespace MaaWpfGui.Main { case "Connected": Connected = true; - _connectedAdb = details["details"]?["adb"]?.ToString(); - _connectedAddress = details["details"]?["address"]?.ToString(); + _connectedAdb = details["details"]!["adb"]!.ToString(); + _connectedAddress = details["details"]!["address"]!.ToString(); SettingsViewModel.ConnectSettings.ConnectAddress = _connectedAddress; break; @@ -1030,7 +1030,7 @@ namespace MaaWpfGui.Main case "ReportToPenguinStats": { - var why = details!["why"].ToString(); + var why = details!["why"]!.ToString(); Instances.TaskQueueViewModel.AddLog(why + "," + LocalizationHelper.GetString("GiveUpUploadingPenguins"), UiLogColor.Error); break; } @@ -1069,8 +1069,8 @@ namespace MaaWpfGui.Main { case "ProcessTask": { - string taskName = details!["details"]?["task"]?.ToString(); - int execTimes = (int)details["details"]["exec_times"]; + string taskName = details!["details"]!["task"]!.ToString(); + int execTimes = (int)details!["details"]!["exec_times"]!; switch (taskName) { @@ -1318,7 +1318,7 @@ namespace MaaWpfGui.Main case "RecruitSpecialTag": { - string special = subTaskDetails!["tag"]?.ToString(); + string special = subTaskDetails!["tag"]!.ToString(); if (special == "支援机械" && Instances.SettingsViewModel.NotChooseLevel1 == false) { break; @@ -1332,7 +1332,7 @@ namespace MaaWpfGui.Main case "RecruitRobotTag": { - string special = subTaskDetails!["tag"]?.ToString(); + string special = subTaskDetails!["tag"]!.ToString(); using var toast = new ToastNotification(LocalizationHelper.GetString("RecruitingTips")); toast.AppendContentText(special).ShowRecruitRobot(); @@ -1381,7 +1381,7 @@ namespace MaaWpfGui.Main case "RecruitTagsSelected": { - var selected = subTaskDetails["tags"] ?? new JArray(); + var selected = subTaskDetails!["tags"] ?? new JArray(); string selectedLog = selected.Aggregate(string.Empty, (current, tag) => current + (tag + "\n")); selectedLog = selectedLog.EndsWith('\n') ? selectedLog.TrimEnd('\n') : LocalizationHelper.GetString("NoDrop"); @@ -1674,7 +1674,7 @@ namespace MaaWpfGui.Main break; case "AccountSwitch": - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" -->> {subTaskDetails["account_name"]}", UiLogColor.Info); // subTaskDetails!["current_account"] + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AccountSwitch") + $" -->> {subTaskDetails!["account_name"]}", UiLogColor.Info); // subTaskDetails!["current_account"] break; case "RoguelikeCollapsalParadigms": string deepen_or_weaken_str = subTaskDetails!["deepen_or_weaken"]?.ToString() ?? "Unknown"; @@ -1933,7 +1933,7 @@ namespace MaaWpfGui.Main private AsstTaskId AsstAppendTaskWithEncoding(string type, JObject? taskParams = null) { - taskParams ??= new(); + taskParams ??= []; return AsstAppendTask(_handle, type, JsonConvert.SerializeObject(taskParams)); } @@ -1944,7 +1944,7 @@ namespace MaaWpfGui.Main return false; } - taskParams ??= new(); + taskParams ??= []; return AsstSetTaskParams(_handle, id, JsonConvert.SerializeObject(taskParams)); } diff --git a/src/MaaWpfGui/Utilities/PowerManagement.cs b/src/MaaWpfGui/Utilities/PowerManagement.cs index c8ef6b14c1..196199399f 100644 --- a/src/MaaWpfGui/Utilities/PowerManagement.cs +++ b/src/MaaWpfGui/Utilities/PowerManagement.cs @@ -25,10 +25,10 @@ namespace MaaWpfGui.Utilities private static extern bool ExitWindowsEx(uint uFlags, uint dwReason); [DllImport("advapi32.dll", SetLastError = true)] - private static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, uint BufferLengthInBytes, IntPtr PreviousState, IntPtr ReturnLengthInBytes); + private static extern bool AdjustTokenPrivileges(IntPtr tokenHandle, bool disableAllPrivileges, ref TOKEN_PRIVILEGES newState, uint bufferLengthInBytes, IntPtr PreviousState, IntPtr ReturnLengthInBytes); [DllImport("advapi32.dll", SetLastError = true)] - private static extern bool OpenProcessToken(IntPtr ProcessHandle, uint DesiredAccess, out IntPtr TokenHandle); + private static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle); [DllImport("kernel32.dll", SetLastError = true)] private static extern IntPtr GetCurrentProcess(); diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index d429a5f1e4..684363193b 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -795,7 +795,7 @@ namespace MaaWpfGui.ViewModels.UI /// /// Gets or sets the list of divider vertical offset. /// - public List DividerVerticalOffsetList { get; set; } = new(); + public List DividerVerticalOffsetList { get; set; } = []; private int _selectedIndex; diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index d43f61da5a..2ec7ca3a81 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -1631,7 +1631,7 @@ namespace MaaWpfGui.ViewModels.UI { var order = Instances.SettingsViewModel.GetInfrastOrderList(); Instances.AsstProxy.AsstSetInfrastTaskParams( - order.ToArray(), + order, Instances.SettingsViewModel.UsesOfDrones, Instances.SettingsViewModel.ContinueTraining, Instances.SettingsViewModel.DormThreshold / 100.0, @@ -1653,7 +1653,7 @@ namespace MaaWpfGui.ViewModels.UI var order = Instances.SettingsViewModel.GetInfrastOrderList(); return Instances.AsstProxy.AsstAppendInfrast( - order.ToArray(), + order, Instances.SettingsViewModel.UsesOfDrones, Instances.SettingsViewModel.ContinueTraining, Instances.SettingsViewModel.DormThreshold / 100.0, diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs index eebf922577..1ddb7b067e 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs @@ -1,3 +1,16 @@ +// +// MaaWpfGui - A part of the MaaCoreArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License v3.0 only as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY +// + #nullable enable using System.Collections.Generic; using MaaWpfGui.Constants; diff --git a/src/MaaWpfGui/WineCompat/MaaDesktopIntegration.cs b/src/MaaWpfGui/WineCompat/MaaDesktopIntegration.cs index f66346f702..d7ea310fd9 100644 --- a/src/MaaWpfGui/WineCompat/MaaDesktopIntegration.cs +++ b/src/MaaWpfGui/WineCompat/MaaDesktopIntegration.cs @@ -1,4 +1,4 @@ -// +// // MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors // diff --git a/src/MaaWpfGui/WineCompat/WineBridgeAvailability.cs b/src/MaaWpfGui/WineCompat/WineBridgeAvailability.cs index 92d8afadb6..b91d8d82c0 100644 --- a/src/MaaWpfGui/WineCompat/WineBridgeAvailability.cs +++ b/src/MaaWpfGui/WineCompat/WineBridgeAvailability.cs @@ -1,6 +1,14 @@ // -// MaaWpfGui - A part of the MAA project +// MaaWpfGui - A part of the MaaCoreArknights project // Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License v3.0 only as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY // public enum WineBridgeAvailability