1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 10:57:27 +08:00
osu-lazer/osu.Game/Screens/Tournament/Teams/StorageBackedTeamList.cs

75 lines
2.5 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-03-03 17:47:56 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
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;
2017-03-03 17:47:56 +08:00
2017-03-03 19:42:22 +08:00
namespace osu.Game.Screens.Tournament.Teams
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";
private readonly Storage storage;
2017-03-03 17:47:56 +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;
}
2017-05-02 17:00:37 +08:00
public IEnumerable<DrawingsTeam> Teams
2017-03-03 17:47:56 +08:00
{
get
{
2017-05-02 17:00:37 +08:00
var teams = new List<DrawingsTeam>();
2017-03-03 17:47:56 +08:00
try
{
using (Stream stream = storage.GetStream(teams_filename, FileAccess.Read, FileMode.Open))
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();
2017-03-03 17:47:56 +08:00
if (string.IsNullOrEmpty(line))
continue;
// ReSharper disable once PossibleNullReferenceException
2017-03-03 17:47:56 +08:00
string[] split = line.Split(':');
if (split.Length < 2)
{
Logger.Log($"Invalid team definition: {line}. Expected \"flag_name : team_name : team_acronym\".");
continue;
}
string flagName = split[0].Trim();
string teamName = split[1].Trim();
string acronym = split.Length >= 3 ? split[2].Trim() : teamName;
acronym = acronym.Substring(0, Math.Min(3, acronym.Length));
2017-05-02 17:00:37 +08:00
teams.Add(new DrawingsTeam
2017-03-03 17:47:56 +08:00
{
FlagName = flagName,
FullName = teamName,
Acronym = acronym
});
}
}
}
catch (Exception ex)
{
Logger.Error(ex, "Failed to read teams.");
}
return teams;
}
}
}
}