mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:47:29 +08:00
Merge pull request #17527 from peppy/switch-osu-folder
Add ability to "migrate" data to another folder which has an existing install
This commit is contained in:
commit
c311e11496
@ -233,6 +233,48 @@ namespace osu.Game.Tests.NonVisual
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMigrationFailsOnExistingData()
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
string customPath2 = prepareCustomPath();
|
||||
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var storage = osu.Dependencies.Get<Storage>();
|
||||
var osuStorage = storage as OsuStorage;
|
||||
|
||||
string originalDirectory = storage.GetFullPath(".");
|
||||
|
||||
const string database_filename = "client.realm";
|
||||
|
||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||
Assert.That(File.Exists(Path.Combine(customPath, database_filename)));
|
||||
|
||||
Directory.CreateDirectory(customPath2);
|
||||
File.Copy(Path.Combine(customPath, database_filename), Path.Combine(customPath2, database_filename));
|
||||
|
||||
// Fails because file already exists.
|
||||
Assert.Throws<ArgumentException>(() => osu.Migrate(customPath2));
|
||||
|
||||
osuStorage?.ChangeDataPath(customPath2);
|
||||
|
||||
Assert.That(osuStorage?.CustomStoragePath, Is.EqualTo(customPath2));
|
||||
Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath2}"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.Exit();
|
||||
cleanupPath(customPath);
|
||||
cleanupPath(customPath2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMigrationToNestedTargetFails()
|
||||
{
|
||||
|
@ -64,12 +64,22 @@ namespace osu.Game.IO
|
||||
/// </summary>
|
||||
public void ResetCustomStoragePath()
|
||||
{
|
||||
storageConfig.SetValue(StorageConfig.FullPath, string.Empty);
|
||||
storageConfig.Save();
|
||||
ChangeDataPath(string.Empty);
|
||||
|
||||
ChangeTargetStorage(defaultStorage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the target data path without immediately switching.
|
||||
/// This does NOT migrate any data.
|
||||
/// The game should immediately be restarted after calling this.
|
||||
/// </summary>
|
||||
public void ChangeDataPath(string newPath)
|
||||
{
|
||||
storageConfig.SetValue(StorageConfig.FullPath, newPath);
|
||||
storageConfig.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to change to the user's custom storage path.
|
||||
/// </summary>
|
||||
@ -117,8 +127,7 @@ namespace osu.Game.IO
|
||||
{
|
||||
bool cleanupSucceeded = base.Migrate(newStorage);
|
||||
|
||||
storageConfig.SetValue(StorageConfig.FullPath, newStorage.GetFullPath("."));
|
||||
storageConfig.Save();
|
||||
ChangeDataPath(newStorage.GetFullPath("."));
|
||||
|
||||
return cleanupSucceeded;
|
||||
}
|
||||
|
@ -3,11 +3,14 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Overlays.Dialog;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||
{
|
||||
@ -16,6 +19,12 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||
[Resolved]
|
||||
private Storage storage { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private DialogOverlay dialogOverlay { get; set; }
|
||||
|
||||
protected override DirectoryInfo InitialPath => new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent;
|
||||
|
||||
public override bool AllowExternalScreenChange => false;
|
||||
@ -32,8 +41,29 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||
|
||||
try
|
||||
{
|
||||
if (target.GetDirectories().Length > 0 || target.GetFiles().Length > 0)
|
||||
var directoryInfos = target.GetDirectories();
|
||||
var fileInfos = target.GetFiles();
|
||||
|
||||
if (directoryInfos.Length > 0 || fileInfos.Length > 0)
|
||||
{
|
||||
// Quick test for whether there's already an osu! install at the target path.
|
||||
if (fileInfos.Any(f => f.Name == @"client.realm"))
|
||||
{
|
||||
dialogOverlay.Push(new ConfirmDialog("The target directory already seems to have an osu! install. Use that data instead?", () =>
|
||||
{
|
||||
dialogOverlay.Push(new ConfirmDialog("To complete this operation, osu! will close. Please open it again to use the new data location.", () =>
|
||||
{
|
||||
(storage as OsuStorage)?.ChangeDataPath(target.FullName);
|
||||
game.GracefullyExit();
|
||||
}, () => { }));
|
||||
},
|
||||
() => { }));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
target = target.CreateSubdirectory("osu-lazer");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user