1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 11:53:21 +08:00

Remove unnecessary parameters and implement delete

This commit is contained in:
Shivam 2020-06-08 19:51:44 +02:00
parent ce66b72390
commit d2ae146c1f

View File

@ -13,17 +13,6 @@ using osu.Game.Tournament.Configuration;
namespace osu.Game.Tournament
{
internal class TournamentVideoStorage : NamespacedResourceStore<byte[]>
{
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<byte[]>
{
public TournamentVideoStorage(Storage storage)
: base(new StorageBackedResourceStore(storage), "videos")
{
AddExtension("m4v");
AddExtension("avi");
AddExtension("mp4");
}
}
}