Merge pull request #3858 from Mailaender/replay-folders

Save Replays in per Mod and Version folders
This commit is contained in:
Paul Chote
2013-09-21 21:50:30 -07:00
2 changed files with 20 additions and 22 deletions

View File

@@ -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
{
@@ -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
{
@@ -92,8 +91,7 @@ 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;
@@ -114,4 +112,3 @@ namespace OpenRA.Network
}
}
}

View File

@@ -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<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
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");
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);