(IFileSystem): added GetFiles(pattern) method.

This commit is contained in:
morkt
2016-04-09 00:34:28 +04:00
parent bbadc4b1fd
commit 1f9a8e5a09

View File

@@ -62,6 +62,11 @@ namespace GameRes
/// </summary>
IEnumerable<Entry> GetFiles ();
/// <summary>
/// Returns enumeration of files within current directory that match specified pattern.
/// </summary>
IEnumerable<Entry> GetFiles (string pattern);
/// <summary>
/// System.IO.Path.Combine() analog.
/// </summary>
@@ -131,6 +136,20 @@ namespace GameRes
}
}
public IEnumerable<Entry> GetFiles (string pattern)
{
string path = Path.GetDirectoryName (pattern);
pattern = Path.GetFileName (pattern);
path = CombinePath (CurrentDirectory, path);
var info = new DirectoryInfo (path);
foreach (var file in info.EnumerateFiles (pattern))
{
if (0 != (file.Attributes & (FileAttributes.Hidden | FileAttributes.System)))
continue;
yield return EntryFromFileInfo (file);
}
}
public IEnumerable<Entry> GetFilesRecursive ()
{
var info = new DirectoryInfo (CurrentDirectory);
@@ -192,7 +211,7 @@ namespace GameRes
public bool FileExists (string filename)
{
return m_dir.ContainsKey (filename);
return m_dir.ContainsKey (CombinePath (CurrentDirectory, filename));
}
public Stream OpenStream (Entry entry)
@@ -218,6 +237,8 @@ namespace GameRes
public abstract string CombinePath (string path1, string path2);
public abstract IEnumerable<Entry> GetFiles (string pattern);
#region IDisposable Members
bool _arc_disposed = false;
@@ -280,6 +301,12 @@ namespace GameRes
return m_arc.Dir;
}
public override IEnumerable<Entry> GetFiles (string pattern)
{
var glob = new FileNameGlob (pattern);
return m_arc.Dir.Where (f => glob.IsMatch (f.Name));
}
public override string CombinePath (string path1, string path2)
{
return Path.Combine (path1, path2);
@@ -366,6 +393,19 @@ namespace GameRes
select file;
}
public override IEnumerable<Entry> GetFiles (string pattern)
{
string path = Path.GetDirectoryName (pattern);
pattern = Path.GetFileName (pattern);
path = CombinePath (CurrentDirectory, path);
if (!string.IsNullOrEmpty (path))
path += PathDelimiter;
var glob = new FileNameGlob (pattern);
return from file in m_arc.Dir
where file.Name.StartsWith (path) && glob.IsMatch (Path.GetFileName (file.Name))
select file;
}
public IEnumerable<Entry> GetFilesRecursive (IEnumerable<Entry> list)
{
var result = new List<Entry>();
@@ -676,8 +716,7 @@ namespace GameRes
/// </summary>
public static IEnumerable<Entry> GetFiles (string pattern)
{
var glob = new FileNameGlob (pattern);
return GetFiles().Where (f => glob.IsMatch (Path.GetFileName (f.Name)));
return m_vfs.Top.GetFiles (pattern);
}
}