Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ricky8955555 committed Jan 23, 2021
1 parent 1ba210b commit c274636
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 64 deletions.
6 changes: 6 additions & 0 deletions src/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.Windows.Forms;

namespace SeewoHelper
{
Expand All @@ -8,6 +9,11 @@ namespace SeewoHelper
/// </summary>
public static class Constants
{
/// <summary>
/// 应用名称
/// </summary>
public static readonly string AppName = Application.ProductName;

/// <summary>
/// 贡献者
/// 若有贡献请修改该字段
Expand Down
1 change: 1 addition & 0 deletions src/Forms/WindowMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SeewoHelper
{
static class Program
{
public static Logger Logger { get; private set; }
public static Logger Logger { get; private set; } = new Logger(Path.Combine(Constants.BaseDirectory, "logs", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".log"));

public static FormStyleController FormStyleController { get; } = new FormStyleController();

Expand All @@ -19,13 +19,12 @@ static class Program
[STAThread]
static void Main()
{
var instance = InstanceUtilities.GetRunningInstance();
using var mutex = new Mutex(true, Constants.AppName, out bool createdNew);

if (instance == null)
{
Logger = new Logger(Path.Combine(Constants.BaseDirectory, "logs", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".log"));
FormStyleController.SetStyle(Configurations.UISettings.Content.Style);
FormStyleController.SetStyle(Configurations.UISettings.Content.Style);

if (createdNew)
{
Application.ThreadException += Application_ThreadException; // 处理主线程的异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // 处理子线程未捕获异常

Expand Down
52 changes: 0 additions & 52 deletions src/Utilities/InstanceUtilities.cs

This file was deleted.

8 changes: 2 additions & 6 deletions src/Utilities/MessageBoxUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace SeewoHelper.Utilities
{
public class MessageBoxUtilities
public static class MessageBoxUtilities
{
/// <summary>
/// 显示提示框
/// </summary>
public static bool Show(string text, string caption, bool showMask = false, UIMessageBoxButtons buttons = UIMessageBoxButtons.OK)
{
Program.Logger.Add($"显示消息框,参数:[text: {text}, caption: {caption}, showMask: {showMask}, buttons: {buttons}]");
return UIMessageBox.Show(text, caption, Program.FormStyleController.CurrentStyle, buttons, showMask);
}

Expand All @@ -17,7 +18,6 @@ public static bool Show(string text, string caption, bool showMask = false, UIMe
/// </summary>
public static bool ShowAsk(string text, bool showMask = false)
{
Program.Logger.Add($"弹出询问信息提示框 , text = {text} , showMask = {showMask}");
return Show(text, "询问", showMask, UIMessageBoxButtons.OKCancel);
}

Expand All @@ -26,7 +26,6 @@ public static bool ShowAsk(string text, bool showMask = false)
/// </summary>
public static void ShowError(string text, bool showMask = false)
{
Program.Logger.Add($"弹出错误信息提示框 , text = {text} , showMask = {showMask}");
Show(text, "错误", showMask);
}

Expand All @@ -35,7 +34,6 @@ public static void ShowError(string text, bool showMask = false)
/// </summary>
public static void ShowInfo(string text, bool showMask = false)
{
Program.Logger.Add($"弹出信息提示框 , text = {text} , showMask = {showMask}");
Show(text, "提示", showMask);
}

Expand All @@ -44,7 +42,6 @@ public static void ShowInfo(string text, bool showMask = false)
/// </summary>
public static void ShowSuccess(string text, bool showMask = false)
{
Program.Logger.Add($"弹出成功信息提示框 , text = {text} , showMask = {showMask}");
Show(text, "成功", showMask);
}

Expand All @@ -53,7 +50,6 @@ public static void ShowSuccess(string text, bool showMask = false)
/// </summary>
public static void ShowWarning(string text, bool showMask = false)
{
Program.Logger.Add($"弹出警告信息提示框 , text = {text} , showMask = {showMask}");
Show(text, "警告", showMask);
}
}
Expand Down

0 comments on commit c274636

Please sign in to comment.