mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(IFileSystem): added GetFiles(pattern) method.
This commit is contained in:
@@ -62,6 +62,11 @@ namespace GameRes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerable<Entry> GetFiles ();
|
IEnumerable<Entry> GetFiles ();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns enumeration of files within current directory that match specified pattern.
|
||||||
|
/// </summary>
|
||||||
|
IEnumerable<Entry> GetFiles (string pattern);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// System.IO.Path.Combine() analog.
|
/// System.IO.Path.Combine() analog.
|
||||||
/// </summary>
|
/// </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 ()
|
public IEnumerable<Entry> GetFilesRecursive ()
|
||||||
{
|
{
|
||||||
var info = new DirectoryInfo (CurrentDirectory);
|
var info = new DirectoryInfo (CurrentDirectory);
|
||||||
@@ -192,7 +211,7 @@ namespace GameRes
|
|||||||
|
|
||||||
public bool FileExists (string filename)
|
public bool FileExists (string filename)
|
||||||
{
|
{
|
||||||
return m_dir.ContainsKey (filename);
|
return m_dir.ContainsKey (CombinePath (CurrentDirectory, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream OpenStream (Entry entry)
|
public Stream OpenStream (Entry entry)
|
||||||
@@ -218,6 +237,8 @@ namespace GameRes
|
|||||||
|
|
||||||
public abstract string CombinePath (string path1, string path2);
|
public abstract string CombinePath (string path1, string path2);
|
||||||
|
|
||||||
|
public abstract IEnumerable<Entry> GetFiles (string pattern);
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
bool _arc_disposed = false;
|
bool _arc_disposed = false;
|
||||||
|
|
||||||
@@ -280,6 +301,12 @@ namespace GameRes
|
|||||||
return m_arc.Dir;
|
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)
|
public override string CombinePath (string path1, string path2)
|
||||||
{
|
{
|
||||||
return Path.Combine (path1, path2);
|
return Path.Combine (path1, path2);
|
||||||
@@ -366,6 +393,19 @@ namespace GameRes
|
|||||||
select file;
|
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)
|
public IEnumerable<Entry> GetFilesRecursive (IEnumerable<Entry> list)
|
||||||
{
|
{
|
||||||
var result = new List<Entry>();
|
var result = new List<Entry>();
|
||||||
@@ -676,8 +716,7 @@ namespace GameRes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static IEnumerable<Entry> GetFiles (string pattern)
|
public static IEnumerable<Entry> GetFiles (string pattern)
|
||||||
{
|
{
|
||||||
var glob = new FileNameGlob (pattern);
|
return m_vfs.Top.GetFiles (pattern);
|
||||||
return GetFiles().Where (f => glob.IsMatch (Path.GetFileName (f.Name)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user