Style & nit fixes

This commit is contained in:
Pavlos Touboulidis
2014-04-28 21:49:41 +03:00
parent a80c4f086a
commit ce8c42b552
3 changed files with 27 additions and 26 deletions

View File

@@ -6,46 +6,46 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see COPYING. * see COPYING.
*/ */
using System.Text;
#endregion #endregion
using System; using System;
using System.IO; using System.IO;
using System.Text;
using OpenRA.Network; using OpenRA.Network;
namespace OpenRA.FileFormats namespace OpenRA.FileFormats
{ {
public class ReplayMetadata public class ReplayMetadata
{ {
public const int MetaStartMarker = -1; // Must be an invalid replay 'client' value // Must be an invalid replay 'client' value
public const int MetaStartMarker = -1;
public const int MetaEndMarker = -2; public const int MetaEndMarker = -2;
public const int MetaVersion = 0x00000001; public const int MetaVersion = 0x00000001;
public string FilePath { get; private set; } public string FilePath { get; private set; }
public DateTime EndTimestampUtc { get; private set; } public DateTime EndTimestampUtc { get; private set; }
public TimeSpan Duration { get { return EndTimestampUtc.Subtract(StartTimestampUtc); } } public TimeSpan Duration { get { return EndTimestampUtc - StartTimestampUtc; } }
public WinState Outcome { get; private set; } public WinState Outcome { get; private set; }
public readonly Lazy<Session> Session; public readonly Lazy<Session> LobbyInfo;
public readonly DateTime StartTimestampUtc; public readonly DateTime StartTimestampUtc;
readonly string sessionData; readonly string lobbyInfoData;
ReplayMetadata() ReplayMetadata()
{ {
Outcome = WinState.Undefined; Outcome = WinState.Undefined;
} }
public ReplayMetadata(DateTime startGameTimestampUtc, Session session) public ReplayMetadata(DateTime startGameTimestampUtc, Session lobbyInfo)
: this() : this()
{ {
if (startGameTimestampUtc.Kind == DateTimeKind.Unspecified) if (startGameTimestampUtc.Kind == DateTimeKind.Unspecified)
throw new ArgumentException("The 'Kind' property of the timestamp must be specified", "startGameTimestamp"); throw new ArgumentException("The 'Kind' property of the timestamp must be specified", "startGameTimestamp");
StartTimestampUtc = startGameTimestampUtc.ToUniversalTime(); StartTimestampUtc = startGameTimestampUtc.ToUniversalTime();
sessionData = session.Serialize(); lobbyInfoData = lobbyInfo.Serialize();
Session = new Lazy<OpenRA.Network.Session>(() => OpenRA.Network.Session.Deserialize(this.sessionData)); LobbyInfo = Exts.Lazy(() => Session.Deserialize(this.lobbyInfoData));
} }
public void FinalizeReplayMetadata(DateTime endGameTimestampUtc, WinState outcome) public void FinalizeReplayMetadata(DateTime endGameTimestampUtc, WinState outcome)
@@ -80,9 +80,9 @@ namespace OpenRA.FileFormats
if (Enum.TryParse(ReadUtf8String(reader), true, out outcome)) if (Enum.TryParse(ReadUtf8String(reader), true, out outcome))
Outcome = outcome; Outcome = outcome;
// Read session // Read lobby info
sessionData = ReadUtf8String(reader); lobbyInfoData = ReadUtf8String(reader);
Session = new Lazy<OpenRA.Network.Session>(() => OpenRA.Network.Session.Deserialize(this.sessionData)); LobbyInfo = Exts.Lazy(() => Session.Deserialize(this.lobbyInfoData));
} }
public void Write(BinaryWriter writer) public void Write(BinaryWriter writer)
@@ -105,8 +105,8 @@ namespace OpenRA.FileFormats
// Write game outcome // Write game outcome
dataLength += WriteUtf8String(writer, Outcome.ToString()); dataLength += WriteUtf8String(writer, Outcome.ToString());
// Write session data // Write lobby info data
dataLength += WriteUtf8String(writer, sessionData); dataLength += WriteUtf8String(writer, lobbyInfoData);
} }
// Write total length & end marker // Write total length & end marker
@@ -116,7 +116,8 @@ namespace OpenRA.FileFormats
public static ReplayMetadata Read(string path, bool enableFallbackMethod = true) public static ReplayMetadata Read(string path, bool enableFallbackMethod = true)
{ {
Func<DateTime> timestampProvider = () => { Func<DateTime> timestampProvider = () =>
{
try try
{ {
return File.GetCreationTimeUtc(path); return File.GetCreationTimeUtc(path);
@@ -159,11 +160,13 @@ namespace OpenRA.FileFormats
{ {
return new ReplayMetadata(reader); return new ReplayMetadata(reader);
} }
catch (InvalidOperationException) catch (InvalidOperationException ex)
{ {
Log.Write("debug", ex.ToString());
} }
catch (NotSupportedException) catch (NotSupportedException ex)
{ {
Log.Write("debug", ex.ToString());
} }
} }
@@ -210,7 +213,7 @@ namespace OpenRA.FileFormats
public MapPreview MapPreview public MapPreview MapPreview
{ {
get { return Game.modData.MapCache[Session.Value.GlobalSettings.Map]; } get { return Game.modData.MapCache[LobbyInfo.Value.GlobalSettings.Map]; }
} }
} }
} }

