(VFS.IsPathEqualsToFileName): new method.

This commit is contained in:
morkt 2016-12-29 16:19:28 +04:00
parent 06718d88e9
commit 1d7369a2e4
7 changed files with 26 additions and 7 deletions

View File

@ -331,7 +331,7 @@ namespace GameRes.Formats.AZSys
if (null != scheme.ContentKey) if (null != scheme.ContentKey)
return scheme.ContentKey.Value; 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); return ReadSysenvSeed (file, dir, scheme.IndexKey);
} }

View File

@ -114,7 +114,7 @@ namespace GameRes.Formats.KAAS
return null; return null;
var dir = new List<Entry> (count); var dir = new List<Entry> (count);
int index_offset = 0x10; 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; int data_offset = index_offset + 8 * count;
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {

View File

@ -80,7 +80,7 @@ namespace GameRes.Formats.MAI
dir_offset += 8; 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<Entry> (count); var dir = new List<Entry> (count);
int next_folder = null == folders ? count : folders[0].Index; int next_folder = null == folders ? count : folders[0].Index;
int folder = 0; int folder = 0;

View File

@ -101,7 +101,7 @@ namespace GameRes.Formats.Rpm
// special case for "instdata.arc" archives // special case for "instdata.arc" archives
if (scheme.Keyword != "inst" 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); scheme = new EncryptionScheme ("inst", scheme.NameLength);
int index_size = count * (scheme.NameLength + 12); int index_size = count * (scheme.NameLength + 12);

View File

@ -54,7 +54,7 @@ namespace GameRes.Formats.Silky
return null; return null;
// rather loose criterion, haven't found anything better yet. // 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<Entry> (count); var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {

View File

@ -136,9 +136,8 @@ namespace GameRes.Formats.Rugp
if (null == arc_man) if (null == arc_man)
return null; return null;
} }
var base_name = Path.GetFileName (file.Name);
var arc_object = arc_man.ArcList.FirstOrDefault(); 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 null;
return new RioReader (arc_man, file); return new RioReader (arc_man, file);
} }

View File

@ -783,6 +783,26 @@ namespace GameRes
{ {
return m_vfs.Top.GetFiles (pattern); return m_vfs.Top.GetFiles (pattern);
} }
static readonly char[] PathSeparatorChars = { '\\', '/', ':' };
/// <summary>
/// Returns true if given <paramref name="path"/> points to a specified <paramref name="filename"/>.
/// </summary>
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 public class FileNameGlob