格式化代码

This commit is contained in:
zhengxuan.zhang
2024-02-21 17:05:21 +08:00
parent 4c87a3c425
commit 08daf2ced4
11 changed files with 1061 additions and 1077 deletions
+39 -39
View File
@@ -12,32 +12,32 @@ namespace HexcalMC.Base
{
public class DebugDfn
{
public static string strDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string strDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string strDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string strStartTime = ""; //程序启动时间
static string strEndTime = ""; //程序关闭时间
public static string StrDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string StrDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string StrDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string _strStartTime = ""; //程序启动时间
static string _strEndTime = ""; //程序关闭时间
public static RichTextBox textBox_Msg;
public static RichTextBox TextBoxMsg;
//=================================================================
public static void StartDebugObj()
{
System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.strDebugFile);
System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.StrDebugFile);
TextWriterTraceListener logger = new TextWriterTraceListener(log);
Trace.Listeners.Add(logger);
strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
_strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
}
public static void SaveDebugFile()
{
AddLog("软件关闭!");
strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
string CopyFileName = strDebugSavePath + "\\DebugFiles\\" + "Debug(" + strStartTime + " To " +
strEndTime + ")" + ".txt";
if (File.Exists(strDebugFile))
File.Copy(strDebugFile, CopyFileName, true);
_strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
string copyFileName = StrDebugSavePath + "\\DebugFiles\\" + "Debug(" + _strStartTime + " To " +
_strEndTime + ")" + ".txt";
if (File.Exists(StrDebugFile))
File.Copy(StrDebugFile, copyFileName, true);
}
//=================================================================
@@ -49,45 +49,45 @@ namespace HexcalMC.Base
MyBase.TraceWriteLine(str);
}
public static void AddLogText(string str, Color m_Color = new Color())
public static void AddLogText(string str, Color mColor = new Color())
{
MyBase.TraceWriteLine(str);
try
{
textBox_Msg.BeginInvoke((EventHandler)delegate
TextBoxMsg.BeginInvoke((EventHandler)delegate
{
Color SetColor = Color.White;
if (m_Color == new Color())
Color setColor = Color.White;
if (mColor == new Color())
{
if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") ||
str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") ||
str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败"))
{
SetColor = Color.Red;
setColor = Color.Red;
}
else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告"))
{
SetColor = Color.DarkOrange;
setColor = Color.DarkOrange;
}
}
else
{
SetColor = m_Color;
setColor = mColor;
}
string strText = DateTime.Now.ToString("HH:mm:ss.ff") + "--" + str + Environment.NewLine;
textBox_Msg.SelectionStart = textBox_Msg.TextLength;
TextBoxMsg.SelectionStart = TextBoxMsg.TextLength;
if (string.IsNullOrEmpty(str))
SetText(textBox_Msg, str, SetColor, false, 16);
SetText(TextBoxMsg, str, setColor, false, 16);
else
SetText(textBox_Msg, strText, SetColor, false, 16);
if (textBox_Msg.Lines.Length > 800)
SetText(TextBoxMsg, strText, setColor, false, 16);
if (TextBoxMsg.Lines.Length > 800)
{
textBox_Msg.Select(0, textBox_Msg.TextLength / 2);
textBox_Msg.Cut();
TextBoxMsg.Select(0, TextBoxMsg.TextLength / 2);
TextBoxMsg.Cut();
}
textBox_Msg.ScrollToCaret();
TextBoxMsg.ScrollToCaret();
});
}
catch
@@ -95,32 +95,32 @@ namespace HexcalMC.Base
}
}
public static void SetText(RichTextBox m_RichTextBox, string strText, Color m_Color, bool bBold = false,
float Size = 16)
public static void SetText(RichTextBox mRichTextBox, string strText, Color mColor, bool bBold = false,
float size = 16)
{
m_RichTextBox.Invoke(((EventHandler)delegate
mRichTextBox.Invoke(((EventHandler)delegate
{
SetFont(m_RichTextBox, m_Color, bBold, Size);
m_RichTextBox.SelectedText = strText;
SetFont(mRichTextBox, mColor, bBold, size);
mRichTextBox.SelectedText = strText;
}));
}
public static void SetFont(RichTextBox m_RichTextBox, Color m_Color, bool bBold = false, float Size = 16)
public static void SetFont(RichTextBox mRichTextBox, Color mColor, bool bBold = false, float size = 16)
{
m_RichTextBox.SelectionColor = m_Color;
mRichTextBox.SelectionColor = mColor;
if (bBold)
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size, System.Drawing.FontStyle.Bold,
mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
else
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size,
mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
}
public static void SetErrorColor(Color InColor)
public static void SetErrorColor(Color inColor)
{
if (textBox_Msg != null)
if (TextBoxMsg != null)
{
textBox_Msg.BeginInvoke((EventHandler)delegate { textBox_Msg.BackColor = InColor; });
TextBoxMsg.BeginInvoke((EventHandler)delegate { TextBoxMsg.BackColor = inColor; });
}
}