Switch method logic

Only comparing 3 of the chars at most to a list of valid 3char
extensions.
This commit is contained in:
Kurt
2015-07-11 23:32:02 -07:00
parent c843d0ede0
commit 2e550b1895

View File

@@ -169,16 +169,12 @@ internal static bool Guess3CHAR(BinaryReader br, out string ext)
ext = ""; // Reset extension
try
{
byte[] magic = Encoding.ASCII.GetBytes(br.ReadChars(4));
if (magic[0] < 0x41)
return false;
for (int i = 0; i < magic.Length && i < 3; i++)
{
if ((magic[i] >= 'a' && magic[i] <= 'z') || (magic[i] >= 'A' && magic[i] <= 'Z') || char.IsDigit((char)magic[i]))
ext += (char)magic[i];
else
return false;
}
byte[] magic = Encoding.ASCII.GetBytes(br.ReadChars(3));
ext = Encoding.ASCII.GetString(magic);
// Return BaseStream position to the start.
br.BaseStream.Position = position;
return validEXT.Contains(ext);
}
catch { }