mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Move responsibility for selecting paths to model managers
This commit is contained in:
parent
f1f03dd541
commit
802da225d4
@ -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<string> GetStableImportPaths() => GetStableStorage().GetDirectories(ImportFromStablePath);
|
||||
|
||||
protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (archive != null)
|
||||
|
@ -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<TModel>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -537,7 +534,7 @@ namespace osu.Game.Database
|
||||
/// <summary>
|
||||
/// Set a storage with access to an osu-stable install for import purposes.
|
||||
/// </summary>
|
||||
public Func<Storage> GetStableStorage { private get; set; }
|
||||
public Func<Storage> GetStableStorage { protected get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
/// <summary>
|
||||
/// Does stable import look for directories rather than files
|
||||
/// Selects paths to import from.
|
||||
/// </summary>
|
||||
protected abstract bool StableDirectoryBased { get; }
|
||||
protected abstract IEnumerable<string> GetStableImportPaths();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
@ -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<BeatmapManager> beatmaps;
|
||||
|
||||
@ -55,6 +54,10 @@ namespace osu.Game.Scoring
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<string> 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<ScoreInfo> GetAllUsableScores() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList();
|
||||
|
@ -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<string> GetStableImportPaths() => GetStableStorage().GetDirectories(ImportFromStablePath);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all usable <see cref="SkinInfo"/>s. Includes the special default skin plus all skins from <see cref="GetAllUserSkins"/>.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user