Clean up all code using CodeMaid

This commit is contained in:
2023-08-02 17:43:01 +08:00
parent e9a3f4014e
commit eef4687ed6
23 changed files with 176 additions and 43 deletions

View File

@ -29,6 +29,7 @@ using GrasscutterTools.Game;
using GrasscutterTools.Game.Gacha; using GrasscutterTools.Game.Gacha;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
using GrasscutterTools.Utils; using GrasscutterTools.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GrasscutterTools.Forms namespace GrasscutterTools.Forms
@ -504,6 +505,5 @@ namespace GrasscutterTools.Forms
} }
#endregion - - #endregion - -
} }
} }

View File

@ -305,7 +305,6 @@ namespace GrasscutterTools.Forms
#endregion - Init - #endregion - Init -
#region - HotKey - #region - HotKey -
/// <summary> /// <summary>
@ -612,6 +611,5 @@ namespace GrasscutterTools.Forms
} }
#endregion - General - #endregion - General -
} }
} }

View File

@ -62,4 +62,4 @@ namespace GrasscutterTools.Game.Activity
[JsonProperty("endTime")] [JsonProperty("endTime")]
public DateTime EndTime { get; set; } public DateTime EndTime { get; set; }
} }
} }

View File

@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.Activity
[JsonProperty("nameTextMapHash")] [JsonProperty("nameTextMapHash")]
public string NameTextMapHash { get; set; } public string NameTextMapHash { get; set; }
} }
} }

View File

@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.CutScene
[JsonProperty("path")] [JsonProperty("path")]
public string Path { get; set; } public string Path { get; set; }
} }
} }

View File

@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.Dungeon
[JsonProperty("nameTextMapHash")] [JsonProperty("nameTextMapHash")]
public string NameTextMapHash { get; set; } public string NameTextMapHash { get; set; }
} }
} }

View File

@ -71,7 +71,8 @@ namespace GrasscutterTools.Game
{ {
get get
{ {
foreach (var map in Values) { foreach (var map in Values)
{
var n = map[id]; var n = map[id];
if (n != ItemMap.EmptyName) if (n != ItemMap.EmptyName)
return n; return n;

View File

@ -48,8 +48,8 @@ namespace GrasscutterTools.OpenCommand
{ {
//try //try
//{ //{
var response = await DoRequest("ping"); var response = await DoRequest("ping");
return response.RetCode == 200; return response.RetCode == 200;
//} //}
//catch (Exception) //catch (Exception)
//{ //{

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using GrasscutterTools.Game; using GrasscutterTools.Game;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
using GrasscutterTools.Utils; using GrasscutterTools.Utils;
@ -98,4 +99,4 @@ namespace GrasscutterTools.Pages
GenSelected("/achievement progress", NUDProgress.Text); GenSelected("/achievement progress", NUDProgress.Text);
} }
} }
} }

View File

@ -200,6 +200,5 @@ namespace GrasscutterTools.Pages
LnkNewVersion.Visible = false; LnkNewVersion.Visible = false;
} }
} }
} }
} }

View File

@ -1,4 +1,23 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -6,6 +25,7 @@ using System.Windows.Forms;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
using GrasscutterTools.Utils; using GrasscutterTools.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GrasscutterTools.Pages namespace GrasscutterTools.Pages
@ -61,7 +81,7 @@ namespace GrasscutterTools.Pages
{ {
Logger.I(TAG, "Cancel all HotKeys"); Logger.I(TAG, "Cancel all HotKeys");
Common.KeyGo.UnRegAllKey(); Common.KeyGo.UnRegAllKey();
if (!HotKeysChanged) return; if (!HotKeysChanged) return;
Logger.I(TAG, "Save all HotKeys to: " + HotKeysFilePath); Logger.I(TAG, "Save all HotKeys to: " + HotKeysFilePath);
File.WriteAllText(HotKeysFilePath, JsonConvert.SerializeObject(Common.KeyGo.Items)); File.WriteAllText(HotKeysFilePath, JsonConvert.SerializeObject(Common.KeyGo.Items));
@ -75,7 +95,8 @@ namespace GrasscutterTools.Pages
item.Tag, item.Tag,
item.HotKey, item.HotKey,
item.Commands item.Commands
}) { Checked = item.IsEnabled }; })
{ Checked = item.IsEnabled };
/// <summary> /// <summary>
/// 列表选中项改变时触发 /// 列表选中项改变时触发
@ -225,7 +246,7 @@ namespace GrasscutterTools.Pages
{ {
// 如果操作失败,还原选项,禁止设置 // 如果操作失败,还原选项,禁止设置
e.NewValue = e.CurrentValue; e.NewValue = e.CurrentValue;
Logger.E(TAG, (isEnable ? "Enable" : "Disable") +" HotKey failed", ex); Logger.E(TAG, (isEnable ? "Enable" : "Disable") + " HotKey failed", ex);
MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
@ -240,4 +261,4 @@ namespace GrasscutterTools.Pages
TxtTag.Text = tag; TxtTag.Text = tag;
} }
} }
} }

