(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.
This commit is contained in:
morkt 2014-09-12 16:03:30 +04:00
parent f02cc382a1
commit ae559f34a6

View File

@ -143,12 +143,7 @@ namespace GameRes
public void Extract (ArcFile file, Entry entry) public void Extract (ArcFile file, Entry entry)
{ {
using (var reader = OpenEntry (file, entry)) using (var reader = OpenEntry (file, entry))
{ CopyEntry (file, reader, entry);
using (var writer = CreateFile (entry))
{
reader.CopyTo (writer);
}
}
} }
/// <summary> /// <summary>
@ -159,13 +154,28 @@ namespace GameRes
return arc.File.CreateStream (entry.Offset, entry.Size); 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);
}
/// <summary> /// <summary>
/// Create file corresponding to <paramref name="entry"/> in current directory and open it /// Create file corresponding to <paramref name="entry"/> in current directory and open it
/// for writing. Overwrites existing file, if any. /// for writing. Overwrites existing file, if any.
/// </summary> /// </summary>
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); string dir = Path.GetDirectoryName (filename);
if (!string.IsNullOrEmpty (dir)) // check for malformed filenames if (!string.IsNullOrEmpty (dir)) // check for malformed filenames
{ {
@ -185,7 +195,7 @@ namespace GameRes
filename = Path.Combine (dir, filename); filename = Path.Combine (dir, filename);
} }
} }
return File.Create (filename); return filename;
} }
/// <summary> /// <summary>