mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:07:52 +08:00
Extract common method for determining stable import usability of directory
This commit is contained in:
parent
9e3b1dbb59
commit
b384c9f938
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
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;
|
||||||
@ -54,6 +57,49 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
public void UpdateStorage(string stablePath) => cachedStorage = new StableStorage(stablePath, gameHost as DesktopGameHost);
|
public void UpdateStorage(string stablePath) => cachedStorage = new StableStorage(stablePath, gameHost as DesktopGameHost);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a valid location to run a stable import from can be determined starting from the supplied <paramref name="directory"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directory">The directory to check for stable import eligibility.</param>
|
||||||
|
/// <param name="stableRoot">
|
||||||
|
/// If the return value is <see langword="true"/>,
|
||||||
|
/// this parameter will contain the <see cref="DirectoryInfo"/> to use as the root directory for importing.
|
||||||
|
/// </param>
|
||||||
|
public bool IsUsableForStableImport(DirectoryInfo? directory, [NotNullWhen(true)] out DirectoryInfo? stableRoot)
|
||||||
|
{
|
||||||
|
if (directory == null)
|
||||||
|
{
|
||||||
|
stableRoot = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A full stable installation will have a configuration file present.
|
||||||
|
// This is the best case scenario, as it may contain a custom beatmap directory we need to traverse to.
|
||||||
|
if (directory.GetFiles(@"osu!.*.cfg").Any())
|
||||||
|
{
|
||||||
|
stableRoot = directory;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The user may only have their songs or skins folders left.
|
||||||
|
// We still want to allow them to import based on this.
|
||||||
|
if (directory.GetDirectories(@"Songs").Any() || directory.GetDirectories(@"Skins").Any())
|
||||||
|
{
|
||||||
|
stableRoot = directory;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The user may have traversed *inside* their songs or skins folders.
|
||||||
|
if (directory.Parent != null && (directory.Name == @"Songs" || directory.Name == @"Skins"))
|
||||||
|
{
|
||||||
|
stableRoot = directory.Parent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
stableRoot = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool CheckSongsFolderHardLinkAvailability()
|
public bool CheckSongsFolderHardLinkAvailability()
|
||||||
{
|
{
|
||||||
var stableStorage = GetCurrentStableStorage();
|
var stableStorage = GetCurrentStableStorage();
|
||||||
|
@ -269,11 +269,11 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
if (directory.OldValue?.FullName == directory.NewValue.FullName)
|
if (directory.OldValue?.FullName == directory.NewValue.FullName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (directory.NewValue?.GetFiles(@"osu!.*.cfg").Any() ?? false)
|
if (legacyImportManager.IsUsableForStableImport(directory.NewValue, out var stableRoot))
|
||||||
{
|
{
|
||||||
this.HidePopover();
|
this.HidePopover();
|
||||||
|
|
||||||
string path = directory.NewValue.FullName;
|
string path = stableRoot.FullName;
|
||||||
|
|
||||||
legacyImportManager.UpdateStorage(path);
|
legacyImportManager.UpdateStorage(path);
|
||||||
Current.Value = path;
|
Current.Value = path;
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Database;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||||
{
|
{
|
||||||
@ -13,18 +15,12 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
{
|
{
|
||||||
private readonly TaskCompletionSource<string> taskCompletionSource;
|
private readonly TaskCompletionSource<string> taskCompletionSource;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private LegacyImportManager legacyImportManager { get; set; } = null!;
|
||||||
|
|
||||||
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
|
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
|
||||||
|
|
||||||
protected override bool IsValidDirectory(DirectoryInfo? info) =>
|
protected override bool IsValidDirectory(DirectoryInfo? info) => legacyImportManager.IsUsableForStableImport(info, out _);
|
||||||
// A full stable installation will have a configuration file present.
|
|
||||||
// This is the best case scenario, as it may contain a custom beatmap directory we need to traverse to.
|
|
||||||
info?.GetFiles("osu!.*.cfg").Any() == true ||
|
|
||||||
// The user may only have their songs or skins folders left.
|
|
||||||
// We still want to allow them to import based on this.
|
|
||||||
info?.GetDirectories("Songs").Any() == true ||
|
|
||||||
info?.GetDirectories("Skins").Any() == true ||
|
|
||||||
// The user may have traverse *inside* their songs or skins folders.
|
|
||||||
shouldUseParentDirectory(info);
|
|
||||||
|
|
||||||
public override LocalisableString HeaderText => "Please select your osu!stable install location";
|
public override LocalisableString HeaderText => "Please select your osu!stable install location";
|
||||||
|
|
||||||
@ -35,7 +31,10 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
|
|
||||||
protected override void OnSelection(DirectoryInfo directory)
|
protected override void OnSelection(DirectoryInfo directory)
|
||||||
{
|
{
|
||||||
taskCompletionSource.TrySetResult(shouldUseParentDirectory(directory) ? directory.Parent!.FullName : directory.FullName);
|
if (!legacyImportManager.IsUsableForStableImport(directory, out var stableRoot))
|
||||||
|
throw new InvalidOperationException($@"{nameof(OnSelection)} was called on an invalid directory. This should never happen.");
|
||||||
|
|
||||||
|
taskCompletionSource.TrySetResult(stableRoot.FullName);
|
||||||
this.Exit();
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +43,5 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
taskCompletionSource.TrySetCanceled();
|
taskCompletionSource.TrySetCanceled();
|
||||||
return base.OnExiting(e);
|
return base.OnExiting(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool shouldUseParentDirectory(DirectoryInfo? info)
|
|
||||||
=> info?.Parent != null && (info.Name == "Songs" || info.Name == "Skins");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user