mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
perf: fix c# warnings & suggestions
link to https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1611
This commit is contained in:
@@ -167,6 +167,10 @@ dotnet_diagnostic.IDE0044.severity = warning
|
||||
dotnet_public_api_analyzer.require_api_files = true
|
||||
|
||||
# CSharp code style settings:
|
||||
|
||||
# IDE0060: Remove unused parameter
|
||||
dotnet_diagnostic.IDE0060.severity = silent
|
||||
|
||||
[*.cs]
|
||||
# Newline settings
|
||||
csharp_new_line_before_open_brace = all
|
||||
@@ -191,9 +195,9 @@ csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
|
||||
|
||||
# Prefer "var" everywhere
|
||||
csharp_style_var_for_built_in_types = true:suggestion
|
||||
csharp_style_var_when_type_is_apparent = true:suggestion
|
||||
csharp_style_var_elsewhere = true:suggestion
|
||||
csharp_style_var_for_built_in_types = true:silent
|
||||
csharp_style_var_when_type_is_apparent = true:silent
|
||||
csharp_style_var_elsewhere = true:silent
|
||||
|
||||
# Prefer method-like constructs to have a block body
|
||||
csharp_style_expression_bodied_methods = false:none
|
||||
@@ -260,6 +264,9 @@ dotnet_diagnostic.SA1642.severity = suggestion
|
||||
# SA1623: Property summary documentation should match accessors
|
||||
dotnet_diagnostic.SA1623.severity = suggestion
|
||||
|
||||
# IDE0007: Prefer "var" everywhere
|
||||
dotnet_diagnostic.IDE0007.severity = silent
|
||||
|
||||
[src/CodeStyle/**.{cs,vb}]
|
||||
# warning RS0005: Do not use generic CodeAction.Create to create CodeAction
|
||||
dotnet_diagnostic.RS0005.severity = none
|
||||
|
||||
@@ -726,16 +726,18 @@ namespace MeoAsstGui
|
||||
mainModel.AddLog(level + " ★ Tags", LogColor.Info);
|
||||
}
|
||||
|
||||
// bool robot = (bool)subTaskDetails["robot"];
|
||||
// if (robot)
|
||||
// {
|
||||
// using (var toast = new ToastNotification(Localization.GetString("RecruitmentOfBot")))
|
||||
// {
|
||||
// toast.AppendContentText(new string('★', 1)).ShowRecruitRobot(row: 2);
|
||||
// }
|
||||
/*
|
||||
bool robot = (bool)subTaskDetails["robot"];
|
||||
if (robot)
|
||||
{
|
||||
using (var toast = new ToastNotification(Localization.GetString("RecruitmentOfBot")))
|
||||
{
|
||||
toast.AppendContentText(new string('★', 1)).ShowRecruitRobot(row: 2);
|
||||
}
|
||||
|
||||
// mainModel.AddLog(1 + " ★ Tag", LogColor.RobotOperator, "Bold");
|
||||
// }
|
||||
mainModel.AddLog(1 + " ★ Tag", LogColor.RobotOperator, "Bold");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -34,7 +35,9 @@ namespace MeoAsstGui
|
||||
/// </summary>
|
||||
public class CopilotViewModel : Screen
|
||||
{
|
||||
#pragma warning disable IDE0052 // 删除未读的私有成员
|
||||
private readonly IWindowManager _windowManager;
|
||||
#pragma warning restore IDE0052 // 删除未读的私有成员
|
||||
private readonly IContainer _container;
|
||||
|
||||
/// <summary>
|
||||
@@ -59,6 +62,7 @@ namespace MeoAsstGui
|
||||
Localization.GetString("CopilotTip2") + "\n\n" +
|
||||
Localization.GetString("CopilotTip3") + "\n\n" +
|
||||
Localization.GetString("CopilotTip4"),
|
||||
/* Localization.GetString("CopilotTip5"),*/
|
||||
LogColor.Message);
|
||||
}
|
||||
|
||||
@@ -128,7 +132,7 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string CopilotIdPrefix = "maa://";
|
||||
private const string CopilotIdPrefix = "maa://";
|
||||
|
||||
private void UpdateFileDoc(string filename)
|
||||
{
|
||||
@@ -147,15 +151,13 @@ namespace MeoAsstGui
|
||||
}
|
||||
else if (int.TryParse(filename, out _))
|
||||
{
|
||||
int copilotID;
|
||||
int.TryParse(filename, out copilotID);
|
||||
int.TryParse(filename, out int copilotID);
|
||||
jsonStr = RequestCopilotServer(copilotID);
|
||||
}
|
||||
else if (filename.ToLower().StartsWith(CopilotIdPrefix))
|
||||
{
|
||||
var copilotIdStr = filename.ToLower().Remove(0, CopilotIdPrefix.Length);
|
||||
int copilotID;
|
||||
int.TryParse(copilotIdStr, out copilotID);
|
||||
int.TryParse(copilotIdStr, out int copilotID);
|
||||
jsonStr = RequestCopilotServer(copilotID);
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ namespace MeoAsstGui
|
||||
|
||||
private string _curStageName = string.Empty;
|
||||
private string _curCopilotData = string.Empty;
|
||||
private const string _tempCopilotFile = "resource/_temp_copilot.json";
|
||||
private const string TempCopilotFile = "resource/_temp_copilot.json";
|
||||
|
||||
private void ParseJsonAndShowInfo(string jsonStr)
|
||||
{
|
||||
@@ -272,7 +274,7 @@ namespace MeoAsstGui
|
||||
|
||||
AddLog(string.Empty, LogColor.Message);
|
||||
int count = 0;
|
||||
foreach (JObject oper in json["opers"])
|
||||
foreach (var oper in json["opers"].Cast<JObject>())
|
||||
{
|
||||
count++;
|
||||
AddLog(string.Format("{0}, {1} 技能", oper["name"], oper["skill"]), LogColor.Message);
|
||||
@@ -280,12 +282,12 @@ namespace MeoAsstGui
|
||||
|
||||
if (json.ContainsKey("groups"))
|
||||
{
|
||||
foreach (JObject group in json["groups"])
|
||||
foreach (var group in json["groups"].Cast<JObject>())
|
||||
{
|
||||
count++;
|
||||
string group_name = group["name"] + ": ";
|
||||
var operInfos = new List<string>();
|
||||
foreach (JObject oper in group["opers"])
|
||||
foreach (var oper in group["opers"].Cast<JObject>())
|
||||
{
|
||||
operInfos.Add(string.Format("{0} {1}", oper["name"], oper["skill"]));
|
||||
}
|
||||
@@ -305,6 +307,7 @@ namespace MeoAsstGui
|
||||
Localization.GetString("CopilotTip2") + "\n\n" +
|
||||
Localization.GetString("CopilotTip3") + "\n\n" +
|
||||
Localization.GetString("CopilotTip4"));
|
||||
/* Localization.GetString("CopilotTip5"));*/
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -317,9 +320,10 @@ namespace MeoAsstGui
|
||||
/// </summary>
|
||||
public void SelectFile()
|
||||
{
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog();
|
||||
|
||||
dialog.Filter = "JSON|*.json";
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
Filter = "JSON|*.json",
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
@@ -376,11 +380,12 @@ namespace MeoAsstGui
|
||||
public async void Start()
|
||||
{
|
||||
ClearLog();
|
||||
/*
|
||||
if (_form)
|
||||
{
|
||||
AddLog(Localization.GetString("AutoSquadTip"), LogColor.Message);
|
||||
}*/
|
||||
|
||||
// if (_form)
|
||||
// {
|
||||
// AddLog(Localization.GetString("AutoSquadTip"), LogColor.Message);
|
||||
// }
|
||||
AddLog(Localization.GetString("ConnectingToEmulator"));
|
||||
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
@@ -402,10 +407,10 @@ namespace MeoAsstGui
|
||||
}
|
||||
|
||||
UpdateFileDoc(Filename);
|
||||
File.Delete(_tempCopilotFile);
|
||||
File.WriteAllText(_tempCopilotFile, _curCopilotData);
|
||||
File.Delete(TempCopilotFile);
|
||||
File.WriteAllText(TempCopilotFile, _curCopilotData);
|
||||
|
||||
bool ret = asstProxy.AsstStartCopilot(_curStageName, _tempCopilotFile, Form);
|
||||
bool ret = asstProxy.AsstStartCopilot(_curStageName, TempCopilotFile, Form);
|
||||
if (ret)
|
||||
{
|
||||
Idle = false;
|
||||
@@ -427,7 +432,7 @@ namespace MeoAsstGui
|
||||
Idle = true;
|
||||
}
|
||||
|
||||
private static readonly string CopilotUiUrl = "https://www.prts.plus/";
|
||||
private const string CopilotUiUrl = "https://www.prts.plus/";
|
||||
private string _url = CopilotUiUrl;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace MeoAsstGui
|
||||
private void InfrastInit()
|
||||
{
|
||||
/* 基建设置 */
|
||||
string[] facility_list = new string[]
|
||||
var facility_list = new string[]
|
||||
{
|
||||
Localization.GetString("Mfg"),
|
||||
Localization.GetString("Trade"),
|
||||
@@ -122,8 +122,7 @@ namespace MeoAsstGui
|
||||
for (int i = 0; i != facility_list.Length; ++i)
|
||||
{
|
||||
var facility = facility_list[i];
|
||||
int order;
|
||||
bool parsed = int.TryParse(ViewStatusStorage.Get("Infrast.Order." + facility, "-1"), out order);
|
||||
bool parsed = int.TryParse(ViewStatusStorage.Get("Infrast.Order." + facility, "-1"), out int order);
|
||||
|
||||
if (!parsed || order < 0)
|
||||
{
|
||||
@@ -386,8 +385,7 @@ namespace MeoAsstGui
|
||||
Process.Start(EmulatorPath);
|
||||
}
|
||||
|
||||
int delay;
|
||||
if (!int.TryParse(EmulatorWaitSeconds, out delay))
|
||||
if (!int.TryParse(EmulatorWaitSeconds, out int delay))
|
||||
{
|
||||
delay = 60;
|
||||
}
|
||||
@@ -400,9 +398,10 @@ namespace MeoAsstGui
|
||||
/// </summary>
|
||||
public void SelectEmulatorExec()
|
||||
{
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog();
|
||||
|
||||
dialog.Filter = Localization.GetString("Executable") + "|*.exe;*.bat;*.lnk";
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
Filter = Localization.GetString("Executable") + "|*.exe;*.bat;*.lnk",
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
@@ -429,7 +428,7 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, string> ServerMapping = new Dictionary<string, string>
|
||||
private readonly Dictionary<string, string> _serverMapping = new Dictionary<string, string>
|
||||
{
|
||||
{ string.Empty, "CN" },
|
||||
{ "Official", "CN" },
|
||||
@@ -441,13 +440,13 @@ namespace MeoAsstGui
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets server type.
|
||||
/// Gets the server type.
|
||||
/// </summary>
|
||||
public string ServerType
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServerMapping[ClientType];
|
||||
return _serverMapping[ClientType];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1660,9 +1659,10 @@ namespace MeoAsstGui
|
||||
/// </summary>
|
||||
public void SelectFile()
|
||||
{
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog();
|
||||
|
||||
dialog.Filter = Localization.GetString("ADBProgram") + "|*.exe";
|
||||
var dialog = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
Filter = Localization.GetString("ADBProgram") + "|*.exe",
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
@@ -1676,8 +1676,8 @@ namespace MeoAsstGui
|
||||
public void UpdateWindowTitle()
|
||||
{
|
||||
var rvm = (RootViewModel)this.Parent;
|
||||
string connectConfigName = string.Empty;
|
||||
foreach (CombData data in ConnectConfigList)
|
||||
var connectConfigName = string.Empty;
|
||||
foreach (var data in ConnectConfigList)
|
||||
{
|
||||
if (data.Value == ConnectConfig)
|
||||
{
|
||||
@@ -1720,6 +1720,7 @@ namespace MeoAsstGui
|
||||
|
||||
/* 界面设置 */
|
||||
#pragma warning disable SA1401 // Fields should be private
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to use tray icon.
|
||||
@@ -1727,25 +1728,28 @@ namespace MeoAsstGui
|
||||
public bool UseTray = true;
|
||||
|
||||
#pragma warning restore SA1401 // Fields should be private
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
// private bool _useTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseTray", bool.TrueString));
|
||||
/*
|
||||
private bool _useTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseTray", bool.TrueString));
|
||||
|
||||
// public bool UseTray
|
||||
// {
|
||||
// get { return _useTray; }
|
||||
// set
|
||||
// {
|
||||
// SetAndNotify(ref _useTray, value);
|
||||
// ViewStatusStorage.Set("GUI.UseTray", value.ToString());
|
||||
// var trayObj = _container.Get<TrayIcon>();
|
||||
// trayObj.SetVisible(value);
|
||||
public bool UseTray
|
||||
{
|
||||
get { return _useTray; }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _useTray, value);
|
||||
ViewStatusStorage.Set("GUI.UseTray", value.ToString());
|
||||
var trayObj = _container.Get<TrayIcon>();
|
||||
trayObj.SetVisible(value);
|
||||
|
||||
if (!Convert.ToBoolean(value))
|
||||
{
|
||||
MinimizeToTray = false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// if (!Convert.ToBoolean(value))
|
||||
// {
|
||||
// MinimizeToTray = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
private bool _minimizeToTray = Convert.ToBoolean(ViewStatusStorage.Get("GUI.MinimizeToTray", bool.FalseString));
|
||||
|
||||
/// <summary>
|
||||
@@ -1872,8 +1876,7 @@ namespace MeoAsstGui
|
||||
|
||||
set
|
||||
{
|
||||
bool parsed = Enum.TryParse(value, out InverseClearType tempEnumValue);
|
||||
if (!parsed)
|
||||
if (!Enum.TryParse(value, out InverseClearType tempEnumValue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1931,7 +1934,7 @@ namespace MeoAsstGui
|
||||
Cheers = false;
|
||||
}
|
||||
|
||||
var backup = _language;
|
||||
// var backup = _language;
|
||||
ViewStatusStorage.Set("GUI.Localization", value);
|
||||
System.Windows.Forms.MessageBoxManager.Yes = Localization.GetString("Ok", value);
|
||||
System.Windows.Forms.MessageBoxManager.No = Localization.GetString("ManualRestart", value);
|
||||
@@ -1974,7 +1977,7 @@ namespace MeoAsstGui
|
||||
ViewStatusStorage.Set("GUI.Cheers", value.ToString());
|
||||
if (_cheers)
|
||||
{
|
||||
setPallasLanguage();
|
||||
SetPallasLanguage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1998,7 +2001,7 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private void setPallasLanguage()
|
||||
private void SetPallasLanguage()
|
||||
{
|
||||
ViewStatusStorage.Set("GUI.Localization", PallasLangKey);
|
||||
var result = _windowManager.ShowMessageBox(
|
||||
|
||||
Reference in New Issue
Block a user