2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
|
using osu.Framework.Platform;
|
2018-08-26 00:24:19 +08:00
|
|
|
|
using osu.Game.Tournament.Components;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings.Components
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
public class StorageBackedTeamList : ITeamList
|
|
|
|
|
{
|
|
|
|
|
private const string teams_filename = "drawings.txt";
|
|
|
|
|
|
|
|
|
|
private readonly Storage storage;
|
|
|
|
|
|
|
|
|
|
public StorageBackedTeamList(Storage storage)
|
|
|
|
|
{
|
|
|
|
|
this.storage = storage;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
public IEnumerable<TournamentTeam> Teams
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-08-25 20:40:40 +08:00
|
|
|
|
var teams = new List<TournamentTeam>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (Stream stream = storage.GetStream(teams_filename, FileAccess.Read, FileMode.Open))
|
|
|
|
|
using (var sr = new StreamReader(stream))
|
|
|
|
|
{
|
|
|
|
|
while (sr.Peek() != -1)
|
|
|
|
|
{
|
|
|
|
|
string line = sr.ReadLine()?.Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once PossibleNullReferenceException
|
|
|
|
|
string[] split = line.Split(':');
|
|
|
|
|
|
|
|
|
|
if (split.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log($"Invalid team definition: {line}. Expected \"flag_name : team_name : team_acronym\".");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
teams.Add(new TournamentTeam
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-25 20:40:40 +08:00
|
|
|
|
FlagName = split[0].Trim(),
|
|
|
|
|
FullName = split[1].Trim(),
|
|
|
|
|
Acronym = split.Length >= 3 ? split[2].Trim() : null
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "Failed to read teams.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return teams;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|