diff --git a/osu.Game.Tournament/TournamentStorage.cs b/osu.Game.Tournament/TournamentStorage.cs index 32dd904b2f..87a2604d0b 100644 --- a/osu.Game.Tournament/TournamentStorage.cs +++ b/osu.Game.Tournament/TournamentStorage.cs @@ -13,17 +13,6 @@ using osu.Game.Tournament.Configuration; namespace osu.Game.Tournament { - internal class TournamentVideoStorage : NamespacedResourceStore - { - public TournamentVideoStorage(Storage storage) - : base(new StorageBackedResourceStore(storage), "videos") - { - AddExtension("m4v"); - AddExtension("avi"); - AddExtension("mp4"); - } - } - internal class TournamentStorage : WrappedStorage { private readonly GameHost host; @@ -72,9 +61,10 @@ namespace osu.Game.Tournament ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(default_path)); storageConfig.Set(StorageConfig.CurrentTournament, default_path); storageConfig.Save(); + deleteRecursive(source); } - private void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true) + private void copyRecursive(DirectoryInfo source, DirectoryInfo destination) { // based off example code https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo @@ -85,10 +75,26 @@ namespace osu.Game.Tournament foreach (DirectoryInfo dir in source.GetDirectories()) { - copyRecursive(dir, destination.CreateSubdirectory(dir.Name), false); + copyRecursive(dir, destination.CreateSubdirectory(dir.Name)); } } + private void deleteRecursive(DirectoryInfo target) + { + foreach (System.IO.FileInfo fi in target.GetFiles()) + { + attemptOperation(() => fi.Delete()); + } + + foreach (DirectoryInfo dir in target.GetDirectories()) + { + attemptOperation(() => dir.Delete(true)); + } + + if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0) + attemptOperation(target.Delete); + } + private void attemptOperation(Action action, int attempts = 10) { while (true) @@ -108,4 +114,14 @@ namespace osu.Game.Tournament } } } + internal class TournamentVideoStorage : NamespacedResourceStore + { + public TournamentVideoStorage(Storage storage) + : base(new StorageBackedResourceStore(storage), "videos") + { + AddExtension("m4v"); + AddExtension("avi"); + AddExtension("mp4"); + } + } }