(IFileSystem.CombinePath): new method.

This commit is contained in:
morkt 2015-09-01 12:15:10 +04:00
parent 72d14c07df
commit 1db7e865cd

View File

@ -35,7 +35,7 @@ namespace GameRes
public interface IFileSystem : IDisposable public interface IFileSystem : IDisposable
{ {
/// <summary> /// <summary>
/// Returns entry corresponding to the given filename within filesystem. /// Returns entry corresponding to the given file or directory within filesystem.
/// </summary> /// </summary>
/// <exception cref="FileNotFoundException">File is not found.</exception> /// <exception cref="FileNotFoundException">File is not found.</exception>
Entry FindFile (string filename); Entry FindFile (string filename);
@ -57,6 +57,11 @@ namespace GameRes
/// </summary> /// </summary>
IEnumerable<Entry> GetFiles (); IEnumerable<Entry> GetFiles ();
/// <summary>
/// System.IO.Path.Combine() analog.
/// </summary>
string CombinePath (string path1, string path2);
/// <summary> /// <summary>
/// Recursively enumerates files in the current directory and its subdirectories. /// Recursively enumerates files in the current directory and its subdirectories.
/// Subdirectory entries are omitted from resulting set. /// Subdirectory entries are omitted from resulting set.
@ -85,6 +90,11 @@ namespace GameRes
set { Directory.SetCurrentDirectory (value); } set { Directory.SetCurrentDirectory (value); }
} }
public string CombinePath (string path1, string path2)
{
return Path.Combine (path1, path2);
}
public Entry FindFile (string filename) public Entry FindFile (string filename)
{ {
var attr = File.GetAttributes (filename); var attr = File.GetAttributes (filename);
@ -215,6 +225,11 @@ namespace GameRes
return m_arc.Dir; return m_arc.Dir;
} }
public virtual string CombinePath (string path1, string path2)
{
return Path.Combine (path1, path2);
}
#region IDisposable Members #region IDisposable Members
bool _arc_disposed = false; bool _arc_disposed = false;
@ -258,6 +273,11 @@ namespace GameRes
set { ChDir (value); } set { ChDir (value); }
} }
public override string CombinePath (string path1, string path2)
{
return string.Join (PathDelimiter, path1, path2);
}
public override Entry FindFile (string filename) public override Entry FindFile (string filename)
{ {
Entry entry = null; Entry entry = null;
@ -318,13 +338,16 @@ namespace GameRes
private void ChDir (string path) private void ChDir (string path)
{ {
if (string.IsNullOrEmpty (path)) if (string.IsNullOrEmpty (path))
{
m_cwd = "";
return; return;
}
var cur_dir = new List<string>(); var cur_dir = new List<string>();
if (-1 != Array.IndexOf (m_path_delimiters, path[0])) if (-1 != Array.IndexOf (m_path_delimiters, path[0]))
{ {
path = path.TrimStart (m_path_delimiters); path = path.TrimStart (m_path_delimiters);
} }
else if (!string.IsNullOrEmpty (m_cwd)) else if (".." == path && !string.IsNullOrEmpty (m_cwd))
{ {
cur_dir.AddRange (m_cwd.Split (m_path_delimiters)); cur_dir.AddRange (m_cwd.Split (m_path_delimiters));
} }
@ -381,17 +404,14 @@ namespace GameRes
{ {
if (entry is SubDirEntry) if (entry is SubDirEntry)
{ {
if (1 == m_fs_stack.Count) if (Count > 1 && ".." == entry.Name && string.IsNullOrEmpty (Top.CurrentDirectory))
{
Top.CurrentDirectory = entry.Name;
return;
}
if (".." == entry.Name && string.IsNullOrEmpty (Top.CurrentDirectory))
{ {
Pop(); Pop();
return;
} }
Top.CurrentDirectory = entry.Name; else
{
Top.CurrentDirectory = entry.Name;
}
return; return;
} }
if (entry.Name == LastVisitedPath && null != LastVisitedArc) if (entry.Name == LastVisitedPath && null != LastVisitedArc)
@ -497,6 +517,11 @@ namespace GameRes
} }
} }
public static string CombinePath (string path1, string path2)
{
return m_vfs.Top.CombinePath (path1, path2);
}
public static Entry FindFile (string filename) public static Entry FindFile (string filename)
{ {
if (".." == filename) if (".." == filename)