From a06bae057e6d76a566850e67e94244967751e959 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 5 Sep 2015 10:04:38 +0400 Subject: [PATCH] TreeArchiveFileSystem fixes. --- GameRes/FileSystem.cs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/GameRes/FileSystem.cs b/GameRes/FileSystem.cs index 94e6c1e8..7aaccdf3 100644 --- a/GameRes/FileSystem.cs +++ b/GameRes/FileSystem.cs @@ -308,6 +308,12 @@ namespace GameRes public override string CombinePath (string path1, string path2) { + if (0 == path1.Length) + return path2; + if (0 == path2.Length) + return path1; + if (path1.EndsWith (PathDelimiter)) + return path1+path2; return string.Join (PathDelimiter, path1, path2); } @@ -325,19 +331,11 @@ namespace GameRes public override IEnumerable GetFiles () { - var root_dir = ""; - IEnumerable dir = m_arc.Dir; - if (!string.IsNullOrEmpty (m_cwd)) - { - root_dir = m_cwd+PathDelimiter; - dir = from entry in dir - where entry.Name.StartsWith (root_dir) - select entry; - if (!dir.Any()) - { - throw new DirectoryNotFoundException(); - } - } + IEnumerable dir = GetFilesRecursive(); + var root_dir = m_cwd; + if (!string.IsNullOrEmpty (root_dir)) + root_dir += PathDelimiter; + var subdirs = new HashSet(); foreach (var entry in dir) { @@ -368,6 +366,23 @@ namespace GameRes select file; } + public IEnumerable GetFilesRecursive (IEnumerable list) + { + var result = new List(); + foreach (var entry in list) + { + if (!(entry is SubDirEntry)) // add ordinary file + result.Add (entry); + else if (".." == entry.Name) // skip reference to parent directory + continue; + else // add all files contained within directory, recursive + result.AddRange (from file in m_arc.Dir + where file.Name.StartsWith (entry.Name+PathDelimiter) + select file); + } + return result; + } + private void ChDir (string path) { if (string.IsNullOrEmpty (path))