GameRes refactoring.

(FormatCatalog.CreateEntry): method renamed to 'Create' and made generic
towards Entry type.
This commit is contained in:
morkt
2015-08-30 22:34:06 +04:00
parent 4bfdc502e4
commit 46dbf2b142
53 changed files with 75 additions and 99 deletions

View File

@@ -103,7 +103,7 @@ namespace GameRes
private Entry EntryFromFileInfo (FileInfo file)
{
var entry = FormatCatalog.Instance.CreateEntry (file.FullName);
var entry = FormatCatalog.Instance.Create<Entry> (file.FullName);
entry.Size = (uint)Math.Min (file.Length, uint.MaxValue);
return entry;
}

View File

@@ -91,9 +91,9 @@ namespace GameRes
/// <summary>
/// Create empty Entry that corresponds to implemented resource.
/// </summary>
public virtual Entry CreateEntry ()
public EntryType Create<EntryType> () where EntryType : Entry, new()
{
return new Entry { Type = this.Type };
return new EntryType { Type = this.Type };
}
protected IResource ()
@@ -363,19 +363,14 @@ namespace GameRes
/// <exception cref="System.ArgumentException">May be thrown if filename contains invalid
/// characters.</exception>
/// </summary>
public Entry CreateEntry (string filename)
public EntryType Create<EntryType> (string filename) where EntryType : Entry, new()
{
Entry entry = null;
string ext = Path.GetExtension (filename);
if (!string.IsNullOrEmpty (ext))
{
ext = ext.TrimStart ('.').ToUpperInvariant();
var range = m_extension_map.GetValues (ext, false);
if (null != range)
entry = range.First().CreateEntry();
}
EntryType entry = null;
var formats = LookupFileName (filename);
if (formats.Any())
entry = formats.First().Create<EntryType>();
if (null == entry)
entry = new Entry();
entry = new EntryType();
entry.Name = filename;
return entry;
}

View File

@@ -173,11 +173,6 @@ namespace GameRes
return null;
}
public override Entry CreateEntry ()
{
return new ImageEntry();
}
public bool IsBuiltin
{
get { return this.GetType().Assembly == typeof(ImageFormat).Assembly; }

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("1.1.6.8")]
[assembly: AssemblyFileVersion ("1.1.6.8")]
[assembly: AssemblyVersion ("1.1.7.89")]
[assembly: AssemblyFileVersion ("1.1.7.89")]