2020-03-12 12:26:58 +08:00
|
|
|
// 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.
|
|
|
|
|
2020-06-08 06:46:40 +08:00
|
|
|
using osu.Framework.Logging;
|
2020-03-12 12:26:58 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-06-08 06:46:40 +08:00
|
|
|
using osu.Game.IO;
|
2020-06-08 09:03:57 +08:00
|
|
|
using System.IO;
|
2020-06-08 06:46:40 +08:00
|
|
|
using osu.Game.Tournament.Configuration;
|
2020-03-12 12:26:58 +08:00
|
|
|
|
2020-06-09 23:28:42 +08:00
|
|
|
namespace osu.Game.Tournament.IO
|
2020-03-12 12:26:58 +08:00
|
|
|
{
|
2020-06-16 23:39:20 +08:00
|
|
|
public class TournamentStorage : MigratableStorage
|
2020-06-08 06:46:40 +08:00
|
|
|
{
|
2020-06-28 21:27:50 +08:00
|
|
|
private const string default_tournament = "default";
|
2020-06-16 23:00:20 +08:00
|
|
|
private readonly Storage storage;
|
2020-06-28 21:27:50 +08:00
|
|
|
private readonly TournamentStorageManager storageConfig;
|
2020-06-24 06:06:27 +08:00
|
|
|
public TournamentVideoResourceStore VideoStore { get; }
|
2020-06-24 06:00:21 +08:00
|
|
|
|
2020-06-16 23:00:20 +08:00
|
|
|
public TournamentStorage(Storage storage)
|
|
|
|
: base(storage.GetStorageForDirectory("tournaments"), string.Empty)
|
2020-06-08 06:46:40 +08:00
|
|
|
{
|
2020-06-16 23:00:20 +08:00
|
|
|
this.storage = storage;
|
2020-06-08 06:46:40 +08:00
|
|
|
|
2020-06-28 21:27:50 +08:00
|
|
|
storageConfig = new TournamentStorageManager(storage);
|
2020-06-11 19:56:16 +08:00
|
|
|
|
2020-06-24 08:40:22 +08:00
|
|
|
if (storage.Exists("tournament.ini"))
|
2020-06-08 06:46:40 +08:00
|
|
|
{
|
2020-06-24 08:40:22 +08:00
|
|
|
ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(storageConfig.Get<string>(StorageConfig.CurrentTournament)));
|
2020-06-08 06:46:40 +08:00
|
|
|
}
|
2020-06-08 09:03:57 +08:00
|
|
|
else
|
2020-07-02 04:57:16 +08:00
|
|
|
Migrate(UnderlyingStorage.GetStorageForDirectory(default_tournament));
|
2020-06-08 09:03:57 +08:00
|
|
|
|
2020-06-11 21:05:28 +08:00
|
|
|
VideoStore = new TournamentVideoResourceStore(this);
|
2020-06-08 06:46:40 +08:00
|
|
|
Logger.Log("Using tournament storage: " + GetFullPath(string.Empty));
|
|
|
|
}
|
2020-06-08 09:03:57 +08:00
|
|
|
|
2020-07-02 04:57:16 +08:00
|
|
|
public override void Migrate(Storage newStorage)
|
2020-06-08 09:03:57 +08:00
|
|
|
{
|
2020-06-16 23:00:20 +08:00
|
|
|
var source = new DirectoryInfo(storage.GetFullPath("tournament"));
|
2020-07-02 04:57:16 +08:00
|
|
|
var destination = new DirectoryInfo(newStorage.GetFullPath("."));
|
2020-06-08 09:03:57 +08:00
|
|
|
|
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);
|
2020-06-22 18:41:43 +08:00
|
|
|
moveFileIfExists("drawings.ini", destination);
|
2020-07-02 04:57:16 +08:00
|
|
|
ChangeTargetStorage(newStorage);
|
2020-06-28 21:27:50 +08:00
|
|
|
storageConfig.Set(StorageConfig.CurrentTournament, default_tournament);
|
|
|
|
storageConfig.Save();
|
2020-06-08 09:03:57 +08:00
|
|
|
}
|
|
|
|
|
2020-06-16 23:14:54 +08:00
|
|
|
private void moveFileIfExists(string file, DirectoryInfo destination)
|
|
|
|
{
|
2020-06-24 06:00:21 +08:00
|
|
|
if (!storage.Exists(file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Logger.Log($"Migrating {file} to default tournament storage.");
|
|
|
|
var fileInfo = new System.IO.FileInfo(storage.GetFullPath(file));
|
|
|
|
AttemptOperation(() => fileInfo.CopyTo(Path.Combine(destination.FullName, fileInfo.Name), true));
|
|
|
|
fileInfo.Delete();
|
2020-06-16 23:14:54 +08:00
|
|
|
}
|
2020-06-08 06:46:40 +08:00
|
|
|
}
|
2020-03-12 12:26:58 +08:00
|
|
|
}
|