Merge pull request #3858 from Mailaender/replay-folders
Save Replays in per Mod and Version folders
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#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
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace OpenRA.Network
|
|||||||
Func<string> chooseFilename;
|
Func<string> chooseFilename;
|
||||||
MemoryStream preStartBuffer = new MemoryStream();
|
MemoryStream preStartBuffer = new MemoryStream();
|
||||||
|
|
||||||
public ReplayRecorderConnection( IConnection inner, Func<string> chooseFilename )
|
public ReplayRecorderConnection(IConnection inner, Func<string> chooseFilename)
|
||||||
{
|
{
|
||||||
this.chooseFilename = chooseFilename;
|
this.chooseFilename = chooseFilename;
|
||||||
this.inner = inner;
|
this.inner = inner;
|
||||||
@@ -34,18 +35,16 @@ namespace OpenRA.Network
|
|||||||
void StartSavingReplay(byte[] initialContent)
|
void StartSavingReplay(byte[] initialContent)
|
||||||
{
|
{
|
||||||
var filename = chooseFilename();
|
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))
|
if (!Directory.Exists(dir))
|
||||||
Directory.CreateDirectory(replaysDirectory);
|
Directory.CreateDirectory(dir);
|
||||||
|
|
||||||
FileStream file = null;
|
FileStream file = null;
|
||||||
var id = -1;
|
var id = -1;
|
||||||
while (file == null)
|
while (file == null)
|
||||||
{
|
{
|
||||||
var fullFilename = Path.Combine(replaysDirectory, id < 0
|
var fullFilename = Path.Combine(dir, id < 0 ? "{0}.rep".F(filename) : "{0}-{1}.rep".F(filename, id));
|
||||||
? "{0}.rep".F(filename)
|
|
||||||
: "{0}-{1}.rep".F(filename, id));
|
|
||||||
id++;
|
id++;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -61,11 +60,11 @@ namespace OpenRA.Network
|
|||||||
public int LocalClientId { get { return inner.LocalClientId; } }
|
public int LocalClientId { get { return inner.LocalClientId; } }
|
||||||
public ConnectionState ConnectionState { get { return inner.ConnectionState; } }
|
public ConnectionState ConnectionState { get { return inner.ConnectionState; } }
|
||||||
|
|
||||||
public void Send( int frame, List<byte[]> orders ) { inner.Send( frame, orders ); }
|
public void Send(int frame, List<byte[]> orders) { inner.Send(frame, orders); }
|
||||||
public void SendImmediate( List<byte[]> orders ) { inner.SendImmediate( orders ); }
|
public void SendImmediate(List<byte[]> orders) { inner.SendImmediate(orders); }
|
||||||
public void SendSync( int frame, byte[] syncData ) { inner.SendSync( frame, syncData ); }
|
public void SendSync(int frame, byte[] syncData) { inner.SendSync(frame, syncData); }
|
||||||
|
|
||||||
public void Receive( Action<int, byte[]> packetFn )
|
public void Receive(Action<int, byte[]> packetFn)
|
||||||
{
|
{
|
||||||
inner.Receive((client, data) =>
|
inner.Receive((client, data) =>
|
||||||
{
|
{
|
||||||
@@ -81,7 +80,7 @@ namespace OpenRA.Network
|
|||||||
writer.Write(data.Length);
|
writer.Write(data.Length);
|
||||||
writer.Write(data);
|
writer.Write(data);
|
||||||
packetFn(client, data);
|
packetFn(client, data);
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsGameStart(byte[] data)
|
bool IsGameStart(byte[] data)
|
||||||
@@ -92,15 +91,14 @@ namespace OpenRA.Network
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
var frame = BitConverter.ToInt32(data, 0);
|
var frame = BitConverter.ToInt32(data, 0);
|
||||||
return frame == 0 && data.ToOrderList(null).Any(
|
return frame == 0 && data.ToOrderList(null).Any(o => o.OrderString == "StartGame");
|
||||||
o => o.OrderString == "StartGame");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if( disposed )
|
if (disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
writer.Close();
|
writer.Close();
|
||||||
@@ -114,4 +112,3 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#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
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -28,14 +28,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
|
panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
|
||||||
|
|
||||||
var rl = panel.Get<ScrollPanelWidget>("REPLAY_LIST");
|
var rl = panel.Get<ScrollPanelWidget>("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<ScrollItemWidget>("REPLAY_TEMPLATE");
|
var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE");
|
||||||
|
|
||||||
rl.RemoveChildren();
|
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)
|
foreach (var replayFile in files)
|
||||||
AddReplay(rl, replayFile, template);
|
AddReplay(rl, replayFile, template);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user