View File

@@ -36,9 +36,7 @@ namespace OpenRA.Network
public ReplayConnection(string replayFilename) public ReplayConnection(string replayFilename)
{ {
using (var rs = File.OpenRead(replayFilename)) using (var rs = File.OpenRead(replayFilename))
{
Read(rs, ref TickCount, ref IsValid, ref LobbyInfo); Read(rs, ref TickCount, ref IsValid, ref LobbyInfo);
}
ordersFrame = LobbyInfo.GlobalSettings.OrderLatency; ordersFrame = LobbyInfo.GlobalSettings.OrderLatency;
} }

View File

@@ -245,7 +245,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_PLAYER_DROPDOWNBUTTON"); var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_PLAYER_DROPDOWNBUTTON");
if (ddb != null) if (ddb != null)
{ {
var options = new HashSet<string>(replays.SelectMany(r => r.Session.Value.Clients.Select(c => c.Name)), StringComparer.OrdinalIgnoreCase).ToList(); var options = new HashSet<string>(replays.SelectMany(r => r.LobbyInfo.Value.Clients.Select(c => c.Name)), StringComparer.OrdinalIgnoreCase).ToList();
options.Sort(StringComparer.OrdinalIgnoreCase); options.Sort(StringComparer.OrdinalIgnoreCase);
options.Insert(0, null); // no filter options.Insert(0, null); // no filter
@@ -273,7 +273,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
bool EvaluateReplayVisibility(ReplayMetadata replay) bool EvaluateReplayVisibility(ReplayMetadata replay)
{ {
// Game type // Game type
if ((filter.Type == GameType.Multiplayer && replay.Session.Value.IsSinglePlayer) || (filter.Type == GameType.Singleplayer && !replay.Session.Value.IsSinglePlayer)) if ((filter.Type == GameType.Multiplayer && replay.LobbyInfo.Value.IsSinglePlayer) || (filter.Type == GameType.Singleplayer && !replay.LobbyInfo.Value.IsSinglePlayer))
return false; return false;
// Date type // Date type
@@ -334,7 +334,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
// Player // Player
if (!string.IsNullOrEmpty(filter.PlayerName)) if (!string.IsNullOrEmpty(filter.PlayerName))
{ {
var player = replay.Session.Value.Clients.Find(c => string.Compare(filter.PlayerName, c.Name, true) == 0); var player = replay.LobbyInfo.Value.Clients.Find(c => string.Compare(filter.PlayerName, c.Name, true) == 0);
if (player == null) if (player == null)
return false; return false;
} }
@@ -361,14 +361,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void SelectReplay(ReplayMetadata replay) void SelectReplay(ReplayMetadata replay)
{ {
selectedReplay = replay; selectedReplay = replay;
selectedSpawns = (selectedReplay != null) ? LobbyUtils.GetSpawnClients(selectedReplay.Session.Value, selectedReplay.MapPreview) : null; selectedSpawns = (selectedReplay != null) ? LobbyUtils.GetSpawnClients(selectedReplay.LobbyInfo.Value, selectedReplay.MapPreview) : null;
if (replay == null) if (replay == null)
return; return;
try try
{ {
var lobby = replay.Session.Value; var lobby = replay.LobbyInfo.Value;
var clients = lobby.Clients.Where(c => c.Slot != null) var clients = lobby.Clients.Where(c => c.Slot != null)
.GroupBy(c => c.Team) .GroupBy(c => c.Team)