Skip to content

Commit 7b0761d

Browse files
committed
Don't spam logs when checking for world changes
1 parent ea5bf3d commit 7b0761d

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

VRCOSC.Game/Util/CurrentWorldExtractor.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static class CurrentWorldExtractor
2424
private static IEnumerable<string>? ids;
2525

2626
public static bool IsCurrentWorldBlacklisted { get; private set; }
27+
public static string? CurrentWorldId { get; private set; }
2728

2829
public static async void UpdateCurrentWorld()
2930
{
@@ -35,15 +36,19 @@ public static async void UpdateCurrentWorld()
3536
return;
3637
}
3738

38-
var currentWorldId = await getCurrentWorldId();
39+
var newCurrentWorldId = await getCurrentWorldId();
40+
if (newCurrentWorldId == CurrentWorldId) return;
3941

40-
if (currentWorldId is null)
42+
CurrentWorldId = newCurrentWorldId;
43+
Logger.Log($"World change detected: {CurrentWorldId}");
44+
45+
if (CurrentWorldId is null)
4146
{
4247
IsCurrentWorldBlacklisted = false;
4348
return;
4449
}
4550

46-
IsCurrentWorldBlacklisted = ids.Contains(currentWorldId);
51+
IsCurrentWorldBlacklisted = ids.Contains(CurrentWorldId);
4752
}
4853

4954
private static async Task requestBlacklist()
@@ -52,21 +57,15 @@ private static async Task requestBlacklist()
5257
{
5358
if (blacklist is not null) return;
5459

55-
Logger.Log("Updating world blacklist");
56-
5760
using var client = new HttpClient();
5861

5962
var response = await client.GetAsync(blacklist_url);
6063
response.EnsureSuccessStatusCode();
6164

62-
Logger.Log("Found blacklist file");
63-
6465
var content = await response.Content.ReadAsStringAsync();
6566
blacklist = JsonConvert.DeserializeObject<Blacklist>(content);
6667
if (blacklist is null) return;
6768

68-
Logger.Log("Successfully extracted blacklist data");
69-
7069
ids = blacklist.Worlds.Select(world => world.ID);
7170
}
7271
catch (Exception)
@@ -80,26 +79,19 @@ private static async Task requestBlacklist()
8079
{
8180
try
8281
{
83-
Logger.Log($"Attempting to find current world using log pattern {logfile_location}\\{logfile_pattern}");
84-
8582
var logFile = Directory.GetFiles(logfile_location, logfile_pattern).MaxBy(d => new FileInfo(d).CreationTime);
8683
if (logFile is null) return null;
8784

88-
Logger.Log($"Found latest log file at {logFile}");
89-
9085
using var fileStream = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
9186
using var textReader = new StreamReader(fileStream);
9287
var content = await textReader.ReadToEndAsync();
9388

94-
Logger.Log("Successfully read latest log file");
95-
9689
var latestWorld = world_regex.Matches(content).LastOrDefault()?.Groups.Values.LastOrDefault();
9790
if (latestWorld is null) return null;
9891

9992
var latestWorldId = latestWorld.Captures.FirstOrDefault();
10093
if (latestWorldId is null) return null;
10194

102-
Logger.Log($"Found current world: {latestWorldId.Value}");
10395
return latestWorldId.Value;
10496
}
10597
catch (Exception)

0 commit comments

Comments
 (0)