diff --git a/CollapseLauncher/Classes/GameManagement/GamePlaytime/RegistryClass/CollapsePlaytime.cs b/CollapseLauncher/Classes/GameManagement/GamePlaytime/RegistryClass/CollapsePlaytime.cs index 8e3ed2a43..bf4bbf1e2 100644 --- a/CollapseLauncher/Classes/GameManagement/GamePlaytime/RegistryClass/CollapsePlaytime.cs +++ b/CollapseLauncher/Classes/GameManagement/GamePlaytime/RegistryClass/CollapsePlaytime.cs @@ -119,7 +119,8 @@ public static CollapsePlaytime Load(RegistryKey root, int hashID, playtimeInner._hashID = hashID; playtimeInner.TotalPlaytime = TimeSpan.FromSeconds(totalTime ?? 0); playtimeInner.LastPlayed = lastPlayed != null ? BaseDate.AddSeconds((int)lastPlayed) : null; - + playtimeInner.CheckStatsReset(); + return playtimeInner; } catch (Exception ex) @@ -190,7 +191,7 @@ public void Reset() } /// - /// Updates the current Playtime TimeSpan to the provided value and saves to the Registry.

+ /// Updates the current Playtime TimeSpan to the provided value and saves to the registry.

///
/// New playtime value /// Reset all other fields @@ -211,32 +212,42 @@ public void Update(TimeSpan timeSpan, bool reset = true, bool forceUpdateDb = fa if (!_isDeserializing.Contains(_hashID)) Save(forceUpdateDb); } + /// + /// Checks if any stats should be reset.
+ /// Afterwards, the values are saved to the registry.

+ ///
+ private void CheckStatsReset() + { + DateTime today = DateTime.Today; + + if (ControlDate == today) + return; + + DailyPlaytime = TimeSpan.Zero; + if (IsDifferentWeek(ControlDate, today)) + WeeklyPlaytime = TimeSpan.Zero; + if (IsDifferentMonth(ControlDate, today)) + MonthlyPlaytime = TimeSpan.Zero; + + ControlDate = today; + } + /// /// Adds a minute to all fields, and checks if any should be reset.
- /// After it saves to the Registry.

+ /// Afterwards, the values are saved to the registry.

///
public void AddMinute() { TimeSpan minute = TimeSpan.FromMinutes(1); - DateTime today = DateTime.Today; TotalPlaytime = TotalPlaytime.Add(minute); LastSession = LastSession.Add(minute); - if (ControlDate == today) - { - DailyPlaytime = DailyPlaytime.Add(minute); - WeeklyPlaytime = WeeklyPlaytime.Add(minute); - MonthlyPlaytime = MonthlyPlaytime.Add(minute); - } - else - { - DailyPlaytime = minute; - WeeklyPlaytime = IsDifferentWeek(ControlDate, today) ? minute : WeeklyPlaytime.Add(minute); - MonthlyPlaytime = IsDifferentMonth(ControlDate, today) ? minute : MonthlyPlaytime.Add(minute); - - ControlDate = today; - } + CheckStatsReset(); + + DailyPlaytime = DailyPlaytime.Add(minute); + WeeklyPlaytime = WeeklyPlaytime.Add(minute); + MonthlyPlaytime = MonthlyPlaytime.Add(minute); if (!_isDeserializing.Contains(_hashID)) Save(); } @@ -318,9 +329,13 @@ public void AddMinute() playtimeInner._gameSettings = _gameSettings; playtimeInner._hashID = _hashID; playtimeInner._gameVersion = _gameVersion; + + playtimeInner.CheckStatsReset(); + playtimeInner.Save(); + DbConfig.SetAndSaveValue(KeyLastUpdated, _unixStampDb.ToString()); LastDbUpdate = DateTime.Now; - playtimeInner.Save(); + return (true, playtimeInner); }