2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2017-03-03 19:42:22 +08:00
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
|
using osu.Framework.Platform;
|
2019-06-18 13:51:48 +08:00
|
|
|
|
using osu.Game.Tournament.Models;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings.Components
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
2017-03-03 19:42:22 +08:00
|
|
|
|
public class StorageBackedTeamList : ITeamList
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
|
|
|
|
private const string teams_filename = "drawings.txt";
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Storage storage;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 19:42:22 +08:00
|
|
|
|
public StorageBackedTeamList(Storage storage)
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
|
|
|
|
this.storage = storage;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
public IEnumerable<TournamentTeam> Teams
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-08-25 20:40:40 +08:00
|
|
|
|
var teams = new List<TournamentTeam>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-07-30 01:00:07 +08:00
|
|
|
|
if (!storage.Exists(teams_filename))
|
|
|
|
|
return teams;
|
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (Stream stream = storage.GetStream(teams_filename, FileAccess.Read, FileMode.Open))
|
2017-05-02 12:02:14 +08:00
|
|
|
|
using (var sr = new StreamReader(stream))
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
|
|
|
|
while (sr.Peek() != -1)
|
|
|
|
|
{
|
2017-03-07 09:59:19 +08:00
|
|
|
|
string line = sr.ReadLine()?.Trim();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-11-20 17:55:48 +08:00
|
|
|
|
// ReSharper disable once PossibleNullReferenceException
|
2017-03-03 17:47:56 +08:00
|
|
|
|
string[] split = line.Split(':');
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
if (split.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log($"Invalid team definition: {line}. Expected \"flag_name : team_name : team_acronym\".");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
teams.Add(new TournamentTeam
|
2017-03-03 17:47:56 +08:00
|
|
|
|
{
|
2019-06-17 15:28:58 +08:00
|
|
|
|
FullName = { Value = split[1].Trim(), },
|
|
|
|
|
Acronym = { Value = split.Length >= 3 ? split[2].Trim() : null, },
|
|
|
|
|
FlagName = { Value = split[0].Trim() }
|
2017-03-03 17:47:56 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "Failed to read teams.");
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
return teams;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|