use HasExtension method instead of string.EndsWith.

This commit is contained in:
morkt 2017-04-10 23:15:13 +04:00
parent e0a5e95081
commit 31a01f2e5d
72 changed files with 105 additions and 114 deletions

View File

@ -109,7 +109,7 @@ namespace GameRes.Formats.AZSys
if (entry.CheckPlacement (file.MaxOffset)) if (entry.CheckPlacement (file.MaxOffset))
{ {
dir.Add (entry); dir.Add (entry);
contains_scripts = contains_scripts || name.EndsWith (".asb", StringComparison.InvariantCultureIgnoreCase); contains_scripts = contains_scripts || name.HasExtension (".asb");
} }
} }
index_offset += 0x40; index_offset += 0x40;

View File

@ -72,7 +72,7 @@ namespace GameRes.Formats.Abel
return null; return null;
var name = Binary.GetCString (name_buffer, 0, name_buffer.Length); var name = Binary.GetCString (name_buffer, 0, name_buffer.Length);
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<Entry> (name);
if (name.EndsWith (".acd", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".acd"))
entry.Type = "script"; entry.Type = "script";
entry.Offset = index.ReadUInt32() + base_offset; entry.Offset = index.ReadUInt32() + base_offset;
entry.Size = index.ReadUInt32(); entry.Size = index.ReadUInt32();
@ -86,10 +86,10 @@ namespace GameRes.Formats.Abel
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (entry.Size > 12 && entry.Name.EndsWith (".cmp", StringComparison.InvariantCultureIgnoreCase) if (entry.Size > 12 && entry.Name.HasExtension (".cmp")
&& arc.File.View.AsciiEqual (entry.Offset, "CMP\0")) && arc.File.View.AsciiEqual (entry.Offset, "CMP\0"))
return OpenCmpEntry (arc, entry); return OpenCmpEntry (arc, entry);
if (entry.Size > 8 && entry.Name.EndsWith (".acd", StringComparison.InvariantCultureIgnoreCase) if (entry.Size > 8 && entry.Name.HasExtension (".acd")
&& arc.File.View.AsciiEqual (entry.Offset, "ACD\0")) && arc.File.View.AsciiEqual (entry.Offset, "ACD\0"))
return OpenAcdEntry (arc, entry); return OpenAcdEntry (arc, entry);
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);

View File

@ -115,7 +115,7 @@ namespace GameRes.Formats.Actgs
var actarc = arc as ActressArchive; var actarc = arc as ActressArchive;
if (null == actarc || null == actarc.Key) if (null == actarc || null == actarc.Key)
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
if (entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".scr"))
{ {
if ('X' != arc.File.View.ReadByte (entry.Offset)) if ('X' != arc.File.View.ReadByte (entry.Offset))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);

View File

@ -47,7 +47,7 @@ namespace GameRes.Formats.AdvSys
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase) if (!file.Name.HasExtension (".dat")
|| !Path.GetFileName (file.Name).StartsWith ("arc", StringComparison.InvariantCultureIgnoreCase)) || !Path.GetFileName (file.Name).StartsWith ("arc", StringComparison.InvariantCultureIgnoreCase))
return null; return null;
long current_offset = 0; long current_offset = 0;

View File

@ -237,7 +237,7 @@ namespace GameRes.Formats.Amaterasu
int update_count = 0; int update_count = 0;
foreach (var entry in list) foreach (var entry in list)
{ {
if (entry.Type != "image" && !entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) if (entry.Type != "image" && !entry.Name.HasExtension (".scr"))
continue; continue;
uint id; uint id;
if (!uint.TryParse (Path.GetFileNameWithoutExtension (entry.Name), NumberStyles.HexNumber, if (!uint.TryParse (Path.GetFileNameWithoutExtension (entry.Name), NumberStyles.HexNumber,

View File

@ -49,7 +49,7 @@ namespace GameRes.Formats.Ags
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".ani", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".ani"))
return null; return null;
uint first_offset = file.View.ReadUInt32 (0); uint first_offset = file.View.ReadUInt32 (0);
if (first_offset < 4 || file.MaxOffset > int.MaxValue || first_offset >= file.MaxOffset || 0 != (first_offset & 3)) if (first_offset < 4 || file.MaxOffset > int.MaxValue || first_offset >= file.MaxOffset || 0 != (first_offset & 3))

View File

@ -148,8 +148,7 @@ namespace GameRes.Formats.Neko
{ {
foreach (var entry in dir.Where (e => string.IsNullOrEmpty (e.Type))) foreach (var entry in dir.Where (e => string.IsNullOrEmpty (e.Type)))
{ {
if (entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase) || if (entry.Name.HasAnyOfExtensions ("txt", "nut"))
entry.Name.EndsWith (".nut", StringComparison.InvariantCultureIgnoreCase))
{ {
entry.Type = "script"; entry.Type = "script";
continue; continue;

View File

@ -84,7 +84,7 @@ namespace GameRes.Formats.SPack
}; };
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".dat"))
entry.Type = "audio"; entry.Type = "audio";
else else
entry.Type = FormatCatalog.Instance.GetTypeFromName (name); entry.Type = FormatCatalog.Instance.GetTypeFromName (name);

View File

@ -78,7 +78,7 @@ namespace GameRes.Formats.Banana // namespace is arbitrary, actual format source
index_offset += 8; index_offset += 8;
if (entry.Offset < index_offset || !entry.CheckPlacement (file.MaxOffset)) if (entry.Offset < index_offset || !entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".scr"))
entry.IsPacked = true; entry.IsPacked = true;
dir.Add (entry); dir.Add (entry);
} }

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.BlackCyc
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".gpk", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".gpk"))
return null; return null;
var gtb_name = Path.ChangeExtension (file.Name, "gtb"); var gtb_name = Path.ChangeExtension (file.Name, "gtb");
if (!VFS.FileExists (gtb_name)) if (!VFS.FileExists (gtb_name))

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.BlackCyc
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".vpk", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".vpk"))
return null; return null;
var vtb_name = Path.ChangeExtension (file.Name, "vtb"); var vtb_name = Path.ChangeExtension (file.Name, "vtb");
if (!VFS.FileExists (vtb_name)) if (!VFS.FileExists (vtb_name))

