mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Merge pull request #9418 from smoogipoo/custom-storage-startup-exception
This commit is contained in:
commit
069a2c8307
@ -2,9 +2,11 @@
|
|||||||
// 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;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -13,12 +15,30 @@ namespace osu.Game.IO
|
|||||||
{
|
{
|
||||||
public class OsuStorage : WrappedStorage
|
public class OsuStorage : WrappedStorage
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates the error (if any) that occurred when initialising the custom storage during initial startup.
|
||||||
|
/// </summary>
|
||||||
|
public readonly OsuStorageError Error;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The custom storage path as selected by the user.
|
||||||
|
/// </summary>
|
||||||
|
[CanBeNull]
|
||||||
|
public string CustomStoragePath => storageConfig.Get<string>(StorageConfig.FullPath);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The default storage path to be used if a custom storage path hasn't been selected or is not accessible.
|
||||||
|
/// </summary>
|
||||||
|
[NotNull]
|
||||||
|
public string DefaultStoragePath => defaultStorage.GetFullPath(".");
|
||||||
|
|
||||||
private readonly GameHost host;
|
private readonly GameHost host;
|
||||||
private readonly StorageConfigManager storageConfig;
|
private readonly StorageConfigManager storageConfig;
|
||||||
|
private readonly Storage defaultStorage;
|
||||||
|
|
||||||
internal static readonly string[] IGNORE_DIRECTORIES = { "cache" };
|
public static readonly string[] IGNORE_DIRECTORIES = { "cache" };
|
||||||
|
|
||||||
internal static readonly string[] IGNORE_FILES =
|
public static readonly string[] IGNORE_FILES =
|
||||||
{
|
{
|
||||||
"framework.ini",
|
"framework.ini",
|
||||||
"storage.ini"
|
"storage.ini"
|
||||||
@ -28,13 +48,53 @@ namespace osu.Game.IO
|
|||||||
: base(defaultStorage, string.Empty)
|
: base(defaultStorage, string.Empty)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
this.defaultStorage = defaultStorage;
|
||||||
|
|
||||||
storageConfig = new StorageConfigManager(defaultStorage);
|
storageConfig = new StorageConfigManager(defaultStorage);
|
||||||
|
|
||||||
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
|
if (!string.IsNullOrEmpty(CustomStoragePath))
|
||||||
|
TryChangeToCustomStorage(out Error);
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(customStoragePath))
|
/// <summary>
|
||||||
ChangeTargetStorage(host.GetStorage(customStoragePath));
|
/// Resets the custom storage path, changing the target storage to the default location.
|
||||||
|
/// </summary>
|
||||||
|
public void ResetCustomStoragePath()
|
||||||
|
{
|
||||||
|
storageConfig.Set(StorageConfig.FullPath, string.Empty);
|
||||||
|
storageConfig.Save();
|
||||||
|
|
||||||
|
ChangeTargetStorage(defaultStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to change to the user's custom storage path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="error">The error that occurred.</param>
|
||||||
|
/// <returns>Whether the custom storage path was used successfully. If not, <paramref name="error"/> will be populated with the reason.</returns>
|
||||||
|
public bool TryChangeToCustomStorage(out OsuStorageError error)
|
||||||
|
{
|
||||||
|
Debug.Assert(!string.IsNullOrEmpty(CustomStoragePath));
|
||||||
|
|
||||||
|
error = OsuStorageError.None;
|
||||||
|
Storage lastStorage = UnderlyingStorage;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Storage userStorage = host.GetStorage(CustomStoragePath);
|
||||||
|
|
||||||
|
if (!userStorage.ExistsDirectory(".") || !userStorage.GetFiles(".").Any())
|
||||||
|
error = OsuStorageError.AccessibleButEmpty;
|
||||||
|
|
||||||
|
ChangeTargetStorage(userStorage);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
error = OsuStorageError.NotAccessible;
|
||||||
|
ChangeTargetStorage(lastStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error == OsuStorageError.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ChangeTargetStorage(Storage newStorage)
|
protected override void ChangeTargetStorage(Storage newStorage)
|
||||||
@ -145,4 +205,23 @@ namespace osu.Game.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum OsuStorageError
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// No error.
|
||||||
|
/// </summary>
|
||||||
|
None,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the target storage directory is accessible but does not already contain game files.
|
||||||
|
/// Only happens when the user changes the storage directory and then moves the files manually or mounts a different device to the same path.
|
||||||
|
/// </summary>
|
||||||
|
AccessibleButEmpty,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the target storage directory cannot be accessed at all.
|
||||||
|
/// </summary>
|
||||||
|
NotAccessible,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,25 +42,34 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
set => icon.Icon = value;
|
set => icon.Icon = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string text;
|
private string headerText;
|
||||||
|
|
||||||
public string HeaderText
|
public string HeaderText
|
||||||
{
|
{
|
||||||
get => text;
|
get => headerText;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (text == value)
|
if (headerText == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
text = value;
|
headerText = value;
|
||||||
|
|
||||||
header.Text = value;
|
header.Text = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string bodyText;
|
||||||
|
|
||||||
public string BodyText
|
public string BodyText
|
||||||
{
|
{
|
||||||
set => body.Text = value;
|
get => bodyText;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (bodyText == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bodyText = value;
|
||||||
|
body.Text = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PopupDialogButton> Buttons
|
public IEnumerable<PopupDialogButton> Buttons
|
||||||
|
34
osu.Game/Screens/Menu/ConfirmExitDialog.cs
Normal file
34
osu.Game/Screens/Menu/ConfirmExitDialog.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// 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 osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Overlays.Dialog;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Menu
|
||||||
|
{
|
||||||
|
public class ConfirmExitDialog : PopupDialog
|
||||||
|
{
|
||||||
|
public ConfirmExitDialog(Action confirm, Action cancel)
|
||||||
|
{
|
||||||
|
HeaderText = "Are you sure you want to exit?";
|
||||||
|
BodyText = "Last chance to back out.";
|
||||||
|
|
||||||
|
Icon = FontAwesome.Solid.ExclamationTriangle;
|
||||||
|
|
||||||
|
Buttons = new PopupDialogButton[]
|
||||||
|
{
|
||||||
|
new PopupDialogOkButton
|
||||||
|
{
|
||||||
|
Text = @"Goodbye",
|
||||||
|
Action = confirm
|
||||||
|
},
|
||||||
|
new PopupDialogCancelButton
|
||||||
|
{
|
||||||
|
Text = @"Just a little more",
|
||||||
|
Action = cancel
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
// 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.Linq;
|
using System.Linq;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -9,15 +8,14 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.IO;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Dialog;
|
|
||||||
using osu.Game.Screens.Backgrounds;
|
using osu.Game.Screens.Backgrounds;
|
||||||
using osu.Game.Screens.Edit;
|
using osu.Game.Screens.Edit;
|
||||||
using osu.Game.Screens.Multi;
|
using osu.Game.Screens.Multi;
|
||||||
@ -171,6 +169,9 @@ namespace osu.Game.Screens.Menu
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Storage storage { get; set; }
|
||||||
|
|
||||||
public override void OnEntering(IScreen last)
|
public override void OnEntering(IScreen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
@ -187,6 +188,9 @@ namespace osu.Game.Screens.Menu
|
|||||||
Track.Start();
|
Track.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (storage is OsuStorage osuStorage && osuStorage.Error != OsuStorageError.None)
|
||||||
|
dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool exitConfirmed;
|
private bool exitConfirmed;
|
||||||
@ -283,30 +287,5 @@ namespace osu.Game.Screens.Menu
|
|||||||
this.FadeOut(3000);
|
this.FadeOut(3000);
|
||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ConfirmExitDialog : PopupDialog
|
|
||||||
{
|
|
||||||
public ConfirmExitDialog(Action confirm, Action cancel)
|
|
||||||
{
|
|
||||||
HeaderText = "Are you sure you want to exit?";
|
|
||||||
BodyText = "Last chance to back out.";
|
|
||||||
|
|
||||||
Icon = FontAwesome.Solid.ExclamationTriangle;
|
|
||||||
|
|
||||||
Buttons = new PopupDialogButton[]
|
|
||||||
{
|
|
||||||
new PopupDialogOkButton
|
|
||||||
{
|
|
||||||
Text = @"Goodbye",
|
|
||||||
Action = confirm
|
|
||||||
},
|
|
||||||
new PopupDialogCancelButton
|
|
||||||
{
|
|
||||||
Text = @"Just a little more",
|
|
||||||
Action = cancel
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
osu.Game/Screens/Menu/StorageErrorDialog.cs
Normal file
79
osu.Game/Screens/Menu/StorageErrorDialog.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// 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 osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.IO;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Dialog;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Menu
|
||||||
|
{
|
||||||
|
public class StorageErrorDialog : PopupDialog
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private DialogOverlay dialogOverlay { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuGameBase osuGame { get; set; }
|
||||||
|
|
||||||
|
public StorageErrorDialog(OsuStorage storage, OsuStorageError error)
|
||||||
|
{
|
||||||
|
HeaderText = "osu! storage error";
|
||||||
|
Icon = FontAwesome.Solid.ExclamationTriangle;
|
||||||
|
|
||||||
|
var buttons = new List<PopupDialogButton>();
|
||||||
|
|
||||||
|
switch (error)
|
||||||
|
{
|
||||||
|
case OsuStorageError.NotAccessible:
|
||||||
|
BodyText = $"The specified osu! data location (\"{storage.CustomStoragePath}\") is not accessible. If it is on external storage, please reconnect the device and try again.";
|
||||||
|
|
||||||
|
buttons.AddRange(new PopupDialogButton[]
|
||||||
|
{
|
||||||
|
new PopupDialogCancelButton
|
||||||
|
{
|
||||||
|
Text = "Try again",
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
if (!storage.TryChangeToCustomStorage(out var nextError))
|
||||||
|
dialogOverlay.Push(new StorageErrorDialog(storage, nextError));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new PopupDialogCancelButton
|
||||||
|
{
|
||||||
|
Text = "Use default location until restart",
|
||||||
|
},
|
||||||
|
new PopupDialogOkButton
|
||||||
|
{
|
||||||
|
Text = "Reset to default location",
|
||||||
|
Action = storage.ResetCustomStoragePath
|
||||||
|
},
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OsuStorageError.AccessibleButEmpty:
|
||||||
|
BodyText = $"The specified osu! data location (\"{storage.CustomStoragePath}\") is empty. If you have moved the files, please close osu! and move them back.";
|
||||||
|
|
||||||
|
// Todo: Provide the option to search for the files similar to migration.
|
||||||
|
buttons.AddRange(new PopupDialogButton[]
|
||||||
|
{
|
||||||
|
new PopupDialogCancelButton
|
||||||
|
{
|
||||||
|
Text = "Start fresh at specified location"
|
||||||
|
},
|
||||||
|
new PopupDialogOkButton
|
||||||
|
{
|
||||||
|
Text = "Reset to default location",
|
||||||
|
Action = storage.ResetCustomStoragePath
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Buttons = buttons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user