From ae559f34a67a6ef0e13793dba9cc9962ce0b7734 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 12 Sep 2014 16:03:30 +0400 Subject: [PATCH] (ArchiveFormat.CopyEntry): new virtual method. the idea is to allow implementations to give extracted file a name different from the one it stored within archive. --- GameRes/GameRes.cs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/GameRes/GameRes.cs b/GameRes/GameRes.cs index fa5264d4..d2226ed5 100644 --- a/GameRes/GameRes.cs +++ b/GameRes/GameRes.cs @@ -143,12 +143,7 @@ namespace GameRes public void Extract (ArcFile file, Entry entry) { using (var reader = OpenEntry (file, entry)) - { - using (var writer = CreateFile (entry)) - { - reader.CopyTo (writer); - } - } + CopyEntry (file, reader, entry); } /// @@ -159,13 +154,28 @@ namespace GameRes return arc.File.CreateStream (entry.Offset, entry.Size); } + public virtual void CopyEntry (ArcFile arc, Stream input, Entry entry) + { + using (var output = CreateFile (entry.Name)) + input.CopyTo (output); + } + /// /// Create file corresponding to in current directory and open it /// for writing. Overwrites existing file, if any. /// - public virtual Stream CreateFile (Entry entry) + public Stream CreateFile (string filename) + { + filename = CreatePath (filename); + if (File.Exists (filename)) + { + // query somehow whether to overwrite existing file or not. + } + return File.Create (filename); + } + + static public string CreatePath (string filename) { - string filename = entry.Name; string dir = Path.GetDirectoryName (filename); if (!string.IsNullOrEmpty (dir)) // check for malformed filenames { @@ -185,7 +195,7 @@ namespace GameRes filename = Path.Combine (dir, filename); } } - return File.Create (filename); + return filename; } ///