View File

@ -63,7 +63,7 @@ namespace GameRes.Formats.BlackRainbow
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".ads", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".ads"))
return null; return null;
var arc_name = Path.GetFileNameWithoutExtension (file.Name); var arc_name = Path.GetFileNameWithoutExtension (file.Name);
foreach (var key in KnownKeys.Values) foreach (var key in KnownKeys.Values)

View File

@ -60,7 +60,7 @@ namespace GameRes.Formats.BlackRainbow
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".hse", StringComparison.InvariantCultureIgnoreCase)) if (!entry.Name.HasExtension (".hse"))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
for (int i = 0; i < data.Length; ++i) for (int i = 0; i < data.Length; ++i)
@ -114,7 +114,7 @@ namespace GameRes.Formats.BlackRainbow
entry.Size = m_index.ReadUInt32(); entry.Size = m_index.ReadUInt32();
if (!entry.CheckPlacement (m_max_offset)) if (!entry.CheckPlacement (m_max_offset))
return false; return false;
if (name.EndsWith (".hse", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".hse"))
entry.Type = "image"; entry.Type = "image";
m_dir.Add (entry); m_dir.Add (entry);
} }

View File

@ -41,7 +41,7 @@ namespace GameRes.Formats.BlueGale
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".snn", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".snn"))
return null; return null;
var inx_name = Path.ChangeExtension (file.Name, "Inx"); var inx_name = Path.ChangeExtension (file.Name, "Inx");
if (!VFS.FileExists (inx_name)) if (!VFS.FileExists (inx_name))

View File

@ -68,7 +68,7 @@ namespace GameRes.Formats.Cadath
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".snr", System.StringComparison.InvariantCultureIgnoreCase) if (!entry.Name.HasExtension (".snr")
|| !arc.File.View.AsciiEqual (entry.Offset, "SNR\x1A")) || !arc.File.View.AsciiEqual (entry.Offset, "SNR\x1A"))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
try try

View File

@ -69,7 +69,7 @@ namespace GameRes.Formats.Cadath
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (!entry.Name.EndsWith (".ns6", StringComparison.InvariantCultureIgnoreCase)) if (!entry.Name.HasExtension (".ns6"))
return input; return input;
byte key = (byte)(entry.Size / 7); byte key = (byte)(entry.Size / 7);
return new XoredStream (input, key); return new XoredStream (input, key);

View File

@ -91,7 +91,7 @@ namespace GameRes.Formats.Circus
entry.Size = LittleEndian.ToUInt32 (index, index_pos+8); entry.Size = LittleEndian.ToUInt32 (index, index_pos+8);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".cps", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".cps"))
entry.Type = "image"; entry.Type = "image";
dir.Add (entry); dir.Add (entry);
index_pos += 0x10; index_pos += 0x10;
@ -108,12 +108,12 @@ namespace GameRes.Formats.Circus
var data = vcarc.File.View.ReadBytes (entry.Offset, entry.Size); var data = vcarc.File.View.ReadBytes (entry.Offset, entry.Size);
for (int i = 0; i < data.Length; ++i) for (int i = 0; i < data.Length; ++i)
data[i] ^= vcarc.Key; data[i] ^= vcarc.Key;
if (entry.Name.EndsWith (".cs", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".cs"))
{ {
for (int i = 0; i < data.Length; ++i) for (int i = 0; i < data.Length; ++i)
--data[i]; --data[i];
} }
else if (entry.Name.EndsWith (".cps", StringComparison.InvariantCultureIgnoreCase)) else if (entry.Name.HasExtension (".cps"))
{ {
data = UnpackCps (data); data = UnpackCps (data);
} }

View File

@ -117,7 +117,7 @@ namespace GameRes.Formats.Pvns
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
Decrypt (data, parc.ArcKey); Decrypt (data, parc.ArcKey);
if (entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) if (entry.Name.HasExtension (".scr")
&& Binary.AsciiEqual (data, "PSRA") && data.Length > 20) && Binary.AsciiEqual (data, "PSRA") && data.Length > 20)
{ {
data = DecryptScript (data, parc.ScriptKey); data = DecryptScript (data, parc.ScriptKey);

View File

@ -47,7 +47,7 @@ namespace GameRes.Formats.Cri
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".spc", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".spc"))
return null; return null;
uint unpacked_size = file.View.ReadUInt32 (0); uint unpacked_size = file.View.ReadUInt32 (0);
if (unpacked_size <= 0x20 || unpacked_size > 0x5000000) if (unpacked_size <= 0x20 || unpacked_size > 0x5000000)

View File

