Ignore invalid replay files instead of crashing.
This commit is contained in:
@@ -78,12 +78,10 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ReplayMetadata Read(string path)
|
public static ReplayMetadata Read(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using (var fs = new FileStream(path, FileMode.Open))
|
using (var fs = new FileStream(path, FileMode.Open))
|
||||||
return Read(fs, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ReplayMetadata Read(FileStream fs, string path)
|
|
||||||
{
|
{
|
||||||
if (!fs.CanSeek)
|
if (!fs.CanSeek)
|
||||||
return null;
|
return null;
|
||||||
@@ -91,33 +89,17 @@ namespace OpenRA.FileFormats
|
|||||||
if (fs.Length < 20)
|
if (fs.Length < 20)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fs.Seek(-(4 + 4), SeekOrigin.End);
|
fs.Seek(-(4 + 4), SeekOrigin.End);
|
||||||
var dataLength = fs.ReadInt32();
|
var dataLength = fs.ReadInt32();
|
||||||
if (fs.ReadInt32() == MetaEndMarker)
|
if (fs.ReadInt32() == MetaEndMarker)
|
||||||
{
|
{
|
||||||
// go back by (end marker + length storage + data + version + start marker) bytes
|
// Go back by (end marker + length storage + data + version + start marker) bytes
|
||||||
fs.Seek(-(4 + 4 + dataLength + 4 + 4), SeekOrigin.Current);
|
fs.Seek(-(4 + 4 + dataLength + 4 + 4), SeekOrigin.Current);
|
||||||
try
|
|
||||||
{
|
|
||||||
return new ReplayMetadata(fs, path);
|
return new ReplayMetadata(fs, path);
|
||||||
}
|
}
|
||||||
catch (YamlException ex)
|
|
||||||
{
|
|
||||||
Log.Write("debug", ex.ToString());
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
Log.Write("debug", ex.ToString());
|
|
||||||
}
|
|
||||||
catch (NotSupportedException ex)
|
|
||||||
{
|
|
||||||
Log.Write("debug", ex.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (IOException ex)
|
|
||||||
{
|
{
|
||||||
Log.Write("debug", ex.ToString());
|
Log.Write("debug", ex.ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user