-
Notifications
You must be signed in to change notification settings - Fork 0
/
XSOLog.cs
111 lines (89 loc) · 3.44 KB
/
XSOLog.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
using System.Text;
using System.Text.RegularExpressions;
namespace XSOVRCParser;
internal static partial class XSOLog
{
public enum InputType
{
Log,
Warning,
Error
}
public static readonly StringBuilder Log = new();
private static DateTime? _logDateTime, _errorDateTime;
private static readonly string[] IgnoredErrors =
{
"AmplitudeAPI", "cdp.cloud.unity3d.com", "[API]", "Curl error",
"[AVProVideo]", "NewFeatureCallouts", "Failed to get texture", "Error auto blending a playable at slot",
"Can't push runtime controller onto a null avatar animator", "could not use Station",
"Could not locate Station",
"Material doesn't have a texture property", "Failed to find translation for term",
"Failed to find translation for key",
"Attempted to access IsInVRMode before tracking was initialized!"
};
//https://stackoverflow.com/a/19436622 C++ would be probably way more ideal, but I don't have such skills yet...
// TODO: fails to get anything that's more than one line because of the current regex
public static InputType GetInputType(string text, out string toPrint)
{
if (text.Contains("Log"))
{
toPrint = text;
return InputType.Log;
}
if (text.Contains("Warning"))
{
toPrint = text;
return InputType.Warning;
}
if (text.Contains("Error"))
{
toPrint = text;
return InputType.Error;
}
toPrint = string.Empty;
return InputType.Log;
}
public static void ConsoleWrite(InputType inputType, string s)
{
DateTime tempDateTime; // Intermediate non-nullable DateTime variable
switch (inputType)
{
case InputType.Log when DateTime.TryParse(LogRegex().Match(s).Groups[1].Value, out tempDateTime):
_logDateTime = tempDateTime;
break;
case InputType.Error when DateTime.TryParse(ErrorRegex().Match(s).Groups[1].Value, out tempDateTime):
_errorDateTime = tempDateTime;
break;
case InputType.Warning:
break;
}
var errorMessage = ErrorMessageRegex().Match(s).Groups[1].Value;
if (string.IsNullOrWhiteSpace(errorMessage) || IgnoredErrors.Any(t => errorMessage.Contains(t))) return;
PrintError(errorMessage);
}
public static void PrintLog(Match regexMatch, ConsoleColor consoleColor = ConsoleColor.Cyan)
{
if (regexMatch == null) throw new NullReferenceException(nameof(regexMatch));
PrintLog(regexMatch.Value, consoleColor);
}
public static void PrintLog(string value, ConsoleColor consoleColor = ConsoleColor.Cyan)
{
AppendToLog($"[{_logDateTime}/PrintLog]: {value}", consoleColor);
}
private static void PrintError(string text)
{
AppendToLog($"[{_errorDateTime}/PrintError]: {text}", ConsoleColor.Red);
}
private static void AppendToLog(string message, ConsoleColor color)
{
Log.AppendLine($"{message}\n");
Console.ForegroundColor = color;
Console.WriteLine($"{message}\n");
}
[GeneratedRegex(@"(.+\S) Log")]
private static partial Regex LogRegex();
[GeneratedRegex(@"(.+\S) Error")]
private static partial Regex ErrorRegex();
[GeneratedRegex(@"Error *- *(.+)")]
private static partial Regex ErrorMessageRegex();
}