@ -54,9 +54,10 @@ namespace GameRes.Formats.Eagls
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (file.Name.HasExtension (".idx"))
return null;
string idx_name = Path.ChangeExtension (file.Name, ".idx"); string idx_name = Path.ChangeExtension (file.Name, ".idx");
if (file.Name.Equals (idx_name, StringComparison.InvariantCultureIgnoreCase) if (!VFS.FileExists (idx_name))
|| !VFS.FileExists (idx_name))
return null; return null;
var idx_entry = VFS.FindFile (idx_name); var idx_entry = VFS.FindFile (idx_name);
if (idx_entry.Size > 0xfffff || idx_entry.Size < 10000) if (idx_entry.Size > 0xfffff || idx_entry.Size < 10000)
@ -81,7 +82,7 @@ namespace GameRes.Formats.Eagls
var name = Binary.GetCString (index, index_offset, name_size); var name = Binary.GetCString (index, index_offset, name_size);
index_offset += name_size; index_offset += name_size;
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<Entry> (name);
if (name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension ("dat"))
{ {
entry.Type = "script"; entry.Type = "script";
has_scripts = true; has_scripts = true;
@ -104,7 +105,7 @@ namespace GameRes.Formats.Eagls
} }
if (0 == dir.Count) if (0 == dir.Count)
return null; return null;
if (dir[0].Name.EndsWith (".gr", StringComparison.InvariantCultureIgnoreCase)) // CG archive if (dir[0].Name.HasExtension ("gr")) // CG archive
{ {
var rng = DetectEncryptionScheme (file, dir[0]); var rng = DetectEncryptionScheme (file, dir[0]);
return new EaglsArchive (file, this, dir, new CgEncryption (rng)); return new EaglsArchive (file, this, dir, new CgEncryption (rng));
@ -121,9 +122,7 @@ namespace GameRes.Formats.Eagls
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
var earc = arc as EaglsArchive; var earc = arc as EaglsArchive;
if (null == earc if (null == earc || !entry.Name.HasAnyOfExtensions ("dat", "gr"))
|| !(entry.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase) ||
entry.Name.EndsWith (".gr", StringComparison.InvariantCultureIgnoreCase)))
return arc.File.CreateStream (entry.Offset, entry.Size); return arc.File.CreateStream (entry.Offset, entry.Size);
return earc.DecryptEntry (entry); return earc.DecryptEntry (entry);

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Entis
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".pac", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".pac"))
return null; return null;
uint index_offset = 0; uint index_offset = 0;
var name_buf = new byte[0x18]; var name_buf = new byte[0x18];

View File

@ -79,8 +79,7 @@ namespace GameRes.Formats.Ffa
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (entry.Size <= 8) if (entry.Size <= 8)
return input; return input;
if (!entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase) && if (!entry.Name.HasAnyOfExtensions ("so4", "so5"))
!entry.Name.EndsWith (".so5", StringComparison.InvariantCultureIgnoreCase))
return input; return input;
int packed = input.ReadInt32(); int packed = input.ReadInt32();
int unpacked = input.ReadInt32(); int unpacked = input.ReadInt32();

View File

@ -76,7 +76,7 @@ namespace GameRes.Formats.Fs
entry.Size = file.View.ReadUInt32 (cur_offset+0x88); entry.Size = file.View.ReadUInt32 (cur_offset+0x88);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".dsf", System.StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".dsf"))
entry.Type = "script"; entry.Type = "script";
dir.Add (entry); dir.Add (entry);
cur_offset += 0x90; cur_offset += 0x90;
@ -305,8 +305,7 @@ namespace GameRes.Formats.Fs
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".def", StringComparison.InvariantCultureIgnoreCase) && if (!entry.Name.HasAnyOfExtensions (".def", ".dsf"))
!entry.Name.EndsWith (".dsf", StringComparison.InvariantCultureIgnoreCase))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
for (int i = 0; i < data.Length; ++i) for (int i = 0; i < data.Length; ++i)

View File

@ -44,7 +44,7 @@ namespace GameRes.Formats.GameSystem
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".CHR", StringComparison.InvariantCultureIgnoreCase) if (!file.Name.HasExtension (".CHR")
|| file.View.ReadUInt32 (0) != file.MaxOffset) || file.View.ReadUInt32 (0) != file.MaxOffset)
return null; return null;
using (var input = file.CreateStream()) using (var input = file.CreateStream())

View File

