mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Add basic blocking migration, move not copy
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
// 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 osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -9,10 +11,15 @@ namespace osu.Game.IO
|
|||||||
{
|
{
|
||||||
public class OsuStorage : WrappedStorage
|
public class OsuStorage : WrappedStorage
|
||||||
{
|
{
|
||||||
|
private readonly GameHost host;
|
||||||
|
private readonly StorageConfigManager storageConfig;
|
||||||
|
|
||||||
public OsuStorage(GameHost host)
|
public OsuStorage(GameHost host)
|
||||||
: base(host.Storage, string.Empty)
|
: base(host.Storage, string.Empty)
|
||||||
{
|
{
|
||||||
var storageConfig = new StorageConfigManager(host.Storage);
|
this.host = host;
|
||||||
|
|
||||||
|
storageConfig = new StorageConfigManager(host.Storage);
|
||||||
|
|
||||||
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
|
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);
|
||||||
|
|
||||||
@ -22,5 +29,34 @@ namespace osu.Game.IO
|
|||||||
Logger.Storage = UnderlyingStorage.GetStorageForDirectory("logs");
|
Logger.Storage = UnderlyingStorage.GetStorageForDirectory("logs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Migrate(string newLocation)
|
||||||
|
{
|
||||||
|
string oldLocation = GetFullPath(".");
|
||||||
|
|
||||||
|
// ensure the new location has no files present, else hard abort
|
||||||
|
if (Directory.Exists(newLocation))
|
||||||
|
{
|
||||||
|
if (Directory.GetFiles(newLocation).Length > 0)
|
||||||
|
throw new InvalidOperationException("Migration destination already has files present");
|
||||||
|
|
||||||
|
Directory.Delete(newLocation, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.Move(oldLocation, newLocation);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(newLocation);
|
||||||
|
// temporary
|
||||||
|
Directory.CreateDirectory(oldLocation);
|
||||||
|
|
||||||
|
// move back exceptions for now
|
||||||
|
Directory.Move(Path.Combine(newLocation, "cache"), Path.Combine(oldLocation, "cache"));
|
||||||
|
File.Move(Path.Combine(newLocation, "framework.ini"), Path.Combine(oldLocation, "framework.ini"));
|
||||||
|
|
||||||
|
ChangeTargetStorage(host.GetStorage(newLocation));
|
||||||
|
|
||||||
|
storageConfig.Set(StorageConfig.FullPath, newLocation);
|
||||||
|
storageConfig.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user