1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
6
2
using System . IO ;
7
- using System . Security . Permissions ;
8
3
using System . Security ;
4
+ using System . Security . Permissions ;
9
5
using System . Windows . Forms ;
10
6
11
7
namespace Universal_THCRAP_Launcher
12
8
{
13
- class Log
9
+ internal class Log
14
10
{
15
- private FileStream fs ;
16
- private StreamWriter sw ;
11
+ private readonly FileStream _fs ;
12
+ private readonly StreamWriter _sw ;
17
13
18
14
public Log ( string logFile )
19
15
{
@@ -29,48 +25,48 @@ public Log(string logFile)
29
25
}
30
26
31
27
// Delete log file if larger than 1 MB
32
- if ( File . Exists ( logFile ) && new System . IO . FileInfo ( logFile ) . Length >= 0x100000 )
28
+ if ( File . Exists ( logFile ) && new FileInfo ( logFile ) . Length >= 0x100000 )
33
29
File . Delete ( logFile ) ;
34
30
35
31
string dirName = Path . GetDirectoryName ( logFile ) ;
36
32
if ( ! Directory . Exists ( dirName ) )
37
33
Directory . CreateDirectory ( dirName ) ;
38
34
39
- fs = new FileStream ( logFile , FileMode . Append , FileAccess . Write , FileShare . ReadWrite ) ;
40
- sw = new StreamWriter ( fs ) ;
35
+ _fs = new FileStream ( logFile , FileMode . Append , FileAccess . Write , FileShare . ReadWrite ) ;
36
+ _sw = new StreamWriter ( _fs ) ;
41
37
}
42
38
43
39
public void WriteLine ( object text )
44
40
{
45
41
Console . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] " + text ) ;
46
- if ( sw == null ) return ;
47
- sw . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] " + text ) ;
48
- sw . Flush ( ) ;
49
- fs . Flush ( ) ;
42
+ if ( _sw == null ) return ;
43
+ _sw . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] " + text ) ;
44
+ _sw . Flush ( ) ;
45
+ _fs . Flush ( ) ;
50
46
}
51
47
52
48
public void Write ( object text )
53
49
{
54
50
Console . Write ( text ) ;
55
- if ( sw == null ) return ;
56
- sw . Write ( text ) ;
57
- sw . Flush ( ) ;
58
- fs . Flush ( ) ;
51
+ if ( _sw == null ) return ;
52
+ _sw . Write ( text ) ;
53
+ _sw . Flush ( ) ;
54
+ _fs . Flush ( ) ;
59
55
}
60
56
61
57
~ Log ( )
62
58
{
63
- if ( sw != null )
59
+ if ( _sw != null )
64
60
{
65
- sw . Flush ( ) ;
66
- sw . Close ( ) ;
67
- sw . Dispose ( ) ;
61
+ _sw . Flush ( ) ;
62
+ _sw . Close ( ) ;
63
+ _sw . Dispose ( ) ;
68
64
}
69
- if ( fs != null )
65
+ if ( _fs != null )
70
66
{
71
- fs . Flush ( ) ;
72
- fs . Close ( ) ;
73
- fs . Dispose ( ) ;
67
+ _fs . Flush ( ) ;
68
+ _fs . Close ( ) ;
69
+ _fs . Dispose ( ) ;
74
70
}
75
71
}
76
72
}
0 commit comments