Skip to content

Commit

Permalink
Clean up all code using CodeMaid
Browse files Browse the repository at this point in the history
  • Loading branch information
jie65535 committed Aug 2, 2023
1 parent e9a3f40 commit eef4687
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Forms/FormGachaBannersEditor3.cs
Expand Up @@ -29,6 +29,7 @@
using GrasscutterTools.Game.Gacha;
using GrasscutterTools.Properties;
using GrasscutterTools.Utils;

using Newtonsoft.Json;

namespace GrasscutterTools.Forms
Expand Down Expand Up @@ -504,6 +505,5 @@ private GachaBanner3 ParseBanner()
}

#endregion - 卡池参数 -

}
}
2 changes: 0 additions & 2 deletions Source/GrasscutterTools/Forms/FormMain.cs
Expand Up @@ -305,7 +305,6 @@ private void SaveSettings()

#endregion - 初始化 Init -


#region - 快捷键执行 HotKey -

/// <summary>
Expand Down Expand Up @@ -612,6 +611,5 @@ private void ShowTip(string message, Control control)
}

#endregion - 通用 General -

}
}
Expand Up @@ -62,4 +62,4 @@ public class ActivityConfigItem
[JsonProperty("endTime")]
public DateTime EndTime { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Game/Activity/NewActivityItem.cs
Expand Up @@ -29,4 +29,4 @@ internal class NewActivityItem
[JsonProperty("nameTextMapHash")]
public string NameTextMapHash { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Game/CutScene/CutSceneItem.cs
Expand Up @@ -29,4 +29,4 @@ internal class CutSceneItem
[JsonProperty("path")]
public string Path { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Game/Dungeon/DungeonItem.cs
Expand Up @@ -29,4 +29,4 @@ internal class DungeonItem
[JsonProperty("nameTextMapHash")]
public string NameTextMapHash { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion Source/GrasscutterTools/Game/ItemMapGroup.cs
Expand Up @@ -71,7 +71,8 @@ public ItemMapGroup(string idNamePairs)
{
get
{
foreach (var map in Values) {
foreach (var map in Values)
{
var n = map[id];
if (n != ItemMap.EmptyName)
return n;
Expand Down
4 changes: 2 additions & 2 deletions Source/GrasscutterTools/OpenCommand/OpenCommandAPI.cs
Expand Up @@ -48,8 +48,8 @@ public async Task<bool> Ping()
{
//try
//{
var response = await DoRequest("ping");
return response.RetCode == 200;
var response = await DoRequest("ping");
return response.RetCode == 200;
//}
//catch (Exception)
//{
Expand Down
3 changes: 2 additions & 1 deletion 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;
Expand Down Expand Up @@ -98,4 +99,4 @@ private void BtnProgress_Click(object sender, EventArgs e)
GenSelected("/achievement progress", NUDProgress.Text);
}
}
}
}
1 change: 0 additions & 1 deletion Source/GrasscutterTools/Pages/PageHome.cs
Expand Up @@ -200,6 +200,5 @@ private void LnkNewVersion_LinkClicked(object sender, LinkLabelLinkClickedEventA
LnkNewVersion.Visible = false;
}
}

}
}
31 changes: 26 additions & 5 deletions Source/GrasscutterTools/Pages/PageHotKey.cs
@@ -1,11 +1,31 @@
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.IO;
using System.Linq;
using System.Windows.Forms;

using GrasscutterTools.Properties;
using GrasscutterTools.Utils;

using Newtonsoft.Json;

namespace GrasscutterTools.Pages
Expand Down Expand Up @@ -61,7 +81,7 @@ public override void OnClosed()
{
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));
Expand All @@ -75,7 +95,8 @@ public override void OnClosed()
item.Tag,
item.HotKey,
item.Commands
}) { Checked = item.IsEnabled };
})
{ Checked = item.IsEnabled };

