diff --git a/GameRes/FileSystem.cs b/GameRes/FileSystem.cs index 7f77a3b6..580457f5 100644 --- a/GameRes/FileSystem.cs +++ b/GameRes/FileSystem.cs @@ -665,11 +665,39 @@ namespace GameRes { m_vfs.Flush(); } - + public static IEnumerable GetFiles () { return m_vfs.Top.GetFiles(); } + + /// + /// Returns enumeration of files within current directory that match specified pattern. + /// + public static IEnumerable 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