@ -72,10 +72,7 @@ namespace GameRes.Formats.GameSystem
entry.UnpackedSize = index.ReadUInt32(); entry.UnpackedSize = index.ReadUInt32();
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (entry.Name.EndsWith (".CRGB", StringComparison.InvariantCultureIgnoreCase) || if (entry.Name.HasAnyOfExtensions ("CRGB", "CHAR", "rol", "edg"))
entry.Name.EndsWith (".CHAR", StringComparison.InvariantCultureIgnoreCase) ||
entry.Name.EndsWith (".rol", StringComparison.InvariantCultureIgnoreCase) ||
entry.Name.EndsWith (".edg", StringComparison.InvariantCultureIgnoreCase))
entry.Type = "image"; entry.Type = "image";
entry.IsPacked = (flags & 0xFF0000) != 0; entry.IsPacked = (flags & 0xFF0000) != 0;
entry.StoredSize = (flags & 0x2000000) != 0; entry.StoredSize = (flags & 0x2000000) != 0;
@ -146,20 +143,19 @@ namespace GameRes.Formats.GameSystem
public override IImageDecoder OpenImage (ArcFile arc, Entry entry) public override IImageDecoder OpenImage (ArcFile arc, Entry entry)
{ {
if (entry.Name.EndsWith (".BGD", StringComparison.InvariantCultureIgnoreCase) || if (entry.Name.HasAnyOfExtensions (".BGD", ".CRGB"))
entry.Name.EndsWith (".CRGB", StringComparison.InvariantCultureIgnoreCase))
{ {
var input = OpenEntry (arc, entry); var input = OpenEntry (arc, entry);
var info = new ImageMetaData { Width = 800, Height = 600, BPP = 24 }; var info = new ImageMetaData { Width = 800, Height = 600, BPP = 24 };
return new CgdReader (BinaryStream.FromStream (input, entry.Name), info); return new CgdReader (BinaryStream.FromStream (input, entry.Name), info);
} }
else if (entry.Name.EndsWith (".edg", StringComparison.InvariantCultureIgnoreCase)) else if (entry.Name.HasExtension (".edg"))
{ {
var input = OpenEntry (arc, entry); var input = OpenEntry (arc, entry);
var info = new ImageMetaData { Width = 460, Height = 345, BPP = 24 }; var info = new ImageMetaData { Width = 460, Height = 345, BPP = 24 };
return new ImgReader (BinaryStream.FromStream (input, entry.Name), info); return new ImgReader (BinaryStream.FromStream (input, entry.Name), info);
} }
else if (entry.Name.EndsWith (".rol", StringComparison.InvariantCultureIgnoreCase)) else if (entry.Name.HasExtension (".rol"))
{ {
var input = OpenEntry (arc, entry); var input = OpenEntry (arc, entry);
uint width = 202; uint width = 202;
@ -167,7 +163,7 @@ namespace GameRes.Formats.GameSystem
var info = new ImageMetaData { Width = width, Height = height, BPP = 24 }; var info = new ImageMetaData { Width = width, Height = height, BPP = 24 };
return new ImgReader (BinaryStream.FromStream (input, entry.Name), info); return new ImgReader (BinaryStream.FromStream (input, entry.Name), info);
} }
else if (entry.Name.EndsWith (".CHAR", StringComparison.InvariantCultureIgnoreCase)) else if (entry.Name.HasExtension (".CHAR"))
{ {
var input = OpenEntry (arc, entry); var input = OpenEntry (arc, entry);
var info = new ChrMetaData { var info = new ChrMetaData {

View File

@ -47,8 +47,8 @@ namespace GameRes.Formats.GameSystem
public override SoundInput TryOpen (IBinaryStream file) public override SoundInput TryOpen (IBinaryStream file)
{ {
bool is_adp4 = file.Name.EndsWith (".adp4", StringComparison.InvariantCultureIgnoreCase); bool is_adp4 = file.Name.HasExtension (".adp4");
bool is_adps = !is_adp4 && file.Name.EndsWith (".adps", StringComparison.InvariantCultureIgnoreCase); bool is_adps = !is_adp4 && file.Name.HasExtension (".adps");
if (!(is_adp4 || is_adps) || file.Length <= 4) if (!(is_adp4 || is_adps) || file.Length <= 4)
return null; return null;
var decoder = new AdpDecoder (file); var decoder = new AdpDecoder (file);

View File

@ -39,7 +39,7 @@ namespace GameRes.Formats.GameSystem
public override ImageMetaData ReadMetaData (IBinaryStream file) public override ImageMetaData ReadMetaData (IBinaryStream file)
{ {
if (!file.Name.EndsWith (".alp", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".alp"))
return null; return null;
var header = file.ReadHeader (8); var header = file.ReadHeader (8);
uint width = header.ToUInt32 (0); uint width = header.ToUInt32 (0);

View File

@ -39,7 +39,7 @@ namespace GameRes.Formats.GameSystem
public override ImageMetaData ReadMetaData (IBinaryStream file) public override ImageMetaData ReadMetaData (IBinaryStream file)
{ {
if (!file.Name.EndsWith (".texb", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".texb"))
return null; return null;
var header = file.ReadHeader (8); var header = file.ReadHeader (8);
uint width = header.ToUInt32 (0); uint width = header.ToUInt32 (0);

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Irrlicht
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".pack", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".pack"))
return null; return null;
long offset = 0; long offset = 0;
var dir = new List<Entry>(); var dir = new List<Entry>();

View File

@ -92,7 +92,7 @@ namespace GameRes.Formats.Ivory
{ {
var name = Binary.GetCString (cnam, entry.NameOffset); var name = Binary.GetCString (cnam, entry.NameOffset);
entry.Name = name; entry.Name = name;
if (name.EndsWith (".px", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".px"))
entry.Type = "audio"; entry.Type = "audio";
else else
entry.Type = FormatCatalog.Instance.GetTypeFromName (name); entry.Type = FormatCatalog.Instance.GetTypeFromName (name);

View File

@ -40,7 +40,7 @@ namespace GameRes.Formats.KAAS
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".pb", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".pb"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (count <= 0 || count > 0xfff) if (count <= 0 || count > 0xfff)

View File

@ -740,7 +740,7 @@ NextEntry:
{ {
if ("image" == entry.Type || "archive" == entry.Type) if ("image" == entry.Type || "archive" == entry.Type)
return false; return false;
if (entry.Name.EndsWith (".ogg", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".ogg"))
return false; return false;
return true; return true;
} }

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Kiss
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".arc", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".arc"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))

View File

@ -88,7 +88,7 @@ namespace GameRes.Formats.Lilim
entry.Offset += current_offset; entry.Offset += current_offset;
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".scr"))
entry.IsCompressed = true; entry.IsCompressed = true;
dir.Add (entry); dir.Add (entry);
} }
@ -153,9 +153,9 @@ namespace GameRes.Formats.Lilim
entry.Size = file.View.ReadUInt32 (index_offset+0x24); entry.Size = file.View.ReadUInt32 (index_offset+0x24);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".scr"))
entry.IsCompressed = true; entry.IsCompressed = true;
else if (name.EndsWith (".cmp", StringComparison.InvariantCultureIgnoreCase)) else if (name.HasExtension (".cmp"))
{ {
entry.IsCompressed = true; entry.IsCompressed = true;
entry.Name = Path.ChangeExtension (entry.Name, ".abm"); entry.Name = Path.ChangeExtension (entry.Name, ".abm");

View File

@ -60,13 +60,13 @@ namespace GameRes.Formats.LiveMaker
// game.ext -- [optional] separate index (could be included into the main body) // game.ext -- [optional] separate index (could be included into the main body)
uint signature = index_file.View.ReadUInt32 (0); uint signature = index_file.View.ReadUInt32 (0);
if (file.Name.EndsWith (".exe", StringComparison.InvariantCultureIgnoreCase) if (file.Name.HasExtension (".exe")
&& (0x5A4D == (signature & 0xFFFF))) // 'MZ' && (0x5A4D == (signature & 0xFFFF))) // 'MZ'
{ {
base_offset = SkipExeData (index_file); base_offset = SkipExeData (index_file);
signature = index_file.View.ReadUInt32 (base_offset); signature = index_file.View.ReadUInt32 (base_offset);
} }
else if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) else if (!file.Name.HasExtension (".dat"))
{ {
return null; return null;
} }

View File

@ -87,9 +87,7 @@ namespace GameRes.Formats.Mg
entry.Size = file.View.ReadUInt32 (cur_offset+0x24); entry.Size = file.View.ReadUInt32 (cur_offset+0x24);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
has_encrypted = has_encrypted has_encrypted = has_encrypted || name.HasAnyOfExtensions ("png", "txt");
|| name.EndsWith (".png", StringComparison.InvariantCultureIgnoreCase)
|| name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase);
dir.Add (entry); dir.Add (entry);
cur_offset += 0x30; cur_offset += 0x30;
} }
@ -113,7 +111,7 @@ namespace GameRes.Formats.Mg
byte[] data = new byte[entry.Size]; byte[] data = new byte[entry.Size];
input.Read (data, 0, data.Length); input.Read (data, 0, data.Length);
data = DecryptBlock (data, mgarc.Key); data = DecryptBlock (data, mgarc.Key);
if (entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension ("txt"))
return DecompressStream (data); return DecompressStream (data);
return new BinMemoryStream (data, entry.Name); return new BinMemoryStream (data, entry.Name);
} }

View File

@ -81,7 +81,7 @@ namespace GameRes.Formats.Mixwill
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
uint encrypted_size = entry.Size; uint encrypted_size = entry.Size;
if (!entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase) if (!entry.Name.HasExtension (".txt")
&& encrypted_size > 0x100) && encrypted_size > 0x100)
encrypted_size = 0x100; encrypted_size = 0x100;
var prefix = arc.File.View.ReadBytes (entry.Offset, encrypted_size); var prefix = arc.File.View.ReadBytes (entry.Offset, encrypted_size);

