@@ -21,6 +21,12 @@ public class ModConsole
2121
2222 private static FilePath logFile ;
2323
24+ private const int CONSOLE_HIDE = 0 ;
25+
26+ private const int CONSOLE_SHOW = 5 ;
27+
28+ private bool visible = false ;
29+
2430 public ModConsole ( )
2531 {
2632 ModConsole . AllocConsole ( ) ;
@@ -33,95 +39,61 @@ public ModConsole()
3339 ModConsole . logFile = FileLocations . BaseFolder . Extend ( "logs" ) . CreateFolder ( ) . ExtendToFile ( current . Year + "-" + current . Month + "-" + current . Day + ".txt" ) ;
3440 }
3541
36- private void hideConsole ( )
37- {
38- ModConsole . ShowWindow ( ModConsole . GetConsoleWindow ( ) , 0 ) ;
39- this . visible = false ;
40- }
41-
42- private void showConsole ( )
43- {
44- ModConsole . ShowWindow ( ModConsole . GetConsoleWindow ( ) , 5 ) ;
45- this . visible = true ;
46- }
47-
42+ /// <summary>
43+ /// call this method if you want to hiden or show console
44+ /// </summary>
4845 public void toggleConsole ( )
4946 {
50- bool flag = this . visible ;
51- if ( flag )
47+ if ( this . visible )
5248 {
53- this . hideConsole ( ) ;
49+ ModConsole . ShowWindow ( ModConsole . GetConsoleWindow ( ) , CONSOLE_HIDE ) ;
5450 }
5551 else
5652 {
57- this . showConsole ( ) ;
53+ ModConsole . ShowWindow ( ModConsole . GetConsoleWindow ( ) , CONSOLE_SHOW ) ;
5854 }
55+ this . visible = ! this . visible ;
5956 }
6057
58+ /// <summary>
59+ /// if you want to print a error with format
60+ /// </summary>
61+ /// <param name="e">Exception of your error</param>
6162 public void logError ( Exception e )
6263 {
6364 StackTrace stackTrace = new StackTrace ( e , true ) ;
6465 StackFrame frame = stackTrace . GetFrame ( 0 ) ;
6566 int fileColumnNumber = frame . GetFileColumnNumber ( ) ;
6667 int fileLineNumber = frame . GetFileLineNumber ( ) ;
6768 string fileName = frame . GetFileName ( ) ;
68- this . tryLogCustom ( "##[ERROR]##" , "ErrorReporter" , LogType . Error ) ;
69- this . tryLogCustom ( e . Message , "ErrorReporter" , LogType . Error ) ;
70- this . tryLogCustom ( e . StackTrace , "ErrorReporter" , LogType . Error ) ;
71- this . tryLogCustom ( fileLineNumber + ":" + fileColumnNumber + "@" + fileName , "ErrorReporter" , LogType . Error ) ;
72- this . tryLogCustom ( "##[ERROR]##" , "ErrorReporter" , LogType . Error ) ;
69+ this . log ( "##[ERROR]##" , "ErrorReporter" , LogType . Error ) ;
70+ this . log ( e . Message , "ErrorReporter" , LogType . Error ) ;
71+ this . log ( e . StackTrace , "ErrorReporter" , LogType . Error ) ;
72+ this . log ( fileLineNumber + ":" + fileColumnNumber + "@" + fileName , "ErrorReporter" , LogType . Error ) ;
73+ this . log ( "##[ERROR]##" , "ErrorReporter" , LogType . Error ) ;
7374 }
7475
75- public void log ( string msg , string tag )
76+ /// <summary>
77+ /// Print message in console with format
78+ /// </summary>
79+ /// <param name="msg">Message that you want to ptint</param>
80+ /// <param name="tag">tag to identify your log</param>
81+ /// <param name="type">what kind of log is it</param>
82+ public void log ( string msg , string tag , LogType type = LogType . Log )
7683 {
7784 string logMessage = "[" + tag + "]: " + msg ;
7885 Console . WriteLine ( logMessage ) ;
7986 logFile . AppendText ( logMessage + "\n " ) ;
8087 }
8188
89+ /// <summary>
90+ /// Print message in console
91+ /// </summary>
92+ /// <param name="msg">message that you want to print</param>
8293 public void log ( string msg )
8394 {
8495 this . log ( msg , "Unkwn" ) ;
8596 }
8697
87- private void tryLogCustom ( string msg , string tag , LogType type )
88- {
89- bool flag = this . logCustom == null ;
90- if ( flag )
91- {
92- this . log ( msg , tag ) ;
93- }
94- else
95- {
96- msg = "[" + tag + "]: " + msg ;
97- try
98- {
99- this . logCustom ( msg , type ) ;
100- }
101- catch ( Exception e )
102- {
103- this . logError ( e ) ;
104- }
105- }
106- }
107-
108- private void tryLogCustom ( string msg , LogType type )
109- {
110- this . tryLogCustom ( msg , "Unkwn" , type ) ;
111- }
112-
113- public void setLogger ( Action < string , LogType > logfunc )
114- {
115- this . logCustom = logfunc ;
116- }
117-
118- private const int SW_HIDE = 0 ;
119-
120- private const int SW_SHOW = 5 ;
121-
122- private bool visible = false ;
123-
124-
125- private Action < string , LogType > logCustom ;
12698 }
12799}
0 commit comments