From 8a53d74d5e4bcffacb32d6c6ecf98568b48843d8 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 22 Aug 2014 10:13:37 +0400 Subject: [PATCH] use invariant case conversion methods. --- GameRes/ArcFile.cs | 4 ++-- GameRes/GameRes.cs | 12 ++++++------ ImagePreview.cs | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/GameRes/ArcFile.cs b/GameRes/ArcFile.cs index f15eea8f..e198bd4c 100644 --- a/GameRes/ArcFile.cs +++ b/GameRes/ArcFile.cs @@ -64,7 +64,7 @@ namespace GameRes /// public static ArcFile TryOpen (string filename) { - var ext = new Lazy (() => Path.GetExtension (filename).TrimStart ('.').ToLower()); + var ext = new Lazy (() => Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant()); var file = new ArcView (filename); try { @@ -74,7 +74,7 @@ namespace GameRes var range = FormatCatalog.Instance.LookupSignature (signature); // check formats that match filename extension first 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) { try diff --git a/GameRes/GameRes.cs b/GameRes/GameRes.cs index 0dcc244f..04db1c9e 100644 --- a/GameRes/GameRes.cs +++ b/GameRes/GameRes.cs @@ -109,7 +109,7 @@ namespace GameRes protected IResource () { - m_extensions = new string[] { Tag.ToLower() }; + m_extensions = new string[] { Tag.ToLowerInvariant() }; m_signatures = new uint[] { Signature }; } } @@ -309,7 +309,7 @@ namespace GameRes { 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) { @@ -325,14 +325,14 @@ namespace GameRes public IEnumerable LookupFileName (string filename) { string ext = Path.GetExtension (filename); - if (null == ext) + if (string.IsNullOrEmpty (ext)) return new IResource[0]; return LookupExtension (ext.TrimStart ('.')); } public IEnumerable LookupExtension (string ext) { - return m_extension_map.GetValues (ext.ToUpper(), true); + return m_extension_map.GetValues (ext.ToUpperInvariant(), true); } public IEnumerable LookupExtension (string ext) where Type : IResource @@ -357,9 +357,9 @@ namespace GameRes { Entry entry = null; 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); if (null != range) entry = range.First().CreateEntry(); diff --git a/ImagePreview.cs b/ImagePreview.cs index 5d8fcd28..5eb2b6c5 100644 --- a/ImagePreview.cs +++ b/ImagePreview.cs @@ -189,7 +189,7 @@ namespace GARbro.GUI { 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)) { // source extension matches target image format, copy file as is @@ -201,9 +201,7 @@ namespace GARbro.GUI if (null == image) throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpret, entry.Name)); string target_ext = target_format.Extensions.First(); - string outdir = Path.GetDirectoryName (entry.Name); - string outname = Path.GetFileNameWithoutExtension (entry.Name)+'.'+target_ext; - outname = Path.Combine (outdir, outname); + string outname = Path.ChangeExtension (entry.Name, target_ext); Trace.WriteLine (string.Format ("{0} => {1}", entry.Name, outname), "ExtractImage"); using (var outfile = arc.CreateFile (new Entry { Name = outname })) {