use invariant case conversion methods.

This commit is contained in:
morkt 2014-08-22 10:13:37 +04:00
parent dc9f0ebb44
commit 8a53d74d5e
3 changed files with 10 additions and 12 deletions

View File

@ -64,7 +64,7 @@ namespace GameRes
/// </returns> /// </returns>
public static ArcFile TryOpen (string filename) public static ArcFile TryOpen (string filename)
{ {
var ext = new Lazy<string> (() => Path.GetExtension (filename).TrimStart ('.').ToLower()); var ext = new Lazy<string> (() => Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant());
var file = new ArcView (filename); var file = new ArcView (filename);
try try
{ {
@ -74,7 +74,7 @@ namespace GameRes
var range = FormatCatalog.Instance.LookupSignature<ArchiveFormat> (signature); var range = FormatCatalog.Instance.LookupSignature<ArchiveFormat> (signature);
// check formats that match filename extension first // check formats that match filename extension first
if (range.Skip(1).Any()) // if range.Count() > 1 if (range.Skip(1).Any()) // if range.Count() > 1
range = range.OrderByDescending (f => f.Extensions.First() == ext.Value); range = range.OrderByDescending (f => f.Extensions.Any() && f.Extensions.First() == ext.Value);
foreach (var impl in range) foreach (var impl in range)
{ {
try try

View File

@ -109,7 +109,7 @@ namespace GameRes
protected IResource () protected IResource ()
{ {
m_extensions = new string[] { Tag.ToLower() }; m_extensions = new string[] { Tag.ToLowerInvariant() };
m_signatures = new uint[] { Signature }; m_signatures = new uint[] { Signature };
} }
} }
@ -309,7 +309,7 @@ namespace GameRes
{ {
foreach (var ext in impl.Extensions) foreach (var ext in impl.Extensions)
{ {
m_extension_map.Add (ext.ToUpper(), impl); m_extension_map.Add (ext.ToUpperInvariant(), impl);
} }
foreach (var signature in impl.Signatures) foreach (var signature in impl.Signatures)
{ {
@ -325,14 +325,14 @@ namespace GameRes
public IEnumerable<IResource> LookupFileName (string filename) public IEnumerable<IResource> LookupFileName (string filename)
{ {
string ext = Path.GetExtension (filename); string ext = Path.GetExtension (filename);
if (null == ext) if (string.IsNullOrEmpty (ext))
return new IResource[0]; return new IResource[0];
return LookupExtension (ext.TrimStart ('.')); return LookupExtension (ext.TrimStart ('.'));
} }
public IEnumerable<IResource> LookupExtension (string ext) public IEnumerable<IResource> LookupExtension (string ext)
{ {
return m_extension_map.GetValues (ext.ToUpper(), true); return m_extension_map.GetValues (ext.ToUpperInvariant(), true);
} }
public IEnumerable<Type> LookupExtension<Type> (string ext) where Type : IResource public IEnumerable<Type> LookupExtension<Type> (string ext) where Type : IResource
@ -357,9 +357,9 @@ namespace GameRes
{ {
Entry entry = null; Entry entry = null;
string ext = Path.GetExtension (filename); string ext = Path.GetExtension (filename);
if (null != ext) if (!string.IsNullOrEmpty (ext))
{ {
ext = ext.TrimStart ('.').ToUpper(); ext = ext.TrimStart ('.').ToUpperInvariant();
var range = m_extension_map.GetValues (ext, false); var range = m_extension_map.GetValues (ext, false);
if (null != range) if (null != range)
entry = range.First().CreateEntry(); entry = range.First().CreateEntry();

View File

@ -189,7 +189,7 @@ namespace GARbro.GUI
{ {
using (var file = arc.OpenEntry (entry)) using (var file = arc.OpenEntry (entry))
{ {
string source_ext = Path.GetExtension (entry.Name).TrimStart ('.').ToLower(); string source_ext = Path.GetExtension (entry.Name).TrimStart ('.').ToLowerInvariant();
if (target_format.Extensions.Any (ext => ext == source_ext)) if (target_format.Extensions.Any (ext => ext == source_ext))
{ {
// source extension matches target image format, copy file as is // source extension matches target image format, copy file as is
@ -201,9 +201,7 @@ namespace GARbro.GUI
if (null == image) if (null == image)
throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpret, entry.Name)); throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpret, entry.Name));
string target_ext = target_format.Extensions.First(); string target_ext = target_format.Extensions.First();
string outdir = Path.GetDirectoryName (entry.Name); string outname = Path.ChangeExtension (entry.Name, target_ext);
string outname = Path.GetFileNameWithoutExtension (entry.Name)+'.'+target_ext;
outname = Path.Combine (outdir, outname);
Trace.WriteLine (string.Format ("{0} => {1}", entry.Name, outname), "ExtractImage"); Trace.WriteLine (string.Format ("{0} => {1}", entry.Name, outname), "ExtractImage");
using (var outfile = arc.CreateFile (new Entry { Name = outname })) using (var outfile = arc.CreateFile (new Entry { Name = outname }))
{ {