diff --git a/RLBotCS/Main.cs b/RLBotCS/Main.cs index 4dfbf33..18316c1 100644 --- a/RLBotCS/Main.cs +++ b/RLBotCS/Main.cs @@ -10,7 +10,7 @@ if (args.Length > 0 && args[0] == "--version") { Console.WriteLine( - "RLBotServer v5.0.0-rc.7\n" + "RLBotServer v5.0.0-rc.8\n" + $"Bridge {BridgeVersion.Version}\n" + "@ https://www.rlbot.org & https://github.com/RLBot/core" ); diff --git a/RLBotCS/ManagerTools/WinReadLog.cs b/RLBotCS/ManagerTools/WinReadLog.cs index df78343..a78d4a3 100644 --- a/RLBotCS/ManagerTools/WinReadLog.cs +++ b/RLBotCS/ManagerTools/WinReadLog.cs @@ -45,25 +45,37 @@ public WinReadLog() if (!File.Exists(LogPath)) return null; - string logContent = File.ReadAllText(LogPath); + string? auth = null; + string? path = null; - int authPrefixIndex = logContent.IndexOf(AUTH_LINE_PREFIX, StringComparison.Ordinal); - int pathPrefixIndex = logContent.IndexOf(PATH_LINE_PREFIX, StringComparison.Ordinal); - if (authPrefixIndex == -1 || pathPrefixIndex == -1) - return null; - - int authStart = authPrefixIndex + AUTH_LINE_PREFIX.Length; - int pathStart = pathPrefixIndex + PATH_LINE_PREFIX.Length; + using var reader = new StreamReader( + LogPath, + Encoding.UTF8, + detectEncodingFromByteOrderMarks: true + ); - int authEnd = logContent.IndexOf('\n', authStart); - int pathEnd = logContent.IndexOf('\n', pathStart); - if (authEnd == -1 || pathEnd == -1) - return null; + string? line; + while ((line = reader.ReadLine()) != null) + { + if (auth == null && line.StartsWith(AUTH_LINE_PREFIX, StringComparison.Ordinal)) + { + auth = line[AUTH_LINE_PREFIX.Length..].TrimEnd('\r', '\n'); + } + else if ( + path == null + && line.StartsWith(PATH_LINE_PREFIX, StringComparison.Ordinal) + ) + { + path = line[PATH_LINE_PREFIX.Length..].TrimEnd('\r', '\n'); + } - string auth = logContent[authStart..authEnd].TrimEnd('\r', '\n'); - string path = logContent[pathStart..pathEnd].TrimEnd('\r', '\n'); + if (auth != null && path != null) + { + return (Path.Combine(path, BINARY_NAME), auth); + } + } - return (Path.Combine(path, BINARY_NAME), auth); + return null; } } #endif