Clean up after failed extraction.
This commit is contained in:
@@ -14,6 +14,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using ICSharpCode.SharpZipLib;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
@@ -67,7 +68,17 @@ namespace OpenRA.Utility
|
|||||||
|
|
||||||
if (!File.Exists(zipFile)) { Console.WriteLine("Error: Could not find {0}", zipFile); return; }
|
if (!File.Exists(zipFile)) { Console.WriteLine("Error: Could not find {0}", zipFile); return; }
|
||||||
string dest = "mods{0}{1}{0}{2}".F(Path.DirectorySeparatorChar,mod,path);
|
string dest = "mods{0}{1}{0}{2}".F(Path.DirectorySeparatorChar,mod,path);
|
||||||
new ZipInputStream(File.OpenRead(zipFile)).ExtractZip(dest);
|
List<string> extracted = new List<string>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new ZipInputStream(File.OpenRead(zipFile)).ExtractZip(dest, extracted);
|
||||||
|
}
|
||||||
|
catch (SharpZipBaseException e)
|
||||||
|
{
|
||||||
|
foreach(var f in extracted)
|
||||||
|
File.Delete(f);
|
||||||
|
Console.WriteLine("Error: Corrupted archive");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DownloadUrl(string argValue)
|
public static void DownloadUrl(string argValue)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OpenRA.Utility
|
namespace OpenRA.Utility
|
||||||
{
|
{
|
||||||
@@ -38,21 +39,7 @@ namespace OpenRA.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExtractPackagesFromZip(string mod, string dest)
|
public static void ExtractZip(this ZipInputStream z, string destPath, List<string> extracted)
|
||||||
{
|
|
||||||
string filepath = string.Format("{0}{1}{2}-packages.zip", dest, Path.DirectorySeparatorChar, mod);
|
|
||||||
string modPackageDir = string.Format("mods{0}{1}{0}packages{0}", Path.DirectorySeparatorChar, mod);
|
|
||||||
|
|
||||||
if (!Directory.Exists(modPackageDir))
|
|
||||||
Directory.CreateDirectory(modPackageDir);
|
|
||||||
|
|
||||||
new ZipInputStream(File.OpenRead(filepath)).ExtractZip(modPackageDir);
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("Done");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ExtractZip(this ZipInputStream z, string destPath)
|
|
||||||
{
|
{
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
while ((entry = z.GetNextEntry()) != null)
|
while ((entry = z.GetNextEntry()) != null)
|
||||||
@@ -62,7 +49,9 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine("Extracting {0}", entry.Name);
|
Console.WriteLine("Extracting {0}", entry.Name);
|
||||||
if (!Directory.Exists(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))))
|
if (!Directory.Exists(Path.Combine(destPath, Path.GetDirectoryName(entry.Name))))
|
||||||
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
||||||
using (var f = File.Create(destPath + Path.DirectorySeparatorChar + entry.Name))
|
var path = destPath + Path.DirectorySeparatorChar + entry.Name;
|
||||||
|
extracted.Add(path);
|
||||||
|
using (var f = File.Create(path))
|
||||||
{
|
{
|
||||||
int bufSize = 2048;
|
int bufSize = 2048;
|
||||||
byte[] buf = new byte[bufSize];
|
byte[] buf = new byte[bufSize];
|
||||||
|
|||||||
Reference in New Issue
Block a user