View File

@ -92,7 +92,7 @@ namespace GameRes.Formats.MoonhirGames
entry.Size = file.View.ReadUInt32 (index_offset+8); entry.Size = file.View.ReadUInt32 (index_offset+8);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".fbx", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".fbx"))
entry.Type = "image"; entry.Type = "image";
has_encrypted = has_encrypted || entry.IsEncrypted; has_encrypted = has_encrypted || entry.IsEncrypted;
dir.Add (entry); dir.Add (entry);

View File

@ -169,7 +169,7 @@ namespace GameRes.Formats.Musica
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".paz", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".paz"))
return null; return null;
uint signature = file.View.ReadUInt32 (0); uint signature = file.View.ReadUInt32 (0);
// XXX encryption is queried for every .paz file // XXX encryption is queried for every .paz file

View File

@ -68,7 +68,7 @@ namespace GameRes.Formats.NScripter
} }
catch { /* ignore parse errors */ } catch { /* ignore parse errors */ }
} }
if (!file.Name.EndsWith (".ns2", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".ns2"))
return null; return null;
var password = QueryPassword(); var password = QueryPassword();

View File

@ -105,7 +105,7 @@ namespace GameRes.Formats.NScripter
} }
} }
catch { /* ignore parse errors */ } catch { /* ignore parse errors */ }
if (zero_signature || !file.Name.EndsWith (".nsa", StringComparison.InvariantCultureIgnoreCase)) if (zero_signature || !file.Name.HasExtension (".nsa"))
return null; return null;
var password = QueryPassword(); var password = QueryPassword();
@ -251,7 +251,7 @@ namespace GameRes.Formats.NScripter
var header_entry = new NsaEntry { Name = entry.Name }; var header_entry = new NsaEntry { Name = entry.Name };
if (Compression.None != ons_options.CompressionType) if (Compression.None != ons_options.CompressionType)
{ {
if (entry.Name.EndsWith (".bmp", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".bmp"))
header_entry.CompressionType = ons_options.CompressionType; header_entry.CompressionType = ons_options.CompressionType;
} }
index_size += 13; index_size += 13;

View File

