-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.cs
141 lines (138 loc) · 4.9 KB
/
Environment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Heloid
{
public static partial class Env
{
public static void Crash(string msg, int ec)
{
for (int h = 0; h < 3; h++)
{
for (int i = 1; i < 8; i++)
{
Console.Write($"\u001b[3{i}m=\u001b[0m");
}
}
Console.WriteLine();
Console.WriteLine("\u001b[31mCrash: \u001b[0m" + msg);
Console.WriteLine("\u001b[31mError Code: \u001b[0m" + ec);
for (int h = 0; h < 3; h++)
{
for (int i = 1; i < 8; i++)
{
Console.Write($"\u001b[3{i}m=\u001b[0m");
}
}
Console.WriteLine();
Console.Write("Shutting down in \u001b[35m5\u001b[0m...");
Thread.Sleep(1000);
Console.Write("\rShutting down in \u001b[35m4\u001b[0m...");
Thread.Sleep(1000);
Console.Write("\rShutting down in \u001b[35m3\u001b[0m...");
Thread.Sleep(1000);
Console.Write("\rShutting down in \u001b[35m2\u001b[0m...");
Thread.Sleep(1000);
Console.Write("\rShutting down in \u001b[35m1\u001b[0m...");
Thread.Sleep(1000);
Console.Write("\rShutting down... \n");
ShutDown(ec);
}
public static void ShutDown(int ec)
{
Console.WriteLine("Pretend this PC has shut down.");
Environment.Exit(ec);
}
public static void Log(string msg, int spaceBefore = 0, bool showDateTime = true, bool trim = true, bool logAll = false)
{
if (string.IsNullOrWhiteSpace(msg))
{
return;
}
if (trim)
{
msg.Trim();
string pattern = @"\u001b\[\d*m";
string logData = Regex.Replace(msg, pattern, "");
logData.Trim();
if (logAll == false && logData.Length > 300)
{
logData = logData.Substring(0, 30) + "..." + "" + logData.Substring(logData.Length - 10);
}
if (showDateTime)
{
logData = DateTime.Now.ToString("ddd, dd/MM/yyyy HH:mm:ss.fffffff") + " - " + logData;
}
else
{
logData = logData;
}
logData = logData.Trim();
for (int i = 0; i < spaceBefore; i++)
{
logData = "\n" + logData;
}
if (!string.IsNullOrWhiteSpace(logLoc) && logInit == true)
{
StreamWriter sr = new StreamWriter(logLoc, append: true);
sr.WriteLine(logData);
sr.Close();
}
else if (!string.IsNullOrWhiteSpace(logLoc) && logInit == false)
{
StreamWriter sr = new StreamWriter(logLoc, append: true);
sr.Write(hold);
logInit = true;
sr.WriteLine(logData);
sr.Close();
}
else
{
hold += logData + "\n";
}
}
else
{
string pattern = @"\u001b\[\d*m";
string logData = Regex.Replace(msg, pattern, "");
if (logAll == false && logData.Length > 300)
{
logData = logData.Substring(0, 30) + "..." + "" + logData.Substring(logData.Length - 10);
}
if (showDateTime)
{
logData = DateTime.Now.ToString("ddd, dd/MM/yyyy HH:mm:ss.fffffff") + " - " + logData;
}
else
{
logData = logData;
}
for (int i = 0; i < spaceBefore; i++)
{
logData = "\n" + logData;
}
if (!string.IsNullOrWhiteSpace(logLoc) && logInit == true)
{
StreamWriter sr = new StreamWriter(logLoc, append: true);
sr.WriteLine(logData);
sr.Close();
}
else if (!string.IsNullOrWhiteSpace(logLoc) && logInit == false)
{
StreamWriter sr = new StreamWriter(logLoc, append: true);
sr.Write(hold);
logInit = true;
sr.WriteLine(logData);
sr.Close();
}
else
{
hold += logData + "\n";
}
}
}
}
}