mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-10-21 19:59:48 +08:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d8d199af7 | |||
c4e29dc000 | |||
72ec031f8a | |||
2300b8d5db | |||
7ec81ab146 | |||
cf3ffeb8c6 | |||
118a7fe0f1 | |||
005c68cc5b |
@@ -34,9 +34,11 @@ namespace GrasscutterTools.Forms
|
||||
{
|
||||
#region - 初始化 Init -
|
||||
|
||||
private const string TAG = "FormMain";
|
||||
|
||||
public FormMain()
|
||||
{
|
||||
Console.WriteLine("FormMain ctor enter");
|
||||
Logger.I(TAG, "FormMain ctor enter");
|
||||
InitializeComponent();
|
||||
Icon = Resources.IconGrasscutter;
|
||||
|
||||
@@ -44,31 +46,34 @@ namespace GrasscutterTools.Forms
|
||||
|
||||
try
|
||||
{
|
||||
var location = Settings.Default.MainFormLocation;
|
||||
// 还原窗体位置
|
||||
if (Settings.Default.MainFormLocation != default)
|
||||
if (location.X > 0 && location.Y > 0)
|
||||
{
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
Location = Settings.Default.MainFormLocation;
|
||||
Console.WriteLine("Restore window location: " + Location.ToString());
|
||||
Location = location;
|
||||
Logger.I(TAG, "Restore window location: " + Location.ToString());
|
||||
}
|
||||
|
||||
// 还原窗体大小
|
||||
if (Settings.Default.MainFormSize != default)
|
||||
{
|
||||
Size = Settings.Default.MainFormSize;
|
||||
Console.WriteLine("Restore window size: " + Size.ToString());
|
||||
Logger.I(TAG, "Restore window size: " + Size.ToString());
|
||||
}
|
||||
|
||||
// 恢复自动复制选项状态
|
||||
ChkAutoCopy.Checked = Settings.Default.AutoCopy;
|
||||
|
||||
// 初始化页面
|
||||
InitPages();
|
||||
// 恢复自动复制选项状态
|
||||
ChkAutoCopy.Checked = Settings.Default.AutoCopy;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.E(TAG, "Loading settings error", ex);
|
||||
MessageBox.Show(Resources.SettingLoadError + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
Console.WriteLine("FormMain ctor completed");
|
||||
Logger.I(TAG, "FormMain ctor completed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +81,7 @@ namespace GrasscutterTools.Forms
|
||||
/// </summary>
|
||||
private void InitPages()
|
||||
{
|
||||
Console.WriteLine("InitPages enter");
|
||||
Logger.I(TAG, "InitPages enter");
|
||||
TCMain.SuspendLayout();
|
||||
var ph = CreatePage<PageHome>();
|
||||
ph.OnLanguageChanged = () => FormMain_Load(this, EventArgs.Empty);
|
||||
@@ -96,7 +101,7 @@ namespace GrasscutterTools.Forms
|
||||
TPScene.Controls.Add(CreatePage<PageScene>());
|
||||
TPAbout.Controls.Add(CreatePage<PageAbout>());
|
||||
TCMain.ResumeLayout();
|
||||
Console.WriteLine("InitPages completed");
|
||||
Logger.I(TAG, "InitPages completed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,7 +117,7 @@ namespace GrasscutterTools.Forms
|
||||
RunCommands = RunCommands,
|
||||
GetCommand = () => CmbCommand.Text,
|
||||
Dock = DockStyle.Fill,
|
||||
Name = nameof(T)
|
||||
Name = typeof(T).Name,
|
||||
};
|
||||
return page;
|
||||
}
|
||||
@@ -122,7 +127,7 @@ namespace GrasscutterTools.Forms
|
||||
/// </summary>
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine("FormMain_Load enter");
|
||||
Logger.I(TAG, "FormMain_Load enter");
|
||||
Text += " - by jie65535 - v" + Common.AppVersion.ToString(3);
|
||||
#if DEBUG
|
||||
Text += "-debug";
|
||||
@@ -137,12 +142,12 @@ namespace GrasscutterTools.Forms
|
||||
{
|
||||
if (tp.Controls.Count > 0 && tp.Controls[0] is BasePage page)
|
||||
{
|
||||
Console.WriteLine($"{page.Name} OnLoad enter");
|
||||
Logger.I(TAG, $"{page.Name} OnLoad enter");
|
||||
page.OnLoad();
|
||||
Console.WriteLine($"{page.Name} OnLoad completed");
|
||||
Logger.I(TAG, $"{page.Name} OnLoad completed");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("FormMain_Load completed");
|
||||
Logger.I(TAG, "FormMain_Load completed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,7 +155,7 @@ namespace GrasscutterTools.Forms
|
||||
/// </summary>
|
||||
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
Console.WriteLine("FormMain FormClosed enter");
|
||||
Logger.I(TAG, "FormMain FormClosed enter");
|
||||
// 遍历每一个页面,通知关闭
|
||||
foreach (TabPage tp in TCMain.Controls)
|
||||
{
|
||||
@@ -160,7 +165,7 @@ namespace GrasscutterTools.Forms
|
||||
|
||||
// 保存当前设置
|
||||
SaveSettings();
|
||||
Console.WriteLine("FormMain FormClosed completed");
|
||||
Logger.I(TAG, "FormMain FormClosed completed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -172,7 +177,8 @@ namespace GrasscutterTools.Forms
|
||||
{
|
||||
// 记录界面状态
|
||||
Settings.Default.AutoCopy = ChkAutoCopy.Checked;
|
||||
Settings.Default.MainFormLocation = Location;
|
||||
if (WindowState == FormWindowState.Normal)
|
||||
Settings.Default.MainFormLocation = Location;
|
||||
// 如果命令窗口已经弹出了,则不要保存多余的高度
|
||||
if (TxtCommandRunLog != null)
|
||||
Settings.Default.MainFormSize = new Size(Width, Height - TxtCommandRunLogMinHeight);
|
||||
@@ -198,7 +204,7 @@ namespace GrasscutterTools.Forms
|
||||
/// <param name="command">命令</param>
|
||||
private void SetCommand(string command)
|
||||
{
|
||||
Console.WriteLine($"SetCommand(\"{command}\")");
|
||||
Logger.I(TAG, $"SetCommand(\"{command}\")");
|
||||
var oldCommand = CmbCommand.Text;
|
||||
CmbCommand.Text = (ModifierKeys == Keys.Shift) ? $"{oldCommand} | {command}" : command;
|
||||
if (ChkAutoCopy.Checked)
|
||||
@@ -337,14 +343,14 @@ namespace GrasscutterTools.Forms
|
||||
var cmd = command.TrimStart('/');
|
||||
try
|
||||
{
|
||||
Console.WriteLine("RunCommand:" + cmd);
|
||||
Logger.I(TAG, "RunCommand:" + cmd);
|
||||
var msg = await Common.OC.Invoke(cmd);
|
||||
TxtCommandRunLog.AppendText(string.IsNullOrEmpty(msg) ? "OK" : msg);
|
||||
TxtCommandRunLog.AppendText(Environment.NewLine);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("RunCommand Error:" + ex.ToString());
|
||||
Logger.W(TAG, "RunCommand Error:", ex);
|
||||
TxtCommandRunLog.AppendText("Error: ");
|
||||
TxtCommandRunLog.AppendText(ex.Message);
|
||||
TxtCommandRunLog.AppendText(Environment.NewLine);
|
||||
|
@@ -248,6 +248,7 @@
|
||||
<Compile Include="Utils\ArtifactUtils.cs" />
|
||||
<Compile Include="Utils\Common.cs" />
|
||||
<Compile Include="Utils\HttpHelper.cs" />
|
||||
<Compile Include="Utils\Logger.cs" />
|
||||
<Compile Include="Utils\ReleaseAPI.cs" />
|
||||
<Compile Include="Utils\UIUtil.cs" />
|
||||
<EmbeddedResource Include="Forms\FormDropEditor.en-US.resx">
|
||||
|
@@ -24,11 +24,14 @@ using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GrasscutterTools.Properties;
|
||||
using GrasscutterTools.Utils;
|
||||
|
||||
namespace GrasscutterTools
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private const string TAG = "Program";
|
||||
|
||||
static Program()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
|
||||
@@ -72,12 +75,22 @@ namespace GrasscutterTools
|
||||
//处理非UI线程异常
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
// 初始化语言环境
|
||||
if (!string.IsNullOrEmpty(Settings.Default.DefaultLanguage))
|
||||
MultiLanguage.SetDefaultLanguage(Settings.Default.DefaultLanguage);
|
||||
Logger.I(TAG, "Program startup");
|
||||
|
||||
try
|
||||
{
|
||||
// 初始化语言环境
|
||||
if (!string.IsNullOrEmpty(Settings.Default.DefaultLanguage))
|
||||
MultiLanguage.SetDefaultLanguage(Settings.Default.DefaultLanguage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.W(TAG, "Loading language error", ex);
|
||||
MessageBox.Show(Resources.SettingLoadError + ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Application.Run(new Forms.FormMain());
|
||||
Console.WriteLine("Program end.");
|
||||
Logger.I(TAG, "Program end.");
|
||||
}
|
||||
|
||||
#region - 全局异常处理 -
|
||||
@@ -85,16 +98,16 @@ namespace GrasscutterTools
|
||||
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||
{
|
||||
string str = GetExceptionMsg(e.Exception, e.ToString());
|
||||
Console.WriteLine("Application_ThreadException");
|
||||
Console.WriteLine(str);
|
||||
Logger.E(TAG, "Application_ThreadException");
|
||||
Logger.E(TAG, str);
|
||||
MessageBox.Show(str, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
|
||||
Console.WriteLine("CurrentDomain_UnhandledException");
|
||||
Console.WriteLine(str);
|
||||
Logger.E(TAG, "CurrentDomain_UnhandledException");
|
||||
Logger.E(TAG, str);
|
||||
MessageBox.Show(str, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
|
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.7.4")]
|
||||
[assembly: AssemblyFileVersion("1.7.4")]
|
||||
[assembly: AssemblyVersion("1.7.6")]
|
||||
[assembly: AssemblyFileVersion("1.7.6")]
|
@@ -23,13 +23,23 @@ namespace GrasscutterTools.Utils
|
||||
/// </summary>
|
||||
public static OpenCommandAPI OC { get; set; }
|
||||
|
||||
private static string AppDataFolder { get; } = GetAppDataFolder();
|
||||
private static string GetAppDataFolder()
|
||||
{
|
||||
var dir = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"GrasscutterTools");
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用数据目录
|
||||
/// </summary>
|
||||
public static string GetAppDataFile(string filename) =>
|
||||
Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"GrasscutterTools",
|
||||
filename);
|
||||
public static string GetAppDataFile(string filename)
|
||||
{
|
||||
return Path.Combine(AppDataFolder, filename);
|
||||
}
|
||||
}
|
||||
}
|
52
Source/GrasscutterTools/Utils/Logger.cs
Normal file
52
Source/GrasscutterTools/Utils/Logger.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Grasscutter Tools
|
||||
* Copyright (C) 2022 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.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GrasscutterTools.Utils
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static readonly string LogPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), $"GcTools-{DateTime.Now:MMdd}.log");
|
||||
|
||||
private static void Write(string message)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine($"{DateTime.Now:mm:ss.fff} {message}");
|
||||
#else
|
||||
// Test log
|
||||
//File.AppendAllText(LogPath, $"{DateTime.Now:mm:ss.fff} {message}{Environment.NewLine}");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void Write(string level, string tag, string message) => Write($"<{level}:{tag}> {message}");
|
||||
|
||||
public static void I(string tag, string info) => Write("INFO", tag, info);
|
||||
|
||||
public static void W(string tag, string message) => Write("WARR", tag, message);
|
||||
|
||||
public static void W(string tag, string message, Exception ex) => Write("WARR", tag, $"{message} {ex}");
|
||||
|
||||
public static void E(string tag, string message) => Write("ERROR", tag, message);
|
||||
|
||||
public static void E(string tag, string message, Exception ex) => Write("ERROR", tag, $"{message} {ex}");
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -32,7 +33,7 @@ namespace GrasscutterTools.Utils
|
||||
/// <param name="filter">过滤内容</param>
|
||||
public static void ListBoxFilter(ListBox listBox, string[] source, string filter)
|
||||
{
|
||||
filter = filter.Trim();
|
||||
filter = filter.Trim().ToLower();
|
||||
listBox.BeginUpdate();
|
||||
listBox.Items.Clear();
|
||||
if (source != null && source.Length > 0)
|
||||
@@ -40,11 +41,75 @@ namespace GrasscutterTools.Utils
|
||||
if (string.IsNullOrEmpty(filter))
|
||||
listBox.Items.AddRange(source);
|
||||
else
|
||||
listBox.Items.AddRange(source.Where(n => n.Contains(filter)).ToArray());
|
||||
listBox.Items.AddRange(source.Where(n => Contains(n, filter)).ToArray());
|
||||
}
|
||||
listBox.EndUpdate();
|
||||
}
|
||||
|
||||
|
||||
private static bool Contains(string source, string filter)
|
||||
{
|
||||
source = source.ToLower();
|
||||
return source.Contains(filter) || (Encoding.Default.CodePage == 936 && ContainsPY(source, filter));
|
||||
}
|
||||
|
||||
private static bool ContainsPY(string source, string filter)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var ch in source)
|
||||
{
|
||||
var py = ch;
|
||||
var bytes = Encoding.Default.GetBytes(new char[] { ch });
|
||||
if (bytes.Length == 2)
|
||||
{
|
||||
py = GetPinYing((bytes[0] << 8) + bytes[1]);
|
||||
py = py == '\0' ? ch : py;
|
||||
}
|
||||
if (filter[i] == py)
|
||||
i++;
|
||||
else i = 0;
|
||||
if (i == filter.Length) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取拼音首字母,范围外返回原值
|
||||
/// </summary>
|
||||
/// <param name="ch">字符</param>
|
||||
/// <returns>拼音首字母</returns>
|
||||
private static char GetPinYing(int i)
|
||||
{
|
||||
if (i < 45217) return '\0';
|
||||
if (i < 45253) return 'a';
|
||||
if (i < 45761) return 'b';
|
||||
if (i < 46318) return 'c';
|
||||
if (i < 46826) return 'd';
|
||||
if (i < 47010) return 'e';
|
||||
if (i < 47297) return 'f';
|
||||
if (i < 47614) return 'g';
|
||||
if (i < 48119) return 'h';
|
||||
if (i < 48119) return 'i';
|
||||
if (i < 49062) return 'j';
|
||||
if (i < 49324) return 'k';
|
||||
if (i < 49896) return 'l';
|
||||
if (i < 50371) return 'm';
|
||||
if (i < 50614) return 'n';
|
||||
if (i < 50622) return 'o';
|
||||
if (i < 50906) return 'p';
|
||||
if (i < 51387) return 'q';
|
||||
if (i < 51446) return 'r';
|
||||
if (i < 52218) return 's';
|
||||
if (i < 52698) return 't';
|
||||
if (i < 52698) return 'u';
|
||||
if (i < 52698) return 'v';
|
||||
if (i < 52980) return 'w';
|
||||
if (i < 53689) return 'x';
|
||||
if (i < 54481) return 'y';
|
||||
if (i < 55290) return 'z';
|
||||
return '\0';
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用浏览器打开网址
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user