mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Create interfaces for DownloadTrackingComposite to consume
This commit is contained in:
parent
d903ad2186
commit
4a6074865e
@ -229,6 +229,8 @@ namespace osu.Game.Beatmaps
|
||||
/// <returns>Results from the provided query.</returns>
|
||||
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().Where(query);
|
||||
|
||||
public override bool IsAvailableLocally(BeatmapSetInfo set) => beatmaps.ConsumableItems.Any(s => s.OnlineBeatmapSetID == set.OnlineBeatmapSetID && !s.DeletePending && !s.Protected);
|
||||
|
||||
protected override BeatmapSetInfo CreateModel(ArchiveReader reader)
|
||||
{
|
||||
// let's make sure there are actually .osu files to import.
|
||||
|
@ -18,18 +18,12 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The model type.</typeparam>
|
||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||
public abstract class ArchiveDownloadModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>
|
||||
public abstract class ArchiveDownloadModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>, IDownloadModelManager<TModel>
|
||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||
where TFileModel : INamedFileInfo, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> download begins.
|
||||
/// </summary>
|
||||
public event Action<ArchiveDownloadModelRequest<TModel>> DownloadBegan;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> download is interrupted, either due to user cancellation or failure.
|
||||
/// </summary>
|
||||
public event Action<ArchiveDownloadModelRequest<TModel>> DownloadFailed;
|
||||
|
||||
private readonly IAPIProvider api;
|
||||
@ -55,12 +49,6 @@ namespace osu.Game.Database
|
||||
/// <returns>The request object.</returns>
|
||||
protected abstract ArchiveDownloadModelRequest<TModel> CreateDownloadRequest(TModel model, object[] options);
|
||||
|
||||
/// <summary>
|
||||
/// Downloads a <see cref="TModel"/>.
|
||||
/// This will post notifications tracking progress.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
|
||||
/// <returns>Whether downloading can happen.</returns>
|
||||
public bool Download(TModel model)
|
||||
{
|
||||
if (!canDownload(model)) return false;
|
||||
@ -72,13 +60,6 @@ namespace osu.Game.Database
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads a <see cref="TModel"/> with optional parameters for the download request.
|
||||
/// This will post notifications tracking progress.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
|
||||
/// <param name="extra">Optional parameters to be used for creating the download request.</param>
|
||||
/// <returns>Whether downloading can happen.</returns>
|
||||
public bool Download(TModel model, params object[] extra)
|
||||
{
|
||||
if (!canDownload(model)) return false;
|
||||
@ -90,12 +71,7 @@ namespace osu.Game.Database
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="TModel"/> is available in the local store already.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> whose existence needs to be checked.</param>
|
||||
/// <returns>Whether the <see cref="TModel"/> exists locally.</returns>
|
||||
public bool IsAvailableLocally(TModel model) => modelStore.ConsumableItems.Any(m => m.Equals(model));
|
||||
public virtual bool IsAvailableLocally(TModel model) => modelStore.ConsumableItems.Any(m => m.Equals(model) && !m.DeletePending);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an existing <see cref="TModel"/> download request if it exists.
|
||||
|
@ -29,7 +29,7 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The model type.</typeparam>
|
||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles
|
||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager
|
||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||
where TFileModel : INamedFileInfo, new()
|
||||
{
|
||||
|
47
osu.Game/Database/IDownloadModelManager.cs
Normal file
47
osu.Game/Database/IDownloadModelManager.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using osu.Game.Online.API;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public interface IDownloadModelManager<TModel> : IModelManager<TModel>
|
||||
where TModel : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> download begins.
|
||||
/// </summary>
|
||||
event Action<ArchiveDownloadModelRequest<TModel>> DownloadBegan;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> download is interrupted, either due to user cancellation or failure.
|
||||
/// </summary>
|
||||
event Action<ArchiveDownloadModelRequest<TModel>> DownloadFailed;
|
||||
|
||||
bool IsAvailableLocally(TModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Downloads a <see cref="TModel"/>.
|
||||
/// This will post notifications tracking progress.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
|
||||
/// <returns>Whether downloading can happen.</returns>
|
||||
bool Download(TModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Downloads a <see cref="TModel"/> with optional parameters for the download request.
|
||||
/// This will post notifications tracking progress.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
|
||||
/// <param name="extra">Optional parameters to be used for creating the download request.</param>
|
||||
/// <returns>Whether downloading can happen.</returns>
|
||||
bool Download(TModel model, params object[] extra);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="TModel"/> is available in the local store already.
|
||||
/// </summary>
|
||||
/// <param name="model">The <see cref="TModel"/> whose existence needs to be checked.</param>
|
||||
/// <returns>Whether the <see cref="TModel"/> exists locally.</returns>
|
||||
ArchiveDownloadModelRequest<TModel> GetExistingDownload(TModel model);
|
||||
}
|
||||
}
|
20
osu.Game/Database/IModelManager.cs
Normal file
20
osu.Game/Database/IModelManager.cs
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public interface IModelManager<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a new <see cref="TModel"/> becomes available in the database.
|
||||
/// This is not guaranteed to run on the update thread.
|
||||
/// </summary>
|
||||
event Action<TModel, bool> ItemAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a <see cref="TModel"/> is removed from the database.
|
||||
/// This is not guaranteed to run on the update thread.
|
||||
/// </summary>
|
||||
event Action<TModel> ItemRemoved;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user