archive extraction methods moved to a separate internal class.

This commit is contained in:
morkt
2015-05-15 21:19:15 +04:00
parent f7e5b40314
commit 98041015c1
6 changed files with 250 additions and 216 deletions

View File

@@ -313,30 +313,5 @@ namespace GARbro.GUI
}, DispatcherPriority.ContextIdle);
}
}
void ExtractImage (ArcFile arc, Entry entry, ImageFormat target_format)
{
using (var file = arc.OpenEntry (entry))
{
string source_ext = Path.GetExtension (entry.Name).TrimStart ('.').ToLowerInvariant();
if (target_format.Extensions.Any (ext => ext == source_ext))
{
// source extension matches target image format, copy file as is
using (var output = arc.CreateFile (entry))
file.CopyTo (output);
return;
}
ImageData image = ImageFormat.Read (file);
if (null == image)
throw new InvalidFormatException (string.Format ("{1}: {0}", guiStrings.MsgUnableInterpret, entry.Name));
string target_ext = target_format.Extensions.First();
string outname = Path.ChangeExtension (entry.Name, target_ext);
Trace.WriteLine (string.Format ("{0} => {1}", entry.Name, outname), "ExtractImage");
using (var outfile = ArchiveFormat.CreateFile (outname))
{
target_format.Write (outfile, image);
}
}
}
}
}