diff --git a/GUI/GarOperation.cs b/GUI/GarOperation.cs index 71039629..c784f97a 100644 --- a/GUI/GarOperation.cs +++ b/GUI/GarOperation.cs @@ -55,7 +55,7 @@ namespace GARbro.GUI protected Stream CreateNewFile (string filename, bool create_path = false) { if (create_path) - filename = GameRes.ArchiveFormat.CreatePath (filename); + filename = GameRes.PhysicalFileSystem.CreatePath (filename); FileMode open_mode = FileMode.CreateNew; if (m_duplicate_action.ApplyToAll && m_duplicate_action.Action == ExistingFileAction.Overwrite) diff --git a/GameRes/ArchiveFormat.cs b/GameRes/ArchiveFormat.cs index 0ffd95d3..00a989b3 100644 --- a/GameRes/ArchiveFormat.cs +++ b/GameRes/ArchiveFormat.cs @@ -49,7 +49,7 @@ namespace GameRes public void Extract (ArcFile file, Entry entry) { using (var input = OpenEntry (file, entry)) - using (var output = CreateFile (entry.Name)) + using (var output = PhysicalFileSystem.CreateFile (entry.Name)) input.CopyTo (output); } @@ -70,40 +70,6 @@ namespace GameRes return ImageFormatDecoder.Create (input); } - /// - /// Create file corresponding to in current directory and open it - /// for writing. Overwrites existing file, if any. - /// - static public Stream CreateFile (string filename) - { - filename = CreatePath (filename); - return File.Create (filename); - } - - static public string CreatePath (string filename) - { - string dir = Path.GetDirectoryName (filename); - if (!string.IsNullOrEmpty (dir)) // check for malformed filenames - { - string root = Path.GetPathRoot (dir); - if (!string.IsNullOrEmpty (root)) - { - dir = dir.Substring (root.Length); // strip root - } - string cwd = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; - dir = Path.GetFullPath (dir); - filename = Path.GetFileName (filename); - // check whether filename would reside within current directory - if (dir.StartsWith (cwd, StringComparison.OrdinalIgnoreCase)) - { - // path looks legit, create it - Directory.CreateDirectory (dir); - filename = Path.Combine (dir, filename); - } - } - return filename; - } - /// /// Create resource within stream containing entries from the /// supplied and applying necessary . diff --git a/GameRes/FileSystem.cs b/GameRes/FileSystem.cs index ae3fee45..534dc61c 100644 --- a/GameRes/FileSystem.cs +++ b/GameRes/FileSystem.cs @@ -138,7 +138,7 @@ namespace GameRes var info = new DirectoryInfo (CurrentDirectory); foreach (var subdir in info.EnumerateDirectories()) { - if (0 != (subdir.Attributes & (FileAttributes.Hidden | FileAttributes.System))) + if (0 != (subdir.Attributes & FileAttributes.System)) continue; yield return new SubDirEntry (subdir.FullName); } @@ -158,7 +158,7 @@ namespace GameRes var info = new DirectoryInfo (path); foreach (var file in info.EnumerateFiles (pattern)) { - if (0 != (file.Attributes & (FileAttributes.Hidden | FileAttributes.System))) + if (0 != (file.Attributes & FileAttributes.System)) continue; yield return EntryFromFileInfo (file); } @@ -169,7 +169,7 @@ namespace GameRes var info = new DirectoryInfo (CurrentDirectory); foreach (var file in info.EnumerateFiles ("*", SearchOption.AllDirectories)) { - if (0 != (file.Attributes & (FileAttributes.Hidden | FileAttributes.System))) + if (0 != (file.Attributes & FileAttributes.System)) continue; yield return EntryFromFileInfo (file); } @@ -202,6 +202,43 @@ namespace GameRes { GC.SuppressFinalize (this); } + + /// + /// Create file named in current directory and open it + /// for writing. Overwrites existing file, if any. + /// + static public Stream CreateFile (string filename) + { + filename = CreatePath (filename); + return File.Create (filename); + } + + /// + /// Create all directories that lead to , if any. + /// + static public string CreatePath (string filename) + { + string dir = Path.GetDirectoryName (filename); + if (!string.IsNullOrEmpty (dir)) // check for malformed filenames + { + string root = Path.GetPathRoot (dir); + if (!string.IsNullOrEmpty (root)) + { + dir = dir.Substring (root.Length); // strip root + } + string cwd = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; + dir = Path.GetFullPath (dir); + filename = Path.GetFileName (filename); + // check whether filename would reside within current directory + if (dir.StartsWith (cwd, StringComparison.OrdinalIgnoreCase)) + { + // path looks legit, create it + Directory.CreateDirectory (dir); + filename = Path.Combine (dir, filename); + } + } + return filename; + } } public abstract class ArchiveFileSystem : IFileSystem