Merge pull request #3161 from ScottNZ/replay

More robust replay file creation
This commit is contained in:
Matthias Mailänder
2013-04-25 00:44:46 -07:00

View File

@@ -39,18 +39,21 @@ namespace OpenRA.Network
if (!Directory.Exists(replaysDirectory))
Directory.CreateDirectory(replaysDirectory);
string fullFilename;
FileStream file = null;
var id = -1;
do
while (file == null)
{
fullFilename = Path.Combine(replaysDirectory, id < 0
var fullFilename = Path.Combine(replaysDirectory, id < 0
? "{0}.rep".F(filename)
: "{0}-{1}.rep".F(filename, id));
id++;
try
{
file = File.Create(fullFilename);
}
catch (IOException) { }
}
while (File.Exists(fullFilename));
var file = File.Create(fullFilename);
file.Write(initialContent);
this.writer = new BinaryWriter(file);
}