diff --git a/ArcFormats/AZSys/ArcAZSys.cs b/ArcFormats/AZSys/ArcAZSys.cs index 03a0e20f..ceef0302 100644 --- a/ArcFormats/AZSys/ArcAZSys.cs +++ b/ArcFormats/AZSys/ArcAZSys.cs @@ -109,7 +109,7 @@ namespace GameRes.Formats.AZSys if (entry.CheckPlacement (file.MaxOffset)) { dir.Add (entry); - contains_scripts = contains_scripts || name.EndsWith (".asb", StringComparison.InvariantCultureIgnoreCase); + contains_scripts = contains_scripts || name.HasExtension (".asb"); } } index_offset += 0x40; diff --git a/ArcFormats/Abel/ArcARC.cs b/ArcFormats/Abel/ArcARC.cs index 4bcaecb8..5c9c4ff1 100644 --- a/ArcFormats/Abel/ArcARC.cs +++ b/ArcFormats/Abel/ArcARC.cs @@ -72,7 +72,7 @@ namespace GameRes.Formats.Abel return null; var name = Binary.GetCString (name_buffer, 0, name_buffer.Length); var entry = FormatCatalog.Instance.Create (name); - if (name.EndsWith (".acd", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".acd")) entry.Type = "script"; entry.Offset = index.ReadUInt32() + base_offset; entry.Size = index.ReadUInt32(); @@ -86,10 +86,10 @@ namespace GameRes.Formats.Abel 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")) 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")) return OpenAcdEntry (arc, entry); return base.OpenEntry (arc, entry); diff --git a/ArcFormats/Actgs/ArcDAT.cs b/ArcFormats/Actgs/ArcDAT.cs index 07460b1a..7ae1f8f7 100644 --- a/ArcFormats/Actgs/ArcDAT.cs +++ b/ArcFormats/Actgs/ArcDAT.cs @@ -115,7 +115,7 @@ namespace GameRes.Formats.Actgs var actarc = arc as ActressArchive; if (null == actarc || null == actarc.Key) 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)) return base.OpenEntry (arc, entry); diff --git a/ArcFormats/AdvSys/ArcAdvSys3.cs b/ArcFormats/AdvSys/ArcAdvSys3.cs index eef3a44b..ae52e4cd 100644 --- a/ArcFormats/AdvSys/ArcAdvSys3.cs +++ b/ArcFormats/AdvSys/ArcAdvSys3.cs @@ -47,7 +47,7 @@ namespace GameRes.Formats.AdvSys 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)) return null; long current_offset = 0; diff --git a/ArcFormats/Amaterasu/ArcAMI.cs b/ArcFormats/Amaterasu/ArcAMI.cs index e56e50f4..eb119887 100644 --- a/ArcFormats/Amaterasu/ArcAMI.cs +++ b/ArcFormats/Amaterasu/ArcAMI.cs @@ -237,7 +237,7 @@ namespace GameRes.Formats.Amaterasu int update_count = 0; foreach (var entry in list) { - if (entry.Type != "image" && !entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Type != "image" && !entry.Name.HasExtension (".scr")) continue; uint id; if (!uint.TryParse (Path.GetFileNameWithoutExtension (entry.Name), NumberStyles.HexNumber, diff --git a/ArcFormats/AnimeGameSystem/ArcANI.cs b/ArcFormats/AnimeGameSystem/ArcANI.cs index ffbf97ef..79a720d7 100644 --- a/ArcFormats/AnimeGameSystem/ArcANI.cs +++ b/ArcFormats/AnimeGameSystem/ArcANI.cs @@ -49,7 +49,7 @@ namespace GameRes.Formats.Ags public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".ani", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".ani")) return null; uint first_offset = file.View.ReadUInt32 (0); if (first_offset < 4 || file.MaxOffset > int.MaxValue || first_offset >= file.MaxOffset || 0 != (first_offset & 3)) diff --git a/ArcFormats/ArcNEKO.cs b/ArcFormats/ArcNEKO.cs index 8ef21223..e7dc9125 100644 --- a/ArcFormats/ArcNEKO.cs +++ b/ArcFormats/ArcNEKO.cs @@ -148,8 +148,7 @@ namespace GameRes.Formats.Neko { foreach (var entry in dir.Where (e => string.IsNullOrEmpty (e.Type))) { - if (entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".nut", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasAnyOfExtensions ("txt", "nut")) { entry.Type = "script"; continue; diff --git a/ArcFormats/ArcSPack.cs b/ArcFormats/ArcSPack.cs index f5a7e22f..d2d67a6b 100644 --- a/ArcFormats/ArcSPack.cs +++ b/ArcFormats/ArcSPack.cs @@ -84,7 +84,7 @@ namespace GameRes.Formats.SPack }; if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".dat")) entry.Type = "audio"; else entry.Type = FormatCatalog.Instance.GetTypeFromName (name); diff --git a/ArcFormats/Banana/ArcPK.cs b/ArcFormats/Banana/ArcPK.cs index aa27add8..5a7f92ac 100644 --- a/ArcFormats/Banana/ArcPK.cs +++ b/ArcFormats/Banana/ArcPK.cs @@ -78,7 +78,7 @@ namespace GameRes.Formats.Banana // namespace is arbitrary, actual format source index_offset += 8; if (entry.Offset < index_offset || !entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".scr")) entry.IsPacked = true; dir.Add (entry); } diff --git a/ArcFormats/BlackCyc/ArcGPK.cs b/ArcFormats/BlackCyc/ArcGPK.cs index 5444bd98..b03b5ff9 100644 --- a/ArcFormats/BlackCyc/ArcGPK.cs +++ b/ArcFormats/BlackCyc/ArcGPK.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.BlackCyc public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".gpk", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".gpk")) return null; var gtb_name = Path.ChangeExtension (file.Name, "gtb"); if (!VFS.FileExists (gtb_name)) diff --git a/ArcFormats/BlackCyc/ArcVPK.cs b/ArcFormats/BlackCyc/ArcVPK.cs index 6204147b..5111e5da 100644 --- a/ArcFormats/BlackCyc/ArcVPK.cs +++ b/ArcFormats/BlackCyc/ArcVPK.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.BlackCyc public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".vpk", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".vpk")) return null; var vtb_name = Path.ChangeExtension (file.Name, "vtb"); if (!VFS.FileExists (vtb_name)) diff --git a/ArcFormats/BlackRainbow/ArcADS.cs b/ArcFormats/BlackRainbow/ArcADS.cs index 8cf479ea..04bc8139 100644 --- a/ArcFormats/BlackRainbow/ArcADS.cs +++ b/ArcFormats/BlackRainbow/ArcADS.cs @@ -63,7 +63,7 @@ namespace GameRes.Formats.BlackRainbow public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".ads", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".ads")) return null; var arc_name = Path.GetFileNameWithoutExtension (file.Name); foreach (var key in KnownKeys.Values) diff --git a/ArcFormats/BlackRainbow/ArcDX.cs b/ArcFormats/BlackRainbow/ArcDX.cs index b8bd139c..f390ba00 100644 --- a/ArcFormats/BlackRainbow/ArcDX.cs +++ b/ArcFormats/BlackRainbow/ArcDX.cs @@ -60,7 +60,7 @@ namespace GameRes.Formats.BlackRainbow 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); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); for (int i = 0; i < data.Length; ++i) @@ -114,7 +114,7 @@ namespace GameRes.Formats.BlackRainbow entry.Size = m_index.ReadUInt32(); if (!entry.CheckPlacement (m_max_offset)) return false; - if (name.EndsWith (".hse", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".hse")) entry.Type = "image"; m_dir.Add (entry); } diff --git a/ArcFormats/BlueGale/ArcSNN.cs b/ArcFormats/BlueGale/ArcSNN.cs index 8243b762..1b5663c9 100644 --- a/ArcFormats/BlueGale/ArcSNN.cs +++ b/ArcFormats/BlueGale/ArcSNN.cs @@ -41,7 +41,7 @@ namespace GameRes.Formats.BlueGale public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".snn", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".snn")) return null; var inx_name = Path.ChangeExtension (file.Name, "Inx"); if (!VFS.FileExists (inx_name)) diff --git a/ArcFormats/Cadath/ArcDAF.cs b/ArcFormats/Cadath/ArcDAF.cs index 49425aa3..79a30831 100644 --- a/ArcFormats/Cadath/ArcDAF.cs +++ b/ArcFormats/Cadath/ArcDAF.cs @@ -68,7 +68,7 @@ namespace GameRes.Formats.Cadath 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")) return base.OpenEntry (arc, entry); try diff --git a/ArcFormats/Cadath/ArcKAR.cs b/ArcFormats/Cadath/ArcKAR.cs index 14cb36d7..ab02bdc6 100644 --- a/ArcFormats/Cadath/ArcKAR.cs +++ b/ArcFormats/Cadath/ArcKAR.cs @@ -69,7 +69,7 @@ namespace GameRes.Formats.Cadath public override Stream OpenEntry (ArcFile arc, Entry entry) { var input = arc.File.CreateStream (entry.Offset, entry.Size); - if (!entry.Name.EndsWith (".ns6", StringComparison.InvariantCultureIgnoreCase)) + if (!entry.Name.HasExtension (".ns6")) return input; byte key = (byte)(entry.Size / 7); return new XoredStream (input, key); diff --git a/ArcFormats/Circus/ArcValkyrieComplex.cs b/ArcFormats/Circus/ArcValkyrieComplex.cs index 789552d8..92c47d6b 100644 --- a/ArcFormats/Circus/ArcValkyrieComplex.cs +++ b/ArcFormats/Circus/ArcValkyrieComplex.cs @@ -91,7 +91,7 @@ namespace GameRes.Formats.Circus entry.Size = LittleEndian.ToUInt32 (index, index_pos+8); if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".cps", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".cps")) entry.Type = "image"; dir.Add (entry); index_pos += 0x10; @@ -108,12 +108,12 @@ namespace GameRes.Formats.Circus var data = vcarc.File.View.ReadBytes (entry.Offset, entry.Size); for (int i = 0; i < data.Length; ++i) data[i] ^= vcarc.Key; - if (entry.Name.EndsWith (".cs", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension (".cs")) { for (int i = 0; i < data.Length; ++i) --data[i]; } - else if (entry.Name.EndsWith (".cps", StringComparison.InvariantCultureIgnoreCase)) + else if (entry.Name.HasExtension (".cps")) { data = UnpackCps (data); } diff --git a/ArcFormats/Cmvs/ArcPBZ.cs b/ArcFormats/Cmvs/ArcPBZ.cs index 69179417..3ac0c6df 100644 --- a/ArcFormats/Cmvs/ArcPBZ.cs +++ b/ArcFormats/Cmvs/ArcPBZ.cs @@ -117,7 +117,7 @@ namespace GameRes.Formats.Pvns return base.OpenEntry (arc, entry); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); Decrypt (data, parc.ArcKey); - if (entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) + if (entry.Name.HasExtension (".scr") && Binary.AsciiEqual (data, "PSRA") && data.Length > 20) { data = DecryptScript (data, parc.ScriptKey); diff --git a/ArcFormats/Cri/ArcSPC.cs b/ArcFormats/Cri/ArcSPC.cs index 953dff8b..07917ebb 100644 --- a/ArcFormats/Cri/ArcSPC.cs +++ b/ArcFormats/Cri/ArcSPC.cs @@ -47,7 +47,7 @@ namespace GameRes.Formats.Cri public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".spc", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".spc")) return null; uint unpacked_size = file.View.ReadUInt32 (0); if (unpacked_size <= 0x20 || unpacked_size > 0x5000000) diff --git a/ArcFormats/Eagls/ArcEAGLS.cs b/ArcFormats/Eagls/ArcEAGLS.cs index 9adfe5ce..9cff7b86 100644 --- a/ArcFormats/Eagls/ArcEAGLS.cs +++ b/ArcFormats/Eagls/ArcEAGLS.cs @@ -54,9 +54,10 @@ namespace GameRes.Formats.Eagls public override ArcFile TryOpen (ArcView file) { + if (file.Name.HasExtension (".idx")) + return null; string idx_name = Path.ChangeExtension (file.Name, ".idx"); - if (file.Name.Equals (idx_name, StringComparison.InvariantCultureIgnoreCase) - || !VFS.FileExists (idx_name)) + if (!VFS.FileExists (idx_name)) return null; var idx_entry = VFS.FindFile (idx_name); 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); index_offset += name_size; var entry = FormatCatalog.Instance.Create (name); - if (name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension ("dat")) { entry.Type = "script"; has_scripts = true; @@ -104,7 +105,7 @@ namespace GameRes.Formats.Eagls } if (0 == dir.Count) 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]); 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) { var earc = arc as EaglsArchive; - if (null == earc - || !(entry.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".gr", StringComparison.InvariantCultureIgnoreCase))) + if (null == earc || !entry.Name.HasAnyOfExtensions ("dat", "gr")) return arc.File.CreateStream (entry.Offset, entry.Size); return earc.DecryptEntry (entry); diff --git a/ArcFormats/Entis/ArcPAC.cs b/ArcFormats/Entis/ArcPAC.cs index 4c9e17d6..e0526da3 100644 --- a/ArcFormats/Entis/ArcPAC.cs +++ b/ArcFormats/Entis/ArcPAC.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Entis public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".pac", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".pac")) return null; uint index_offset = 0; var name_buf = new byte[0x18]; diff --git a/ArcFormats/Ffa/ArcBlackPackage.cs b/ArcFormats/Ffa/ArcBlackPackage.cs index eb72e2ed..d7c24df2 100644 --- a/ArcFormats/Ffa/ArcBlackPackage.cs +++ b/ArcFormats/Ffa/ArcBlackPackage.cs @@ -79,8 +79,7 @@ namespace GameRes.Formats.Ffa var input = arc.File.CreateStream (entry.Offset, entry.Size); if (entry.Size <= 8) return input; - if (!entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase) && - !entry.Name.EndsWith (".so5", StringComparison.InvariantCultureIgnoreCase)) + if (!entry.Name.HasAnyOfExtensions ("so4", "so5")) return input; int packed = input.ReadInt32(); int unpacked = input.ReadInt32(); diff --git a/ArcFormats/FlyingShine/ArcPD.cs b/ArcFormats/FlyingShine/ArcPD.cs index 07db5f33..679f004c 100644 --- a/ArcFormats/FlyingShine/ArcPD.cs +++ b/ArcFormats/FlyingShine/ArcPD.cs @@ -76,7 +76,7 @@ namespace GameRes.Formats.Fs entry.Size = file.View.ReadUInt32 (cur_offset+0x88); if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".dsf", System.StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".dsf")) entry.Type = "script"; dir.Add (entry); cur_offset += 0x90; @@ -305,8 +305,7 @@ namespace GameRes.Formats.Fs public override Stream OpenEntry (ArcFile arc, Entry entry) { - if (!entry.Name.EndsWith (".def", StringComparison.InvariantCultureIgnoreCase) && - !entry.Name.EndsWith (".dsf", StringComparison.InvariantCultureIgnoreCase)) + if (!entry.Name.HasAnyOfExtensions (".def", ".dsf")) return base.OpenEntry (arc, entry); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); for (int i = 0; i < data.Length; ++i) diff --git a/ArcFormats/GameSystem/ArcCHR.cs b/ArcFormats/GameSystem/ArcCHR.cs index 3a5585de..d8620c5b 100644 --- a/ArcFormats/GameSystem/ArcCHR.cs +++ b/ArcFormats/GameSystem/ArcCHR.cs @@ -44,7 +44,7 @@ namespace GameRes.Formats.GameSystem public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".CHR", StringComparison.InvariantCultureIgnoreCase) + if (!file.Name.HasExtension (".CHR") || file.View.ReadUInt32 (0) != file.MaxOffset) return null; using (var input = file.CreateStream()) diff --git a/ArcFormats/GameSystem/ArcPureMail.cs b/ArcFormats/GameSystem/ArcPureMail.cs index cfea4e36..0f9a2315 100644 --- a/ArcFormats/GameSystem/ArcPureMail.cs +++ b/ArcFormats/GameSystem/ArcPureMail.cs @@ -72,10 +72,7 @@ namespace GameRes.Formats.GameSystem entry.UnpackedSize = index.ReadUInt32(); if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (entry.Name.EndsWith (".CRGB", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".CHAR", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".rol", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".edg", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasAnyOfExtensions ("CRGB", "CHAR", "rol", "edg")) entry.Type = "image"; entry.IsPacked = (flags & 0xFF0000) != 0; entry.StoredSize = (flags & 0x2000000) != 0; @@ -146,20 +143,19 @@ namespace GameRes.Formats.GameSystem public override IImageDecoder OpenImage (ArcFile arc, Entry entry) { - if (entry.Name.EndsWith (".BGD", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".CRGB", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasAnyOfExtensions (".BGD", ".CRGB")) { var input = OpenEntry (arc, entry); var info = new ImageMetaData { Width = 800, Height = 600, BPP = 24 }; 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 info = new ImageMetaData { Width = 460, Height = 345, BPP = 24 }; 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); uint width = 202; @@ -167,7 +163,7 @@ namespace GameRes.Formats.GameSystem var info = new ImageMetaData { Width = width, Height = height, BPP = 24 }; 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 info = new ChrMetaData { diff --git a/ArcFormats/GameSystem/AudioADP4.cs b/ArcFormats/GameSystem/AudioADP4.cs index 658be187..6778b7d7 100644 --- a/ArcFormats/GameSystem/AudioADP4.cs +++ b/ArcFormats/GameSystem/AudioADP4.cs @@ -47,8 +47,8 @@ namespace GameRes.Formats.GameSystem public override SoundInput TryOpen (IBinaryStream file) { - bool is_adp4 = file.Name.EndsWith (".adp4", StringComparison.InvariantCultureIgnoreCase); - bool is_adps = !is_adp4 && file.Name.EndsWith (".adps", StringComparison.InvariantCultureIgnoreCase); + bool is_adp4 = file.Name.HasExtension (".adp4"); + bool is_adps = !is_adp4 && file.Name.HasExtension (".adps"); if (!(is_adp4 || is_adps) || file.Length <= 4) return null; var decoder = new AdpDecoder (file); diff --git a/ArcFormats/GameSystem/ImageALP.cs b/ArcFormats/GameSystem/ImageALP.cs index 1714d916..422e13b1 100644 --- a/ArcFormats/GameSystem/ImageALP.cs +++ b/ArcFormats/GameSystem/ImageALP.cs @@ -39,7 +39,7 @@ namespace GameRes.Formats.GameSystem public override ImageMetaData ReadMetaData (IBinaryStream file) { - if (!file.Name.EndsWith (".alp", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".alp")) return null; var header = file.ReadHeader (8); uint width = header.ToUInt32 (0); diff --git a/ArcFormats/GameSystem/ImageTEXB.cs b/ArcFormats/GameSystem/ImageTEXB.cs index 60c40a92..885ad13f 100644 --- a/ArcFormats/GameSystem/ImageTEXB.cs +++ b/ArcFormats/GameSystem/ImageTEXB.cs @@ -39,7 +39,7 @@ namespace GameRes.Formats.GameSystem public override ImageMetaData ReadMetaData (IBinaryStream file) { - if (!file.Name.EndsWith (".texb", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".texb")) return null; var header = file.ReadHeader (8); uint width = header.ToUInt32 (0); diff --git a/ArcFormats/Irrlicht/ArcPACK.cs b/ArcFormats/Irrlicht/ArcPACK.cs index d17f0bc9..c69a6399 100644 --- a/ArcFormats/Irrlicht/ArcPACK.cs +++ b/ArcFormats/Irrlicht/ArcPACK.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Irrlicht public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".pack", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".pack")) return null; long offset = 0; var dir = new List(); diff --git a/ArcFormats/Ivory/ArcPK.cs b/ArcFormats/Ivory/ArcPK.cs index 7cd9bebe..2587c806 100644 --- a/ArcFormats/Ivory/ArcPK.cs +++ b/ArcFormats/Ivory/ArcPK.cs @@ -92,7 +92,7 @@ namespace GameRes.Formats.Ivory { var name = Binary.GetCString (cnam, entry.NameOffset); entry.Name = name; - if (name.EndsWith (".px", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".px")) entry.Type = "audio"; else entry.Type = FormatCatalog.Instance.GetTypeFromName (name); diff --git a/ArcFormats/Kaas/ArcPB.cs b/ArcFormats/Kaas/ArcPB.cs index 9701abdc..11e7d181 100644 --- a/ArcFormats/Kaas/ArcPB.cs +++ b/ArcFormats/Kaas/ArcPB.cs @@ -40,7 +40,7 @@ namespace GameRes.Formats.KAAS public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".pb", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".pb")) return null; int count = file.View.ReadInt32 (0); if (count <= 0 || count > 0xfff) diff --git a/ArcFormats/KiriKiri/ArcXP3.cs b/ArcFormats/KiriKiri/ArcXP3.cs index fd5b857f..c245cef7 100644 --- a/ArcFormats/KiriKiri/ArcXP3.cs +++ b/ArcFormats/KiriKiri/ArcXP3.cs @@ -740,7 +740,7 @@ NextEntry: { if ("image" == entry.Type || "archive" == entry.Type) return false; - if (entry.Name.EndsWith (".ogg", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension (".ogg")) return false; return true; } diff --git a/ArcFormats/Kiss/ArcARC.cs b/ArcFormats/Kiss/ArcARC.cs index a14a1f61..6643d53c 100644 --- a/ArcFormats/Kiss/ArcARC.cs +++ b/ArcFormats/Kiss/ArcARC.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Kiss public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".arc", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".arc")) return null; int count = file.View.ReadInt32 (0); if (!IsSaneCount (count)) diff --git a/ArcFormats/Lilim/ArcAOS.cs b/ArcFormats/Lilim/ArcAOS.cs index 331a3395..e7fc4e61 100644 --- a/ArcFormats/Lilim/ArcAOS.cs +++ b/ArcFormats/Lilim/ArcAOS.cs @@ -88,7 +88,7 @@ namespace GameRes.Formats.Lilim entry.Offset += current_offset; if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".scr")) entry.IsCompressed = true; dir.Add (entry); } @@ -153,9 +153,9 @@ namespace GameRes.Formats.Lilim entry.Size = file.View.ReadUInt32 (index_offset+0x24); if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".scr")) entry.IsCompressed = true; - else if (name.EndsWith (".cmp", StringComparison.InvariantCultureIgnoreCase)) + else if (name.HasExtension (".cmp")) { entry.IsCompressed = true; entry.Name = Path.ChangeExtension (entry.Name, ".abm"); diff --git a/ArcFormats/LiveMaker/ArcVF.cs b/ArcFormats/LiveMaker/ArcVF.cs index 7feaab70..bfffaca4 100644 --- a/ArcFormats/LiveMaker/ArcVF.cs +++ b/ArcFormats/LiveMaker/ArcVF.cs @@ -60,13 +60,13 @@ namespace GameRes.Formats.LiveMaker // game.ext -- [optional] separate index (could be included into the main body) uint signature = index_file.View.ReadUInt32 (0); - if (file.Name.EndsWith (".exe", StringComparison.InvariantCultureIgnoreCase) + if (file.Name.HasExtension (".exe") && (0x5A4D == (signature & 0xFFFF))) // 'MZ' { base_offset = SkipExeData (index_file); signature = index_file.View.ReadUInt32 (base_offset); } - else if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + else if (!file.Name.HasExtension (".dat")) { return null; } diff --git a/ArcFormats/MangaGamer/ArcMGPK.cs b/ArcFormats/MangaGamer/ArcMGPK.cs index 01296f67..2e5d17f9 100644 --- a/ArcFormats/MangaGamer/ArcMGPK.cs +++ b/ArcFormats/MangaGamer/ArcMGPK.cs @@ -87,9 +87,7 @@ namespace GameRes.Formats.Mg entry.Size = file.View.ReadUInt32 (cur_offset+0x24); if (!entry.CheckPlacement (file.MaxOffset)) return null; - has_encrypted = has_encrypted - || name.EndsWith (".png", StringComparison.InvariantCultureIgnoreCase) - || name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase); + has_encrypted = has_encrypted || name.HasAnyOfExtensions ("png", "txt"); dir.Add (entry); cur_offset += 0x30; } @@ -113,7 +111,7 @@ namespace GameRes.Formats.Mg byte[] data = new byte[entry.Size]; input.Read (data, 0, data.Length); data = DecryptBlock (data, mgarc.Key); - if (entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension ("txt")) return DecompressStream (data); return new BinMemoryStream (data, entry.Name); } diff --git a/ArcFormats/Mixwill/ArcARC0.cs b/ArcFormats/Mixwill/ArcARC0.cs index c3e767af..b12961dc 100644 --- a/ArcFormats/Mixwill/ArcARC0.cs +++ b/ArcFormats/Mixwill/ArcARC0.cs @@ -81,7 +81,7 @@ namespace GameRes.Formats.Mixwill public override Stream OpenEntry (ArcFile arc, Entry entry) { uint encrypted_size = entry.Size; - if (!entry.Name.EndsWith (".txt", StringComparison.InvariantCultureIgnoreCase) + if (!entry.Name.HasExtension (".txt") && encrypted_size > 0x100) encrypted_size = 0x100; var prefix = arc.File.View.ReadBytes (entry.Offset, encrypted_size); diff --git a/ArcFormats/Moonhir/ArcFPK.cs b/ArcFormats/Moonhir/ArcFPK.cs index babef05e..11cdae9e 100644 --- a/ArcFormats/Moonhir/ArcFPK.cs +++ b/ArcFormats/Moonhir/ArcFPK.cs @@ -92,7 +92,7 @@ namespace GameRes.Formats.MoonhirGames entry.Size = file.View.ReadUInt32 (index_offset+8); if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".fbx", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".fbx")) entry.Type = "image"; has_encrypted = has_encrypted || entry.IsEncrypted; dir.Add (entry); diff --git a/ArcFormats/Musica/ArcPAZ.cs b/ArcFormats/Musica/ArcPAZ.cs index 433dbd8c..99868499 100644 --- a/ArcFormats/Musica/ArcPAZ.cs +++ b/ArcFormats/Musica/ArcPAZ.cs @@ -169,7 +169,7 @@ namespace GameRes.Formats.Musica public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".paz", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".paz")) return null; uint signature = file.View.ReadUInt32 (0); // XXX encryption is queried for every .paz file diff --git a/ArcFormats/NScripter/ArcNS2.cs b/ArcFormats/NScripter/ArcNS2.cs index 93ae84e4..5535f3ec 100644 --- a/ArcFormats/NScripter/ArcNS2.cs +++ b/ArcFormats/NScripter/ArcNS2.cs @@ -68,7 +68,7 @@ namespace GameRes.Formats.NScripter } catch { /* ignore parse errors */ } } - if (!file.Name.EndsWith (".ns2", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".ns2")) return null; var password = QueryPassword(); diff --git a/ArcFormats/NScripter/ArcNSA.cs b/ArcFormats/NScripter/ArcNSA.cs index f7d2832d..58a26094 100644 --- a/ArcFormats/NScripter/ArcNSA.cs +++ b/ArcFormats/NScripter/ArcNSA.cs @@ -105,7 +105,7 @@ namespace GameRes.Formats.NScripter } } catch { /* ignore parse errors */ } - if (zero_signature || !file.Name.EndsWith (".nsa", StringComparison.InvariantCultureIgnoreCase)) + if (zero_signature || !file.Name.HasExtension (".nsa")) return null; var password = QueryPassword(); @@ -251,7 +251,7 @@ namespace GameRes.Formats.NScripter var header_entry = new NsaEntry { Name = entry.Name }; if (Compression.None != ons_options.CompressionType) { - if (entry.Name.EndsWith (".bmp", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension (".bmp")) header_entry.CompressionType = ons_options.CompressionType; } index_size += 13; diff --git a/ArcFormats/NSystem/ArcFJSYS.cs b/ArcFormats/NSystem/ArcFJSYS.cs index 446277df..b9458aa4 100644 --- a/ArcFormats/NSystem/ArcFJSYS.cs +++ b/ArcFormats/NSystem/ArcFJSYS.cs @@ -83,7 +83,7 @@ namespace GameRes.Formats.NSystem entry.Offset = file.View.ReadInt64 (index_offset+8); if (!entry.CheckPlacement (file.MaxOffset)) return null; - has_scripts = has_scripts || name.EndsWith (".msd", StringComparison.InvariantCultureIgnoreCase); + has_scripts = has_scripts || name.HasExtension (".msd"); dir.Add (entry); index_offset += 0x10; } @@ -100,7 +100,7 @@ namespace GameRes.Formats.NSystem { var msarc = arc as MsdArchive; 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 ")) return base.OpenEntry (arc, entry); var input = arc.File.CreateStream (entry.Offset, entry.Size); diff --git a/ArcFormats/Nags/ArcNFS.cs b/ArcFormats/Nags/ArcNFS.cs index 653c9ac0..33c8adf2 100644 --- a/ArcFormats/Nags/ArcNFS.cs +++ b/ArcFormats/Nags/ArcNFS.cs @@ -82,7 +82,7 @@ namespace GameRes.Formats.Nags public override Stream OpenEntry (ArcFile arc, Entry entry) { var input = arc.File.CreateStream (entry.Offset, entry.Size); - if (!entry.Name.EndsWith (".scb", StringComparison.InvariantCultureIgnoreCase)) + if (!entry.Name.HasExtension (".scb")) return input; return new InputCryptoStream (input, new NotTransform()); } diff --git a/ArcFormats/Nejii/ArcPCD.cs b/ArcFormats/Nejii/ArcPCD.cs index 009c337f..7ba49a38 100644 --- a/ArcFormats/Nejii/ArcPCD.cs +++ b/ArcFormats/Nejii/ArcPCD.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Nejii 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; // check if first entry looks like WAVEFORMAT ushort channels = file.View.ReadUInt16 (0x12); diff --git a/ArcFormats/NekoSDK/ArcPAK.cs b/ArcFormats/NekoSDK/ArcPAK.cs index 033657f5..e6730e75 100644 --- a/ArcFormats/NekoSDK/ArcPAK.cs +++ b/ArcFormats/NekoSDK/ArcPAK.cs @@ -87,7 +87,7 @@ namespace GameRes.Formats.NekoSDK entry.Size = file.View.ReadUInt32 (index_offset+4) ^ (uint)key; if (!entry.CheckPlacement (file.MaxOffset)) return null; - if (name.EndsWith (".alp", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".alp")) entry.Type = ""; dir.Add (entry); index_offset += 8; diff --git a/ArcFormats/NonColor/ArcDAT.cs b/ArcFormats/NonColor/ArcDAT.cs index db12e7df..0e225e2c 100644 --- a/ArcFormats/NonColor/ArcDAT.cs +++ b/ArcFormats/NonColor/ArcDAT.cs @@ -101,7 +101,7 @@ namespace GameRes.Formats.NonColor public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".dat")) return null; int count = file.View.ReadInt32 (0) ^ 0x26ACA46E; if (!IsSaneCount (count)) diff --git a/ArcFormats/Propeller/ArcMGR.cs b/ArcFormats/Propeller/ArcMGR.cs index 1525d7ae..261af6c7 100644 --- a/ArcFormats/Propeller/ArcMGR.cs +++ b/ArcFormats/Propeller/ArcMGR.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.Propeller public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".mgr", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".mgr")) return null; int count = file.View.ReadInt16 (0); if (count <= 0 || count >= 0x100) diff --git a/ArcFormats/Propeller/ArcMPK.cs b/ArcFormats/Propeller/ArcMPK.cs index 458da5ba..399d9f16 100644 --- a/ArcFormats/Propeller/ArcMPK.cs +++ b/ArcFormats/Propeller/ArcMPK.cs @@ -77,7 +77,7 @@ namespace GameRes.Formats.Propeller public override Stream OpenEntry (ArcFile arc, Entry entry) { var input = arc.File.CreateStream (entry.Offset, entry.Size); - if (!entry.Name.EndsWith (".msc", StringComparison.InvariantCultureIgnoreCase) + if (!entry.Name.HasExtension (".msc") || 0x88 != input.PeekByte()) return input; return new XoredStream (input, 0x88); diff --git a/ArcFormats/RPM/ArcARC.cs b/ArcFormats/RPM/ArcARC.cs index f695ded5..b0bb8c1b 100644 --- a/ArcFormats/RPM/ArcARC.cs +++ b/ArcFormats/RPM/ArcARC.cs @@ -94,7 +94,7 @@ namespace GameRes.Formats.Rpm return null; var scheme = GuessScheme (file, count); // 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(); if (null == scheme) return null; diff --git a/ArcFormats/RealLive/ArcG00.cs b/ArcFormats/RealLive/ArcG00.cs index bfef3d1e..0ab02113 100644 --- a/ArcFormats/RealLive/ArcG00.cs +++ b/ArcFormats/RealLive/ArcG00.cs @@ -68,7 +68,7 @@ namespace GameRes.Formats.RealLive public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".g00", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".g00")) return null; if (file.View.ReadByte (0) != 2) return null; diff --git a/ArcFormats/RealLive/ArcOVK.cs b/ArcFormats/RealLive/ArcOVK.cs index 432147ea..f7f2b26c 100644 --- a/ArcFormats/RealLive/ArcOVK.cs +++ b/ArcFormats/RealLive/ArcOVK.cs @@ -41,7 +41,7 @@ namespace GameRes.Formats.RealLive public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".ovk", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".ovk")) return null; int count = file.View.ReadInt32 (0); if (!IsSaneCount (count)) diff --git a/ArcFormats/RiddleSoft/ArcPAC.cs b/ArcFormats/RiddleSoft/ArcPAC.cs index 026eaa1f..6bf0e122 100644 --- a/ArcFormats/RiddleSoft/ArcPAC.cs +++ b/ArcFormats/RiddleSoft/ArcPAC.cs @@ -57,7 +57,7 @@ namespace GameRes.Formats.Riddle string name = file.View.ReadString (index_offset, 0x10); uint size = file.View.ReadUInt32 (index_offset+0x10); var entry = new PackedEntry { Name = name }; - if (name.EndsWith (".scp", StringComparison.InvariantCultureIgnoreCase)) + if (name.HasExtension (".scp")) { entry.Type = "script"; entry.IsPacked = size > 12 && file.View.AsciiEqual (index_offset+0x14, "CMP1"); diff --git a/ArcFormats/Silky/ArcAWF.cs b/ArcFormats/Silky/ArcAWF.cs index 036f1c10..5ea77a15 100644 --- a/ArcFormats/Silky/ArcAWF.cs +++ b/ArcFormats/Silky/ArcAWF.cs @@ -43,7 +43,7 @@ namespace GameRes.Formats.Silky public override ArcFile TryOpen (ArcView file) { // enforce extension to avoid false positives - if (!file.Name.EndsWith (".awf", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".awf")) return null; int count = file.View.ReadInt32 (0); if (!IsSaneCount (count)) @@ -74,7 +74,7 @@ namespace GameRes.Formats.Silky 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); // prepend WAV header var header = new byte[0x2C]; diff --git a/ArcFormats/Silky/ArcAzurite.cs b/ArcFormats/Silky/ArcAzurite.cs index dae514c7..7e1170d2 100644 --- a/ArcFormats/Silky/ArcAzurite.cs +++ b/ArcFormats/Silky/ArcAzurite.cs @@ -41,7 +41,7 @@ namespace GameRes.Formats.Silky public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".arc", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".arc")) return null; uint index_size = file.View.ReadUInt32 (0); if (index_size < 10 || index_size >= file.MaxOffset-4) diff --git a/ArcFormats/Silky/ArcIFL.cs b/ArcFormats/Silky/ArcIFL.cs index a7d4f5b5..218dbe88 100644 --- a/ArcFormats/Silky/ArcIFL.cs +++ b/ArcFormats/Silky/ArcIFL.cs @@ -69,7 +69,7 @@ namespace GameRes.Formats.Silky public override Stream OpenEntry (ArcFile arc, Entry entry) { if (entry.Size <= 8 - || !entry.Name.EndsWith (".snc", StringComparison.InvariantCultureIgnoreCase) + || !entry.Name.HasExtension (".snc") || !arc.File.View.AsciiEqual (entry.Offset, "CMP_")) return arc.File.CreateStream (entry.Offset, entry.Size); int unpacked_size = arc.File.View.ReadInt32 (entry.Offset+4); diff --git a/ArcFormats/TopCat/ArcTCD3.cs b/ArcFormats/TopCat/ArcTCD3.cs index a4175ae1..401295fa 100644 --- a/ArcFormats/TopCat/ArcTCD3.cs +++ b/ArcFormats/TopCat/ArcTCD3.cs @@ -115,12 +115,11 @@ namespace GameRes.Formats.TopCat public override Stream OpenEntry (ArcFile arc, Entry entry) { - if (entry.Name.EndsWith (".OGG", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension (".OGG")) return RestoreOggStream (arc, entry); - if (entry.Name.EndsWith (".TSF", StringComparison.InvariantCultureIgnoreCase) || - entry.Name.EndsWith (".TCT", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasAnyOfExtensions (".TSF", ".TCT")) return OpenScript (arc, entry); - if (entry.Name.EndsWith (".SPD", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasExtension (".SPD")) return OpenSpdc (arc, entry); return base.OpenEntry (arc, entry); } diff --git a/ArcFormats/Triangle/ArcCGF.cs b/ArcFormats/Triangle/ArcCGF.cs index 1109b432..e8d6f61d 100644 --- a/ArcFormats/Triangle/ArcCGF.cs +++ b/ArcFormats/Triangle/ArcCGF.cs @@ -78,7 +78,7 @@ namespace GameRes.Formats.Triangle var name = file.View.ReadString (index_offset, entry_size-4); uint flags = next_offset >> 30; Entry entry; - if (1 == flags || name.EndsWith (".iaf", StringComparison.InvariantCultureIgnoreCase)) + if (1 == flags || name.HasExtension (".iaf")) entry = new Entry(); else entry = new CgfEntry { Flags = flags }; diff --git a/ArcFormats/Triangle/ArcIAF.cs b/ArcFormats/Triangle/ArcIAF.cs index 3646a483..b8df51fd 100644 --- a/ArcFormats/Triangle/ArcIAF.cs +++ b/ArcFormats/Triangle/ArcIAF.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Triangle public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".iaf", StringComparison.InvariantCultureIgnoreCase) + if (!file.Name.HasExtension (".iaf") || file.MaxOffset < 0x20) return null; uint size = file.View.ReadUInt32 (1); diff --git a/ArcFormats/UMeSoft/ArcPK.cs b/ArcFormats/UMeSoft/ArcPK.cs index 3d0294f2..b213a1cf 100644 --- a/ArcFormats/UMeSoft/ArcPK.cs +++ b/ArcFormats/UMeSoft/ArcPK.cs @@ -83,8 +83,7 @@ namespace GameRes.Formats.UMeSoft public override Stream OpenEntry (ArcFile arc, Entry entry) { - if (!entry.Name.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) && - !entry.Name.EndsWith (".tbl", StringComparison.InvariantCultureIgnoreCase)) + if (!entry.Name.HasAnyOfExtensions ("scr", "tbl")) return base.OpenEntry (arc, entry); int output_size = arc.File.View.ReadInt32 (entry.Offset); if (output_size <= 0) diff --git a/ArcFormats/Valkyria/ArcODN.cs b/ArcFormats/Valkyria/ArcODN.cs index e332342e..0c44068a 100644 --- a/ArcFormats/Valkyria/ArcODN.cs +++ b/ArcFormats/Valkyria/ArcODN.cs @@ -65,7 +65,7 @@ namespace GameRes.Formats.Valkyria public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".odn", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".odn")) return null; var reader = new OdnIndexReader (file); var dir = reader.ReadIndex(); diff --git a/ArcFormats/Will/ArcPulltop.cs b/ArcFormats/Will/ArcPulltop.cs index c885d8f2..5d0dad4c 100644 --- a/ArcFormats/Will/ArcPulltop.cs +++ b/ArcFormats/Will/ArcPulltop.cs @@ -97,7 +97,7 @@ namespace GameRes.Formats.Will public override Stream OpenEntry (ArcFile arc, Entry entry) { - if (!entry.Name.EndsWith (".ws2", StringComparison.InvariantCultureIgnoreCase)) + if (!IsScriptFile (entry.Name)) return base.OpenEntry (arc, entry); var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); for (int i = 0; i < data.Length; ++i) @@ -107,6 +107,11 @@ namespace GameRes.Formats.Will return new BinMemoryStream (data, entry.Name); } + static bool IsScriptFile (string name) + { + return name.HasAnyOfExtensions ("ws2", "json"); + } + public override void Create (Stream output, IEnumerable list, ResourceOptions options, EntryCallback callback) { @@ -132,7 +137,7 @@ namespace GameRes.Formats.Will var size = input.Length; if (size > uint.MaxValue || current_offset + size > uint.MaxValue) throw new FileSizeException(); - if (entry.Name.EndsWith (".ws2", StringComparison.InvariantCultureIgnoreCase)) + if (IsScriptFile (entry.Name)) CopyScript (input, output); else input.CopyTo (output); diff --git a/ArcFormats/Will/ArcWILL.cs b/ArcFormats/Will/ArcWILL.cs index 871178c8..3398eaef 100644 --- a/ArcFormats/Will/ArcWILL.cs +++ b/ArcFormats/Will/ArcWILL.cs @@ -275,8 +275,7 @@ namespace GameRes.Formats.Will private static bool IsScriptFile (string filename) { - return filename.EndsWith (".scr", StringComparison.InvariantCultureIgnoreCase) - || filename.EndsWith (".wsc", StringComparison.InvariantCultureIgnoreCase); + return filename.HasAnyOfExtensions ("scr", "wsc"); } } } diff --git a/ArcFormats/Will/ImageWIP.cs b/ArcFormats/Will/ImageWIP.cs index 2e682a1c..711846dc 100644 --- a/ArcFormats/Will/ImageWIP.cs +++ b/ArcFormats/Will/ImageWIP.cs @@ -95,7 +95,7 @@ namespace GameRes.Formats.Will if (24 == meta.BPP) { 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"); if (VFS.FileExists (mask_name)) diff --git a/ArcFormats/Yatagarasu/ArcPKG.cs b/ArcFormats/Yatagarasu/ArcPKG.cs index 06540ebf..5a93da07 100644 --- a/ArcFormats/Yatagarasu/ArcPKG.cs +++ b/ArcFormats/Yatagarasu/ArcPKG.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.Yatagarasu public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".pkg", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".pkg")) return null; 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 diff --git a/ArcFormats/Youkai/ArcDAT.cs b/ArcFormats/Youkai/ArcDAT.cs index 81fff414..d99b9b3a 100644 --- a/ArcFormats/Youkai/ArcDAT.cs +++ b/ArcFormats/Youkai/ArcDAT.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.Youkai public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".dat")) return null; int count = file.View.ReadInt32 (0); if (!IsSaneCount (count) || 0 != file.View.ReadInt32 (4)) @@ -91,7 +91,7 @@ namespace GameRes.Formats.Youkai public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".dat")) return null; int count = file.View.ReadInt32 (0); if (!IsSaneCount (count)) @@ -132,7 +132,7 @@ namespace GameRes.Formats.Youkai public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".dat")) return null; uint data_offset = file.View.ReadUInt32 (0); int count = file.View.ReadInt32 (4); diff --git a/ArcFormats/YuRis/ArcYPF.cs b/ArcFormats/YuRis/ArcYPF.cs index 41d17413..24316612 100644 --- a/ArcFormats/YuRis/ArcYPF.cs +++ b/ArcFormats/YuRis/ArcYPF.cs @@ -143,7 +143,7 @@ namespace GameRes.Formats.YuRis input = new ZLibStream (input, CompressionMode.Decompress); uint unpacked_size = null == packed_entry ? entry.Size : packed_entry.UnpackedSize; if (null == ypf || 0 == ypf.ScriptKey || unpacked_size <= 0x20 - || !entry.Name.EndsWith (".ybn", StringComparison.InvariantCultureIgnoreCase)) + || !entry.Name.HasExtension (".ybn")) return input; using (input) { diff --git a/ArcFormats/Yuka/ArcYKC.cs b/ArcFormats/Yuka/ArcYKC.cs index 99bdd42f..a5a0cb52 100644 --- a/ArcFormats/Yuka/ArcYKC.cs +++ b/ArcFormats/Yuka/ArcYKC.cs @@ -90,7 +90,7 @@ namespace GameRes.Formats.Yuka public override Stream OpenEntry (ArcFile arc, Entry entry) { if (entry.Size < 0x24 - || !entry.Name.EndsWith (".yks", StringComparison.InvariantCultureIgnoreCase) + || !entry.Name.HasExtension (".yks") || !arc.File.View.AsciiEqual (entry.Offset, "YKS001") || 1 != arc.File.View.ReadUInt16 (entry.Offset+6)) return base.OpenEntry (arc, entry); diff --git a/ArcFormats/elf/ArcAi5Win.cs b/ArcFormats/elf/ArcAi5Win.cs index 3ea2e343..73ea0f05 100644 --- a/ArcFormats/elf/ArcAi5Win.cs +++ b/ArcFormats/elf/ArcAi5Win.cs @@ -94,8 +94,7 @@ namespace GameRes.Formats.Elf public override Stream OpenEntry (ArcFile arc, Entry entry) { var input = arc.File.CreateStream (entry.Offset, entry.Size); - if (entry.Name.EndsWith (".mes", StringComparison.InvariantCultureIgnoreCase) - || entry.Name.EndsWith (".lib", StringComparison.InvariantCultureIgnoreCase)) + if (entry.Name.HasAnyOfExtensions ("mes", "lib")) return new LzssStream (input); return input; } diff --git a/ArcFormats/elf/ArcVOL.cs b/ArcFormats/elf/ArcVOL.cs index 7c9420d7..814de0b1 100644 --- a/ArcFormats/elf/ArcVOL.cs +++ b/ArcFormats/elf/ArcVOL.cs @@ -46,7 +46,7 @@ namespace GameRes.Formats.Elf public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".vol", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".vol")) return null; uint first_offset = file.View.ReadUInt32 (0); if (first_offset < 0x10 || 0 != (first_offset & 0xF) || first_offset >= file.MaxOffset) diff --git a/ArcFormats/rUGP/ArcRIO.cs b/ArcFormats/rUGP/ArcRIO.cs index 3542e002..e6686a65 100644 --- a/ArcFormats/rUGP/ArcRIO.cs +++ b/ArcFormats/rUGP/ArcRIO.cs @@ -115,7 +115,7 @@ namespace GameRes.Formats.Rugp if (CRioArchive.RioSignature == file.View.ReadUInt32 (0)) return new RioReader (file); - if (file.Name.EndsWith (".ici", StringComparison.InvariantCultureIgnoreCase)) + if (file.Name.HasExtension (".ici")) return null; var ici_name = file.Name + ".ici"; if (!VFS.FileExists (ici_name)) diff --git a/ArcFormats/uGOS/ArcDET.cs b/ArcFormats/uGOS/ArcDET.cs index b4445e94..64ce06db 100644 --- a/ArcFormats/uGOS/ArcDET.cs +++ b/ArcFormats/uGOS/ArcDET.cs @@ -42,7 +42,7 @@ namespace GameRes.Formats.uGOS public override ArcFile TryOpen (ArcView file) { - if (!file.Name.EndsWith (".det", StringComparison.InvariantCultureIgnoreCase)) + if (!file.Name.HasExtension (".det")) return null; var name_file = Path.ChangeExtension (file.Name, "nme"); var index_file = Path.ChangeExtension (file.Name, "atm"); diff --git a/Experimental/CellWorks/ArcDB.cs b/Experimental/CellWorks/ArcDB.cs index ca613368..8e7c8009 100644 --- a/Experimental/CellWorks/ArcDB.cs +++ b/Experimental/CellWorks/ArcDB.cs @@ -47,7 +47,7 @@ namespace GameRes.Formats.CellWorks public override ArcFile TryOpen (ArcView file) { - if (VFS.IsVirtual || !file.Name.EndsWith (".dat", StringComparison.InvariantCultureIgnoreCase)) + if (VFS.IsVirtual || !file.Name.HasExtension (".dat")) return null; var db_files = VFS.GetFiles (VFS.CombinePath (VFS.GetDirectoryName (file.Name), "*.db")); if (!db_files.Any())