1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Allow retrieving count of available stable imports

This commit is contained in:
Dean Herbert 2022-05-16 19:57:00 +09:00
parent 4412fec41a
commit 6448c97929
3 changed files with 37 additions and 0 deletions

View File

@ -111,6 +111,18 @@ namespace osu.Game.Collections
public Action<Notification> PostNotification { protected get; set; }
public Task<int> GetAvailableCount(StableStorage stableStorage)
{
if (!stableStorage.Exists(database_name))
return Task.FromResult(0);
return Task.Run(() =>
{
using (var stream = stableStorage.GetStream(database_name))
return readCollections(stream).Count;
});
}
/// <summary>
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
/// </summary>

View File

@ -49,6 +49,29 @@ namespace osu.Game.Database
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
public async Task<int> GetImportCount(StableContent content)
{
var stableStorage = await getStableStorage().ConfigureAwait(false);
switch (content)
{
case StableContent.Beatmaps:
return await new LegacyBeatmapImporter(beatmaps).GetAvailableCount(stableStorage);
case StableContent.Skins:
return await new LegacySkinImporter(skins).GetAvailableCount(stableStorage);
case StableContent.Collections:
return await collections.GetAvailableCount(stableStorage);
case StableContent.Scores:
return await new LegacyScoreImporter(scores).GetAvailableCount(stableStorage);
default:
throw new ArgumentException($"Only one {nameof(StableContent)} flag should be specified.");
}
}
public async Task ImportFromStableAsync(StableContent content)
{
var stableStorage = await getStableStorage().ConfigureAwait(false);

View File

@ -34,6 +34,8 @@ namespace osu.Game.Database
Importer = importer;
}
public Task<int> GetAvailableCount(StableStorage stableStorage) => Task.Run(() => GetStableImportPaths(stableStorage).Count());
public Task ImportFromStableAsync(StableStorage stableStorage)
{
var storage = PrepareStableStorage(stableStorage);