From b72921b30ee888c73d38b3f2f49303f3a3cb71b8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 15 Sep 2017 12:44:48 +0900 Subject: [PATCH 1/4] Ensure an OnlineBeatmapID is present before attempting API requests --- osu.Game/Online/API/Requests/GetScoresRequest.cs | 12 +++--------- osu.Game/Screens/Select/Leaderboards/Leaderboard.cs | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index ef9ee85d25..13bd8d288d 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; -using osu.Framework.IO.Network; using osu.Game.Beatmaps; using osu.Game.Users; using osu.Game.Rulesets.Replays; @@ -19,6 +18,9 @@ namespace osu.Game.Online.API.Requests public GetScoresRequest(BeatmapInfo beatmap) { + if (!beatmap.OnlineBeatmapID.HasValue) + throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}."); + this.beatmap = beatmap; Success += onSuccess; @@ -30,14 +32,6 @@ namespace osu.Game.Online.API.Requests score.ApplyBeatmap(beatmap); } - protected override WebRequest CreateWebRequest() - { - var req = base.CreateWebRequest(); - //req.AddParameter(@"c", beatmap.Hash); - //req.AddParameter(@"f", beatmap.Path); - return req; - } - protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores"; } diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 0506784614..7d65b8b648 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -130,7 +130,7 @@ namespace osu.Game.Screens.Select.Leaderboards Scores = null; getScoresRequest?.Cancel(); - if (api == null || Beatmap == null) return; + if (api == null || Beatmap?.OnlineBeatmapID == null) return; loading.Show(); From 47b62803d866c6101486dd65d3e4f0f116f03707 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Fri, 15 Sep 2017 15:47:56 -0500 Subject: [PATCH 2/4] Account for all files instead of just the main directory ones --- osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs index dc38181717..8857a4ad42 100644 --- a/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs @@ -26,7 +26,7 @@ namespace osu.Game.Beatmaps.IO // no-op } - public override IEnumerable Filenames => Directory.GetFiles(path).Select(Path.GetFileName).ToArray(); + public override IEnumerable Filenames => Directory.GetDirectories(path).Select(Path.GetFileName).ToArray(); public override Stream GetUnderlyingStream() => null; } From 51a5e963bb80aff199e34df8ed5f1e96150746e2 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Sat, 16 Sep 2017 15:10:24 +0300 Subject: [PATCH 3/4] Dispose IDisposable object before method returns --- osu.Game/Online/API/OAuth.cs | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/osu.Game/Online/API/OAuth.cs b/osu.Game/Online/API/OAuth.cs index c96b21a855..5410bcc55d 100644 --- a/osu.Game/Online/API/OAuth.cs +++ b/osu.Game/Online/API/OAuth.cs @@ -27,42 +27,45 @@ namespace osu.Game.Online.API internal bool AuthenticateWithLogin(string username, string password) { - var req = new AccessTokenRequestPassword(username, password) + using (var req = new AccessTokenRequestPassword(username, password) { Url = $@"{endpoint}/oauth/token", Method = HttpMethod.POST, ClientId = clientId, ClientSecret = clientSecret - }; - - try + }) { - req.BlockingPerform(); - } - catch - { - return false; - } + try + { + req.BlockingPerform(); + } + catch + { + return false; + } - Token = req.ResponseObject; - return true; + Token = req.ResponseObject; + return true; + } } internal bool AuthenticateWithRefresh(string refresh) { try { - var req = new AccessTokenRequestRefresh(refresh) + using (var req = new AccessTokenRequestRefresh(refresh) { Url = $@"{endpoint}/oauth/token", Method = HttpMethod.POST, ClientId = clientId, ClientSecret = clientSecret - }; - req.BlockingPerform(); + }) + { + req.BlockingPerform(); - Token = req.ResponseObject; - return true; + Token = req.ResponseObject; + return true; + } } catch { From 8944d0f705c6a1e4ac3b1a8b0fb9269f2f3e00b2 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sat, 16 Sep 2017 18:44:32 -0500 Subject: [PATCH 4/4] make it only look for files instead of directories --- osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs index 8857a4ad42..21042ad8bd 100644 --- a/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Game/Beatmaps/IO/LegacyFilesystemReader.cs @@ -26,7 +26,7 @@ namespace osu.Game.Beatmaps.IO // no-op } - public override IEnumerable Filenames => Directory.GetDirectories(path).Select(Path.GetFileName).ToArray(); + public override IEnumerable Filenames => Directory.GetFiles(path, "*", SearchOption.AllDirectories).Select(Path.GetFileName).ToArray(); public override Stream GetUnderlyingStream() => null; }