C#: updated the generic compression/decompression functions to make sure the folder of the given output file exists before creating the file.

This commit is contained in:
barubary 2011-04-05 16:41:43 +00:00
parent bd9c45a89b
commit 2c6ef5570a

View File

@ -50,6 +50,10 @@ namespace DSDecmp.Formats
/// <param name="outfile">The target location of the decompressed file.</param>
public void Decompress(string infile, string outfile)
{
// make sure the output directory exists
string outDirectory = Path.GetDirectoryName(outfile);
if (!Directory.Exists(outDirectory))
Directory.CreateDirectory(outDirectory);
// open the two given files, and delegate to the format-specific code.
using (FileStream inStream = new FileStream(infile, FileMode.Open),
outStream = new FileStream(outfile, FileMode.Create))
@ -83,6 +87,10 @@ namespace DSDecmp.Formats
/// <returns>The size of the compressed file.</returns>
public int Compress(string infile, string outfile)
{
// make sure the output directory exists
string outDirectory = Path.GetDirectoryName(outfile);
if (!Directory.Exists(outDirectory))
Directory.CreateDirectory(outDirectory);
// open the proper Streams, and delegate to the format-specific code.
using (FileStream inStream = File.Open(infile, FileMode.Open),
outStream = File.Create(outfile))