mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add drag-n-drop zip support
This commit is contained in:
@@ -44,11 +44,66 @@ namespace SabreTools
|
|||||||
// This is where the main loop would go
|
// This is where the main loop would go
|
||||||
if (File.Exists(_basePath))
|
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
|
// Get a list of files including size and hashes
|
||||||
Crc32 crc = new Crc32();
|
Crc32 crc = new Crc32();
|
||||||
MD5 md5 = MD5.Create();
|
MD5 md5 = MD5.Create();
|
||||||
SHA1 sha1 = SHA1.Create();
|
SHA1 sha1 = SHA1.Create();
|
||||||
|
|
||||||
|
// If the file was an archive and was extracted successfully, check it
|
||||||
|
if (!encounteredErrors)
|
||||||
|
{
|
||||||
|
foreach (string entry in Directory.GetFiles(_tempDir, "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
string fileCRC = String.Empty;
|
||||||
|
string fileMD5 = String.Empty;
|
||||||
|
string fileSHA1 = String.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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: " + 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 fileCRC = String.Empty;
|
||||||
string fileMD5 = String.Empty;
|
string fileMD5 = String.Empty;
|
||||||
string fileSHA1 = String.Empty;
|
string fileSHA1 = String.Empty;
|
||||||
@@ -83,6 +138,13 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
catch (IOException) { }
|
catch (IOException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the temp directory
|
||||||
|
if (Directory.Exists(_tempDir))
|
||||||
|
{
|
||||||
|
Directory.Delete(_tempDir, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (string item in Directory.GetFiles(_basePath, "*", SearchOption.AllDirectories))
|
foreach (string item in Directory.GetFiles(_basePath, "*", SearchOption.AllDirectories))
|
||||||
|
|||||||
Reference in New Issue
Block a user