@ -83,7 +83,7 @@ namespace GameRes.Formats.NSystem
entry.Offset = file.View.ReadInt64 (index_offset+8); entry.Offset = file.View.ReadInt64 (index_offset+8);
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
has_scripts = has_scripts || name.EndsWith (".msd", StringComparison.InvariantCultureIgnoreCase); has_scripts = has_scripts || name.HasExtension (".msd");
dir.Add (entry); dir.Add (entry);
index_offset += 0x10; index_offset += 0x10;
} }
@ -100,7 +100,7 @@ namespace GameRes.Formats.NSystem
{ {
var msarc = arc as MsdArchive; var msarc = arc as MsdArchive;
if (null == msarc || string.IsNullOrEmpty (msarc.Key) if (null == msarc || string.IsNullOrEmpty (msarc.Key)
|| !entry.Name.EndsWith (".msd", StringComparison.InvariantCultureIgnoreCase) || !entry.Name.HasExtension (".msd")
|| arc.File.View.AsciiEqual (entry.Offset, "MSCENARIO FILE ")) || arc.File.View.AsciiEqual (entry.Offset, "MSCENARIO FILE "))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);

View File

@ -82,7 +82,7 @@ namespace GameRes.Formats.Nags
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (!entry.Name.EndsWith (".scb", StringComparison.InvariantCultureIgnoreCase)) if (!entry.Name.HasExtension (".scb"))
return input; return input;
return new InputCryptoStream (input, new NotTransform()); return new InputCryptoStream (input, new NotTransform());
} }

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Nejii
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (file.MaxOffset < 0x30 || !file.Name.EndsWith (".pcd", StringComparison.InvariantCultureIgnoreCase)) if (file.MaxOffset < 0x30 || !file.Name.HasExtension (".pcd"))
return null; return null;
// check if first entry looks like WAVEFORMAT // check if first entry looks like WAVEFORMAT
ushort channels = file.View.ReadUInt16 (0x12); ushort channels = file.View.ReadUInt16 (0x12);

View File

@ -87,7 +87,7 @@ namespace GameRes.Formats.NekoSDK
entry.Size = file.View.ReadUInt32 (index_offset+4) ^ (uint)key; entry.Size = file.View.ReadUInt32 (index_offset+4) ^ (uint)key;
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
if (name.EndsWith (".alp", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".alp"))
entry.Type = ""; entry.Type = "";
dir.Add (entry); dir.Add (entry);
index_offset += 8; index_offset += 8;

View File

@ -101,7 +101,7 @@ namespace GameRes.Formats.NonColor
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".dat"))
return null; return null;
int count = file.View.ReadInt32 (0) ^ 0x26ACA46E; int count = file.View.ReadInt32 (0) ^ 0x26ACA46E;
if (!IsSaneCount (count)) if (!IsSaneCount (count))

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.Propeller
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".mgr", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".mgr"))
return null; return null;
int count = file.View.ReadInt16 (0); int count = file.View.ReadInt16 (0);
if (count <= 0 || count >= 0x100) if (count <= 0 || count >= 0x100)

View File

@ -77,7 +77,7 @@ namespace GameRes.Formats.Propeller
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (!entry.Name.EndsWith (".msc", StringComparison.InvariantCultureIgnoreCase) if (!entry.Name.HasExtension (".msc")
|| 0x88 != input.PeekByte()) || 0x88 != input.PeekByte())
return input; return input;
return new XoredStream (input, 0x88); return new XoredStream (input, 0x88);

View File

@ -94,7 +94,7 @@ namespace GameRes.Formats.Rpm
return null; return null;
var scheme = GuessScheme (file, count); var scheme = GuessScheme (file, count);
// additional filename extension check avoids dialog popup on false positives // additional filename extension check avoids dialog popup on false positives
if (null == scheme && KnownSchemes.Count > 0 && file.Name.EndsWith (".arc", StringComparison.InvariantCultureIgnoreCase)) if (null == scheme && KnownSchemes.Count > 0 && file.Name.HasExtension (".arc"))
scheme = QueryScheme(); scheme = QueryScheme();
if (null == scheme) if (null == scheme)
return null; return null;

View File

@ -68,7 +68,7 @@ namespace GameRes.Formats.RealLive
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".g00", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".g00"))
return null; return null;
if (file.View.ReadByte (0) != 2) if (file.View.ReadByte (0) != 2)
return null; return null;

View File

@ -41,7 +41,7 @@ namespace GameRes.Formats.RealLive
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".ovk", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".ovk"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))

View File

@ -57,7 +57,7 @@ namespace GameRes.Formats.Riddle
string name = file.View.ReadString (index_offset, 0x10); string name = file.View.ReadString (index_offset, 0x10);
uint size = file.View.ReadUInt32 (index_offset+0x10); uint size = file.View.ReadUInt32 (index_offset+0x10);
var entry = new PackedEntry { Name = name }; var entry = new PackedEntry { Name = name };
if (name.EndsWith (".scp", StringComparison.InvariantCultureIgnoreCase)) if (name.HasExtension (".scp"))
{ {
entry.Type = "script"; entry.Type = "script";
entry.IsPacked = size > 12 && file.View.AsciiEqual (index_offset+0x14, "CMP1"); entry.IsPacked = size > 12 && file.View.AsciiEqual (index_offset+0x14, "CMP1");

View File

@ -43,7 +43,7 @@ namespace GameRes.Formats.Silky
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
// enforce extension to avoid false positives // enforce extension to avoid false positives
if (!file.Name.EndsWith (".awf", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".awf"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))
@ -74,7 +74,7 @@ namespace GameRes.Formats.Silky
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (entry.Name.EndsWith (".mp3", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".mp3"))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
// prepend WAV header // prepend WAV header
var header = new byte[0x2C]; var header = new byte[0x2C];

View File

@ -41,7 +41,7 @@ namespace GameRes.Formats.Silky
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".arc", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".arc"))
return null; return null;
uint index_size = file.View.ReadUInt32 (0); uint index_size = file.View.ReadUInt32 (0);
if (index_size < 10 || index_size >= file.MaxOffset-4) if (index_size < 10 || index_size >= file.MaxOffset-4)

