[ALL] One utility class now

This commit is contained in:
Matt Nadareski
2017-11-08 00:27:00 -08:00
parent 65ef5785ef
commit 5dd08cba63
40 changed files with 1014 additions and 1037 deletions

View File

@@ -136,7 +136,7 @@ namespace SabreTools.Library.FileTypes
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false)
{
// Get the file stream for the file and write out
return Write(FileTools.TryOpenRead(inputFile), outDir, rom, date: date);
return Write(Utilities.TryOpenRead(inputFile), outDir, rom, date: date);
}
/// <summary>
@@ -169,7 +169,7 @@ namespace SabreTools.Library.FileTypes
inputStream.Seek(0, SeekOrigin.Begin);
// Get the output archive name from the first rebuild rom
string archiveFileName = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".xz") ? "" : ".xz"));
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".xz") ? "" : ".xz"));
// Set internal variables
SevenZipBase.SetLibraryPath("7za.dll");
@@ -301,19 +301,19 @@ namespace SabreTools.Library.FileTypes
// If the old file exists, delete it and replace
if (File.Exists(archiveFileName))
{
FileTools.TryDeleteFile(archiveFileName);
Utilities.TryDeleteFile(archiveFileName);
}
File.Move(tempFile, archiveFileName);
// Now make the file T7Z
// TODO: Add ACTUAL T7Z compatible code
BinaryWriter bw = new BinaryWriter(FileTools.TryOpenReadWrite(archiveFileName));
BinaryWriter bw = new BinaryWriter(Utilities.TryOpenReadWrite(archiveFileName));
bw.Seek(0, SeekOrigin.Begin);
bw.Write(Constants.Torrent7ZipHeader);
bw.Seek(0, SeekOrigin.End);
using (oldZipFile = new SevenZipExtractor(FileTools.TryOpenReadWrite(archiveFileName)))
using (oldZipFile = new SevenZipExtractor(Utilities.TryOpenReadWrite(archiveFileName)))
{
// Get the correct signature to use (Default 0, Unicode 1, SingleFile 2, StripFileNames 4)
@@ -371,7 +371,7 @@ namespace SabreTools.Library.FileTypes
}
// Get the output archive name from the first rebuild rom
string archiveFileName = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".xz") ? "" : ".xz"));
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".xz") ? "" : ".xz"));
// Set internal variables
SevenZipBase.SetLibraryPath("7za.dll");
@@ -426,8 +426,8 @@ namespace SabreTools.Library.FileTypes
zipFile.CompressionMode = CompressionMode.Append;
}
FileTools.CleanDirectory(tempPath);
FileTools.TryDeleteDirectory(tempPath);
Utilities.CleanDirectory(tempPath);
Utilities.TryDeleteDirectory(tempPath);
}
// Otherwise, sort the input files and write out in the correct order
@@ -482,7 +482,7 @@ namespace SabreTools.Library.FileTypes
// If we have the input file, add it now
if (index < 0)
{
FileStream inputStream = FileTools.TryOpenRead(inputFiles[-index - 1]);
FileStream inputStream = Utilities.TryOpenRead(inputFiles[-index - 1]);
// Create a stream dictionary
Dictionary<string, Stream> dict = new Dictionary<string, Stream>();
@@ -525,19 +525,19 @@ namespace SabreTools.Library.FileTypes
// If the old file exists, delete it and replace
if (File.Exists(archiveFileName))
{
FileTools.TryDeleteFile(archiveFileName);
Utilities.TryDeleteFile(archiveFileName);
}
File.Move(tempFile, archiveFileName);
// Now make the file T7Z
// TODO: Add ACTUAL T7Z compatible code
BinaryWriter bw = new BinaryWriter(FileTools.TryOpenReadWrite(archiveFileName));
BinaryWriter bw = new BinaryWriter(Utilities.TryOpenReadWrite(archiveFileName));
bw.Seek(0, SeekOrigin.Begin);
bw.Write(Constants.Torrent7ZipHeader);
bw.Seek(0, SeekOrigin.End);
using (oldZipFile = new SevenZipExtractor(FileTools.TryOpenReadWrite(archiveFileName)))
using (oldZipFile = new SevenZipExtractor(Utilities.TryOpenReadWrite(archiveFileName)))
{
// Get the correct signature to use (Default 0, Unicode 1, SingleFile 2, StripFileNames 4)
byte[] tempsig = Constants.Torrent7ZipSignature;