mirror of
https://github.com/nsnail/dot.git
synced 2025-06-17 13:03:22 +08:00
异常日志
This commit is contained in:
parent
bd2f88a1d6
commit
67ef6b9fa0
@ -20,6 +20,7 @@ OPTIONS:
|
||||
COMMANDS:
|
||||
git Git batch operation tool
|
||||
color Screen coordinate color selection tool
|
||||
tran Translation tools
|
||||
guid GUID tool
|
||||
ip IP tools
|
||||
json Json tool
|
||||
@ -31,7 +32,6 @@ COMMANDS:
|
||||
tolf Convert newline characters to LF
|
||||
get <url> Multithreaded download tool
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Some functional examples
|
||||
|
@ -19,6 +19,7 @@ OPTIONS:
|
||||
COMMANDS:
|
||||
git Git批量操作工具
|
||||
color 屏幕坐标颜色选取工具
|
||||
tran 翻译工具
|
||||
guid GUID工具
|
||||
ip IP工具
|
||||
json Json工具
|
||||
|
@ -10,8 +10,9 @@ internal static class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var app = new CommandApp();
|
||||
CustomCulture(ref args);
|
||||
|
||||
var app = new CommandApp();
|
||||
app.Configure(config => {
|
||||
config.SetApplicationName(AssemblyInfo.ASSEMBLY_PRODUCT);
|
||||
config.SetApplicationVersion(AssemblyInfo.ASSEMBLY_VERSION);
|
||||
@ -36,8 +37,21 @@ internal static class Program
|
||||
|
||||
config.ValidateExamples();
|
||||
});
|
||||
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
return app.Run(args);
|
||||
}
|
||||
|
||||
private static void CustomCulture(ref string[] args)
|
||||
{
|
||||
var i = Array.IndexOf(args, "/e");
|
||||
if (i < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(args[i + 1]);
|
||||
var argsList = args.ToList();
|
||||
argsList.RemoveAt(i);
|
||||
argsList.RemoveAt(i);
|
||||
args = argsList.ToArray();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#if NET7_0_WINDOWS
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using NSExt.Extensions;
|
||||
|
||||
namespace Dot.Tran;
|
||||
|
||||
@ -14,7 +15,10 @@ internal sealed class Main : ToolBase<Option>
|
||||
AnsiConsole.MarkupLine(Str.StartTranslate);
|
||||
AnsiConsole.MarkupLine(Str.HideTranslate);
|
||||
var th = new Thread(() => {
|
||||
using var frm = new FrmMain();
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
|
||||
Application.ThreadException += UIThreadException;
|
||||
using var frm = new WinMain();
|
||||
Application.Run();
|
||||
});
|
||||
th.SetApartmentState(ApartmentState.STA);
|
||||
@ -22,6 +26,22 @@ internal sealed class Main : ToolBase<Option>
|
||||
th.Join();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static void Log(string msg)
|
||||
{
|
||||
var file = Path.Combine(Path.GetTempPath(), $"{DateTime.Now.yyyyMMdd()}.dotlog");
|
||||
File.AppendAllText(file, $"{Environment.NewLine}{msg}");
|
||||
}
|
||||
|
||||
private static void UIThreadException(object sender, ThreadExceptionEventArgs e)
|
||||
{
|
||||
Log(e.Json());
|
||||
}
|
||||
|
||||
private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Log(e.Json());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -12,7 +12,7 @@ using Size = System.Drawing.Size;
|
||||
namespace Dot.Tran;
|
||||
|
||||
[SupportedOSPlatform(nameof(OSPlatform.Windows))]
|
||||
internal sealed partial class FrmMain : Form
|
||||
internal sealed partial class WinMain : Form
|
||||
{
|
||||
private const int _RETRY_WAIT_MIL_SEC = 1000; // 重试等待时间(秒)
|
||||
private const string _TRANSLATE_API_URL = $"{_TRANSLATE_HOME_URL}/v2transapi";
|
||||
@ -28,7 +28,7 @@ internal sealed partial class FrmMain : Form
|
||||
private nint _nextClipViewer; // 下一个剪贴板监视链对象句柄
|
||||
private string _token = "ae72ebad4113270fd26ada5125301268";
|
||||
|
||||
public FrmMain()
|
||||
public WinMain()
|
||||
{
|
||||
InitForm();
|
||||
InitHook();
|
||||
@ -38,7 +38,7 @@ internal sealed partial class FrmMain : Form
|
||||
_nextClipViewer = Win32.SetClipboardViewer(Handle);
|
||||
}
|
||||
|
||||
~FrmMain()
|
||||
~WinMain()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user