From 20cf6c191b0ac906a8eab73d2e999e24a407941a Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 8 Apr 2017 19:23:46 +0400 Subject: [PATCH] use ResourceInstance for formats instantiation. --- ArcFormats/AudioOGG.cs | 2 +- ArcFormats/MAI/ArcMAI.cs | 25 +++++++++++++------------ ArcFormats/Majiro/ImageRCT.cs | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ArcFormats/AudioOGG.cs b/ArcFormats/AudioOGG.cs index 63bbe1db..a332ff3a 100644 --- a/ArcFormats/AudioOGG.cs +++ b/ArcFormats/AudioOGG.cs @@ -138,6 +138,6 @@ namespace GameRes.Formats public static AudioFormat Instance { get { return s_OggFormat.Value; } } - static readonly Lazy s_OggFormat = new Lazy (() => FormatCatalog.Instance.AudioFormats.FirstOrDefault (x => x.Tag == "OGG")); + static readonly ResourceInstance s_OggFormat = new ResourceInstance ("OGG"); } } diff --git a/ArcFormats/MAI/ArcMAI.cs b/ArcFormats/MAI/ArcMAI.cs index 68e6056e..ea0c1701 100644 --- a/ArcFormats/MAI/ArcMAI.cs +++ b/ArcFormats/MAI/ArcMAI.cs @@ -100,19 +100,16 @@ namespace GameRes.Formats.MAI return null; var offset = file.View.ReadUInt32 (index_offset+0x10); var entry = new AutoEntry (Path.Combine (current_folder, name), () => { - uint signature = file.View.ReadUInt32 (offset); if (is_mask_arc) - return ImageFormat.FindByTag ("MSK/MAI"); - else if (0x4d43 == (signature & 0xffff)) // 'CM' - return ImageFormat.FindByTag ("CM/MAI"); - else if (0x4d41 == (signature & 0xffff)) // 'AM' - return ImageFormat.FindByTag ("AM/MAI"); - else if (0x4d42 == (signature & 0xffff)) // 'BM' - return ImageFormat.Bmp; - else if (signature != 0) - return FormatCatalog.Instance.LookupSignature (signature).FirstOrDefault(); - else - return null; + return s_MskFormat.Value; + uint signature = file.View.ReadUInt32 (offset); + switch (signature & 0xFFFF) + { + case 0x4D43: return s_CmFormat.Value; + case 0x4D41: return s_AmFormat.Value; + case 0x4D42: return ImageFormat.Bmp; + default: return AutoEntry.DetectFileType (signature); + } }); entry.Offset = offset; entry.Size = file.View.ReadUInt32 (index_offset+0x14); @@ -123,5 +120,9 @@ namespace GameRes.Formats.MAI } return new ArcFile (file, this, dir); } + + static readonly ResourceInstance s_AmFormat = new ResourceInstance ("AM/MAI"); + static readonly ResourceInstance s_CmFormat = new ResourceInstance ("CM/MAI"); + static readonly ResourceInstance s_MskFormat = new ResourceInstance ("MSK/MAI"); } } diff --git a/ArcFormats/Majiro/ImageRCT.cs b/ArcFormats/Majiro/ImageRCT.cs index 45a92190..79d1454b 100644 --- a/ArcFormats/Majiro/ImageRCT.cs +++ b/ArcFormats/Majiro/ImageRCT.cs @@ -152,7 +152,7 @@ namespace GameRes.Formats.Majiro return ImageData.Create (meta, PixelFormats.Bgr24, null, pixels, (int)meta.Width*3); } - static readonly Lazy s_rc8_format = new Lazy (() => FindByTag ("RC8")); + static readonly ResourceInstance s_rc8_format = new ResourceInstance ("RC8"); ImageData ApplyMaskToImage (RctMetaData info, byte[] image, string mask_name) { @@ -298,7 +298,7 @@ namespace GameRes.Formats.Majiro return options.Password; } - static readonly Lazy s_Majiro = new Lazy (() => FormatCatalog.Instance.ArcFormats.FirstOrDefault (x => x.Tag == "MAJIRO")); + static readonly ResourceInstance s_Majiro = new ResourceInstance ("MAJIRO"); private string FindImageKey () {