mirror of
https://github.com/ppy/osu
synced 2024-12-23 15:22:37 +00:00
Refactor ModelDownloader
to allow for different OnlineID matching
This commit is contained in:
parent
9015ac6ba8
commit
617e6febb6
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user