2020-03-12 13:26:58 +09: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.
|
|
|
|
|
2023-07-22 09:59:00 +01:00
|
|
|
using System;
|
2021-03-29 15:03:10 +02:00
|
|
|
using System.Collections.Generic;
|
2023-07-22 09:59:00 +01:00
|
|
|
using System.Linq;
|
2020-12-07 13:11:13 +01:00
|
|
|
using osu.Framework.Bindables;
|
2020-06-08 00:46:40 +02:00
|
|
|
using osu.Framework.Logging;
|
2020-03-12 13:26:58 +09:00
|
|
|
using osu.Framework.Platform;
|
2020-06-08 00:46:40 +02:00
|
|
|
using osu.Game.IO;
|
|
|
|
using osu.Game.Tournament.Configuration;
|
2020-03-12 13:26:58 +09:00
|
|
|
|
2020-06-09 17:28:42 +02:00
|
|
|
namespace osu.Game.Tournament.IO
|
2020-03-12 13:26:58 +09:00
|
|
|
{
|
2022-10-28 13:00:39 +09:00
|
|
|
public class TournamentStorage : WrappedStorage
|
2020-06-08 00:46:40 +02:00
|
|
|
{
|
2021-03-29 15:03:10 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The storage where all tournaments are located.
|
|
|
|
/// </summary>
|
|
|
|
public readonly Storage AllTournaments;
|
|
|
|
|
2020-12-07 13:11:13 +01:00
|
|
|
public readonly Bindable<string> CurrentTournament;
|
2020-06-24 00:00:21 +02:00
|
|
|
|
2022-10-28 13:00:39 +09:00
|
|
|
protected TournamentConfigManager TournamentConfigManager { get; }
|
|
|
|
|
2020-06-16 17:00:20 +02:00
|
|
|
public TournamentStorage(Storage storage)
|
|
|
|
: base(storage.GetStorageForDirectory("tournaments"), string.Empty)
|
2020-06-08 00:46:40 +02:00
|
|
|
{
|
2021-03-29 15:03:10 +02:00
|
|
|
AllTournaments = UnderlyingStorage;
|
2020-06-08 00:46:40 +02:00
|
|
|
|
2022-10-28 13:00:39 +09:00
|
|
|
TournamentConfigManager = new TournamentConfigManager(storage);
|
2020-06-11 13:56:16 +02:00
|
|
|
|
2022-10-28 13:00:39 +09:00
|
|
|
CurrentTournament = TournamentConfigManager.GetBindable<string>(StorageConfig.CurrentTournament);
|
|
|
|
|
|
|
|
ChangeTargetStorage(AllTournaments.GetStorageForDirectory(CurrentTournament.Value));
|
2020-06-08 03:03:57 +02:00
|
|
|
|
2020-06-08 00:46:40 +02:00
|
|
|
Logger.Log("Using tournament storage: " + GetFullPath(string.Empty));
|
2020-12-07 13:11:13 +01:00
|
|
|
|
2020-12-07 21:38:15 +01:00
|
|
|
CurrentTournament.BindValueChanged(updateTournament);
|
2020-06-08 00:46:40 +02:00
|
|
|
}
|
2020-06-08 03:03:57 +02:00
|
|
|
|
2020-12-07 13:11:13 +01:00
|
|
|
private void updateTournament(ValueChangedEvent<string> newTournament)
|
|
|
|
{
|
2021-03-29 15:03:10 +02:00
|
|
|
ChangeTargetStorage(AllTournaments.GetStorageForDirectory(newTournament.NewValue));
|
2020-12-07 13:11:13 +01:00
|
|
|
Logger.Log("Changing tournament storage: " + GetFullPath(string.Empty));
|
|
|
|
}
|
|
|
|
|
2024-02-08 18:01:00 +01:00
|
|
|
public IEnumerable<string> ListTournaments() => AllTournaments.GetDirectories(string.Empty).Order(StringComparer.CurrentCultureIgnoreCase);
|
2020-06-08 00:46:40 +02:00
|
|
|
}
|
2020-03-12 13:26:58 +09:00
|
|
|
}
|