Fix single-line SMDB corner case

This commit is contained in:
Matt Nadareski
2020-07-28 16:17:54 -07:00
parent e12d01cdb6
commit 1f25dc4bac

View File

@@ -100,17 +100,32 @@ namespace SabreTools.Library.Tools
// For everything else, we need to read it // For everything else, we need to read it
try try
{ {
// Get the first two non-whitespace, non-comment lines to check // Get the first two non-whitespace, non-comment lines to check, if possible
StreamReader sr = File.OpenText(filename); string first = string.Empty, second = string.Empty;
string first = sr.ReadLine().ToLowerInvariant();
while (string.IsNullOrWhiteSpace(first) || first.StartsWith("<!--"))
first = sr.ReadLine().ToLowerInvariant();
string second = sr.ReadLine().ToLowerInvariant(); try
while (string.IsNullOrWhiteSpace(second) || second.StartsWith("<!--")) {
second = sr.ReadLine().ToLowerInvariant(); using (StreamReader sr = File.OpenText(filename))
{
first = sr.ReadLine().ToLowerInvariant();
while ((string.IsNullOrWhiteSpace(first) || first.StartsWith("<!--"))
&& !sr.EndOfStream)
{
first = sr.ReadLine().ToLowerInvariant();
}
sr.Dispose(); if (!sr.EndOfStream)
{
second = sr.ReadLine().ToLowerInvariant();
while (string.IsNullOrWhiteSpace(second) || second.StartsWith("<!--")
&& !sr.EndOfStream)
{
second = sr.ReadLine().ToLowerInvariant();
}
}
}
}
catch { }
// If we have an XML-based DAT // If we have an XML-based DAT
if (first.Contains("<?xml") && first.Contains("?>")) if (first.Contains("<?xml") && first.Contains("?>"))