From 83cd2fd31763a773bdf78c2e2f6119b09df5c1f3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 14 Mar 2018 10:07:16 +0900 Subject: [PATCH] Move token saving logic to APIAccess --- osu.Game/Online/API/APIAccess.cs | 21 +++++++++++++++++++-- osu.Game/OsuGameBase.cs | 8 +------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 40584006cd..91b77dcf1f 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -16,7 +16,7 @@ using osu.Game.Users; namespace osu.Game.Online.API { - public class APIAccess : IAPIProvider + public class APIAccess : IAPIProvider, IDisposable { private readonly OsuConfigManager config; private readonly OAuth authentication; @@ -27,7 +27,7 @@ namespace osu.Game.Online.API private ConcurrentQueue queue = new ConcurrentQueue(); - public Scheduler Scheduler = new Scheduler(); + public readonly Scheduler Scheduler = new Scheduler(); /// /// The username/email provided by the user when initiating a login. @@ -310,6 +310,23 @@ namespace osu.Game.Online.API { Scheduler.Update(); } + + private void dispose() + { + config.Set(OsuSetting.Token, config.Get(OsuSetting.SavePassword) ? Token : string.Empty); + config.Save(); + } + + public void Dispose() + { + dispose(); + GC.SuppressFinalize(this); + } + + ~APIAccess() + { + dispose(); + } } public enum APIState diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 2096318a32..a3e4d34659 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -245,14 +245,8 @@ namespace osu.Game protected override void Dispose(bool isDisposing) { - //refresh token may have changed. - if (LocalConfig != null && API != null) - { - LocalConfig.Set(OsuSetting.Token, LocalConfig.Get(OsuSetting.SavePassword) ? API.Token : string.Empty); - LocalConfig.Save(); - } - base.Dispose(isDisposing); + API.Dispose(); } private readonly List fileImporters = new List();