From 9d3b93f71749652a470af7eb1bbc9593587ca7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Thu, 19 Sep 2013 20:49:07 +0200 Subject: [PATCH] save replays in per mod and version folders StyleCop cleanups --- .../Network/ReplayRecorderConnection.cs | 33 +++++++++---------- .../Widgets/Logic/ReplayBrowserLogic.cs | 9 ++--- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/OpenRA.Game/Network/ReplayRecorderConnection.cs b/OpenRA.Game/Network/ReplayRecorderConnection.cs index 00558fc982..748e473e5b 100644 --- a/OpenRA.Game/Network/ReplayRecorderConnection.cs +++ b/OpenRA.Game/Network/ReplayRecorderConnection.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using OpenRA.Widgets; namespace OpenRA.Network { @@ -23,7 +24,7 @@ namespace OpenRA.Network Func chooseFilename; MemoryStream preStartBuffer = new MemoryStream(); - public ReplayRecorderConnection( IConnection inner, Func chooseFilename ) + public ReplayRecorderConnection(IConnection inner, Func chooseFilename) { this.chooseFilename = chooseFilename; this.inner = inner; @@ -34,18 +35,16 @@ namespace OpenRA.Network void StartSavingReplay(byte[] initialContent) { var filename = chooseFilename(); - var replaysDirectory = Path.Combine(Platform.SupportDir, "Replays"); + var dir = new[] { Platform.SupportDir, "Replays", WidgetUtils.ActiveModId(), WidgetUtils.ActiveModVersion() }.Aggregate(Path.Combine); - if (!Directory.Exists(replaysDirectory)) - Directory.CreateDirectory(replaysDirectory); + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); FileStream file = null; var id = -1; while (file == null) { - var fullFilename = Path.Combine(replaysDirectory, id < 0 - ? "{0}.rep".F(filename) - : "{0}-{1}.rep".F(filename, id)); + var fullFilename = Path.Combine(dir, id < 0 ? "{0}.rep".F(filename) : "{0}-{1}.rep".F(filename, id)); id++; try { @@ -61,11 +60,11 @@ namespace OpenRA.Network public int LocalClientId { get { return inner.LocalClientId; } } public ConnectionState ConnectionState { get { return inner.ConnectionState; } } - public void Send( int frame, List orders ) { inner.Send( frame, orders ); } - public void SendImmediate( List orders ) { inner.SendImmediate( orders ); } - public void SendSync( int frame, byte[] syncData ) { inner.SendSync( frame, syncData ); } + public void Send(int frame, List orders) { inner.Send(frame, orders); } + public void SendImmediate(List orders) { inner.SendImmediate(orders); } + public void SendSync(int frame, byte[] syncData) { inner.SendSync(frame, syncData); } - public void Receive( Action packetFn ) + public void Receive(Action packetFn) { inner.Receive((client, data) => { @@ -81,7 +80,7 @@ namespace OpenRA.Network writer.Write(data.Length); writer.Write(data); packetFn(client, data); - } ); + }); } bool IsGameStart(byte[] data) @@ -92,15 +91,14 @@ namespace OpenRA.Network return false; var frame = BitConverter.ToInt32(data, 0); - return frame == 0 && data.ToOrderList(null).Any( - o => o.OrderString == "StartGame"); + return frame == 0 && data.ToOrderList(null).Any(o => o.OrderString == "StartGame"); } bool disposed; public void Dispose() { - if( disposed ) + if (disposed) return; writer.Close(); @@ -113,5 +111,4 @@ namespace OpenRA.Network Dispose(); } } -} - +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs index ae9a5e992d..9c43b610f3 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ReplayBrowserLogic.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -28,14 +28,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic panel.Get("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; var rl = panel.Get("REPLAY_LIST"); - var replayDir = Path.Combine(Platform.SupportDir, "Replays"); + + var dir = new[] { Platform.SupportDir, "Replays", WidgetUtils.ActiveModId(), WidgetUtils.ActiveModVersion() }.Aggregate(Path.Combine); var template = panel.Get("REPLAY_TEMPLATE"); rl.RemoveChildren(); - if (Directory.Exists(replayDir)) + if (Directory.Exists(dir)) { - var files = Directory.GetFiles(replayDir, "*.rep").Reverse(); + var files = Directory.GetFiles(dir, "*.rep").Reverse(); foreach (var replayFile in files) AddReplay(rl, replayFile, template);