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

View File

@@ -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);