View File

@ -75,7 +75,6 @@ namespace GrasscutterTools.Pages
Scenes = GameData.Dungeons.Lines; Scenes = GameData.Dungeons.Lines;
} }
/// <summary> /// <summary>
/// 选中过场时触发 /// 选中过场时触发
/// </summary> /// </summary>

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using GrasscutterTools.Game.Props; using GrasscutterTools.Game.Props;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
@ -94,4 +94,4 @@ namespace GrasscutterTools.Pages
LblPlayerPropertyDesc.Text = selectedItem.Description; LblPlayerPropertyDesc.Text = selectedItem.Description;
} }
} }
} }

View File

@ -4,11 +4,13 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using GrasscutterTools.Game; using GrasscutterTools.Game;
using GrasscutterTools.Game.Activity; using GrasscutterTools.Game.Activity;
using GrasscutterTools.Game.CutScene; using GrasscutterTools.Game.CutScene;
using GrasscutterTools.Game.Dungeon; using GrasscutterTools.Game.Dungeon;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GrasscutterTools.Pages namespace GrasscutterTools.Pages
@ -77,8 +79,6 @@ namespace GrasscutterTools.Pages
} }
} }
private void BtnConvertCutScene_Click(object sender, EventArgs e) private void BtnConvertCutScene_Click(object sender, EventArgs e)
{ {
var src = new OpenFileDialog var src = new OpenFileDialog
@ -114,7 +114,7 @@ namespace GrasscutterTools.Pages
Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text; Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text;
return true; return true;
} }
else else
{ {
MessageBox.Show("请填写正确的Res路径", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("请填写正确的Res路径", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false; return false;
@ -156,7 +156,7 @@ namespace GrasscutterTools.Pages
var dungeonFilePath = Path.Combine(TxtProjectResRoot.Text, language, "Dungeon.txt"); var dungeonFilePath = Path.Combine(TxtProjectResRoot.Text, language, "Dungeon.txt");
File.WriteAllLines( File.WriteAllLines(
dungeonFilePath, dungeonFilePath,
dungeons.Select(it => $"{it.Id}:{TextMapData.GetText(it.NameTextMapHash)}"), dungeons.Select(it => $"{it.Id}:{TextMapData.GetText(it.NameTextMapHash)}"),
Encoding.UTF8); Encoding.UTF8);
} }
@ -214,4 +214,4 @@ namespace GrasscutterTools.Pages
// Encoding.UTF8); // Encoding.UTF8);
} }
} }
} }

View File

@ -20,10 +20,10 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using GrasscutterTools.OpenCommand; using GrasscutterTools.OpenCommand;
using GrasscutterTools.Properties; using GrasscutterTools.Properties;
using GrasscutterTools.Utils; using GrasscutterTools.Utils;
@ -100,7 +100,6 @@ namespace GrasscutterTools
return 0; return 0;
} }
#region - - #region - -
/// <summary> /// <summary>
@ -155,7 +154,6 @@ namespace GrasscutterTools
// UID // UID
//Settings.Default.RemoteUid = decimal.Parse(parser.GetToggleValueOrDefault("uid", Settings.Default.RemoteUid.ToString())); //Settings.Default.RemoteUid = decimal.Parse(parser.GetToggleValueOrDefault("uid", Settings.Default.RemoteUid.ToString()));
if (!string.IsNullOrEmpty(Settings.Default.Host) && !string.IsNullOrEmpty(Settings.Default.TokenCache)) if (!string.IsNullOrEmpty(Settings.Default.Host) && !string.IsNullOrEmpty(Settings.Default.TokenCache))
{ {
Common.OC = new OpenCommandAPI(Settings.Default.Host, Settings.Default.TokenCache); Common.OC = new OpenCommandAPI(Settings.Default.Host, Settings.Default.TokenCache);
@ -218,7 +216,7 @@ namespace GrasscutterTools
return raw.Trim().Replace("\\r", "\r").Replace("\\n", "\n"); return raw.Trim().Replace("\\r", "\r").Replace("\\n", "\n");
} }
#endregion #endregion - -
#region - - #region - -

