Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move stable import handling into its own class
- Loading branch information
Showing
13 changed files
with
122 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using osu.Framework.Platform; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.IO; | ||
|
||
namespace osu.Game.Database | ||
{ | ||
public class StableBeatmapImporter : StableImporter<BeatmapSetInfo> | ||
{ | ||
protected override string ImportFromStablePath => "."; | ||
|
||
protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage(); | ||
|
||
public StableBeatmapImporter(IModelImporter<BeatmapSetInfo> importer) | ||
: base(importer) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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 | ||
{ | ||
/// <summary> | ||
/// A class which handled importing various user data from osu-stable. | ||
/// </summary> | ||
public class StableImporter<TModel> | ||
where TModel : class | ||
{ | ||
/// <summary> | ||
/// The relative path from osu-stable's data directory to import items from. | ||
/// </summary> | ||
protected virtual string ImportFromStablePath => null; | ||
|
||
/// <summary> | ||
/// Select paths to import from stable where all paths should be absolute. Default implementation iterates all directories in <see cref="ImportFromStablePath"/>. | ||
/// </summary> | ||
protected virtual IEnumerable<string> GetStableImportPaths(Storage storage) => storage.GetDirectories(ImportFromStablePath) | ||
.Select(path => storage.GetFullPath(path)); | ||
|
||
protected readonly IModelImporter<TModel> Importer; | ||
|
||
public StableImporter(IModelImporter<TModel> 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)); | ||
} | ||
|
||
/// <summary> | ||
/// Run any required traversal operations on the stable storage location before performing operations. | ||
/// </summary> | ||
/// <param name="stableStorage">The stable storage.</param> | ||
/// <returns>The usable storage. Return the unchanged <paramref name="stableStorage"/> if no traversal is required.</returns> | ||
protected virtual Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ScoreInfo> | ||
{ | ||
protected override string ImportFromStablePath => Path.Combine("Data", "r"); | ||
|
||
protected override IEnumerable<string> 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<ScoreInfo> importer) | ||
: base(importer) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using osu.Game.Skinning; | ||
|
||
namespace osu.Game.Database | ||
{ | ||
public class StableSkinImporter : StableImporter<SkinInfo> | ||
{ | ||
protected override string ImportFromStablePath => "Skins"; | ||
|
||
public StableSkinImporter(IModelImporter<SkinInfo> importer) | ||
: base(importer) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters