Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qubqub committed Sep 16, 2023
1 parent 5311c4f commit 6ce4048
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 85 deletions.
19 changes: 14 additions & 5 deletions Entities/LogFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Start(string logDirectory, string fileName) {
if (this.running) { return; }

this.filePath = Path.Combine(logDirectory, fileName);
this.prevFilePath = Path.Combine(logDirectory, Path.GetFileNameWithoutExtension(fileName) + "-prev.log");
this.prevFilePath = Path.Combine(logDirectory, $"{Path.GetFileNameWithoutExtension(fileName)}-prev.log");
this.stop = false;
this.watcher = new Thread(this.ReadLogFile) { IsBackground = true };
this.watcher.Start();
Expand All @@ -112,7 +112,7 @@ private void ReadLogFile() {
List<LogLine> tempLines = new List<LogLine>();
DateTime lastDate = DateTime.MinValue;
bool completed = false;
string currentFilePath = prevFilePath;
string currentFilePath = this.prevFilePath;
long offset = 0;
while (!this.stop) {
try {
Expand All @@ -128,6 +128,15 @@ private void ReadLogFile() {
DateTime currentDate = lastDate;
while ((line = sr.ReadLine()) != null) {
LogLine logLine = new LogLine(line, sr.Position);

// if (line.IndexOf("Discovering subsystems at path", StringComparison.OrdinalIgnoreCase) > 0) {
// string subsystemsPath = line.Substring(44);
// if (subsystemsPath.IndexOf("steamapps", StringComparison.OrdinalIgnoreCase) > 0) {
// // Steam
// } else {
// // Epic Games
// }
// }

if (logLine.IsValid) {
int index;
Expand Down Expand Up @@ -763,10 +772,10 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
this.InitStaticVariable();
} else if (line.Line.IndexOf("[GameSession] Changing state from GameOver to Results", StringComparison.OrdinalIgnoreCase) > 0) {
if (logRound.Info == null || !logRound.Info.UseShareCode) { return false; }
if (0 < round.Count) {
if (round.Count > 0) {
foreach (RoundInfo temp in round) {
temp.ShowStart = temp.Start;
temp.Playing = false;
temp.ShowStart = temp.Start;

logRound.PrivateLobby = temp.PrivateLobby;
logRound.CurrentlyInParty = temp.InParty;
Expand All @@ -786,7 +795,7 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {

if (temp.Finish.HasValue) {
if (temp.Position > 0) {
double rankPercentage = (((double)temp.Position / (double)temp.Players) * 100d);
double rankPercentage = (Convert.ToDouble(temp.Position) / Convert.ToDouble(temp.Players)) * 100d;
if (temp.Position == 1) {
temp.Tier = 1; //gold
} else if (temp.Position == 2 || rankPercentage <= 20d) {
Expand Down
165 changes: 92 additions & 73 deletions Views/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,68 @@ private void UpdateTimer() {
}
}
}
private void SetRoundLabel(LevelStats level, LevelType levelType, string roundName, int overlaySetting) {
if (Stats.IsQueued && (overlaySetting == 1 || overlaySetting == 5)) {
this.lblRound.LevelColor = Color.Empty;
this.lblRound.RoundIcon = null;
this.lblRound.ImageWidth = 0;
this.lblRound.ImageHeight = 0;
this.lblRound.Text = $"{Multilingual.GetWord("overlay_queued_players")} :";
this.lblRound.TextRight = Stats.QueuedPlayers.ToString();
this.lblRound.ForeColor = this.ForeColor;
} else {
this.lblRound.UseShareCode = this.lastRound.UseShareCode;
if (this.StatsForm.CurrentSettings.ColorByRoundType) {
this.lblRound.Text = $"{Multilingual.GetWord("overlay_round_abbreviation_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_abbreviation_suffix")} :";
this.lblRound.LevelColor = levelType.LevelBackColor(this.lastRound.IsFinal, this.lastRound.IsTeam, 223);
this.lblRound.LevelTrueColor = levelType.LevelBackColor(false, this.lastRound.IsTeam, 127);
this.lblRound.RoundIcon = level?.RoundBigIcon;
if (this.lblRound.RoundIcon.Height != 23) {
this.lblRound.ImageHeight = 23;
this.lblRound.ImageWidth = (int)Math.Ceiling(Convert.ToDouble(this.lblRound.ImageHeight) / this.lblRound.RoundIcon.Height * this.lblRound.RoundIcon.Width);
} else {
this.lblRound.ImageHeight = this.lblRound.RoundIcon.Height;
this.lblRound.ImageWidth = this.lblRound.RoundIcon.Width;
}
} else {
this.lblRound.Text = $"{Multilingual.GetWord("overlay_round_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_suffix")} :";
this.lblRound.LevelColor = Color.Empty;
this.lblRound.RoundIcon = null;
this.lblRound.ImageWidth = 0;
this.lblRound.ImageHeight = 0;
}

if (((Stats.CurrentLanguage == 0 || Stats.CurrentLanguage == 1) && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(0).Name))
|| (Stats.CurrentLanguage == 2 && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(2).Name))
|| (Stats.CurrentLanguage == 3 && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(3).Name))
|| ((Stats.CurrentLanguage == 4 || Stats.CurrentLanguage == 5) && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(4).Name))
|| this.lastRound.UseShareCode) {
if (roundName.Length > 30) { roundName = roundName.Substring(0, 30); }
} else {
if (roundName.Length > 21) { roundName = roundName.Substring(0, 21); }
}

this.lblRound.TextRight = roundName;
}
}
private void SetWinsLabel(StatSummary levelInfo, int overlaySetting) {
if (Stats.IsQueued && overlaySetting == 3) {
this.lblWins.Text = $"{Multilingual.GetWord("overlay_queued_players")} :";
this.lblWins.TextRight = Stats.QueuedPlayers.ToString();
this.lblWins.ForeColor = this.ForeColor;
} else {
this.lblWins.Text = $"{Multilingual.GetWord("overlay_wins")} :";
float winChance = levelInfo.TotalWins * 100f / (levelInfo.TotalShows == 0 ? 1 : levelInfo.TotalShows);
string winChanceDisplay = this.StatsForm.CurrentSettings.HideOverlayPercentages ? string.Empty : $"{Multilingual.GetWord("overlay_win")} - {winChance:0.0}%";
if (this.StatsForm.CurrentSettings.PreviousWins > 0) {
this.lblWins.TextRight = $"{levelInfo.TotalWins} ({levelInfo.AllWins + this.StatsForm.CurrentSettings.PreviousWins}){winChanceDisplay}";
} else {
this.lblWins.TextRight = this.StatsForm.CurrentSettings.FilterType != 1
? $"{levelInfo.TotalWins} ({levelInfo.AllWins}){winChanceDisplay}"
: $"{levelInfo.TotalWins}{winChanceDisplay}";
}
}
}
private void SetFinalsLabel(StatSummary levelInfo, int overlaySetting) {
if (this.StatsForm.CurrentSettings.DisplayCurrentTime && !Stats.IsPrePlaying && overlaySetting == 3) {
this.lblFinals.OverlaySetting = overlaySetting;
Expand Down Expand Up @@ -625,25 +687,31 @@ private void SetFastestLabel(StatSummary levelInfo, LevelType type, int overlayS
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_current_time")} :";
this.lblFastest.TextRight = $"{DateTime.Now:HH\\:mm\\:ss}";
} else {
this.lblFastest.SecondProgress = 0;
int fastestSwitchCount = this.switchCount;
if (!this.StatsForm.CurrentSettings.SwitchBetweenLongest) {
fastestSwitchCount = this.StatsForm.CurrentSettings.OnlyShowLongest ? 0
: this.levelException == 1 ? 1 : this.levelException == 2 ? 2 : type.FastestLabel();
}
switch (fastestSwitchCount % ((levelInfo.BestScore.HasValue && this.levelException != 1) ? 3 : 2)) {
case 0:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_longest")} :";
this.lblFastest.TextRight = levelInfo.LongestFinish.HasValue ? $"{levelInfo.LongestFinish:m\\:ss\\.ff}" : "-";
break;
case 1:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_fastest")} :";
this.lblFastest.TextRight = levelInfo.BestFinish.HasValue ? $"{levelInfo.BestFinish:m\\:ss\\.ff}" : "-";
break;
case 2:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_best_score")} :";
this.lblFastest.TextRight = $"{levelInfo.BestScore}";
break;
if (Stats.IsQueued && overlaySetting == 6) {
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_queued_players")} :";
this.lblFastest.TextRight = Stats.QueuedPlayers.ToString();
this.lblFastest.ForeColor = this.ForeColor;
} else {
this.lblFastest.SecondProgress = 0;
int fastestSwitchCount = this.switchCount;
if (!this.StatsForm.CurrentSettings.SwitchBetweenLongest) {
fastestSwitchCount = this.StatsForm.CurrentSettings.OnlyShowLongest ? 0
: this.levelException == 1 ? 1 : this.levelException == 2 ? 2 : type.FastestLabel();
}
switch (fastestSwitchCount % ((levelInfo.BestScore.HasValue && this.levelException != 1) ? 3 : 2)) {
case 0:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_longest")} :";
this.lblFastest.TextRight = levelInfo.LongestFinish.HasValue ? $"{levelInfo.LongestFinish:m\\:ss\\.ff}" : "-";
break;
case 1:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_fastest")} :";
this.lblFastest.TextRight = levelInfo.BestFinish.HasValue ? $"{levelInfo.BestFinish:m\\:ss\\.ff}" : "-";
break;
case 2:
this.lblFastest.Text = $"{Multilingual.GetWord("overlay_best_score")} :";
this.lblFastest.TextRight = $"{levelInfo.BestScore}";
break;
}
}
}
}
Expand Down Expand Up @@ -837,11 +905,12 @@ private void SetFinishLabel(StatSummary levelInfo, LevelType levelType, int over
this.lblFinish.TextRight = $@"{DateTime.Now.ToString(Multilingual.GetWord("level_date_format"))}";
this.lblFinish.ForeColor = this.ForeColor;
} else {
this.lblFinish.Text = Stats.IsQueued ? $"{Multilingual.GetWord("overlay_queued_players")} :" : $"{Multilingual.GetWord("overlay_finish")} :";
if (Stats.IsQueued) {
if (Stats.IsQueued && (overlaySetting == 0 || overlaySetting == 2 || overlaySetting == 4)) {
this.lblFinish.Text = $"{Multilingual.GetWord("overlay_queued_players")} :";
this.lblFinish.TextRight = Stats.QueuedPlayers.ToString();
this.lblFinish.ForeColor = this.ForeColor;
} else {
this.lblFinish.Text = $"{Multilingual.GetWord("overlay_finish")} :";
DateTime start = this.lastRound.Start;
DateTime? finish = this.lastRound.Finish;
if (finish.HasValue) {
Expand Down Expand Up @@ -912,60 +981,10 @@ private void UpdateInfo() {
}

LevelType levelType = (level?.Type).GetValueOrDefault();

StatSummary levelInfo = this.StatsForm.GetLevelInfo(this.lastRound.UseShareCode ? this.lastRound.ShowNameId : roundName, this.levelException, this.lastRound.UseShareCode, levelType);

//if (this.lastRound.UseShareCode) {
// roundName = this.StatsForm.GetRoundNameFromShareCode(roundName);
//}

if (((Stats.CurrentLanguage == 0 || Stats.CurrentLanguage == 1) && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(0).Name))
|| (Stats.CurrentLanguage == 2 && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(2).Name))
|| (Stats.CurrentLanguage == 3 && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(3).Name))
|| ((Stats.CurrentLanguage == 4 || Stats.CurrentLanguage == 5) && this.Font.FontFamily.Name.Equals(GetDefaultFontFamilies(4).Name))
|| this.lastRound.UseShareCode) {
if (roundName.Length > 30) { roundName = roundName.Substring(0, 30); }
} else {
if (roundName.Length > 21) { roundName = roundName.Substring(0, 21); }
}

this.lblRound.UseShareCode = this.lastRound.UseShareCode;
if (this.StatsForm.CurrentSettings.ColorByRoundType) {
this.lblRound.Text = $"{Multilingual.GetWord("overlay_round_abbreviation_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_abbreviation_suffix")} :";
this.lblRound.LevelColor = levelType.LevelBackColor(this.lastRound.IsFinal, this.lastRound.IsTeam, 223);
this.lblRound.LevelTrueColor = levelType.LevelBackColor(false, this.lastRound.IsTeam, 127);
this.lblRound.RoundIcon = level?.RoundBigIcon;
if (this.lblRound.RoundIcon.Height != 23) {
this.lblRound.ImageHeight = 23;
this.lblRound.ImageWidth = (int)Math.Ceiling(Convert.ToDouble(this.lblRound.ImageHeight) / this.lblRound.RoundIcon.Height * this.lblRound.RoundIcon.Width);
} else {
this.lblRound.ImageHeight = this.lblRound.RoundIcon.Height;
this.lblRound.ImageWidth = this.lblRound.RoundIcon.Width;
}
} else {
//this.lblRound.Text = this.lblRound.IsCreativeRound ?
// $"{Multilingual.GetWord("overlay_round_abbreviation_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_abbreviation_suffix")} :" :
// $"{Multilingual.GetWord("overlay_round_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_suffix")} :";
this.lblRound.Text = $"{Multilingual.GetWord("overlay_round_prefix")}{this.lastRound.Round}{Multilingual.GetWord("overlay_round_suffix")} :";
this.lblRound.LevelColor = Color.Empty;
this.lblRound.RoundIcon = null;
this.lblRound.ImageWidth = 0;
this.lblRound.ImageHeight = 0;
}

this.lblRound.TextRight = roundName;

this.lblWins.Text = $"{Multilingual.GetWord("overlay_wins")} :";
float winChance = levelInfo.TotalWins * 100f / (levelInfo.TotalShows == 0 ? 1 : levelInfo.TotalShows);
string winChanceDisplay = this.StatsForm.CurrentSettings.HideOverlayPercentages ? string.Empty : $"{Multilingual.GetWord("overlay_win")} - {winChance:0.0}%";
if (this.StatsForm.CurrentSettings.PreviousWins > 0) {
this.lblWins.TextRight = $"{levelInfo.TotalWins} ({levelInfo.AllWins + this.StatsForm.CurrentSettings.PreviousWins}){winChanceDisplay}";
} else {
this.lblWins.TextRight = this.StatsForm.CurrentSettings.FilterType != 1
? $"{levelInfo.TotalWins} ({levelInfo.AllWins}){winChanceDisplay}"
: $"{levelInfo.TotalWins}{winChanceDisplay}";
}

this.SetRoundLabel(level, levelType, roundName, overlaySetting);
this.SetWinsLabel(levelInfo, overlaySetting);
this.SetFinalsLabel(levelInfo, overlaySetting);
this.SetQualifyChanceLabel(levelInfo, overlaySetting);
this.SetPlayersLabel(overlaySetting);
Expand Down
Loading

0 comments on commit 6ce4048

Please sign in to comment.