Refactor ModelDownloader to allow for different OnlineID matching

This commit is contained in:
Dean Herbert 2021-10-27 20:02:51 +09:00
parent 9015ac6ba8
commit 617e6febb6
4 changed files with 13 additions and 7 deletions

View File

@ -13,6 +13,9 @@ namespace osu.Game.Beatmaps
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
public override ArchiveDownloadRequest<BeatmapSetInfo> GetExistingDownload(BeatmapSetInfo model)
=> CurrentDownloads.Find(r => r.Model.OnlineID == model.OnlineID);
public BeatmapModelDownloader(IBeatmapModelManager beatmapModelManager, IAPIProvider api, GameHost host = null)
: base(beatmapModelManager, api, host)
{

View File

@ -15,7 +15,7 @@ using osu.Game.Overlays.Notifications;
namespace osu.Game.Database
{
public abstract class ModelDownloader<TModel> : IModelDownloader<TModel>
where TModel : class, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>, IHasOnlineID
where TModel : class, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>
{
public Action<Notification> PostNotification { protected get; set; }
@ -30,7 +30,7 @@ namespace osu.Game.Database
private readonly IModelManager<TModel> modelManager;
private readonly IAPIProvider api;
private readonly List<ArchiveDownloadRequest<TModel>> currentDownloads = new List<ArchiveDownloadRequest<TModel>>();
protected readonly List<ArchiveDownloadRequest<TModel>> CurrentDownloads = new List<ArchiveDownloadRequest<TModel>>();
protected ModelDownloader(IModelManager<TModel> modelManager, IAPIProvider api, IIpcHost importHost = null)
{
@ -74,7 +74,7 @@ namespace osu.Game.Database
if (!imported.Any())
downloadFailed.Value = new WeakReference<ArchiveDownloadRequest<TModel>>(request);
currentDownloads.Remove(request);
CurrentDownloads.Remove(request);
}, TaskCreationOptions.LongRunning);
};
@ -86,7 +86,7 @@ namespace osu.Game.Database
return true;
};
currentDownloads.Add(request);
CurrentDownloads.Add(request);
PostNotification?.Invoke(notification);
api.PerformAsync(request);
@ -96,7 +96,7 @@ namespace osu.Game.Database
void triggerFailure(Exception error)
{
currentDownloads.Remove(request);
CurrentDownloads.Remove(request);
downloadFailed.Value = new WeakReference<ArchiveDownloadRequest<TModel>>(request);
@ -107,7 +107,7 @@ namespace osu.Game.Database
}
}
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.OnlineID == model.OnlineID);
public abstract ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model);
private bool canDownload(TModel model) => GetExistingDownload(model) == null && api != null;

View File

@ -19,7 +19,7 @@ using osu.Game.Utils;
namespace osu.Game.Scoring
{
public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete, IEquatable<ScoreInfo>, IDeepCloneable<ScoreInfo>, IHasOnlineID
public class ScoreInfo : IHasFiles<ScoreFileInfo>, IHasPrimaryKey, ISoftDelete, IEquatable<ScoreInfo>, IDeepCloneable<ScoreInfo>
{
public int ID { get; set; }

View File

@ -16,5 +16,8 @@ namespace osu.Game.Scoring
}
protected override ArchiveDownloadRequest<ScoreInfo> CreateDownloadRequest(ScoreInfo score, bool minimiseDownload) => new DownloadReplayRequest(score);
public override ArchiveDownloadRequest<ScoreInfo> GetExistingDownload(ScoreInfo model)
=> CurrentDownloads.Find(r => r.Model.OnlineScoreID == model.OnlineScoreID);
}
}