Don't crash (due to replay file being in use) if we have two instances of the game playing

This commit is contained in:
Scott_NZ
2013-02-25 21:12:14 +13:00
parent e57de0ebce
commit b5bd6191c2
2 changed files with 16 additions and 5 deletions

View File

@@ -58,7 +58,7 @@ namespace OpenRA
static string ChooseReplayFilename()
{
return DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddTHHmmssZ.rep");
return DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddTHHmmssZ");
}
static void JoinInner(OrderManager om)

View File

@@ -34,12 +34,23 @@ namespace OpenRA.Network
void StartSavingReplay(byte[] initialContent)
{
var filename = chooseFilename();
var replayPath = Path.Combine(Platform.SupportDir, "Replays");
var replaysDirectory = Path.Combine(Platform.SupportDir, "Replays");
if (!Directory.Exists(replayPath))
Directory.CreateDirectory(replayPath);
if (!Directory.Exists(replaysDirectory))
Directory.CreateDirectory(replaysDirectory);
var file = File.Create(Path.Combine(replayPath, filename));
string fullFilename;
var id = -1;
do
{
fullFilename = Path.Combine(replaysDirectory, id < 0
? "{0}.rep".F(filename)
: "{0}-{1}.rep".F(filename, id));
id++;
}
while (File.Exists(fullFilename));
var file = File.Create(fullFilename);
file.Write(initialContent);
this.writer = new BinaryWriter(file);
}