mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 05:35:34 +08:00
(ArchiveFormat): CreateFile and CreatePath methods moved to PhysicalFileSystem.
This commit is contained in:
parent
5ab09b0af4
commit
e7d531e214
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create file corresponding to <paramref name="entry"/> in current directory and open it
|
||||
/// for writing. Overwrites existing file, if any.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create resource within stream <paramref name="file"/> containing entries from the
|
||||
/// supplied <paramref name="list"/> and applying necessary <paramref name="options"/>.
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create file named <paramref name="filename"/> in current directory and open it
|
||||
/// for writing. Overwrites existing file, if any.
|
||||
/// </summary>
|
||||
static public Stream CreateFile (string filename)
|
||||
{
|
||||
filename = CreatePath (filename);
|
||||
return File.Create (filename);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create all directories that lead to <paramref name="filename"/>, if any.
|
||||
/// </summary>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user