mirror of https://github.com/ppy/osu
Make APIAccess a component
This commit is contained in:
parent
83cd2fd317
commit
07642546bb
|
@ -8,15 +8,15 @@
|
|||
using System.Net;
|
||||
using System.Threading;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
{
|
||||
public class APIAccess : IAPIProvider, IDisposable
|
||||
public class APIAccess : Component, IAPIProvider
|
||||
{
|
||||
private readonly OsuConfigManager config;
|
||||
private readonly OAuth authentication;
|
||||
|
@ -27,8 +27,6 @@ public class APIAccess : IAPIProvider, IDisposable
|
|||
|
||||
private ConcurrentQueue<APIRequest> queue = new ConcurrentQueue<APIRequest>();
|
||||
|
||||
public readonly Scheduler Scheduler = new Scheduler();
|
||||
|
||||
/// <summary>
|
||||
/// The username/email provided by the user when initiating a login.
|
||||
/// </summary>
|
||||
|
@ -306,27 +304,13 @@ public void Logout(bool clearUsername = true)
|
|||
Id = 1,
|
||||
};
|
||||
|
||||
public void Update()
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
Scheduler.Update();
|
||||
}
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
private void dispose()
|
||||
{
|
||||
config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? Token : string.Empty);
|
||||
config.Save();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~APIAccess()
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public enum APIState
|
||||
|
|
|
@ -14,7 +14,7 @@ protected override WebRequest CreateWebRequest()
|
|||
return request;
|
||||
}
|
||||
|
||||
private void request_Progress(long current, long total) => API.Scheduler.Add(delegate { Progress?.Invoke(current, total); });
|
||||
private void request_Progress(long current, long total) => Progress?.Invoke(current, total);
|
||||
|
||||
protected APIDownloadRequest()
|
||||
{
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
{
|
||||
public interface IAPIProvider : IUpdateable
|
||||
public interface IAPIProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// The local user.
|
||||
|
|
|
@ -56,8 +56,6 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles
|
|||
|
||||
protected override string MainResourceFile => @"osu.Game.Resources.dll";
|
||||
|
||||
public APIAccess API;
|
||||
|
||||
private Container content;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
@ -108,12 +106,14 @@ private void load()
|
|||
|
||||
dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio));
|
||||
|
||||
dependencies.Cache(API = new APIAccess(LocalConfig));
|
||||
dependencies.CacheAs<IAPIProvider>(API);
|
||||
var api = new APIAccess(LocalConfig);
|
||||
|
||||
dependencies.Cache(api);
|
||||
dependencies.CacheAs<IAPIProvider>(api);
|
||||
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
|
||||
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, API, Host));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Host));
|
||||
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory, Host, BeatmapManager, RulesetStore));
|
||||
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||
|
@ -180,6 +180,8 @@ private void load()
|
|||
};
|
||||
|
||||
FileStore.Cleanup();
|
||||
|
||||
AddInternal(api);
|
||||
}
|
||||
|
||||
private void runMigrations()
|
||||
|
@ -237,18 +239,6 @@ public override void SetHost(GameHost host)
|
|||
base.SetHost(host);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
API.Update();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
API.Dispose();
|
||||
}
|
||||
|
||||
private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>();
|
||||
|
||||
public void Import(params string[] paths)
|
||||
|
|
|
@ -186,7 +186,7 @@ private void attachDownload(DownloadBeatmapSetRequest request)
|
|||
progressBar.FadeOut(500);
|
||||
};
|
||||
|
||||
request.DownloadProgressed += progress => progressBar.Current.Value = progress;
|
||||
request.DownloadProgressed += progress => Schedule(() => progressBar.Current.Value = progress);
|
||||
|
||||
request.Success += data =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue