mirror of https://github.com/ppy/osu
Add basic blocking migration, move not copy
This commit is contained in:
parent
754afb9c0b
commit
49a03f1c06
|
@ -1,6 +1,8 @@
|
|||
// 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 System.IO;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Configuration;
|
||||
|
@ -9,10 +11,15 @@ namespace osu.Game.IO
|
|||
{
|
||||
public class OsuStorage : WrappedStorage
|
||||
{
|
||||
private readonly GameHost host;
|
||||
private readonly StorageConfigManager storageConfig;
|
||||
|
||||
public OsuStorage(GameHost host)
|
||||
: 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);
|
||||
|
||||
|
@ -22,5 +29,34 @@ public OsuStorage(GameHost host)
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue