1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:42:56 +08:00

Merge branch 'master' into improve-text-search

This commit is contained in:
Dean Herbert 2018-12-19 20:45:00 +09:00 committed by GitHub
commit e15ff98915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 52 deletions

View File

@ -149,8 +149,10 @@ namespace osu.Game.Database
try try
{ {
notification.Text = $"Importing ({++current} of {paths.Length})\n{Path.GetFileName(path)}"; notification.Text = $"Importing ({++current} of {paths.Length})\n{Path.GetFileName(path)}";
TModel import;
using (ArchiveReader reader = getReaderFrom(path)) using (ArchiveReader reader = getReaderFrom(path))
imported.Add(Import(reader)); imported.Add(import = Import(reader));
notification.Progress = (float)current / paths.Length; notification.Progress = (float)current / paths.Length;
@ -160,7 +162,7 @@ namespace osu.Game.Database
// TODO: Add a check to prevent files from storage to be deleted. // TODO: Add a check to prevent files from storage to be deleted.
try try
{ {
if (File.Exists(path)) if (import != null && File.Exists(path))
File.Delete(path); File.Delete(path);
} }
catch (Exception e) catch (Exception e)

View File

@ -102,7 +102,7 @@ namespace osu.Game.Online.API
if (queue.Count == 0) if (queue.Count == 0)
{ {
log.Add(@"Queueing a ping request"); log.Add(@"Queueing a ping request");
Queue(new ListChannelsRequest { Timeout = 5000 }); Queue(new GetUserRequest());
} }
break; break;
@ -173,7 +173,6 @@ namespace osu.Game.Online.API
req = queue.Dequeue(); req = queue.Dequeue();
} }
// TODO: handle failures better
handleRequest(req); handleRequest(req);
} }
@ -191,45 +190,30 @@ namespace osu.Game.Online.API
/// <summary> /// <summary>
/// Handle a single API request. /// Handle a single API request.
/// Ensures all exceptions are caught and dealt with correctly.
/// </summary> /// </summary>
/// <param name="req">The request.</param> /// <param name="req">The request.</param>
/// <returns>true if we should remove this request from the queue.</returns> /// <returns>true if the request succeeded.</returns>
private bool handleRequest(APIRequest req) private bool handleRequest(APIRequest req)
{ {
try try
{ {
Logger.Log($@"Performing request {req}", LoggingTarget.Network);
req.Failure += ex =>
{
if (ex is WebException we)
handleWebException(we);
};
req.Perform(this); req.Perform(this);
//we could still be in initialisation, at which point we don't want to say we're Online yet. //we could still be in initialisation, at which point we don't want to say we're Online yet.
if (IsLoggedIn) if (IsLoggedIn) State = APIState.Online;
State = APIState.Online;
failureCount = 0; failureCount = 0;
return true; return true;
} }
catch (WebException we) catch (WebException we)
{ {
var removeFromQueue = handleWebException(we); handleWebException(we);
return false;
if (removeFromQueue)
req.Fail(we);
return removeFromQueue;
} }
catch (Exception e) catch (Exception e)
{ {
if (e is TimeoutException) return false;
log.Add(@"API level timeout exception was hit");
req.Fail(e);
return true;
} }
} }
@ -284,8 +268,12 @@ namespace osu.Game.Online.API
//we might try again at an api level. //we might try again at an api level.
return false; return false;
State = APIState.Failing; if (State == APIState.Online)
flushQueue(); {
State = APIState.Failing;
flushQueue();
}
return true; return true;
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using osu.Framework.IO.Network; using osu.Framework.IO.Network;
using osu.Framework.Logging;
namespace osu.Game.Online.API namespace osu.Game.Online.API
{ {
@ -35,23 +36,12 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
public abstract class APIRequest public abstract class APIRequest
{ {
/// <summary>
/// The maximum amount of time before this request will fail.
/// </summary>
public int Timeout = WebRequest.DEFAULT_TIMEOUT;
protected virtual string Target => string.Empty; protected virtual string Target => string.Empty;
protected virtual WebRequest CreateWebRequest() => new WebRequest(Uri); protected virtual WebRequest CreateWebRequest() => new WebRequest(Uri);
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}"; protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
private double remainingTime => Math.Max(0, Timeout - (DateTimeOffset.UtcNow - (startTime ?? DateTimeOffset.MinValue)).TotalMilliseconds);
public bool ExceededTimeout => remainingTime == 0;
private DateTimeOffset? startTime;
protected APIAccess API; protected APIAccess API;
protected WebRequest WebRequest; protected WebRequest WebRequest;
@ -75,27 +65,24 @@ namespace osu.Game.Online.API
{ {
API = api; API = api;
if (checkAndProcessFailure()) if (checkAndScheduleFailure())
return; return;
if (startTime == null)
startTime = DateTimeOffset.UtcNow;
if (remainingTime <= 0)
throw new TimeoutException(@"API request timeout hit");
WebRequest = CreateWebRequest(); WebRequest = CreateWebRequest();
WebRequest.Failed += Fail; WebRequest.Failed += Fail;
WebRequest.AllowRetryOnTimeout = false; WebRequest.AllowRetryOnTimeout = false;
WebRequest.AddHeader("Authorization", $"Bearer {api.AccessToken}"); WebRequest.AddHeader("Authorization", $"Bearer {api.AccessToken}");
if (checkAndProcessFailure()) if (checkAndScheduleFailure())
return; return;
if (!WebRequest.Aborted) //could have been aborted by a Cancel() call if (!WebRequest.Aborted) //could have been aborted by a Cancel() call
{
Logger.Log($@"Performing request {this}", LoggingTarget.Network);
WebRequest.Perform(); WebRequest.Perform();
}
if (checkAndProcessFailure()) if (checkAndScheduleFailure())
return; return;
api.Schedule(delegate { Success?.Invoke(); }); api.Schedule(delegate { Success?.Invoke(); });
@ -105,19 +92,21 @@ namespace osu.Game.Online.API
public void Fail(Exception e) public void Fail(Exception e)
{ {
cancelled = true; if (cancelled) return;
cancelled = true;
WebRequest?.Abort(); WebRequest?.Abort();
Logger.Log($@"Failing request {this} ({e})", LoggingTarget.Network);
pendingFailure = () => Failure?.Invoke(e); pendingFailure = () => Failure?.Invoke(e);
checkAndProcessFailure(); checkAndScheduleFailure();
} }
/// <summary> /// <summary>
/// Checked for cancellation or error. Also queues up the Failed event if we can. /// Checked for cancellation or error. Also queues up the Failed event if we can.
/// </summary> /// </summary>
/// <returns>Whether we are in a failed or cancelled state.</returns> /// <returns>Whether we are in a failed or cancelled state.</returns>
private bool checkAndProcessFailure() private bool checkAndScheduleFailure()
{ {
if (API == null || pendingFailure == null) return cancelled; if (API == null || pendingFailure == null) return cancelled;

View File

@ -20,7 +20,7 @@ using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Chat.Selection namespace osu.Game.Overlays.Chat.Selection
{ {
public class ChannelSelectionOverlay : OsuFocusedOverlayContainer public class ChannelSelectionOverlay : WaveOverlayContainer
{ {
public static readonly float WIDTH_PADDING = 170; public static readonly float WIDTH_PADDING = 170;
@ -39,6 +39,11 @@ namespace osu.Game.Overlays.Chat.Selection
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Waves.FirstWaveColour = OsuColour.FromHex("353535");
Waves.SecondWaveColour = OsuColour.FromHex("434343");
Waves.ThirdWaveColour = OsuColour.FromHex("515151");
Waves.FourthWaveColour = OsuColour.FromHex("595959");
Children = new Drawable[] Children = new Drawable[]
{ {
new Container new Container

View File

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2018.1214.0" /> <PackageReference Include="ppy.osu.Framework" Version="2018.1219.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />