Add drag-n-drop zip support

This commit is contained in:
Matt Nadareski
2016-04-11 19:20:39 -07:00
parent fa1a39197a
commit 6ca81d568d

View File

@@ -44,44 +44,106 @@ namespace SabreTools
// This is where the main loop would go
if (File.Exists(_basePath))
{
// Create the temporary output directory
Directory.CreateDirectory(_tempDir);
psi.Arguments = _baseExtract + " " + _basePath;
Process zip = Process.Start(psi);
zip.WaitForExit();
bool encounteredErrors = zip.StandardError.ReadToEnd().Contains("ERROR");
// Get a list of files including size and hashes
Crc32 crc = new Crc32();
MD5 md5 = MD5.Create();
SHA1 sha1 = SHA1.Create();
string fileCRC = String.Empty;
string fileMD5 = String.Empty;
string fileSHA1 = String.Empty;
try
// If the file was an archive and was extracted successfully, check it
if (!encounteredErrors)
{
using (FileStream fs = File.Open(_basePath, FileMode.Open))
foreach (string entry in Directory.GetFiles(_tempDir, "*", SearchOption.AllDirectories))
{
foreach (byte b in crc.ComputeHash(fs))
string fileCRC = String.Empty;
string fileMD5 = String.Empty;
string fileSHA1 = String.Empty;
try
{
fileCRC += b.ToString("x2").ToLower();
using (FileStream fs = File.Open(entry, FileMode.Open))
{
foreach (byte b in crc.ComputeHash(fs))
{
fileCRC += b.ToString("x2").ToLower();
}
}
using (FileStream fs = File.Open(entry, FileMode.Open))
{
fileMD5 = BitConverter.ToString(md5.ComputeHash(fs)).Replace("-", "");
}
using (FileStream fs = File.Open(entry, FileMode.Open))
{
fileSHA1 = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", "");
}
}
catch (IOException)
{
continue;
}
}
using (FileStream fs = File.Open(_basePath, FileMode.Open))
{
fileMD5 = BitConverter.ToString(md5.ComputeHash(fs)).Replace("-", "");
}
using (FileStream fs = File.Open(_basePath, FileMode.Open))
{
fileSHA1 = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", "");
}
roms.Add(new Tuple<string, string, long, string, string, string>(
"Default",
_basePath,
(new FileInfo(_basePath)).Length,
fileCRC,
fileMD5,
fileSHA1));
roms.Add(new Tuple<string, string, long, string, string, string>(
Path.GetFileNameWithoutExtension(_basePath),
entry.Remove(0, _tempDir.Length),
(new FileInfo(entry)).Length,
fileCRC,
fileMD5,
fileSHA1));
Console.WriteLine("File parsed: " + _basePath.Remove(0, _basePath.Length));
Console.WriteLine("File parsed: " + entry.Remove(0, _tempDir.Length));
}
}
// Otherwise, just get the info on the file itself
else if (!Directory.Exists(_basePath) && File.Exists(_basePath))
{
string fileCRC = String.Empty;
string fileMD5 = String.Empty;
string fileSHA1 = String.Empty;
try
{
using (FileStream fs = File.Open(_basePath, FileMode.Open))
{
foreach (byte b in crc.ComputeHash(fs))
{
fileCRC += b.ToString("x2").ToLower();
}
}
using (FileStream fs = File.Open(_basePath, FileMode.Open))
{
fileMD5 = BitConverter.ToString(md5.ComputeHash(fs)).Replace("-", "");
}
using (FileStream fs = File.Open(_basePath, FileMode.Open))
{
fileSHA1 = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", "");
}
roms.Add(new Tuple<string, string, long, string, string, string>(
"Default",
_basePath,
(new FileInfo(_basePath)).Length,
fileCRC,
fileMD5,
fileSHA1));
Console.WriteLine("File parsed: " + _basePath.Remove(0, _basePath.Length));
}
catch (IOException) { }
}
// Delete the temp directory
if (Directory.Exists(_tempDir))
{
Directory.Delete(_tempDir, true);
}
catch (IOException) { }
}
else
{