mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Implement collection import
This commit is contained in:
@ -4,8 +4,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -25,12 +27,13 @@ namespace osu.Game.Collections
|
|||||||
|
|
||||||
private const string database_name = "collection.db";
|
private const string database_name = "collection.db";
|
||||||
|
|
||||||
|
public readonly BindableList<BeatmapCollection> Collections = new BindableList<BeatmapCollection>();
|
||||||
|
|
||||||
|
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
public IBindableList<BeatmapCollection> Collections => collections;
|
|
||||||
private readonly BindableList<BeatmapCollection> collections = new BindableList<BeatmapCollection>();
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
@ -40,12 +43,12 @@ namespace osu.Game.Collections
|
|||||||
if (host.Storage.Exists(database_name))
|
if (host.Storage.Exists(database_name))
|
||||||
{
|
{
|
||||||
using (var stream = host.Storage.GetStream(database_name))
|
using (var stream = host.Storage.GetStream(database_name))
|
||||||
collections.AddRange(readCollection(stream));
|
importCollections(readCollections(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var c in collections)
|
foreach (var c in Collections)
|
||||||
c.Changed += backgroundSave;
|
c.Changed += backgroundSave;
|
||||||
collections.CollectionChanged += (_, __) => backgroundSave();
|
Collections.CollectionChanged += (_, __) => backgroundSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -56,26 +59,55 @@ namespace osu.Game.Collections
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
|
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// public Task ImportFromStableAsync()
|
public Task ImportFromStableAsync()
|
||||||
// {
|
{
|
||||||
// var stable = GetStableStorage?.Invoke();
|
var stable = GetStableStorage?.Invoke();
|
||||||
//
|
|
||||||
// if (stable == null)
|
if (stable == null)
|
||||||
// {
|
{
|
||||||
// Logger.Log("No osu!stable installation available!", LoggingTarget.Information, LogLevel.Error);
|
Logger.Log("No osu!stable installation available!", LoggingTarget.Information, LogLevel.Error);
|
||||||
// return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (!stable.ExistsDirectory(database_name))
|
if (!stable.Exists(database_name))
|
||||||
// {
|
{
|
||||||
// // This handles situations like when the user does not have a Skins folder
|
// This handles situations like when the user does not have a collections.db file
|
||||||
// Logger.Log($"No {database_name} folder available in osu!stable installation", LoggingTarget.Information, LogLevel.Error);
|
Logger.Log($"No {database_name} available in osu!stable installation", LoggingTarget.Information, LogLevel.Error);
|
||||||
// return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return Task.Run(async () => await Import(GetStableImportPaths(GetStableStorage()).Select(f => stable.GetFullPath(f)).ToArray()));
|
return Task.Run(() =>
|
||||||
// }
|
{
|
||||||
private List<BeatmapCollection> readCollection(Stream stream)
|
var storage = GetStableStorage();
|
||||||
|
|
||||||
|
if (storage.Exists(database_name))
|
||||||
|
{
|
||||||
|
using (var stream = storage.GetStream(database_name))
|
||||||
|
{
|
||||||
|
var collection = readCollections(stream);
|
||||||
|
Schedule(() => importCollections(collection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importCollections(List<BeatmapCollection> newCollections)
|
||||||
|
{
|
||||||
|
foreach (var newCol in newCollections)
|
||||||
|
{
|
||||||
|
var existing = Collections.FirstOrDefault(c => c.Name == newCol.Name);
|
||||||
|
if (existing == null)
|
||||||
|
Collections.Add(existing = new BeatmapCollection { Name = newCol.Name });
|
||||||
|
|
||||||
|
foreach (var newBeatmap in newCol.Beatmaps)
|
||||||
|
{
|
||||||
|
if (!existing.Beatmaps.Contains(newBeatmap))
|
||||||
|
existing.Beatmaps.Add(newBeatmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BeatmapCollection> readCollections(Stream stream)
|
||||||
{
|
{
|
||||||
var result = new List<BeatmapCollection>();
|
var result = new List<BeatmapCollection>();
|
||||||
|
|
||||||
@ -147,9 +179,9 @@ namespace osu.Game.Collections
|
|||||||
using (var sw = new SerializationWriter(host.Storage.GetStream(database_name, FileAccess.Write)))
|
using (var sw = new SerializationWriter(host.Storage.GetStream(database_name, FileAccess.Write)))
|
||||||
{
|
{
|
||||||
sw.Write(database_version);
|
sw.Write(database_version);
|
||||||
sw.Write(collections.Count);
|
sw.Write(Collections.Count);
|
||||||
|
|
||||||
foreach (var c in collections)
|
foreach (var c in Collections)
|
||||||
{
|
{
|
||||||
sw.Write(c.Name);
|
sw.Write(c.Name);
|
||||||
sw.Write(c.Beatmaps.Count);
|
sw.Write(c.Beatmaps.Count);
|
||||||
|
@ -549,6 +549,8 @@ namespace osu.Game
|
|||||||
ScoreManager.GetStableStorage = GetStorageForStableInstall;
|
ScoreManager.GetStableStorage = GetStorageForStableInstall;
|
||||||
ScoreManager.PresentImport = items => PresentScore(items.First());
|
ScoreManager.PresentImport = items => PresentScore(items.First());
|
||||||
|
|
||||||
|
CollectionManager.GetStableStorage = GetStorageForStableInstall;
|
||||||
|
|
||||||
Container logoContainer;
|
Container logoContainer;
|
||||||
BackButton.Receptor receptor;
|
BackButton.Receptor receptor;
|
||||||
|
|
||||||
|
@ -225,9 +225,8 @@ namespace osu.Game
|
|||||||
dependencies.Cache(difficultyManager);
|
dependencies.Cache(difficultyManager);
|
||||||
AddInternal(difficultyManager);
|
AddInternal(difficultyManager);
|
||||||
|
|
||||||
var collectionManager = new CollectionManager();
|
dependencies.Cache(CollectionManager = new CollectionManager());
|
||||||
dependencies.Cache(collectionManager);
|
AddInternal(CollectionManager);
|
||||||
AddInternal(collectionManager);
|
|
||||||
|
|
||||||
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Collections;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -19,6 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
private TriangleButton importBeatmapsButton;
|
private TriangleButton importBeatmapsButton;
|
||||||
private TriangleButton importScoresButton;
|
private TriangleButton importScoresButton;
|
||||||
private TriangleButton importSkinsButton;
|
private TriangleButton importSkinsButton;
|
||||||
|
private TriangleButton importCollectionsButton;
|
||||||
private TriangleButton deleteBeatmapsButton;
|
private TriangleButton deleteBeatmapsButton;
|
||||||
private TriangleButton deleteScoresButton;
|
private TriangleButton deleteScoresButton;
|
||||||
private TriangleButton deleteSkinsButton;
|
private TriangleButton deleteSkinsButton;
|
||||||
@ -26,7 +28,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
private TriangleButton undeleteButton;
|
private TriangleButton undeleteButton;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, DialogOverlay dialogOverlay)
|
private void load(BeatmapManager beatmaps, ScoreManager scores, SkinManager skins, CollectionManager collections, DialogOverlay dialogOverlay)
|
||||||
{
|
{
|
||||||
if (beatmaps.SupportsImportFromStable)
|
if (beatmaps.SupportsImportFromStable)
|
||||||
{
|
{
|
||||||
@ -93,20 +95,43 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AddRange(new Drawable[]
|
Add(deleteSkinsButton = new DangerousSettingsButton
|
||||||
{
|
{
|
||||||
deleteSkinsButton = new DangerousSettingsButton
|
Text = "Delete ALL skins",
|
||||||
|
Action = () =>
|
||||||
{
|
{
|
||||||
Text = "Delete ALL skins",
|
dialogOverlay?.Push(new DeleteAllBeatmapsDialog(() =>
|
||||||
|
{
|
||||||
|
deleteSkinsButton.Enabled.Value = false;
|
||||||
|
Task.Run(() => skins.Delete(skins.GetAllUserSkins())).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (collections.SupportsImportFromStable)
|
||||||
|
{
|
||||||
|
Add(importCollectionsButton = new SettingsButton
|
||||||
|
{
|
||||||
|
Text = "Import collections from stable",
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
dialogOverlay?.Push(new DeleteAllBeatmapsDialog(() =>
|
importCollectionsButton.Enabled.Value = false;
|
||||||
{
|
collections.ImportFromStableAsync().ContinueWith(t => Schedule(() => importCollectionsButton.Enabled.Value = true));
|
||||||
deleteSkinsButton.Enabled.Value = false;
|
|
||||||
Task.Run(() => skins.Delete(skins.GetAllUserSkins())).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Add(new DangerousSettingsButton
|
||||||
|
{
|
||||||
|
Text = "Delete ALL collections",
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
dialogOverlay?.Push(new DeleteAllBeatmapsDialog(() => collections.Collections.Clear()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
restoreButton = new SettingsButton
|
restoreButton = new SettingsButton
|
||||||
{
|
{
|
||||||
Text = "Restore all hidden difficulties",
|
Text = "Restore all hidden difficulties",
|
||||||
|
Reference in New Issue
Block a user