/// <summary>
/// 列表选中项改变时触发
Expand Down Expand Up @@ -225,7 +246,7 @@ private void LvHotKeyList_ItemCheck(object sender, ItemCheckEventArgs e)
{
// 如果操作失败,还原选项,禁止设置
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);
}
}
Expand All @@ -240,4 +261,4 @@ public void AddNewHotKey(string tag)
TxtTag.Text = tag;
}
}
}
}
1 change: 0 additions & 1 deletion Source/GrasscutterTools/Pages/PageScene.cs
Expand Up @@ -75,7 +75,6 @@ private void RbListDungeons_CheckedChanged(object sender, EventArgs e)
Scenes = GameData.Dungeons.Lines;
}


/// <summary>
/// 选中过场时触发
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions 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;

Expand Down Expand Up @@ -94,4 +94,4 @@ private void CmbPlayerProperty_SelectedIndexChanged(object sender, EventArgs e)
LblPlayerPropertyDesc.Text = selectedItem.Description;
}
}
}
}
10 changes: 5 additions & 5 deletions Source/GrasscutterTools/Pages/PageTools.cs
Expand Up @@ -4,11 +4,13 @@
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
Expand Down Expand Up @@ -77,8 +79,6 @@ private void BtnUpdateResources_Click(object sender, EventArgs e)
}
}



private void BtnConvertCutScene_Click(object sender, EventArgs e)
{
var src = new OpenFileDialog
Expand Down Expand Up @@ -114,7 +114,7 @@ private bool CheckInputPaths()
Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text;
return true;
}
else
else
{
MessageBox.Show("请填写正确的Res路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
Expand Down Expand Up @@ -156,7 +156,7 @@ private void UpdateDungeonsForLanguage(IEnumerable<DungeonItem> dungeons, string

var dungeonFilePath = Path.Combine(TxtProjectResRoot.Text, language, "Dungeon.txt");
File.WriteAllLines(
dungeonFilePath,
dungeonFilePath,
dungeons.Select(it => $"{it.Id}:{TextMapData.GetText(it.NameTextMapHash)}"),
Encoding.UTF8);
}
Expand Down Expand Up @@ -214,4 +214,4 @@ private void UpdateActivityForLanguage(IReadOnlyCollection<NewActivityItem> acti
// Encoding.UTF8);
}
}
}
}
6 changes: 2 additions & 4 deletions Source/GrasscutterTools/Program.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +100,6 @@ private static int Main(string[] args)
return 0;
}


#region - 命令行参数 -

/// <summary>
Expand Down Expand Up @@ -155,7 +154,6 @@ private static int HandleCommandLine(string[] args)
// 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);
Expand Down Expand Up @@ -218,7 +216,7 @@ private static string FormatCommand(string raw)
return raw.Trim().Replace("\\r", "\r").Replace("\\n", "\n");
}

#endregion
#endregion - 命令行参数 -

#region - 全局异常处理 -

Expand Down
21 changes: 20 additions & 1 deletion 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 <https://www.gnu.org/licenses/>.
*
**/

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
Expand Down
2 changes: 1 addition & 1 deletion Source/GrasscutterTools/Utils/Common.cs
Expand Up @@ -24,6 +24,7 @@ internal static class Common
public static OpenCommandAPI OC { get; set; }

private static string AppDataFolder { get; } = GetAppDataFolder();

private static string GetAppDataFolder()
{
var dir = Path.Combine(
Expand All @@ -42,7 +43,6 @@ public static string GetAppDataFile(string filename)
return Path.Combine(AppDataFolder, filename);
}


public static KeyGo KeyGo { get; set; }
}
}
21 changes: 20 additions & 1 deletion 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 <https://www.gnu.org/licenses/>.
*
**/

using System;
using System.Net.Http.Headers;
using System.Threading.Tasks;

Expand Down
27 changes: 25 additions & 2 deletions 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 <https://www.gnu.org/licenses/>.
*
**/

using System;
using System.Runtime.InteropServices;

namespace GrasscutterTools.Utils
Expand All @@ -10,12 +29,16 @@ public class GuiRedirect
{
[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();
Expand Down Expand Up @@ -61,4 +84,4 @@ public static void Redirect()
SetStdHandle(StandardHandle.Error, GetStdHandle(StandardHandle.Output));
}
}
}
}

0 comments on commit eef4687

Please sign in to comment.