View File

@ -69,7 +69,7 @@ namespace GameRes.Formats.Silky
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (entry.Size <= 8 if (entry.Size <= 8
|| !entry.Name.EndsWith (".snc", StringComparison.InvariantCultureIgnoreCase) || !entry.Name.HasExtension (".snc")
|| !arc.File.View.AsciiEqual (entry.Offset, "CMP_")) || !arc.File.View.AsciiEqual (entry.Offset, "CMP_"))
return arc.File.CreateStream (entry.Offset, entry.Size); return arc.File.CreateStream (entry.Offset, entry.Size);
int unpacked_size = arc.File.View.ReadInt32 (entry.Offset+4); int unpacked_size = arc.File.View.ReadInt32 (entry.Offset+4);

View File

@ -115,12 +115,11 @@ namespace GameRes.Formats.TopCat
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (entry.Name.EndsWith (".OGG", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".OGG"))
return RestoreOggStream (arc, entry); return RestoreOggStream (arc, entry);
if (entry.Name.EndsWith (".TSF", StringComparison.InvariantCultureIgnoreCase) || if (entry.Name.HasAnyOfExtensions (".TSF", ".TCT"))
entry.Name.EndsWith (".TCT", StringComparison.InvariantCultureIgnoreCase))
return OpenScript (arc, entry); return OpenScript (arc, entry);
if (entry.Name.EndsWith (".SPD", StringComparison.InvariantCultureIgnoreCase)) if (entry.Name.HasExtension (".SPD"))
return OpenSpdc (arc, entry); return OpenSpdc (arc, entry);
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
} }

View File

@ -78,7 +78,7 @@ namespace GameRes.Formats.Triangle
var name = file.View.ReadString (index_offset, entry_size-4); var name = file.View.ReadString (index_offset, entry_size-4);
uint flags = next_offset >> 30; uint flags = next_offset >> 30;
Entry entry; Entry entry;
if (1 == flags || name.EndsWith (".iaf", StringComparison.InvariantCultureIgnoreCase)) if (1 == flags || name.HasExtension (".iaf"))
entry = new Entry(); entry = new Entry();
else else
entry = new CgfEntry { Flags = flags }; entry = new CgfEntry { Flags = flags };

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Triangle
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".iaf", StringComparison.InvariantCultureIgnoreCase) if (!file.Name.HasExtension (".iaf")
|| file.MaxOffset < 0x20) || file.MaxOffset < 0x20)
return null; return null;
uint size = file.View.ReadUInt32 (1); uint size = file.View.ReadUInt32 (1);

View File

@ -83,8 +83,7 @@ namespace GameRes.Formats.UMeSoft
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) && if (!entry.Name.HasAnyOfExtensions ("scr", "tbl"))
!entry.Name.EndsWith (".tbl", StringComparison.InvariantCultureIgnoreCase))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
int output_size = arc.File.View.ReadInt32 (entry.Offset); int output_size = arc.File.View.ReadInt32 (entry.Offset);
if (output_size <= 0) if (output_size <= 0)

View File

@ -65,7 +65,7 @@ namespace GameRes.Formats.Valkyria
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".odn", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".odn"))
return null; return null;
var reader = new OdnIndexReader (file); var reader = new OdnIndexReader (file);
var dir = reader.ReadIndex(); var dir = reader.ReadIndex();

View File

@ -97,7 +97,7 @@ namespace GameRes.Formats.Will
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (!entry.Name.EndsWith (".ws2", StringComparison.InvariantCultureIgnoreCase)) if (!IsScriptFile (entry.Name))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
for (int i = 0; i < data.Length; ++i) for (int i = 0; i < data.Length; ++i)
@ -107,6 +107,11 @@ namespace GameRes.Formats.Will
return new BinMemoryStream (data, entry.Name); return new BinMemoryStream (data, entry.Name);
} }
static bool IsScriptFile (string name)
{
return name.HasAnyOfExtensions ("ws2", "json");
}
public override void Create (Stream output, IEnumerable<Entry> list, ResourceOptions options, public override void Create (Stream output, IEnumerable<Entry> list, ResourceOptions options,
EntryCallback callback) EntryCallback callback)
{ {
@ -132,7 +137,7 @@ namespace GameRes.Formats.Will
var size = input.Length; var size = input.Length;
if (size > uint.MaxValue || current_offset + size > uint.MaxValue) if (size > uint.MaxValue || current_offset + size > uint.MaxValue)
throw new FileSizeException(); throw new FileSizeException();
if (entry.Name.EndsWith (".ws2", StringComparison.InvariantCultureIgnoreCase)) if (IsScriptFile (entry.Name))
CopyScript (input, output); CopyScript (input, output);
else else
input.CopyTo (output); input.CopyTo (output);

View File

@ -275,8 +275,7 @@ namespace GameRes.Formats.Will
private static bool IsScriptFile (string filename) private static bool IsScriptFile (string filename)
{ {
return filename.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) return filename.HasAnyOfExtensions ("scr", "wsc");
|| filename.EndsWith (".wsc", StringComparison.InvariantCultureIgnoreCase);
} }
} }
} }

View File