View File

@ -1,4 +1,23 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;

View File

@ -24,6 +24,7 @@ namespace GrasscutterTools.Utils
public static OpenCommandAPI OC { get; set; } public static OpenCommandAPI OC { get; set; }
private static string AppDataFolder { get; } = GetAppDataFolder(); private static string AppDataFolder { get; } = GetAppDataFolder();
private static string GetAppDataFolder() private static string GetAppDataFolder()
{ {
var dir = Path.Combine( var dir = Path.Combine(
@ -42,7 +43,6 @@ namespace GrasscutterTools.Utils
return Path.Combine(AppDataFolder, filename); return Path.Combine(AppDataFolder, filename);
} }
public static KeyGo KeyGo { get; set; } public static KeyGo KeyGo { get; set; }
} }
} }

View File

@ -1,4 +1,23 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,23 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace GrasscutterTools.Utils namespace GrasscutterTools.Utils
@ -10,12 +29,16 @@ namespace GrasscutterTools.Utils
{ {
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AttachConsole(int dwProcessId); private static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetStdHandle(StandardHandle nStdHandle); private static extern IntPtr GetStdHandle(StandardHandle nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetStdHandle(StandardHandle nStdHandle, IntPtr handle); private static extern bool SetStdHandle(StandardHandle nStdHandle, IntPtr handle);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
private static extern FileType GetFileType(IntPtr handle); private static extern FileType GetFileType(IntPtr handle);
//[DllImport("kernel32.dll", SetLastError = true)] //[DllImport("kernel32.dll", SetLastError = true)]
//[return: MarshalAs(UnmanagedType.Bool)] //[return: MarshalAs(UnmanagedType.Bool)]
//static extern bool AllocConsole(); //static extern bool AllocConsole();
@ -61,4 +84,4 @@ namespace GrasscutterTools.Utils
SetStdHandle(StandardHandle.Error, GetStdHandle(StandardHandle.Output)); SetStdHandle(StandardHandle.Error, GetStdHandle(StandardHandle.Output));
} }
} }
} }

View File

@ -1,4 +1,22 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GrasscutterTools.Utils namespace GrasscutterTools.Utils

View File

@ -1,4 +1,23 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -254,4 +273,4 @@ namespace GrasscutterTools.Utils
/// </value> /// </value>
public bool Handle { get; set; } public bool Handle { get; set; }
} }
} }

View File

@ -1,15 +1,34 @@
using System; /**
* Grasscutter Tools
* Copyright (C) 2023 jie65535
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace GrasscutterTools.Utils namespace GrasscutterTools.Utils
{ {
/// <summary> /// <summary>
/// Simple command line toggles parser: /// Simple command line toggles parser:
/// - toggles are identified with (any number of) '-' prefixes /// - toggles are identified with (any number of) '-' prefixes
/// - toggle can be with or without associated value /// - toggle can be with or without associated value
/// - toggles are case-insensitive /// - toggles are case-insensitive
/// ///
/// <example>--toggle_without_value -toggle value</example> /// <example>--toggle_without_value -toggle value</example>
/// <see cref="https://gist.github.com/jchapuis/64b5adf9d0f3062e6a72dded110a6028"/> /// <see cref="https://gist.github.com/jchapuis/64b5adf9d0f3062e6a72dded110a6028"/>
/// </summary> /// </summary>
@ -39,4 +58,4 @@ namespace GrasscutterTools.Utils
public bool IsEmpty => toggles.Count == 0; public bool IsEmpty => toggles.Count == 0;
} }
} }

View File

@ -46,7 +46,6 @@ namespace GrasscutterTools.Utils
listBox.EndUpdate(); listBox.EndUpdate();
} }
private static bool Contains(string source, string filter) private static bool Contains(string source, string filter)
{ {
source = source.ToLower(); source = source.ToLower();