Massive commit that will break everything!

This commit is contained in:
Natsumi
2021-08-30 12:05:42 +12:00
parent 1eda658158
commit 2418d902cf
10 changed files with 1252 additions and 1212 deletions

View File

@@ -3,6 +3,7 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using CefSharp;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -30,6 +31,8 @@ namespace VRCX
private readonly List<string[]> m_LogList;
private Thread m_Thread;
private bool m_ResetLog;
private bool m_FirstRun = true;
private static DateTime tillDate = DateTime.Now;
// NOTE
// FileSystemWatcher() is unreliable
@@ -64,6 +67,17 @@ namespace VRCX
thread.Interrupt();
thread.Join();
}
public void Reset()
{
m_ResetLog = true;
m_Thread?.Interrupt();
}
public void SetDateTill(string date)
{
tillDate = DateTime.Parse(date);
}
private void ThreadLoop()
{
@@ -86,6 +100,7 @@ namespace VRCX
{
if (m_ResetLog == true)
{
m_FirstRun = true;
m_ResetLog = false;
m_LogContextMap.Clear();
m_LogListLock.EnterWriteLock();
@@ -109,26 +124,17 @@ namespace VRCX
// sort by creation time
Array.Sort(fileInfos, (a, b) => a.CreationTimeUtc.CompareTo(b.CreationTimeUtc));
var utcNow = DateTime.UtcNow;
var minLimitDateTime = utcNow.AddDays(-7d);
var minRefreshDateTime = utcNow.AddMinutes(-3d);
foreach (var fileInfo in fileInfos)
{
var lastWriteTimeUtc = fileInfo.LastWriteTimeUtc;
if (lastWriteTimeUtc < minLimitDateTime)
fileInfo.Refresh();
if (fileInfo.Exists == false)
{
continue;
}
if (lastWriteTimeUtc >= minRefreshDateTime)
if (DateTime.Compare(fileInfo.LastWriteTime, tillDate) < 0)
{
fileInfo.Refresh();
if (fileInfo.Exists == false)
{
continue;
}
continue;
}
if (m_LogContextMap.TryGetValue(fileInfo.Name, out LogContext logContext) == true)
@@ -155,6 +161,8 @@ namespace VRCX
{
m_LogContextMap.Remove(name);
}
m_FirstRun = false;
}
private void ParseLog(FileInfo fileInfo, LogContext logContext)
@@ -184,6 +192,20 @@ namespace VRCX
continue;
}
if (DateTime.TryParseExact(
line.Substring(0, 19),
"yyyy.MM.dd HH:mm:ss",
CultureInfo.InvariantCulture,
DateTimeStyles.AssumeLocal,
out DateTime lineDate
))
{
if (DateTime.Compare(lineDate, tillDate) <= 0)
{
continue;
}
}
var offset = 34;
if (line[offset] == '[')
{
@@ -194,7 +216,8 @@ namespace VRCX
ParseLogJoinBlocked(fileInfo, logContext, line, offset) == true ||
ParseLogAvatarPedestalChange(fileInfo, logContext, line, offset) == true ||
ParseLogVideoError(fileInfo, logContext, line, offset) == true ||
ParseLogVideoPlay(fileInfo, logContext, line, offset) == true)
ParseLogVideoPlay(fileInfo, logContext, line, offset) == true ||
ParseLogWorldVRCX(fileInfo, logContext, line, offset) == true)
{
continue;
}
@@ -221,6 +244,12 @@ namespace VRCX
m_LogListLock.EnterWriteLock();
try
{
if (!m_FirstRun)
{
var logLine = System.Text.Json.JsonSerializer.Serialize(item);
if (MainForm.Instance != null && MainForm.Instance.Browser != null)
MainForm.Instance.Browser.ExecuteScriptAsync("$app.addGameLogEvent", logLine);
}
m_LogList.Add(item);
}
finally
@@ -244,7 +273,7 @@ namespace VRCX
dt = DateTime.UtcNow;
}
return $"{dt:yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'}";
return $"{dt:yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'}";
}
private bool ParseLogLocation(FileInfo fileInfo, LogContext logContext, string line, int offset)
@@ -515,6 +544,28 @@ namespace VRCX
return true;
}
private bool ParseLogWorldVRCX(FileInfo fileInfo, LogContext logContext, string line, int offset)
{
// [VRCX] VideoPlay(PyPyDance) "https://jd.pypy.moe/api/v1/videos/-Q3pdlsQxOk.mp4",0.5338666,260.6938,"1339 : Le Freak (Random)"
if (string.Compare(line, offset, "[VRCX] ", 0, 7, StringComparison.Ordinal) == 0)
{
var data = line.Substring(offset + 7);
AppendLog(new[]
{
fileInfo.Name,
ConvertLogTimeToISO8601(line),
"vrcx",
data
});
return true;
}
return false;
}
private bool ParseLogSDK2VideoPlay(FileInfo fileInfo, LogContext logContext, string line, int offset)
{
// 2021.04.23 13:12:25 Log - User Natsumi-sama added URL https://www.youtube.com/watch?v=dQw4w9WgXcQ
@@ -579,14 +630,10 @@ namespace VRCX
return true;
}
public void Reset()
{
m_ResetLog = true;
m_Thread?.Interrupt();
}
public string[][] Get()
{
Update();
if (m_ResetLog == false &&
m_LogList.Count > 0)
{