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 @@ private void collectionsChanged(object sender, NotifyCollectionChangedEventArgs
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 @@ public class LegacyImportManager : Component
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 @@ protected LegacyModelImporter(IModelImporter<TModel> importer)
Importer = importer;
}
public Task<int> GetAvailableCount(StableStorage stableStorage) => Task.Run(() => GetStableImportPaths(stableStorage).Count());
public Task ImportFromStableAsync(StableStorage stableStorage)
{
var storage = PrepareStableStorage(stableStorage);