From 802da225d48c387907cccb3666cccb010135d5dd Mon Sep 17 00:00:00 2001 From: HoLLy Date: Fri, 21 Jun 2019 17:32:47 +0200 Subject: [PATCH] Move responsibility for selecting paths to model managers --- osu.Game/Beatmaps/BeatmapManager.cs | 4 ++-- osu.Game/Database/ArchiveModelManager.cs | 21 +++++++-------------- osu.Game/Scoring/ScoreManager.cs | 7 +++++-- osu.Game/Skinning/SkinManager.cs | 4 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index b6fa0ec95a..e357f741d3 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -62,8 +62,6 @@ namespace osu.Game.Beatmaps protected override string ImportFromStablePath => "Songs"; - protected override bool StableDirectoryBased => true; - private readonly RulesetStore rulesets; private readonly BeatmapStore beatmaps; @@ -96,6 +94,8 @@ namespace osu.Game.Beatmaps updateQueue = new BeatmapUpdateQueue(api); } + protected override IEnumerable GetStableImportPaths() => GetStableStorage().GetDirectories(ImportFromStablePath); + protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default) { if (archive != null) diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index e22aa92546..75bc656862 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -146,12 +146,11 @@ namespace osu.Game.Database notification.Progress = 0; notification.Text = "Import is initialising..."; - string[] filteredPaths = paths.Where(canImportPath).ToArray(); int current = 0; var imported = new List(); - await Task.WhenAll(filteredPaths.Select(async path => + await Task.WhenAll(paths.Select(async path => { notification.CancellationToken.ThrowIfCancellationRequested(); @@ -164,8 +163,8 @@ namespace osu.Game.Database imported.Add(model); current++; - notification.Text = $"Imported {current} of {filteredPaths.Length} {HumanisedModelName}s"; - notification.Progress = (float)current / filteredPaths.Length; + notification.Text = $"Imported {current} of {paths.Length} {HumanisedModelName}s"; + notification.Progress = (float)current / paths.Length; } } catch (TaskCanceledException) @@ -201,8 +200,6 @@ namespace osu.Game.Database notification.State = ProgressNotificationState.Completed; } - - bool canImportPath(string path) => StableDirectoryBased || HandledExtensions.Any(ext => Path.GetExtension(path)?.ToLowerInvariant() == ext); } /// @@ -537,7 +534,7 @@ namespace osu.Game.Database /// /// Set a storage with access to an osu-stable install for import purposes. /// - public Func GetStableStorage { private get; set; } + public Func GetStableStorage { protected get; set; } /// /// Denotes whether an osu-stable installation is present to perform automated imports from. @@ -550,9 +547,9 @@ namespace osu.Game.Database protected virtual string ImportFromStablePath => null; /// - /// Does stable import look for directories rather than files + /// Selects paths to import from. /// - protected abstract bool StableDirectoryBased { get; } + protected abstract IEnumerable GetStableImportPaths(); /// /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. @@ -574,11 +571,7 @@ namespace osu.Game.Database return Task.CompletedTask; } - return Task.Run(async () => - { - var paths = StableDirectoryBased ? stable.GetDirectories(ImportFromStablePath) : stable.GetFiles(ImportFromStablePath); - await Import(paths.Select(f => stable.GetFullPath(f)).ToArray()); - }); + return Task.Run(async () => await Import(GetStableImportPaths().Select(f => stable.GetFullPath(f)).ToArray())); } #endregion diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index a8124968d8..bb1b15e9bd 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore; @@ -24,8 +25,6 @@ namespace osu.Game.Scoring protected override string ImportFromStablePath => @"Data\r"; - protected override bool StableDirectoryBased => false; - private readonly RulesetStore rulesets; private readonly Func beatmaps; @@ -55,6 +54,10 @@ namespace osu.Game.Scoring } } + protected override IEnumerable GetStableImportPaths() + => GetStableStorage().GetFiles(ImportFromStablePath) + .Where(p => HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.InvariantCultureIgnoreCase) ?? false)); + public Score GetScore(ScoreInfo score) => new LegacyDatabasedScore(score, rulesets, beatmaps(), Files.Store); public List GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList(); diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index dafaf0c9dc..899bab8b94 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -32,8 +32,6 @@ namespace osu.Game.Skinning protected override string ImportFromStablePath => "Skins"; - protected override bool StableDirectoryBased => true; - public SkinManager(Storage storage, DatabaseContextFactory contextFactory, IIpcHost importHost, AudioManager audio) : base(storage, contextFactory, new SkinStore(contextFactory, storage), importHost) { @@ -56,6 +54,8 @@ namespace osu.Game.Skinning }; } + protected override IEnumerable GetStableImportPaths() => GetStableStorage().GetDirectories(ImportFromStablePath); + /// /// Returns a list of all usable s. Includes the special default skin plus all skins from . ///