use ResourceInstance for formats instantiation.

This commit is contained in:
morkt 2017-04-08 19:23:46 +04:00
parent 3b74dae09f
commit 20cf6c191b
3 changed files with 16 additions and 15 deletions

View File

@ -138,6 +138,6 @@ namespace GameRes.Formats
public static AudioFormat Instance { get { return s_OggFormat.Value; } } public static AudioFormat Instance { get { return s_OggFormat.Value; } }
static readonly Lazy<AudioFormat> s_OggFormat = new Lazy<AudioFormat> (() => FormatCatalog.Instance.AudioFormats.FirstOrDefault (x => x.Tag == "OGG")); static readonly ResourceInstance<AudioFormat> s_OggFormat = new ResourceInstance<AudioFormat> ("OGG");
} }
} }

View File

@ -100,19 +100,16 @@ namespace GameRes.Formats.MAI
return null; return null;
var offset = file.View.ReadUInt32 (index_offset+0x10); var offset = file.View.ReadUInt32 (index_offset+0x10);
var entry = new AutoEntry (Path.Combine (current_folder, name), () => { var entry = new AutoEntry (Path.Combine (current_folder, name), () => {
uint signature = file.View.ReadUInt32 (offset);
if (is_mask_arc) if (is_mask_arc)
return ImageFormat.FindByTag ("MSK/MAI"); return s_MskFormat.Value;
else if (0x4d43 == (signature & 0xffff)) // 'CM' uint signature = file.View.ReadUInt32 (offset);
return ImageFormat.FindByTag ("CM/MAI"); switch (signature & 0xFFFF)
else if (0x4d41 == (signature & 0xffff)) // 'AM' {
return ImageFormat.FindByTag ("AM/MAI"); case 0x4D43: return s_CmFormat.Value;
else if (0x4d42 == (signature & 0xffff)) // 'BM' case 0x4D41: return s_AmFormat.Value;
return ImageFormat.Bmp; case 0x4D42: return ImageFormat.Bmp;
else if (signature != 0) default: return AutoEntry.DetectFileType (signature);
return FormatCatalog.Instance.LookupSignature (signature).FirstOrDefault(); }
else
return null;
}); });
entry.Offset = offset; entry.Offset = offset;
entry.Size = file.View.ReadUInt32 (index_offset+0x14); entry.Size = file.View.ReadUInt32 (index_offset+0x14);
@ -123,5 +120,9 @@ namespace GameRes.Formats.MAI
} }
return new ArcFile (file, this, dir); return new ArcFile (file, this, dir);
} }
static readonly ResourceInstance<ImageFormat> s_AmFormat = new ResourceInstance<ImageFormat> ("AM/MAI");
static readonly ResourceInstance<ImageFormat> s_CmFormat = new ResourceInstance<ImageFormat> ("CM/MAI");
static readonly ResourceInstance<ImageFormat> s_MskFormat = new ResourceInstance<ImageFormat> ("MSK/MAI");
} }
} }

View File

@ -152,7 +152,7 @@ namespace GameRes.Formats.Majiro
return ImageData.Create (meta, PixelFormats.Bgr24, null, pixels, (int)meta.Width*3); return ImageData.Create (meta, PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
} }
static readonly Lazy<ImageFormat> s_rc8_format = new Lazy<ImageFormat> (() => FindByTag ("RC8")); static readonly ResourceInstance<ImageFormat> s_rc8_format = new ResourceInstance<ImageFormat> ("RC8");
ImageData ApplyMaskToImage (RctMetaData info, byte[] image, string mask_name) ImageData ApplyMaskToImage (RctMetaData info, byte[] image, string mask_name)
{ {
@ -298,7 +298,7 @@ namespace GameRes.Formats.Majiro
return options.Password; return options.Password;
} }
static readonly Lazy<ArchiveFormat> s_Majiro = new Lazy<ArchiveFormat> (() => FormatCatalog.Instance.ArcFormats.FirstOrDefault (x => x.Tag == "MAJIRO")); static readonly ResourceInstance<ArchiveFormat> s_Majiro = new ResourceInstance<ArchiveFormat> ("MAJIRO");
private string FindImageKey () private string FindImageKey ()
{ {