From 49a03f1c06ca6824fc8e131ddd1e8f845c4ea1f2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 6 May 2020 18:31:36 +0900 Subject: [PATCH] Add basic blocking migration, move not copy --- osu.Game/IO/OsuStorage.cs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/osu.Game/IO/OsuStorage.cs b/osu.Game/IO/OsuStorage.cs index ee42c491d1..f6cac2f4f1 100644 --- a/osu.Game/IO/OsuStorage.cs +++ b/osu.Game/IO/OsuStorage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . 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(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(); + } } }