mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
(ArchiveFileSystem): base abstract class for flat ant tree archive file systems.
This commit is contained in:
parent
047d07f376
commit
81ab95ebf1
@ -192,7 +192,7 @@ namespace GameRes
|
|||||||
public IFileSystem CreateFileSystem ()
|
public IFileSystem CreateFileSystem ()
|
||||||
{
|
{
|
||||||
if (m_interface.IsHierarchic)
|
if (m_interface.IsHierarchic)
|
||||||
return new ArchiveFileSystem (this);
|
return new TreeArchiveFileSystem (this);
|
||||||
else
|
else
|
||||||
return new FlatArchiveFileSystem (this);
|
return new FlatArchiveFileSystem (this);
|
||||||
}
|
}
|
||||||
|
@ -170,29 +170,16 @@ namespace GameRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FlatArchiveFileSystem : IFileSystem
|
public abstract class ArchiveFileSystem : IFileSystem
|
||||||
{
|
{
|
||||||
protected readonly ArcFile m_arc;
|
protected readonly ArcFile m_arc;
|
||||||
protected readonly Dictionary<string, Entry> m_dir;
|
protected readonly Dictionary<string, Entry> m_dir;
|
||||||
|
|
||||||
public ArcFile Source { get { return m_arc; } }
|
public ArcFile Source { get { return m_arc; } }
|
||||||
|
|
||||||
public virtual string CurrentDirectory
|
public abstract string CurrentDirectory { get; set; }
|
||||||
{
|
|
||||||
get { return ""; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty (value))
|
|
||||||
return;
|
|
||||||
if (".." == value || "." == value)
|
|
||||||
return;
|
|
||||||
if ("\\" == value || "/" == value)
|
|
||||||
return;
|
|
||||||
throw new DirectoryNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlatArchiveFileSystem (ArcFile arc)
|
public ArchiveFileSystem (ArcFile arc)
|
||||||
{
|
{
|
||||||
m_arc = arc;
|
m_arc = arc;
|
||||||
m_dir = new Dictionary<string, Entry> (arc.Dir.Count, StringComparer.InvariantCultureIgnoreCase);
|
m_dir = new Dictionary<string, Entry> (arc.Dir.Count, StringComparer.InvariantCultureIgnoreCase);
|
||||||
@ -222,28 +209,13 @@ namespace GameRes
|
|||||||
return m_arc.OpenView (entry);
|
return m_arc.OpenView (entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Entry FindFile (string filename)
|
public abstract Entry FindFile (string filename);
|
||||||
{
|
|
||||||
Entry entry = null;
|
|
||||||
if (!m_dir.TryGetValue (filename, out entry))
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IEnumerable<Entry> GetFiles ()
|
public abstract IEnumerable<Entry> GetFiles ();
|
||||||
{
|
|
||||||
return m_arc.Dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IEnumerable<Entry> GetFilesRecursive ()
|
public abstract IEnumerable<Entry> GetFilesRecursive ();
|
||||||
{
|
|
||||||
return m_arc.Dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual string CombinePath (string path1, string path2)
|
public abstract 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;
|
||||||
@ -268,7 +240,52 @@ namespace GameRes
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ArchiveFileSystem : FlatArchiveFileSystem
|
public class FlatArchiveFileSystem : ArchiveFileSystem
|
||||||
|
{
|
||||||
|
public override string CurrentDirectory
|
||||||
|
{
|
||||||
|
get { return ""; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty (value))
|
||||||
|
return;
|
||||||
|
if (".." == value || "." == value)
|
||||||
|
return;
|
||||||
|
if ("\\" == value || "/" == value)
|
||||||
|
return;
|
||||||
|
throw new DirectoryNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlatArchiveFileSystem (ArcFile arc) : base (arc)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Entry FindFile (string filename)
|
||||||
|
{
|
||||||
|
Entry entry = null;
|
||||||
|
if (!m_dir.TryGetValue (filename, out entry))
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Entry> GetFiles ()
|
||||||
|
{
|
||||||
|
return m_arc.Dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Entry> GetFilesRecursive ()
|
||||||
|
{
|
||||||
|
return m_arc.Dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string CombinePath (string path1, string path2)
|
||||||
|
{
|
||||||
|
return Path.Combine (path1, path2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TreeArchiveFileSystem : ArchiveFileSystem
|
||||||
{
|
{
|
||||||
private string m_cwd;
|
private string m_cwd;
|
||||||
|
|
||||||
@ -276,7 +293,7 @@ namespace GameRes
|
|||||||
|
|
||||||
private static readonly char[] m_path_delimiters = { '/', '\\' };
|
private static readonly char[] m_path_delimiters = { '/', '\\' };
|
||||||
|
|
||||||
public ArchiveFileSystem (ArcFile arc) : base (arc)
|
public TreeArchiveFileSystem (ArcFile arc) : base (arc)
|
||||||
{
|
{
|
||||||
m_cwd = "";
|
m_cwd = "";
|
||||||
PathDelimiter = "/";
|
PathDelimiter = "/";
|
||||||
@ -436,8 +453,9 @@ namespace GameRes
|
|||||||
if (entry.Name == LastVisitedPath && null != LastVisitedArc)
|
if (entry.Name == LastVisitedPath && null != LastVisitedArc)
|
||||||
{
|
{
|
||||||
Push (LastVisitedPath, LastVisitedArc);
|
Push (LastVisitedPath, LastVisitedArc);
|
||||||
if (LastVisitedArc is FlatArchiveFileSystem)
|
var fs = LastVisitedArc as ArchiveFileSystem;
|
||||||
CurrentArchive = (LastVisitedArc as FlatArchiveFileSystem).Source;
|
if (null != fs)
|
||||||
|
CurrentArchive = fs.Source;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Flush();
|
Flush();
|
||||||
@ -469,8 +487,8 @@ namespace GameRes
|
|||||||
Flush();
|
Flush();
|
||||||
LastVisitedArc = m_fs_stack.Pop();
|
LastVisitedArc = m_fs_stack.Pop();
|
||||||
LastVisitedPath = m_arc_name_stack.Pop();
|
LastVisitedPath = m_arc_name_stack.Pop();
|
||||||
if (m_fs_stack.Count > 1 && m_fs_stack.Peek() is FlatArchiveFileSystem)
|
if (m_fs_stack.Count > 1 && m_fs_stack.Peek() is ArchiveFileSystem)
|
||||||
CurrentArchive = (m_fs_stack.Peek() as FlatArchiveFileSystem).Source;
|
CurrentArchive = (m_fs_stack.Peek() as ArchiveFileSystem).Source;
|
||||||
else
|
else
|
||||||
CurrentArchive = null;
|
CurrentArchive = null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user