2021-05-08 09:00:22 +00:00
|
|
|
|
// 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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-05-09 15:12:58 +00:00
|
|
|
|
using osu.Framework;
|
2021-05-08 09:00:22 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.EnumExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Collections;
|
|
|
|
|
using osu.Game.IO;
|
2021-05-09 17:50:43 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2021-05-08 09:00:22 +00:00
|
|
|
|
using osu.Game.Overlays.Settings.Sections.Maintenance;
|
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
2021-05-09 17:50:43 +00:00
|
|
|
|
{
|
2021-05-08 09:00:22 +00:00
|
|
|
|
public class StableImportManager : Component
|
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private SkinManager skins { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scores { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private CollectionManager collections { get; set; }
|
|
|
|
|
|
2021-05-09 17:52:26 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuGame game { get; set; }
|
|
|
|
|
|
2021-05-08 09:00:22 +00:00
|
|
|
|
[Resolved]
|
2021-05-09 17:50:43 +00:00
|
|
|
|
private DialogOverlay dialogOverlay { get; set; }
|
2021-05-08 09:00:22 +00:00
|
|
|
|
|
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
|
private DesktopGameHost desktopGameHost { get; set; }
|
|
|
|
|
|
|
|
|
|
private StableStorage cachedStorage;
|
|
|
|
|
|
2021-05-09 15:12:58 +00:00
|
|
|
|
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
|
|
|
|
|
|
2021-05-08 09:00:22 +00:00
|
|
|
|
public async Task ImportFromStableAsync(StableContent content)
|
|
|
|
|
{
|
2021-05-09 15:12:58 +00:00
|
|
|
|
var stableStorage = await getStableStorage().ConfigureAwait(false);
|
2021-05-08 09:00:22 +00:00
|
|
|
|
var importTasks = new List<Task>();
|
|
|
|
|
|
2021-05-17 14:30:13 +00:00
|
|
|
|
Task beatmapImportTask = Task.CompletedTask;
|
2021-05-08 09:00:22 +00:00
|
|
|
|
if (content.HasFlagFast(StableContent.Beatmaps))
|
2021-05-09 16:15:21 +00:00
|
|
|
|
importTasks.Add(beatmapImportTask = beatmaps.ImportFromStableAsync(stableStorage));
|
|
|
|
|
|
|
|
|
|
if (content.HasFlagFast(StableContent.Skins))
|
|
|
|
|
importTasks.Add(skins.ImportFromStableAsync(stableStorage));
|
2021-05-08 09:00:22 +00:00
|
|
|
|
|
|
|
|
|
if (content.HasFlagFast(StableContent.Collections))
|
2021-05-17 14:30:13 +00:00
|
|
|
|
importTasks.Add(beatmapImportTask.ContinueWith(_ => collections.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion));
|
2021-05-08 09:00:22 +00:00
|
|
|
|
|
|
|
|
|
if (content.HasFlagFast(StableContent.Scores))
|
2021-05-17 14:30:13 +00:00
|
|
|
|
importTasks.Add(beatmapImportTask.ContinueWith(_ => scores.ImportFromStableAsync(stableStorage), TaskContinuationOptions.OnlyOnRanToCompletion));
|
2021-05-08 09:00:22 +00:00
|
|
|
|
|
|
|
|
|
await Task.WhenAll(importTasks.ToArray()).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<StableStorage> getStableStorage()
|
|
|
|
|
{
|
|
|
|
|
if (cachedStorage != null)
|
|
|
|
|
return cachedStorage;
|
|
|
|
|
|
2021-05-17 16:39:04 +00:00
|
|
|
|
var stableStorage = game.GetStorageForStableInstall();
|
|
|
|
|
if (stableStorage != null)
|
|
|
|
|
return cachedStorage = stableStorage;
|
|
|
|
|
|
2021-05-09 17:50:43 +00:00
|
|
|
|
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
2021-05-09 19:29:41 +00:00
|
|
|
|
Schedule(() => dialogOverlay.Push(new StableDirectoryLocationDialog(taskCompletionSource)));
|
2021-05-08 09:00:22 +00:00
|
|
|
|
var stablePath = await taskCompletionSource.Task.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return cachedStorage = new StableStorage(stablePath, desktopGameHost);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum StableContent
|
|
|
|
|
{
|
2021-05-17 19:02:45 +00:00
|
|
|
|
Beatmaps = 1 << 0,
|
|
|
|
|
Scores = 1 << 1,
|
|
|
|
|
Skins = 1 << 2,
|
|
|
|
|
Collections = 1 << 3,
|
2021-05-08 09:00:22 +00:00
|
|
|
|
All = Beatmaps | Scores | Skins | Collections
|
|
|
|
|
}
|
|
|
|
|
}
|