From 6cab7b877dc40883e860ad4e7f10c7e8c5fa68e3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 15:36:12 +0900 Subject: [PATCH 1/6] Move stable import handling into its own class --- osu.Game/Beatmaps/BeatmapManager.cs | 5 -- osu.Game/Beatmaps/BeatmapModelManager.cs | 4 -- osu.Game/Database/ArchiveModelManager.cs | 34 ------------ osu.Game/Database/IModelManager.cs | 7 --- osu.Game/Database/StableBeatmapImporter.cs | 18 +++++++ osu.Game/Database/StableImportManager.cs | 10 ++-- osu.Game/Database/StableImporter.cs | 60 ++++++++++++++++++++++ osu.Game/Database/StableScoreImporter.cs | 23 +++++++++ osu.Game/Database/StableSkinImporter.cs | 14 +++++ osu.Game/Scoring/ScoreManager.cs | 6 --- osu.Game/Scoring/ScoreModelManager.cs | 6 --- osu.Game/Skinning/SkinManager.cs | 5 -- osu.Game/Skinning/SkinModelManager.cs | 2 - 13 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 osu.Game/Database/StableBeatmapImporter.cs create mode 100644 osu.Game/Database/StableImporter.cs create mode 100644 osu.Game/Database/StableScoreImporter.cs create mode 100644 osu.Game/Database/StableSkinImporter.cs diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 0594cd1316..2cca3ceaeb 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -225,11 +225,6 @@ namespace osu.Game.Beatmaps remove => beatmapModelManager.ItemRemoved -= value; } - public Task ImportFromStableAsync(StableStorage stableStorage) - { - return beatmapModelManager.ImportFromStableAsync(stableStorage); - } - public void Export(BeatmapSetInfo item) { beatmapModelManager.Export(item); diff --git a/osu.Game/Beatmaps/BeatmapModelManager.cs b/osu.Game/Beatmaps/BeatmapModelManager.cs index ae395c6da6..63cdd0b852 100644 --- a/osu.Game/Beatmaps/BeatmapModelManager.cs +++ b/osu.Game/Beatmaps/BeatmapModelManager.cs @@ -58,10 +58,6 @@ namespace osu.Game.Beatmaps protected override string[] HashableFileTypes => new[] { ".osu" }; - protected override string ImportFromStablePath => "."; - - protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage(); - private readonly BeatmapStore beatmaps; private readonly RulesetStore rulesets; diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index adbb71c8da..e5919cb5c4 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -728,17 +728,6 @@ namespace osu.Game.Database #region osu-stable import - /// - /// The relative path from osu-stable's data directory to import items from. - /// - protected virtual string ImportFromStablePath => null; - - /// - /// Select paths to import from stable where all paths should be absolute. Default implementation iterates all directories in . - /// - protected virtual IEnumerable GetStableImportPaths(Storage storage) => storage.GetDirectories(ImportFromStablePath) - .Select(path => storage.GetFullPath(path)); - /// /// Whether this specified path should be removed after successful import. /// @@ -746,29 +735,6 @@ namespace osu.Game.Database /// Whether to perform deletion. protected virtual bool ShouldDeleteArchive(string path) => false; - public Task ImportFromStableAsync(StableStorage stableStorage) - { - var storage = PrepareStableStorage(stableStorage); - - // Handle situations like when the user does not have a Skins folder. - if (!storage.ExistsDirectory(ImportFromStablePath)) - { - string fullPath = storage.GetFullPath(ImportFromStablePath); - - Logger.Log(@$"Folder ""{fullPath}"" not available in the target osu!stable installation to import {HumanisedModelName}s.", LoggingTarget.Information, LogLevel.Error); - return Task.CompletedTask; - } - - return Task.Run(async () => await Import(GetStableImportPaths(storage).ToArray()).ConfigureAwait(false)); - } - - /// - /// Run any required traversal operations on the stable storage location before performing operations. - /// - /// The stable storage. - /// The usable storage. Return the unchanged if no traversal is required. - protected virtual Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage; - #endregion /// diff --git a/osu.Game/Database/IModelManager.cs b/osu.Game/Database/IModelManager.cs index 15ad455f21..6c9cca7c7a 100644 --- a/osu.Game/Database/IModelManager.cs +++ b/osu.Game/Database/IModelManager.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Threading.Tasks; -using osu.Game.IO; namespace osu.Game.Database { @@ -26,11 +24,6 @@ namespace osu.Game.Database /// event Action ItemRemoved; - /// - /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. - /// - Task ImportFromStableAsync(StableStorage stableStorage); - /// /// Exports an item to a legacy (.zip based) package. /// diff --git a/osu.Game/Database/StableBeatmapImporter.cs b/osu.Game/Database/StableBeatmapImporter.cs new file mode 100644 index 0000000000..7aaa8ba013 --- /dev/null +++ b/osu.Game/Database/StableBeatmapImporter.cs @@ -0,0 +1,18 @@ +using osu.Framework.Platform; +using osu.Game.Beatmaps; +using osu.Game.IO; + +namespace osu.Game.Database +{ + public class StableBeatmapImporter : StableImporter + { + protected override string ImportFromStablePath => "."; + + protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage(); + + public StableBeatmapImporter(IModelImporter importer) + : base(importer) + { + } + } +} \ No newline at end of file diff --git a/osu.Game/Database/StableImportManager.cs b/osu.Game/Database/StableImportManager.cs index fe8c14c085..0a30fcb2be 100644 --- a/osu.Game/Database/StableImportManager.cs +++ b/osu.Game/Database/StableImportManager.cs @@ -51,18 +51,22 @@ namespace osu.Game.Database var stableStorage = await getStableStorage().ConfigureAwait(false); var importTasks = new List(); + var beatmapImporter = new StableBeatmapImporter(beatmaps); + var skinImporter = new StableSkinImporter(skins); + var scoreImporter = new StableScoreImporter(scores); + Task beatmapImportTask = Task.CompletedTask; if (content.HasFlagFast(StableContent.Beatmaps)) - importTasks.Add(beatmapImportTask = beatmaps.ImportFromStableAsync(stableStorage)); + importTasks.Add(beatmapImportTask = beatmapImporter.ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Skins)) - importTasks.Add(skins.ImportFromStableAsync(stableStorage)); + importTasks.Add(skinImporter.ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Collections)) importTasks.Add(beatmapImportTask.ContinueWith(_ => collections.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); if (content.HasFlagFast(StableContent.Scores)) - importTasks.Add(beatmapImportTask.ContinueWith(_ => scores.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); + importTasks.Add(beatmapImportTask.ContinueWith(_ => scoreImporter.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); await Task.WhenAll(importTasks.ToArray()).ConfigureAwait(false); } diff --git a/osu.Game/Database/StableImporter.cs b/osu.Game/Database/StableImporter.cs new file mode 100644 index 0000000000..e56737959e --- /dev/null +++ b/osu.Game/Database/StableImporter.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using osu.Framework.Logging; +using osu.Framework.Platform; +using osu.Game.IO; + +namespace osu.Game.Database +{ + /// + /// A class which handled importing various user data from osu-stable. + /// + public class StableImporter + where TModel : class + { + /// + /// The relative path from osu-stable's data directory to import items from. + /// + protected virtual string ImportFromStablePath => null; + + /// + /// Select paths to import from stable where all paths should be absolute. Default implementation iterates all directories in . + /// + protected virtual IEnumerable GetStableImportPaths(Storage storage) => storage.GetDirectories(ImportFromStablePath) + .Select(path => storage.GetFullPath(path)); + + protected readonly IModelImporter Importer; + + public StableImporter(IModelImporter importer) + { + Importer = importer; + } + + public Task ImportFromStableAsync(StableStorage stableStorage) + { + var storage = PrepareStableStorage(stableStorage); + + // Handle situations like when the user does not have a Skins folder. + if (!storage.ExistsDirectory(ImportFromStablePath)) + { + string fullPath = storage.GetFullPath(ImportFromStablePath); + + Logger.Log(@$"Folder ""{fullPath}"" not available in the target osu!stable installation to import {Importer.HumanisedModelName}s.", LoggingTarget.Information, LogLevel.Error); + return Task.CompletedTask; + } + + return Task.Run(async () => await Importer.Import(GetStableImportPaths(storage).ToArray()).ConfigureAwait(false)); + } + + /// + /// Run any required traversal operations on the stable storage location before performing operations. + /// + /// The stable storage. + /// The usable storage. Return the unchanged if no traversal is required. + protected virtual Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage; + } +} diff --git a/osu.Game/Database/StableScoreImporter.cs b/osu.Game/Database/StableScoreImporter.cs new file mode 100644 index 0000000000..fede10c7ea --- /dev/null +++ b/osu.Game/Database/StableScoreImporter.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using osu.Framework.Platform; +using osu.Game.Scoring; + +namespace osu.Game.Database +{ + public class StableScoreImporter : StableImporter + { + protected override string ImportFromStablePath => Path.Combine("Data", "r"); + + protected override IEnumerable GetStableImportPaths(Storage storage) + => storage.GetFiles(ImportFromStablePath).Where(p => Importer.HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.OrdinalIgnoreCase) ?? false)) + .Select(path => storage.GetFullPath(path)); + + public StableScoreImporter(IModelImporter importer) + : base(importer) + { + } + } +} diff --git a/osu.Game/Database/StableSkinImporter.cs b/osu.Game/Database/StableSkinImporter.cs new file mode 100644 index 0000000000..65601e85b7 --- /dev/null +++ b/osu.Game/Database/StableSkinImporter.cs @@ -0,0 +1,14 @@ +using osu.Game.Skinning; + +namespace osu.Game.Database +{ + public class StableSkinImporter : StableImporter + { + protected override string ImportFromStablePath => "Skins"; + + public StableSkinImporter(IModelImporter importer) + : base(importer) + { + } + } +} \ No newline at end of file diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 29144e7bdc..d25671d77e 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -15,7 +15,6 @@ using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Database; -using osu.Game.IO; using osu.Game.IO.Archives; using osu.Game.Online.API; using osu.Game.Overlays.Notifications; @@ -263,11 +262,6 @@ namespace osu.Game.Scoring remove => scoreModelManager.ItemRemoved -= value; } - public Task ImportFromStableAsync(StableStorage stableStorage) - { - return scoreModelManager.ImportFromStableAsync(stableStorage); - } - public void Export(ScoreInfo item) { scoreModelManager.Export(item); diff --git a/osu.Game/Scoring/ScoreModelManager.cs b/osu.Game/Scoring/ScoreModelManager.cs index c194a7166d..9da739237b 100644 --- a/osu.Game/Scoring/ScoreModelManager.cs +++ b/osu.Game/Scoring/ScoreModelManager.cs @@ -26,8 +26,6 @@ namespace osu.Game.Scoring protected override string[] HashableFileTypes => new[] { ".osr" }; - protected override string ImportFromStablePath => Path.Combine("Data", "r"); - private readonly RulesetStore rulesets; private readonly Func beatmaps; @@ -81,9 +79,5 @@ namespace osu.Game.Scoring using (var inputStream = Files.Storage.GetStream(file.FileInfo.GetStoragePath())) inputStream.CopyTo(outputStream); } - - protected override IEnumerable GetStableImportPaths(Storage storage) - => storage.GetFiles(ImportFromStablePath).Where(p => HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.OrdinalIgnoreCase) ?? false)) - .Select(path => storage.GetFullPath(path)); } } diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index a840e17ed1..679b35799e 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -301,11 +301,6 @@ namespace osu.Game.Skinning remove => skinModelManager.ItemRemoved -= value; } - public Task ImportFromStableAsync(StableStorage stableStorage) - { - return skinModelManager.ImportFromStableAsync(stableStorage); - } - public void Export(SkinInfo item) { skinModelManager.Export(item); diff --git a/osu.Game/Skinning/SkinModelManager.cs b/osu.Game/Skinning/SkinModelManager.cs index f28b0c066b..572ae5cbfc 100644 --- a/osu.Game/Skinning/SkinModelManager.cs +++ b/osu.Game/Skinning/SkinModelManager.cs @@ -34,8 +34,6 @@ namespace osu.Game.Skinning protected override string[] HashableFileTypes => new[] { ".ini", ".json" }; - protected override string ImportFromStablePath => "Skins"; - protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == @".osk"; protected override SkinInfo CreateModel(ArchiveReader archive) => new SkinInfo { Name = archive.Name ?? @"No name" }; From 9dcb20a8217ff9dfe62487c8d578a7e42ab8ab35 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 15:39:05 +0900 Subject: [PATCH 2/6] Rename `Stable` to `Legacy` and add xmldoc --- ...ImportManager.cs => LeagcyImportManager.cs} | 11 +++++++---- ...mapImporter.cs => LegacyBeatmapImporter.cs} | 6 +++--- .../{StableImporter.cs => LegacyImporter.cs} | 6 +++--- ...ScoreImporter.cs => LegacyScoreImporter.cs} | 4 ++-- ...leSkinImporter.cs => LegacySkinImporter.cs} | 4 ++-- osu.Game/OsuGame.cs | 4 ++-- .../Sections/Maintenance/GeneralSettings.cs | 18 +++++++++--------- osu.Game/Screens/Select/SongSelect.cs | 6 +++--- 8 files changed, 31 insertions(+), 28 deletions(-) rename osu.Game/Database/{StableImportManager.cs => LeagcyImportManager.cs} (90%) rename osu.Game/Database/{StableBeatmapImporter.cs => LegacyBeatmapImporter.cs} (74%) rename osu.Game/Database/{StableImporter.cs => LegacyImporter.cs} (92%) rename osu.Game/Database/{StableScoreImporter.cs => LegacyScoreImporter.cs} (83%) rename osu.Game/Database/{StableSkinImporter.cs => LegacySkinImporter.cs} (59%) diff --git a/osu.Game/Database/StableImportManager.cs b/osu.Game/Database/LeagcyImportManager.cs similarity index 90% rename from osu.Game/Database/StableImportManager.cs rename to osu.Game/Database/LeagcyImportManager.cs index 0a30fcb2be..9f3f9d007a 100644 --- a/osu.Game/Database/StableImportManager.cs +++ b/osu.Game/Database/LeagcyImportManager.cs @@ -19,7 +19,10 @@ using osu.Game.Skinning; namespace osu.Game.Database { - public class StableImportManager : Component + /// + /// Handles migration of legacy user data from osu-stable. + /// + public class LeagcyImportManager : Component { [Resolved] private SkinManager skins { get; set; } @@ -51,9 +54,9 @@ namespace osu.Game.Database var stableStorage = await getStableStorage().ConfigureAwait(false); var importTasks = new List(); - var beatmapImporter = new StableBeatmapImporter(beatmaps); - var skinImporter = new StableSkinImporter(skins); - var scoreImporter = new StableScoreImporter(scores); + var beatmapImporter = new LegacyBeatmapImporter(beatmaps); + var skinImporter = new LegacySkinImporter(skins); + var scoreImporter = new LegacyScoreImporter(scores); Task beatmapImportTask = Task.CompletedTask; if (content.HasFlagFast(StableContent.Beatmaps)) diff --git a/osu.Game/Database/StableBeatmapImporter.cs b/osu.Game/Database/LegacyBeatmapImporter.cs similarity index 74% rename from osu.Game/Database/StableBeatmapImporter.cs rename to osu.Game/Database/LegacyBeatmapImporter.cs index 7aaa8ba013..a377c39b90 100644 --- a/osu.Game/Database/StableBeatmapImporter.cs +++ b/osu.Game/Database/LegacyBeatmapImporter.cs @@ -4,15 +4,15 @@ using osu.Game.IO; namespace osu.Game.Database { - public class StableBeatmapImporter : StableImporter + public class LegacyBeatmapImporter : LegacyImporter { protected override string ImportFromStablePath => "."; protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage(); - public StableBeatmapImporter(IModelImporter importer) + public LegacyBeatmapImporter(IModelImporter importer) : base(importer) { } } -} \ No newline at end of file +} diff --git a/osu.Game/Database/StableImporter.cs b/osu.Game/Database/LegacyImporter.cs similarity index 92% rename from osu.Game/Database/StableImporter.cs rename to osu.Game/Database/LegacyImporter.cs index e56737959e..4480aa9ee8 100644 --- a/osu.Game/Database/StableImporter.cs +++ b/osu.Game/Database/LegacyImporter.cs @@ -11,9 +11,9 @@ using osu.Game.IO; namespace osu.Game.Database { /// - /// A class which handled importing various user data from osu-stable. + /// A class which handles importing legacy user data of a single type from osu-stable. /// - public class StableImporter + public abstract class LegacyImporter where TModel : class { /// @@ -29,7 +29,7 @@ namespace osu.Game.Database protected readonly IModelImporter Importer; - public StableImporter(IModelImporter importer) + protected LegacyImporter(IModelImporter importer) { Importer = importer; } diff --git a/osu.Game/Database/StableScoreImporter.cs b/osu.Game/Database/LegacyScoreImporter.cs similarity index 83% rename from osu.Game/Database/StableScoreImporter.cs rename to osu.Game/Database/LegacyScoreImporter.cs index fede10c7ea..4cc2be60e6 100644 --- a/osu.Game/Database/StableScoreImporter.cs +++ b/osu.Game/Database/LegacyScoreImporter.cs @@ -7,7 +7,7 @@ using osu.Game.Scoring; namespace osu.Game.Database { - public class StableScoreImporter : StableImporter + public class LegacyScoreImporter : LegacyImporter { protected override string ImportFromStablePath => Path.Combine("Data", "r"); @@ -15,7 +15,7 @@ namespace osu.Game.Database => storage.GetFiles(ImportFromStablePath).Where(p => Importer.HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.OrdinalIgnoreCase) ?? false)) .Select(path => storage.GetFullPath(path)); - public StableScoreImporter(IModelImporter importer) + public LegacyScoreImporter(IModelImporter importer) : base(importer) { } diff --git a/osu.Game/Database/StableSkinImporter.cs b/osu.Game/Database/LegacySkinImporter.cs similarity index 59% rename from osu.Game/Database/StableSkinImporter.cs rename to osu.Game/Database/LegacySkinImporter.cs index 65601e85b7..357da1b005 100644 --- a/osu.Game/Database/StableSkinImporter.cs +++ b/osu.Game/Database/LegacySkinImporter.cs @@ -2,11 +2,11 @@ using osu.Game.Skinning; namespace osu.Game.Database { - public class StableSkinImporter : StableImporter + public class LegacySkinImporter : LegacyImporter { protected override string ImportFromStablePath => "Skins"; - public StableSkinImporter(IModelImporter importer) + public LegacySkinImporter(IModelImporter importer) : base(importer) { } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 574a5e5393..9b9ec585e8 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -116,7 +116,7 @@ namespace osu.Game private readonly DifficultyRecommender difficultyRecommender = new DifficultyRecommender(); [Cached] - private readonly StableImportManager stableImportManager = new StableImportManager(); + private readonly LeagcyImportManager leagcyImportManager = new LeagcyImportManager(); [Cached] private readonly ScreenshotManager screenshotManager = new ScreenshotManager(); @@ -782,7 +782,7 @@ namespace osu.Game PostNotification = n => Notifications.Post(n), }, Add, true); - loadComponentSingleFile(stableImportManager, Add); + loadComponentSingleFile(leagcyImportManager, Add); loadComponentSingleFile(screenshotManager, Add); diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 43df58a8b1..9dfd0d8ff4 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -31,9 +31,9 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private SettingsButton undeleteButton; [BackgroundDependencyLoader(permitNulls: true)] - private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] StableImportManager stableImportManager, DialogOverlay dialogOverlay) + private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] LeagcyImportManager leagcyImportManager, DialogOverlay dialogOverlay) { - if (stableImportManager?.SupportsImportFromStable == true) + if (leagcyImportManager?.SupportsImportFromStable == true) { Add(importBeatmapsButton = new SettingsButton { @@ -41,7 +41,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importBeatmapsButton.Enabled.Value = false; - stableImportManager.ImportFromStableAsync(StableContent.Beatmaps).ContinueWith(t => Schedule(() => importBeatmapsButton.Enabled.Value = true)); + leagcyImportManager.ImportFromStableAsync(StableContent.Beatmaps).ContinueWith(t => Schedule(() => importBeatmapsButton.Enabled.Value = true)); } }); } @@ -59,7 +59,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance } }); - if (stableImportManager?.SupportsImportFromStable == true) + if (leagcyImportManager?.SupportsImportFromStable == true) { Add(importScoresButton = new SettingsButton { @@ -67,7 +67,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importScoresButton.Enabled.Value = false; - stableImportManager.ImportFromStableAsync(StableContent.Scores).ContinueWith(t => Schedule(() => importScoresButton.Enabled.Value = true)); + leagcyImportManager.ImportFromStableAsync(StableContent.Scores).ContinueWith(t => Schedule(() => importScoresButton.Enabled.Value = true)); } }); } @@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance } }); - if (stableImportManager?.SupportsImportFromStable == true) + if (leagcyImportManager?.SupportsImportFromStable == true) { Add(importSkinsButton = new SettingsButton { @@ -93,7 +93,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importSkinsButton.Enabled.Value = false; - stableImportManager.ImportFromStableAsync(StableContent.Skins).ContinueWith(t => Schedule(() => importSkinsButton.Enabled.Value = true)); + leagcyImportManager.ImportFromStableAsync(StableContent.Skins).ContinueWith(t => Schedule(() => importSkinsButton.Enabled.Value = true)); } }); } @@ -113,7 +113,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance if (collectionManager != null) { - if (stableImportManager?.SupportsImportFromStable == true) + if (leagcyImportManager?.SupportsImportFromStable == true) { Add(importCollectionsButton = new SettingsButton { @@ -121,7 +121,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importCollectionsButton.Enabled.Value = false; - stableImportManager.ImportFromStableAsync(StableContent.Collections).ContinueWith(t => Schedule(() => importCollectionsButton.Enabled.Value = true)); + leagcyImportManager.ImportFromStableAsync(StableContent.Collections).ContinueWith(t => Schedule(() => importCollectionsButton.Enabled.Value = true)); } }); } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 2c36bf5fc8..b6933a9830 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -51,7 +51,7 @@ namespace osu.Game.Screens.Select protected virtual bool ShowFooter => true; - protected virtual bool DisplayStableImportPrompt => stableImportManager?.SupportsImportFromStable == true; + protected virtual bool DisplayStableImportPrompt => leagcyImportManager?.SupportsImportFromStable == true; public override bool? AllowTrackAdjustments => true; @@ -90,7 +90,7 @@ namespace osu.Game.Screens.Select private BeatmapManager beatmaps { get; set; } [Resolved(CanBeNull = true)] - private StableImportManager stableImportManager { get; set; } + private LeagcyImportManager leagcyImportManager { get; set; } protected ModSelectOverlay ModSelect { get; private set; } @@ -297,7 +297,7 @@ namespace osu.Game.Screens.Select { dialogOverlay.Push(new ImportFromStablePopup(() => { - Task.Run(() => stableImportManager.ImportFromStableAsync(StableContent.All)); + Task.Run(() => leagcyImportManager.ImportFromStableAsync(StableContent.All)); })); } }); From 2df793ca228e69032fcb0e8027ebd4bf4a138589 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 15:44:04 +0900 Subject: [PATCH 3/6] Inline individual importers to avoid unnecessary construction for singular import types --- osu.Game/Database/LeagcyImportManager.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/osu.Game/Database/LeagcyImportManager.cs b/osu.Game/Database/LeagcyImportManager.cs index 9f3f9d007a..8ee63429e2 100644 --- a/osu.Game/Database/LeagcyImportManager.cs +++ b/osu.Game/Database/LeagcyImportManager.cs @@ -54,22 +54,18 @@ namespace osu.Game.Database var stableStorage = await getStableStorage().ConfigureAwait(false); var importTasks = new List(); - var beatmapImporter = new LegacyBeatmapImporter(beatmaps); - var skinImporter = new LegacySkinImporter(skins); - var scoreImporter = new LegacyScoreImporter(scores); - Task beatmapImportTask = Task.CompletedTask; if (content.HasFlagFast(StableContent.Beatmaps)) - importTasks.Add(beatmapImportTask = beatmapImporter.ImportFromStableAsync(stableStorage)); + importTasks.Add(beatmapImportTask = new LegacyBeatmapImporter(beatmaps).ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Skins)) - importTasks.Add(skinImporter.ImportFromStableAsync(stableStorage)); + importTasks.Add(new LegacySkinImporter(skins).ImportFromStableAsync(stableStorage)); if (content.HasFlagFast(StableContent.Collections)) importTasks.Add(beatmapImportTask.ContinueWith(_ => collections.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); if (content.HasFlagFast(StableContent.Scores)) - importTasks.Add(beatmapImportTask.ContinueWith(_ => scoreImporter.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); + importTasks.Add(beatmapImportTask.ContinueWith(_ => new LegacyScoreImporter(scores).ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion)); await Task.WhenAll(importTasks.ToArray()).ConfigureAwait(false); } From a0fa030f55385cb3f85d1a2d4c1d8e99e65cbb07 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 16:33:04 +0900 Subject: [PATCH 4/6] Rename base class to `LegacyModelImporter` --- osu.Game/Database/LegacyBeatmapImporter.cs | 2 +- .../Database/{LegacyImporter.cs => LegacyModelImporter.cs} | 4 ++-- osu.Game/Database/LegacyScoreImporter.cs | 2 +- osu.Game/Database/LegacySkinImporter.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename osu.Game/Database/{LegacyImporter.cs => LegacyModelImporter.cs} (95%) diff --git a/osu.Game/Database/LegacyBeatmapImporter.cs b/osu.Game/Database/LegacyBeatmapImporter.cs index a377c39b90..041a692655 100644 --- a/osu.Game/Database/LegacyBeatmapImporter.cs +++ b/osu.Game/Database/LegacyBeatmapImporter.cs @@ -4,7 +4,7 @@ using osu.Game.IO; namespace osu.Game.Database { - public class LegacyBeatmapImporter : LegacyImporter + public class LegacyBeatmapImporter : LegacyModelImporter { protected override string ImportFromStablePath => "."; diff --git a/osu.Game/Database/LegacyImporter.cs b/osu.Game/Database/LegacyModelImporter.cs similarity index 95% rename from osu.Game/Database/LegacyImporter.cs rename to osu.Game/Database/LegacyModelImporter.cs index 4480aa9ee8..dacb7327ea 100644 --- a/osu.Game/Database/LegacyImporter.cs +++ b/osu.Game/Database/LegacyModelImporter.cs @@ -13,7 +13,7 @@ namespace osu.Game.Database /// /// A class which handles importing legacy user data of a single type from osu-stable. /// - public abstract class LegacyImporter + public abstract class LegacyModelImporter where TModel : class { /// @@ -29,7 +29,7 @@ namespace osu.Game.Database protected readonly IModelImporter Importer; - protected LegacyImporter(IModelImporter importer) + protected LegacyModelImporter(IModelImporter importer) { Importer = importer; } diff --git a/osu.Game/Database/LegacyScoreImporter.cs b/osu.Game/Database/LegacyScoreImporter.cs index 4cc2be60e6..984aa8a1ac 100644 --- a/osu.Game/Database/LegacyScoreImporter.cs +++ b/osu.Game/Database/LegacyScoreImporter.cs @@ -7,7 +7,7 @@ using osu.Game.Scoring; namespace osu.Game.Database { - public class LegacyScoreImporter : LegacyImporter + public class LegacyScoreImporter : LegacyModelImporter { protected override string ImportFromStablePath => Path.Combine("Data", "r"); diff --git a/osu.Game/Database/LegacySkinImporter.cs b/osu.Game/Database/LegacySkinImporter.cs index 357da1b005..b102e26bc6 100644 --- a/osu.Game/Database/LegacySkinImporter.cs +++ b/osu.Game/Database/LegacySkinImporter.cs @@ -2,7 +2,7 @@ using osu.Game.Skinning; namespace osu.Game.Database { - public class LegacySkinImporter : LegacyImporter + public class LegacySkinImporter : LegacyModelImporter { protected override string ImportFromStablePath => "Skins"; From ec9a09d5a42a0a2818c369faf22e134802e73917 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 16:56:19 +0900 Subject: [PATCH 5/6] Add missing licence headers --- osu.Game/Database/LegacyBeatmapImporter.cs | 3 +++ osu.Game/Database/LegacyScoreImporter.cs | 3 +++ osu.Game/Database/LegacySkinImporter.cs | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/LegacyBeatmapImporter.cs b/osu.Game/Database/LegacyBeatmapImporter.cs index 041a692655..97f6eba6c2 100644 --- a/osu.Game/Database/LegacyBeatmapImporter.cs +++ b/osu.Game/Database/LegacyBeatmapImporter.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.IO; diff --git a/osu.Game/Database/LegacyScoreImporter.cs b/osu.Game/Database/LegacyScoreImporter.cs index 984aa8a1ac..48445b7bdb 100644 --- a/osu.Game/Database/LegacyScoreImporter.cs +++ b/osu.Game/Database/LegacyScoreImporter.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Game/Database/LegacySkinImporter.cs b/osu.Game/Database/LegacySkinImporter.cs index b102e26bc6..2f05ccae45 100644 --- a/osu.Game/Database/LegacySkinImporter.cs +++ b/osu.Game/Database/LegacySkinImporter.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using osu.Game.Skinning; namespace osu.Game.Database @@ -11,4 +14,4 @@ namespace osu.Game.Database { } } -} \ No newline at end of file +} From 79459c1aebc968ac4821161399126075b6301c93 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Nov 2021 17:12:15 +0900 Subject: [PATCH 6/6] Fix typo in class and variable names --- ...ImportManager.cs => LegacyImportManager.cs} | 2 +- osu.Game/OsuGame.cs | 4 ++-- .../Sections/Maintenance/GeneralSettings.cs | 18 +++++++++--------- osu.Game/Screens/Select/SongSelect.cs | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) rename osu.Game/Database/{LeagcyImportManager.cs => LegacyImportManager.cs} (98%) diff --git a/osu.Game/Database/LeagcyImportManager.cs b/osu.Game/Database/LegacyImportManager.cs similarity index 98% rename from osu.Game/Database/LeagcyImportManager.cs rename to osu.Game/Database/LegacyImportManager.cs index 8ee63429e2..4dc26b18bb 100644 --- a/osu.Game/Database/LeagcyImportManager.cs +++ b/osu.Game/Database/LegacyImportManager.cs @@ -22,7 +22,7 @@ namespace osu.Game.Database /// /// Handles migration of legacy user data from osu-stable. /// - public class LeagcyImportManager : Component + public class LegacyImportManager : Component { [Resolved] private SkinManager skins { get; set; } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9b9ec585e8..0e050304f0 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -116,7 +116,7 @@ namespace osu.Game private readonly DifficultyRecommender difficultyRecommender = new DifficultyRecommender(); [Cached] - private readonly LeagcyImportManager leagcyImportManager = new LeagcyImportManager(); + private readonly LegacyImportManager legacyImportManager = new LegacyImportManager(); [Cached] private readonly ScreenshotManager screenshotManager = new ScreenshotManager(); @@ -782,7 +782,7 @@ namespace osu.Game PostNotification = n => Notifications.Post(n), }, Add, true); - loadComponentSingleFile(leagcyImportManager, Add); + loadComponentSingleFile(legacyImportManager, Add); loadComponentSingleFile(screenshotManager, Add); diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 9dfd0d8ff4..5bc89ec77c 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -31,9 +31,9 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private SettingsButton undeleteButton; [BackgroundDependencyLoader(permitNulls: true)] - private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] LeagcyImportManager leagcyImportManager, DialogOverlay dialogOverlay) + private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, [CanBeNull] CollectionManager collectionManager, [CanBeNull] LegacyImportManager legacyImportManager, DialogOverlay dialogOverlay) { - if (leagcyImportManager?.SupportsImportFromStable == true) + if (legacyImportManager?.SupportsImportFromStable == true) { Add(importBeatmapsButton = new SettingsButton { @@ -41,7 +41,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importBeatmapsButton.Enabled.Value = false; - leagcyImportManager.ImportFromStableAsync(StableContent.Beatmaps).ContinueWith(t => Schedule(() => importBeatmapsButton.Enabled.Value = true)); + legacyImportManager.ImportFromStableAsync(StableContent.Beatmaps).ContinueWith(t => Schedule(() => importBeatmapsButton.Enabled.Value = true)); } }); } @@ -59,7 +59,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance } }); - if (leagcyImportManager?.SupportsImportFromStable == true) + if (legacyImportManager?.SupportsImportFromStable == true) { Add(importScoresButton = new SettingsButton { @@ -67,7 +67,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importScoresButton.Enabled.Value = false; - leagcyImportManager.ImportFromStableAsync(StableContent.Scores).ContinueWith(t => Schedule(() => importScoresButton.Enabled.Value = true)); + legacyImportManager.ImportFromStableAsync(StableContent.Scores).ContinueWith(t => Schedule(() => importScoresButton.Enabled.Value = true)); } }); } @@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance } }); - if (leagcyImportManager?.SupportsImportFromStable == true) + if (legacyImportManager?.SupportsImportFromStable == true) { Add(importSkinsButton = new SettingsButton { @@ -93,7 +93,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importSkinsButton.Enabled.Value = false; - leagcyImportManager.ImportFromStableAsync(StableContent.Skins).ContinueWith(t => Schedule(() => importSkinsButton.Enabled.Value = true)); + legacyImportManager.ImportFromStableAsync(StableContent.Skins).ContinueWith(t => Schedule(() => importSkinsButton.Enabled.Value = true)); } }); } @@ -113,7 +113,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance if (collectionManager != null) { - if (leagcyImportManager?.SupportsImportFromStable == true) + if (legacyImportManager?.SupportsImportFromStable == true) { Add(importCollectionsButton = new SettingsButton { @@ -121,7 +121,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { importCollectionsButton.Enabled.Value = false; - leagcyImportManager.ImportFromStableAsync(StableContent.Collections).ContinueWith(t => Schedule(() => importCollectionsButton.Enabled.Value = true)); + legacyImportManager.ImportFromStableAsync(StableContent.Collections).ContinueWith(t => Schedule(() => importCollectionsButton.Enabled.Value = true)); } }); } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index b6933a9830..25efe22892 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -51,7 +51,7 @@ namespace osu.Game.Screens.Select protected virtual bool ShowFooter => true; - protected virtual bool DisplayStableImportPrompt => leagcyImportManager?.SupportsImportFromStable == true; + protected virtual bool DisplayStableImportPrompt => legacyImportManager?.SupportsImportFromStable == true; public override bool? AllowTrackAdjustments => true; @@ -90,7 +90,7 @@ namespace osu.Game.Screens.Select private BeatmapManager beatmaps { get; set; } [Resolved(CanBeNull = true)] - private LeagcyImportManager leagcyImportManager { get; set; } + private LegacyImportManager legacyImportManager { get; set; } protected ModSelectOverlay ModSelect { get; private set; } @@ -297,7 +297,7 @@ namespace osu.Game.Screens.Select { dialogOverlay.Push(new ImportFromStablePopup(() => { - Task.Run(() => leagcyImportManager.ImportFromStableAsync(StableContent.All)); + Task.Run(() => legacyImportManager.ImportFromStableAsync(StableContent.All)); })); } });