1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-04 13:53:15 +08:00
osu-lazer/osu.Game.Tournament/IO/TournamentStorage.cs

73 lines
2.7 KiB
C#
Raw Normal View History

// 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 osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.IO;
using System.IO;
using osu.Game.Tournament.Configuration;
namespace osu.Game.Tournament.IO
{
2020-06-16 23:39:20 +08:00
public class TournamentStorage : MigratableStorage
{
private readonly Storage storage;
2020-06-11 21:05:28 +08:00
internal readonly TournamentVideoResourceStore VideoStore;
2020-06-11 19:56:16 +08:00
private const string default_tournament = "default";
public TournamentStorage(Storage storage)
: base(storage.GetStorageForDirectory("tournaments"), string.Empty)
{
this.storage = storage;
TournamentStorageManager storageConfig = new TournamentStorageManager(storage);
2020-06-11 19:56:16 +08:00
var currentTournament = storageConfig.Get<string>(StorageConfig.CurrentTournament);
if (!string.IsNullOrEmpty(currentTournament))
{
2020-06-09 00:25:20 +08:00
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(currentTournament));
}
else
{
2020-06-22 18:59:56 +08:00
migrate();
2020-06-11 19:56:16 +08:00
storageConfig.Set(StorageConfig.CurrentTournament, default_tournament);
storageConfig.Save();
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(default_tournament));
}
2020-06-11 21:05:28 +08:00
VideoStore = new TournamentVideoResourceStore(this);
Logger.Log("Using tournament storage: " + GetFullPath(string.Empty));
}
2020-06-22 18:59:56 +08:00
private void migrate()
{
var source = new DirectoryInfo(storage.GetFullPath("tournament"));
2020-06-11 19:56:16 +08:00
var destination = new DirectoryInfo(GetFullPath(default_tournament));
2020-06-16 23:39:20 +08:00
if (source.Exists)
{
Logger.Log("Migrating tournament assets to default tournament storage.");
2020-06-22 18:43:01 +08:00
CopyRecursive(source, destination);
DeleteRecursive(source);
2020-06-16 23:39:20 +08:00
}
2020-06-12 02:11:44 +08:00
2020-06-16 23:14:54 +08:00
moveFileIfExists("bracket.json", destination);
moveFileIfExists("drawings.txt", destination);
moveFileIfExists("drawings_results.txt", destination);
moveFileIfExists("drawings.ini", destination);
}
2020-06-16 23:14:54 +08:00
private void moveFileIfExists(string file, DirectoryInfo destination)
{
if (storage.Exists(file))
{
Logger.Log($"Migrating {file} to default tournament storage.");
var fileInfo = new System.IO.FileInfo(storage.GetFullPath(file));
2020-06-22 18:43:01 +08:00
AttemptOperation(() => fileInfo.CopyTo(Path.Combine(destination.FullName, fileInfo.Name), true));
2020-06-16 23:15:43 +08:00
fileInfo.Delete();
2020-06-16 23:14:54 +08:00
}
}
}
}