From eef4687ed68b25ca83ed85fd89a8862038bb6fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Wed, 2 Aug 2023 17:43:01 +0800 Subject: [PATCH] Clean up all code using CodeMaid --- .../Forms/FormGachaBannersEditor3.cs | 2 +- Source/GrasscutterTools/Forms/FormMain.cs | 2 -- .../Game/Activity/ActivityConfigItem.cs | 2 +- .../Game/Activity/NewActivityItem.cs | 2 +- .../Game/CutScene/CutSceneItem.cs | 2 +- .../Game/Dungeon/DungeonItem.cs | 2 +- Source/GrasscutterTools/Game/ItemMapGroup.cs | 3 +- .../OpenCommand/OpenCommandAPI.cs | 4 +-- .../GrasscutterTools/Pages/PageAchievement.cs | 3 +- Source/GrasscutterTools/Pages/PageHome.cs | 1 - Source/GrasscutterTools/Pages/PageHotKey.cs | 31 ++++++++++++++++--- Source/GrasscutterTools/Pages/PageScene.cs | 1 - Source/GrasscutterTools/Pages/PageSetProp.cs | 4 +-- Source/GrasscutterTools/Pages/PageTools.cs | 10 +++--- Source/GrasscutterTools/Program.cs | 6 ++-- Source/GrasscutterTools/Utils/AppHotKey.cs | 21 ++++++++++++- Source/GrasscutterTools/Utils/Common.cs | 2 +- Source/GrasscutterTools/Utils/GithubHelper.cs | 21 ++++++++++++- Source/GrasscutterTools/Utils/GuiRedirect.cs | 27 ++++++++++++++-- Source/GrasscutterTools/Utils/HotKeyItem.cs | 20 +++++++++++- Source/GrasscutterTools/Utils/KeyGo.cs | 23 ++++++++++++-- Source/GrasscutterTools/Utils/ToggleParser.cs | 29 ++++++++++++++--- Source/GrasscutterTools/Utils/UIUtil.cs | 1 - 23 files changed, 176 insertions(+), 43 deletions(-) diff --git a/Source/GrasscutterTools/Forms/FormGachaBannersEditor3.cs b/Source/GrasscutterTools/Forms/FormGachaBannersEditor3.cs index b353960..6e379ad 100644 --- a/Source/GrasscutterTools/Forms/FormGachaBannersEditor3.cs +++ b/Source/GrasscutterTools/Forms/FormGachaBannersEditor3.cs @@ -29,6 +29,7 @@ using GrasscutterTools.Game; using GrasscutterTools.Game.Gacha; using GrasscutterTools.Properties; using GrasscutterTools.Utils; + using Newtonsoft.Json; namespace GrasscutterTools.Forms @@ -504,6 +505,5 @@ namespace GrasscutterTools.Forms } #endregion - 卡池参数 - - } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Forms/FormMain.cs b/Source/GrasscutterTools/Forms/FormMain.cs index 7c51b1e..9efc5c4 100644 --- a/Source/GrasscutterTools/Forms/FormMain.cs +++ b/Source/GrasscutterTools/Forms/FormMain.cs @@ -305,7 +305,6 @@ namespace GrasscutterTools.Forms #endregion - 初始化 Init - - #region - 快捷键执行 HotKey - /// @@ -612,6 +611,5 @@ namespace GrasscutterTools.Forms } #endregion - 通用 General - - } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Game/Activity/ActivityConfigItem.cs b/Source/GrasscutterTools/Game/Activity/ActivityConfigItem.cs index 03c245a..41cb95e 100644 --- a/Source/GrasscutterTools/Game/Activity/ActivityConfigItem.cs +++ b/Source/GrasscutterTools/Game/Activity/ActivityConfigItem.cs @@ -62,4 +62,4 @@ namespace GrasscutterTools.Game.Activity [JsonProperty("endTime")] public DateTime EndTime { get; set; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Game/Activity/NewActivityItem.cs b/Source/GrasscutterTools/Game/Activity/NewActivityItem.cs index e032ba5..d72becf 100644 --- a/Source/GrasscutterTools/Game/Activity/NewActivityItem.cs +++ b/Source/GrasscutterTools/Game/Activity/NewActivityItem.cs @@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.Activity [JsonProperty("nameTextMapHash")] public string NameTextMapHash { get; set; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Game/CutScene/CutSceneItem.cs b/Source/GrasscutterTools/Game/CutScene/CutSceneItem.cs index 28bba74..2626e2c 100644 --- a/Source/GrasscutterTools/Game/CutScene/CutSceneItem.cs +++ b/Source/GrasscutterTools/Game/CutScene/CutSceneItem.cs @@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.CutScene [JsonProperty("path")] public string Path { get; set; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Game/Dungeon/DungeonItem.cs b/Source/GrasscutterTools/Game/Dungeon/DungeonItem.cs index b7a5fed..b8994c7 100644 --- a/Source/GrasscutterTools/Game/Dungeon/DungeonItem.cs +++ b/Source/GrasscutterTools/Game/Dungeon/DungeonItem.cs @@ -29,4 +29,4 @@ namespace GrasscutterTools.Game.Dungeon [JsonProperty("nameTextMapHash")] public string NameTextMapHash { get; set; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Game/ItemMapGroup.cs b/Source/GrasscutterTools/Game/ItemMapGroup.cs index ddf296e..a93b985 100644 --- a/Source/GrasscutterTools/Game/ItemMapGroup.cs +++ b/Source/GrasscutterTools/Game/ItemMapGroup.cs @@ -71,7 +71,8 @@ namespace GrasscutterTools.Game { get { - foreach (var map in Values) { + foreach (var map in Values) + { var n = map[id]; if (n != ItemMap.EmptyName) return n; diff --git a/Source/GrasscutterTools/OpenCommand/OpenCommandAPI.cs b/Source/GrasscutterTools/OpenCommand/OpenCommandAPI.cs index 6641fa8..0c21531 100644 --- a/Source/GrasscutterTools/OpenCommand/OpenCommandAPI.cs +++ b/Source/GrasscutterTools/OpenCommand/OpenCommandAPI.cs @@ -48,8 +48,8 @@ namespace GrasscutterTools.OpenCommand { //try //{ - var response = await DoRequest("ping"); - return response.RetCode == 200; + var response = await DoRequest("ping"); + return response.RetCode == 200; //} //catch (Exception) //{ diff --git a/Source/GrasscutterTools/Pages/PageAchievement.cs b/Source/GrasscutterTools/Pages/PageAchievement.cs index 4d0a021..d6549ee 100644 --- a/Source/GrasscutterTools/Pages/PageAchievement.cs +++ b/Source/GrasscutterTools/Pages/PageAchievement.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Windows.Forms; + using GrasscutterTools.Game; using GrasscutterTools.Properties; using GrasscutterTools.Utils; @@ -98,4 +99,4 @@ namespace GrasscutterTools.Pages GenSelected("/achievement progress", NUDProgress.Text); } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageHome.cs b/Source/GrasscutterTools/Pages/PageHome.cs index 3011b5b..0dd4e39 100644 --- a/Source/GrasscutterTools/Pages/PageHome.cs +++ b/Source/GrasscutterTools/Pages/PageHome.cs @@ -200,6 +200,5 @@ namespace GrasscutterTools.Pages LnkNewVersion.Visible = false; } } - } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageHotKey.cs b/Source/GrasscutterTools/Pages/PageHotKey.cs index 2d43319..4818790 100644 --- a/Source/GrasscutterTools/Pages/PageHotKey.cs +++ b/Source/GrasscutterTools/Pages/PageHotKey.cs @@ -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 . + * + **/ + +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -6,6 +25,7 @@ using System.Windows.Forms; using GrasscutterTools.Properties; using GrasscutterTools.Utils; + using Newtonsoft.Json; namespace GrasscutterTools.Pages @@ -61,7 +81,7 @@ namespace GrasscutterTools.Pages { Logger.I(TAG, "Cancel all HotKeys"); Common.KeyGo.UnRegAllKey(); - + if (!HotKeysChanged) return; Logger.I(TAG, "Save all HotKeys to: " + HotKeysFilePath); File.WriteAllText(HotKeysFilePath, JsonConvert.SerializeObject(Common.KeyGo.Items)); @@ -75,7 +95,8 @@ namespace GrasscutterTools.Pages item.Tag, item.HotKey, item.Commands - }) { Checked = item.IsEnabled }; + }) + { Checked = item.IsEnabled }; /// /// 列表选中项改变时触发 @@ -225,7 +246,7 @@ namespace GrasscutterTools.Pages { // 如果操作失败,还原选项,禁止设置 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); } } @@ -240,4 +261,4 @@ namespace GrasscutterTools.Pages TxtTag.Text = tag; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageScene.cs b/Source/GrasscutterTools/Pages/PageScene.cs index 681b2da..cbebc50 100644 --- a/Source/GrasscutterTools/Pages/PageScene.cs +++ b/Source/GrasscutterTools/Pages/PageScene.cs @@ -75,7 +75,6 @@ namespace GrasscutterTools.Pages Scenes = GameData.Dungeons.Lines; } - /// /// 选中过场时触发 /// diff --git a/Source/GrasscutterTools/Pages/PageSetProp.cs b/Source/GrasscutterTools/Pages/PageSetProp.cs index dfa3273..9cb3f48 100644 --- a/Source/GrasscutterTools/Pages/PageSetProp.cs +++ b/Source/GrasscutterTools/Pages/PageSetProp.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; -using System.Linq; using System.Windows.Forms; + using GrasscutterTools.Game.Props; using GrasscutterTools.Properties; @@ -94,4 +94,4 @@ namespace GrasscutterTools.Pages LblPlayerPropertyDesc.Text = selectedItem.Description; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Pages/PageTools.cs b/Source/GrasscutterTools/Pages/PageTools.cs index b2dc127..6b809c2 100644 --- a/Source/GrasscutterTools/Pages/PageTools.cs +++ b/Source/GrasscutterTools/Pages/PageTools.cs @@ -4,11 +4,13 @@ using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; + using GrasscutterTools.Game; using GrasscutterTools.Game.Activity; using GrasscutterTools.Game.CutScene; using GrasscutterTools.Game.Dungeon; using GrasscutterTools.Properties; + using Newtonsoft.Json; namespace GrasscutterTools.Pages @@ -77,8 +79,6 @@ namespace GrasscutterTools.Pages } } - - private void BtnConvertCutScene_Click(object sender, EventArgs e) { var src = new OpenFileDialog @@ -114,7 +114,7 @@ namespace GrasscutterTools.Pages Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text; return true; } - else + else { MessageBox.Show("请填写正确的Res路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; @@ -156,7 +156,7 @@ namespace GrasscutterTools.Pages var dungeonFilePath = Path.Combine(TxtProjectResRoot.Text, language, "Dungeon.txt"); File.WriteAllLines( - dungeonFilePath, + dungeonFilePath, dungeons.Select(it => $"{it.Id}:{TextMapData.GetText(it.NameTextMapHash)}"), Encoding.UTF8); } @@ -214,4 +214,4 @@ namespace GrasscutterTools.Pages // Encoding.UTF8); } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Program.cs b/Source/GrasscutterTools/Program.cs index 25b44ed..abf8e8b 100644 --- a/Source/GrasscutterTools/Program.cs +++ b/Source/GrasscutterTools/Program.cs @@ -20,10 +20,10 @@ using System; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Windows.Forms; + using GrasscutterTools.OpenCommand; using GrasscutterTools.Properties; using GrasscutterTools.Utils; @@ -100,7 +100,6 @@ namespace GrasscutterTools return 0; } - #region - 命令行参数 - /// @@ -155,7 +154,6 @@ namespace GrasscutterTools // UID //Settings.Default.RemoteUid = decimal.Parse(parser.GetToggleValueOrDefault("uid", Settings.Default.RemoteUid.ToString())); - if (!string.IsNullOrEmpty(Settings.Default.Host) && !string.IsNullOrEmpty(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"); } - #endregion + #endregion - 命令行参数 - #region - 全局异常处理 - diff --git a/Source/GrasscutterTools/Utils/AppHotKey.cs b/Source/GrasscutterTools/Utils/AppHotKey.cs index 4228120..898b019 100644 --- a/Source/GrasscutterTools/Utils/AppHotKey.cs +++ b/Source/GrasscutterTools/Utils/AppHotKey.cs @@ -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 . + * + **/ + +using System; using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Forms; diff --git a/Source/GrasscutterTools/Utils/Common.cs b/Source/GrasscutterTools/Utils/Common.cs index b15491a..20bc111 100644 --- a/Source/GrasscutterTools/Utils/Common.cs +++ b/Source/GrasscutterTools/Utils/Common.cs @@ -24,6 +24,7 @@ namespace GrasscutterTools.Utils public static OpenCommandAPI OC { get; set; } private static string AppDataFolder { get; } = GetAppDataFolder(); + private static string GetAppDataFolder() { var dir = Path.Combine( @@ -42,7 +43,6 @@ namespace GrasscutterTools.Utils return Path.Combine(AppDataFolder, filename); } - public static KeyGo KeyGo { get; set; } } } \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/GithubHelper.cs b/Source/GrasscutterTools/Utils/GithubHelper.cs index ce1c1fa..e9cd38b 100644 --- a/Source/GrasscutterTools/Utils/GithubHelper.cs +++ b/Source/GrasscutterTools/Utils/GithubHelper.cs @@ -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 . + * + **/ + +using System; using System.Net.Http.Headers; using System.Threading.Tasks; diff --git a/Source/GrasscutterTools/Utils/GuiRedirect.cs b/Source/GrasscutterTools/Utils/GuiRedirect.cs index 62e4443..04d8d95 100644 --- a/Source/GrasscutterTools/Utils/GuiRedirect.cs +++ b/Source/GrasscutterTools/Utils/GuiRedirect.cs @@ -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 . + * + **/ + +using System; using System.Runtime.InteropServices; namespace GrasscutterTools.Utils @@ -10,12 +29,16 @@ namespace GrasscutterTools.Utils { [DllImport("kernel32.dll", SetLastError = true)] private static extern bool AttachConsole(int dwProcessId); + [DllImport("kernel32.dll", SetLastError = true)] private static extern IntPtr GetStdHandle(StandardHandle nStdHandle); + [DllImport("kernel32.dll", SetLastError = true)] private static extern bool SetStdHandle(StandardHandle nStdHandle, IntPtr handle); + [DllImport("kernel32.dll", SetLastError = true)] private static extern FileType GetFileType(IntPtr handle); + //[DllImport("kernel32.dll", SetLastError = true)] //[return: MarshalAs(UnmanagedType.Bool)] //static extern bool AllocConsole(); @@ -61,4 +84,4 @@ namespace GrasscutterTools.Utils SetStdHandle(StandardHandle.Error, GetStdHandle(StandardHandle.Output)); } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/HotKeyItem.cs b/Source/GrasscutterTools/Utils/HotKeyItem.cs index c9777ca..4ccc98e 100644 --- a/Source/GrasscutterTools/Utils/HotKeyItem.cs +++ b/Source/GrasscutterTools/Utils/HotKeyItem.cs @@ -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 . + * + **/ + using Newtonsoft.Json; namespace GrasscutterTools.Utils diff --git a/Source/GrasscutterTools/Utils/KeyGo.cs b/Source/GrasscutterTools/Utils/KeyGo.cs index 29e54a2..f6f4010 100644 --- a/Source/GrasscutterTools/Utils/KeyGo.cs +++ b/Source/GrasscutterTools/Utils/KeyGo.cs @@ -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 . + * + **/ + +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -254,4 +273,4 @@ namespace GrasscutterTools.Utils /// public bool Handle { get; set; } } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/ToggleParser.cs b/Source/GrasscutterTools/Utils/ToggleParser.cs index e537e22..1f7eb51 100644 --- a/Source/GrasscutterTools/Utils/ToggleParser.cs +++ b/Source/GrasscutterTools/Utils/ToggleParser.cs @@ -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 . + * + **/ + +using System; using System.Collections.Generic; using System.Linq; namespace GrasscutterTools.Utils { /// - /// Simple command line toggles parser: + /// Simple command line toggles parser: /// - 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 - /// + /// /// --toggle_without_value -toggle value /// /// @@ -39,4 +58,4 @@ namespace GrasscutterTools.Utils public bool IsEmpty => toggles.Count == 0; } -} +} \ No newline at end of file diff --git a/Source/GrasscutterTools/Utils/UIUtil.cs b/Source/GrasscutterTools/Utils/UIUtil.cs index 0827868..e2bb76b 100644 --- a/Source/GrasscutterTools/Utils/UIUtil.cs +++ b/Source/GrasscutterTools/Utils/UIUtil.cs @@ -46,7 +46,6 @@ namespace GrasscutterTools.Utils listBox.EndUpdate(); } - private static bool Contains(string source, string filter) { source = source.ToLower();