mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DATFromDir] Try to delete the copied file in more places
This commit is contained in:
@@ -244,6 +244,13 @@ namespace SabreTools
|
|||||||
if (type != null && !_archivesAsFiles)
|
if (type != null && !_archivesAsFiles)
|
||||||
{
|
{
|
||||||
List<Rom> extracted = FileTools.GetArchiveFileInfo(newItem, _logger);
|
List<Rom> extracted = FileTools.GetArchiveFileInfo(newItem, _logger);
|
||||||
|
|
||||||
|
// Cue to delete the file if it's a copy
|
||||||
|
if (_copyFiles && item != newItem)
|
||||||
|
{
|
||||||
|
FileTools.DeleteDirectory(Path.GetDirectoryName(newItem));
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Rom rom in extracted)
|
foreach (Rom rom in extracted)
|
||||||
{
|
{
|
||||||
ProcessFileHelper(newItem,
|
ProcessFileHelper(newItem,
|
||||||
@@ -256,6 +263,12 @@ namespace SabreTools
|
|||||||
else if (File.Exists(newItem))
|
else if (File.Exists(newItem))
|
||||||
{
|
{
|
||||||
ProcessFile(newItem, newBasePath, "");
|
ProcessFile(newItem, newBasePath, "");
|
||||||
|
|
||||||
|
// Cue to delete the file if it's a copy
|
||||||
|
if (_copyFiles && item != newItem)
|
||||||
|
{
|
||||||
|
FileTools.DeleteDirectory(Path.GetDirectoryName(newItem));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, attempt to extract the files to the temporary directory
|
// Otherwise, attempt to extract the files to the temporary directory
|
||||||
@@ -272,6 +285,12 @@ namespace SabreTools
|
|||||||
// If the file was an archive and was extracted successfully, check it
|
// If the file was an archive and was extracted successfully, check it
|
||||||
if (!encounteredErrors)
|
if (!encounteredErrors)
|
||||||
{
|
{
|
||||||
|
// Cue to delete the file if it's a copy
|
||||||
|
if (_copyFiles && item != newItem)
|
||||||
|
{
|
||||||
|
FileTools.DeleteDirectory(Path.GetDirectoryName(newItem));
|
||||||
|
}
|
||||||
|
|
||||||
_logger.Log(Path.GetFileName(item) + " treated like an archive");
|
_logger.Log(Path.GetFileName(item) + " treated like an archive");
|
||||||
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
||||||
Parallel.ForEach(extracted,
|
Parallel.ForEach(extracted,
|
||||||
@@ -290,13 +309,13 @@ namespace SabreTools
|
|||||||
else if (File.Exists(newItem))
|
else if (File.Exists(newItem))
|
||||||
{
|
{
|
||||||
ProcessFile(newItem, newBasePath, "");
|
ProcessFile(newItem, newBasePath, "");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cue to delete the file if it's a copy
|
// Cue to delete the file if it's a copy
|
||||||
if (_copyFiles && item != newItem)
|
if (_copyFiles && item != newItem)
|
||||||
{
|
{
|
||||||
FileTools.DeleteFile(newItem);
|
FileTools.DeleteDirectory(Path.GetDirectoryName(newItem));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the sub temp directory
|
// Delete the sub temp directory
|
||||||
|
|||||||
@@ -289,7 +289,6 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
writeStream.Write(ibuffer, 0, ilen);
|
writeStream.Write(ibuffer, 0, ilen);
|
||||||
}
|
}
|
||||||
freadStream.Close();
|
|
||||||
freadStream.Dispose();
|
freadStream.Dispose();
|
||||||
zipFile.CloseWriteStream(Convert.ToUInt32(roms[-index - 1].CRC, 16));
|
zipFile.CloseWriteStream(Convert.ToUInt32(roms[-index - 1].CRC, 16));
|
||||||
}
|
}
|
||||||
@@ -493,13 +492,14 @@ namespace SabreTools.Helper
|
|||||||
return encounteredErrors;
|
return encounteredErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
IReader reader = null;
|
|
||||||
SevenZipArchive sza = null;
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
using (FileStream fs = File.OpenRead(input))
|
||||||
{
|
{
|
||||||
if (at == ArchiveType.SevenZip && sevenzip != ArchiveScanLevel.External)
|
if (at == ArchiveType.SevenZip && sevenzip != ArchiveScanLevel.External)
|
||||||
{
|
{
|
||||||
sza = SevenZipArchive.Open(File.OpenRead(input));
|
using (SevenZipArchive sza = SevenZipArchive.Open(fs))
|
||||||
|
{
|
||||||
logger.Log("Found archive of type: " + at);
|
logger.Log("Found archive of type: " + at);
|
||||||
|
|
||||||
// Create the temp directory
|
// Create the temp directory
|
||||||
@@ -512,6 +512,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
encounteredErrors = false;
|
encounteredErrors = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (at == ArchiveType.GZip && gz != ArchiveScanLevel.External)
|
else if (at == ArchiveType.GZip && gz != ArchiveScanLevel.External)
|
||||||
{
|
{
|
||||||
logger.Log("Found archive of type: " + at);
|
logger.Log("Found archive of type: " + at);
|
||||||
@@ -519,21 +520,19 @@ namespace SabreTools.Helper
|
|||||||
// Create the temp directory
|
// Create the temp directory
|
||||||
Directory.CreateDirectory(tempDir);
|
Directory.CreateDirectory(tempDir);
|
||||||
|
|
||||||
using (FileStream itemstream = File.OpenRead(input))
|
|
||||||
{
|
|
||||||
using (FileStream outstream = File.Create(Path.Combine(tempDir, Path.GetFileNameWithoutExtension(input))))
|
using (FileStream outstream = File.Create(Path.Combine(tempDir, Path.GetFileNameWithoutExtension(input))))
|
||||||
{
|
{
|
||||||
using (GZipStream gzstream = new GZipStream(itemstream, CompressionMode.Decompress))
|
using (GZipStream gzstream = new GZipStream(fs, CompressionMode.Decompress))
|
||||||
{
|
{
|
||||||
gzstream.CopyTo(outstream);
|
gzstream.CopyTo(outstream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
encounteredErrors = false;
|
encounteredErrors = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reader = ReaderFactory.Open(File.OpenRead(input));
|
using (IReader reader = ReaderFactory.Open(fs))
|
||||||
|
{
|
||||||
logger.Log("Found archive of type: " + at);
|
logger.Log("Found archive of type: " + at);
|
||||||
|
|
||||||
if ((at == ArchiveType.Zip && zip != ArchiveScanLevel.External) ||
|
if ((at == ArchiveType.Zip && zip != ArchiveScanLevel.External) ||
|
||||||
@@ -553,6 +552,8 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (EndOfStreamException)
|
catch (EndOfStreamException)
|
||||||
{
|
{
|
||||||
// Catch this but don't count it as an error because SharpCompress is unsafe
|
// Catch this but don't count it as an error because SharpCompress is unsafe
|
||||||
@@ -566,11 +567,6 @@ namespace SabreTools.Helper
|
|||||||
// Don't log file open errors
|
// Don't log file open errors
|
||||||
encounteredErrors = true;
|
encounteredErrors = true;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
reader?.Dispose();
|
|
||||||
sza?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return encounteredErrors;
|
return encounteredErrors;
|
||||||
}
|
}
|
||||||
@@ -694,7 +690,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the information from the file stream
|
// Get the information from the file stream
|
||||||
Rom rom = GetSingleStreamInfo(File.OpenRead(input), noMD5, noSHA1, offset);
|
Rom rom = GetSingleStreamInfo(File.OpenRead(input), noMD5, noSHA1, offset, false);
|
||||||
|
|
||||||
// Add unique data from the file
|
// Add unique data from the file
|
||||||
rom.Name = Path.GetFileName(input);
|
rom.Name = Path.GetFileName(input);
|
||||||
@@ -779,7 +775,6 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
if (!keepReadOpen)
|
if (!keepReadOpen)
|
||||||
{
|
{
|
||||||
input.Close();
|
|
||||||
input.Dispose();
|
input.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1243,6 +1238,11 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="filename">Name of the file to be deleted</param>
|
/// <param name="filename">Name of the file to be deleted</param>
|
||||||
public async static void DeleteFile(string filename)
|
public async static void DeleteFile(string filename)
|
||||||
{
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File.SetAttributes(filename, 0);
|
File.SetAttributes(filename, 0);
|
||||||
FileInfo fi = new FileInfo(filename);
|
FileInfo fi = new FileInfo(filename);
|
||||||
fi.IsReadOnly = false;
|
fi.IsReadOnly = false;
|
||||||
@@ -1259,6 +1259,31 @@ namespace SabreTools.Helper
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a directory asynchronously
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dirname">Name of the directory to be deleted</param>
|
||||||
|
public async static void DeleteDirectory(string dirname)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(dirname))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectoryInfo di = new DirectoryInfo(dirname);
|
||||||
|
await Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
while (di.Exists)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
di.Delete(true);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user