@ -95,7 +95,7 @@ namespace GameRes.Formats.Will
if (24 == meta.BPP) if (24 == meta.BPP)
{ {
byte[] raw = reader.Data; byte[] raw = reader.Data;
if (ApplyMask && !meta.FileName.EndsWith (".msk", StringComparison.InvariantCultureIgnoreCase)) if (ApplyMask && !meta.FileName.HasExtension (".msk"))
{ {
var mask_name = Path.ChangeExtension (meta.FileName, "msk"); var mask_name = Path.ChangeExtension (meta.FileName, "msk");
if (VFS.FileExists (mask_name)) if (VFS.FileExists (mask_name))

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.Yatagarasu
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".pkg", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".pkg"))
return null; return null;
uint key = file.View.ReadUInt32 (0x84); // last bytes of the first entry name uint key = file.View.ReadUInt32 (0x84); // last bytes of the first entry name
if (key != file.View.ReadUInt32 (0x10C)) // keys of the first two entries supposed to be the same if (key != file.View.ReadUInt32 (0x10C)) // keys of the first two entries supposed to be the same

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.Youkai
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".dat"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count) || 0 != file.View.ReadInt32 (4)) if (!IsSaneCount (count) || 0 != file.View.ReadInt32 (4))
@ -91,7 +91,7 @@ namespace GameRes.Formats.Youkai
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".dat"))
return null; return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))
@ -132,7 +132,7 @@ namespace GameRes.Formats.Youkai
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".dat"))
return null; return null;
uint data_offset = file.View.ReadUInt32 (0); uint data_offset = file.View.ReadUInt32 (0);
int count = file.View.ReadInt32 (4); int count = file.View.ReadInt32 (4);

View File

@ -143,7 +143,7 @@ namespace GameRes.Formats.YuRis
input = new ZLibStream (input, CompressionMode.Decompress); input = new ZLibStream (input, CompressionMode.Decompress);
uint unpacked_size = null == packed_entry ? entry.Size : packed_entry.UnpackedSize; uint unpacked_size = null == packed_entry ? entry.Size : packed_entry.UnpackedSize;
if (null == ypf || 0 == ypf.ScriptKey || unpacked_size <= 0x20 if (null == ypf || 0 == ypf.ScriptKey || unpacked_size <= 0x20
|| !entry.Name.EndsWith (".ybn", StringComparison.InvariantCultureIgnoreCase)) || !entry.Name.HasExtension (".ybn"))
return input; return input;
using (input) using (input)
{ {

View File

@ -90,7 +90,7 @@ namespace GameRes.Formats.Yuka
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
if (entry.Size < 0x24 if (entry.Size < 0x24
|| !entry.Name.EndsWith (".yks", StringComparison.InvariantCultureIgnoreCase) || !entry.Name.HasExtension (".yks")
|| !arc.File.View.AsciiEqual (entry.Offset, "YKS001") || !arc.File.View.AsciiEqual (entry.Offset, "YKS001")
|| 1 != arc.File.View.ReadUInt16 (entry.Offset+6)) || 1 != arc.File.View.ReadUInt16 (entry.Offset+6))
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);

View File

@ -94,8 +94,7 @@ namespace GameRes.Formats.Elf
public override Stream OpenEntry (ArcFile arc, Entry entry) public override Stream OpenEntry (ArcFile arc, Entry entry)
{ {
var input = arc.File.CreateStream (entry.Offset, entry.Size); var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (entry.Name.EndsWith (".mes", StringComparison.InvariantCultureIgnoreCase) if (entry.Name.HasAnyOfExtensions ("mes", "lib"))
|| entry.Name.EndsWith (".lib", StringComparison.InvariantCultureIgnoreCase))
return new LzssStream (input); return new LzssStream (input);
return input; return input;
} }

View File

@ -46,7 +46,7 @@ namespace GameRes.Formats.Elf
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".vol", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".vol"))
return null; return null;
uint first_offset = file.View.ReadUInt32 (0); uint first_offset = file.View.ReadUInt32 (0);
if (first_offset < 0x10 || 0 != (first_offset & 0xF) || first_offset >= file.MaxOffset) if (first_offset < 0x10 || 0 != (first_offset & 0xF) || first_offset >= file.MaxOffset)

View File

@ -115,7 +115,7 @@ namespace GameRes.Formats.Rugp
if (CRioArchive.RioSignature == file.View.ReadUInt32 (0)) if (CRioArchive.RioSignature == file.View.ReadUInt32 (0))
return new RioReader (file); return new RioReader (file);
if (file.Name.EndsWith (".ici", StringComparison.InvariantCultureIgnoreCase)) if (file.Name.HasExtension (".ici"))
return null; return null;
var ici_name = file.Name + ".ici"; var ici_name = file.Name + ".ici";
if (!VFS.FileExists (ici_name)) if (!VFS.FileExists (ici_name))

View File

@ -42,7 +42,7 @@ namespace GameRes.Formats.uGOS
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.Name.EndsWith (".det", StringComparison.InvariantCultureIgnoreCase)) if (!file.Name.HasExtension (".det"))
return null; return null;
var name_file = Path.ChangeExtension (file.Name, "nme"); var name_file = Path.ChangeExtension (file.Name, "nme");
var index_file = Path.ChangeExtension (file.Name, "atm"); var index_file = Path.ChangeExtension (file.Name, "atm");

View File

@ -47,7 +47,7 @@ namespace GameRes.Formats.CellWorks
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (VFS.IsVirtual || !file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) if (VFS.IsVirtual || !file.Name.HasExtension (".dat"))
return null; return null;
var db_files = VFS.GetFiles (VFS.CombinePath (VFS.GetDirectoryName (file.Name), "*.db")); var db_files = VFS.GetFiles (VFS.CombinePath (VFS.GetDirectoryName (file.Name), "*.db"));
if (!db_files.Any()) if (!db_files.Any())