mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
added filename glob matching.
This commit is contained in:
parent
ecce8f59ef
commit
05aa1568ea
@ -670,6 +670,34 @@ namespace GameRes
|
||||
{
|
||||
return m_vfs.Top.GetFiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns enumeration of files within current directory that match specified pattern.
|
||||
/// </summary>
|
||||
public static IEnumerable<Entry> GetFiles (string pattern)
|
||||
{
|
||||
var glob = new FileNameGlob (pattern);
|
||||
return GetFiles().Where (f => glob.IsMatch (Path.GetFileName (f.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
public class FileNameGlob
|
||||
{
|
||||
Regex m_glob;
|
||||
|
||||
public FileNameGlob (string pattern)
|
||||
{
|
||||
pattern = Regex.Escape (pattern);
|
||||
if (pattern.EndsWith (@"\.\*")) // "*" and "*.*" are equivalent
|
||||
pattern = pattern.Remove (pattern.Length-4) + @"(?:\..*)?";
|
||||
pattern = pattern.Replace (@"\*", ".*").Replace (@"\?", ".");
|
||||
m_glob = new Regex ("^"+pattern+"$", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
public bool IsMatch (string str)
|
||||
{
|
||||
return m_glob.IsMatch (str);
|
||||
}
|
||||
}
|
||||
|
||||
public class UnknownFormatException : FileFormatException
|
||||
|
Loading…
x
Reference in New Issue
Block a user