From 1d7369a2e462a91dd610708c41bd845cd57dcd80 Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 29 Dec 2016 16:19:28 +0400 Subject: [PATCH] (VFS.IsPathEqualsToFileName): new method. --- ArcFormats/AZSys/ArcEncrypted.cs | 2 +- ArcFormats/Kaas/ArcKAAS.cs | 2 +- ArcFormats/MAI/ArcMAI.cs | 2 +- ArcFormats/RPM/ArcARC.cs | 2 +- ArcFormats/Silky/ArcAWF.cs | 2 +- ArcFormats/rUGP/ArcRIO.cs | 3 +-- GameRes/FileSystem.cs | 20 ++++++++++++++++++++ 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ArcFormats/AZSys/ArcEncrypted.cs b/ArcFormats/AZSys/ArcEncrypted.cs index 1ad23e8e..f3a21370 100644 --- a/ArcFormats/AZSys/ArcEncrypted.cs +++ b/ArcFormats/AZSys/ArcEncrypted.cs @@ -331,7 +331,7 @@ namespace GameRes.Formats.AZSys if (null != scheme.ContentKey) return scheme.ContentKey.Value; - if ("system.arc".Equals (Path.GetFileName (file.Name), StringComparison.InvariantCultureIgnoreCase)) + if (VFS.IsPathEqualsToFileName (file.Name, "system.arc")) { return ReadSysenvSeed (file, dir, scheme.IndexKey); } diff --git a/ArcFormats/Kaas/ArcKAAS.cs b/ArcFormats/Kaas/ArcKAAS.cs index 565508d6..25ba01fe 100644 --- a/ArcFormats/Kaas/ArcKAAS.cs +++ b/ArcFormats/Kaas/ArcKAAS.cs @@ -114,7 +114,7 @@ namespace GameRes.Formats.KAAS return null; var dir = new List (count); int index_offset = 0x10; - bool is_voice = Path.GetFileName (file.Name).Equals ("voice.pb", StringComparison.InvariantCultureIgnoreCase); + bool is_voice = VFS.IsPathEqualsToFileName (file.Name, "voice.pb"); int data_offset = index_offset + 8 * count; for (int i = 0; i < count; ++i) { diff --git a/ArcFormats/MAI/ArcMAI.cs b/ArcFormats/MAI/ArcMAI.cs index 964bc9f0..68e6056e 100644 --- a/ArcFormats/MAI/ArcMAI.cs +++ b/ArcFormats/MAI/ArcMAI.cs @@ -80,7 +80,7 @@ namespace GameRes.Formats.MAI dir_offset += 8; } } - bool is_mask_arc = "mask.arc" == Path.GetFileName (file.Name).ToLowerInvariant(); + bool is_mask_arc = VFS.IsPathEqualsToFileName (file.Name, "mask.arc"); var dir = new List (count); int next_folder = null == folders ? count : folders[0].Index; int folder = 0; diff --git a/ArcFormats/RPM/ArcARC.cs b/ArcFormats/RPM/ArcARC.cs index c01a2a5e..f695ded5 100644 --- a/ArcFormats/RPM/ArcARC.cs +++ b/ArcFormats/RPM/ArcARC.cs @@ -101,7 +101,7 @@ namespace GameRes.Formats.Rpm // special case for "instdata.arc" archives if (scheme.Keyword != "inst" - && Path.GetFileName (file.Name).Equals ("instdata.arc", StringComparison.InvariantCultureIgnoreCase)) + && VFS.IsPathEqualsToFileName (file.Name, "instdata.arc")) scheme = new EncryptionScheme ("inst", scheme.NameLength); int index_size = count * (scheme.NameLength + 12); diff --git a/ArcFormats/Silky/ArcAWF.cs b/ArcFormats/Silky/ArcAWF.cs index 0f9d2fe5..036f1c10 100644 --- a/ArcFormats/Silky/ArcAWF.cs +++ b/ArcFormats/Silky/ArcAWF.cs @@ -54,7 +54,7 @@ namespace GameRes.Formats.Silky return null; // rather loose criterion, haven't found anything better yet. - bool is_mp3 = Path.GetFileName (file.Name).Equals ("voice.awf", StringComparison.InvariantCultureIgnoreCase); + bool is_mp3 = VFS.IsPathEqualsToFileName (file.Name, "voice.awf"); var dir = new List (count); for (int i = 0; i < count; ++i) { diff --git a/ArcFormats/rUGP/ArcRIO.cs b/ArcFormats/rUGP/ArcRIO.cs index 9d6c3c46..3542e002 100644 --- a/ArcFormats/rUGP/ArcRIO.cs +++ b/ArcFormats/rUGP/ArcRIO.cs @@ -136,9 +136,8 @@ namespace GameRes.Formats.Rugp if (null == arc_man) return null; } - var base_name = Path.GetFileName (file.Name); var arc_object = arc_man.ArcList.FirstOrDefault(); - if (null == arc_object || !base_name.Equals (arc_object.RioName, StringComparison.InvariantCultureIgnoreCase)) + if (null == arc_object || !VFS.IsPathEqualsToFileName (file.Name, arc_object.RioName)) return null; return new RioReader (arc_man, file); } diff --git a/GameRes/FileSystem.cs b/GameRes/FileSystem.cs index 0ae9c2da..cfb6c9e2 100644 --- a/GameRes/FileSystem.cs +++ b/GameRes/FileSystem.cs @@ -783,6 +783,26 @@ namespace GameRes { return m_vfs.Top.GetFiles (pattern); } + + static readonly char[] PathSeparatorChars = { '\\', '/', ':' }; + + /// + /// Returns true if given points to a specified . + /// + public static bool IsPathEqualsToFileName (string path, string filename) + { + // first, filter out completely different paths + if (!path.EndsWith (filename, StringComparison.InvariantCultureIgnoreCase)) + return false; + // now, compare length of filename portion of the path + int filename_index = path.LastIndexOfAny (PathSeparatorChars); + if (-1 == filename_index) + filename_index = 0; + else + filename_index++; + int filename_portion_length = path.Length - filename_index; + return filename.Length == filename_portion_length; + } } public class FileNameGlob