mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Extract out IO namespace, Part 3
This commit is contained in:
@@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="filename">Filename respresenting the AaruFormat file</param>
|
||||
public static AaruFormat Create(string filename)
|
||||
{
|
||||
using (FileStream fs = FileExtensions.TryOpenRead(filename))
|
||||
using (FileStream fs = File.OpenRead(filename))
|
||||
{
|
||||
return Create(fs);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace SabreTools.Library.FileTypes
|
||||
BaseArchive archive = null;
|
||||
|
||||
// First get the archive type
|
||||
FileType? at = input.GetFileType();
|
||||
FileType? at = GetFileType(input);
|
||||
|
||||
// If we got back null, then it's not an archive, so we we return
|
||||
if (at == null)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -110,7 +111,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
if (getHashes)
|
||||
{
|
||||
BaseFile temp = FileExtensions.GetInfo(this.Filename, hashes: this.AvailableHashes);
|
||||
BaseFile temp = GetInfo(this.Filename, hashes: this.AvailableHashes);
|
||||
if (temp != null)
|
||||
{
|
||||
this.Parent = temp.Parent;
|
||||
@@ -165,6 +166,141 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Static Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns the file type of an input file
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to check</param>
|
||||
/// <returns>FileType of inputted file (null on error)</returns>
|
||||
public static FileType? GetFileType(string input)
|
||||
{
|
||||
FileType? outFileType = null;
|
||||
|
||||
// If the file is null, then we have no archive type
|
||||
if (input == null)
|
||||
return outFileType;
|
||||
|
||||
// First line of defense is going to be the extension, for better or worse
|
||||
if (!PathExtensions.HasValidArchiveExtension(input))
|
||||
return outFileType;
|
||||
|
||||
// Read the first bytes of the file and get the magic number
|
||||
BinaryReader br = new BinaryReader(File.OpenRead(input));
|
||||
byte[] magic = br.ReadBytes(8);
|
||||
br.Dispose();
|
||||
|
||||
// Now try to match it to a known signature
|
||||
if (magic.StartsWith(Constants.SevenZipSignature))
|
||||
{
|
||||
outFileType = FileType.SevenZipArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.AaruFormatSignature))
|
||||
{
|
||||
outFileType = FileType.AaruFormat;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.CHDSignature))
|
||||
{
|
||||
outFileType = FileType.CHD;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.GzSignature))
|
||||
{
|
||||
outFileType = FileType.GZipArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.LRZipSignature))
|
||||
{
|
||||
outFileType = FileType.LRZipArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.LZ4Signature)
|
||||
|| magic.StartsWith(Constants.LZ4SkippableMinSignature)
|
||||
|| magic.StartsWith(Constants.LZ4SkippableMaxSignature))
|
||||
{
|
||||
outFileType = FileType.LZ4Archive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.RarSignature)
|
||||
|| magic.StartsWith(Constants.RarFiveSignature))
|
||||
{
|
||||
outFileType = FileType.RarArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.TarSignature)
|
||||
|| magic.StartsWith(Constants.TarZeroSignature))
|
||||
{
|
||||
outFileType = FileType.TapeArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.XZSignature))
|
||||
{
|
||||
outFileType = FileType.XZArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.ZipSignature)
|
||||
|| magic.StartsWith(Constants.ZipSignatureEmpty)
|
||||
|| magic.StartsWith(Constants.ZipSignatureSpanned))
|
||||
{
|
||||
outFileType = FileType.ZipArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.ZPAQSignature))
|
||||
{
|
||||
outFileType = FileType.ZPAQArchive;
|
||||
}
|
||||
else if (magic.StartsWith(Constants.ZstdSignature))
|
||||
{
|
||||
outFileType = FileType.ZstdArchive;
|
||||
}
|
||||
|
||||
return outFileType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single file
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="header">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||
public static BaseFile GetInfo(string input, string header = null, Hash hashes = Hash.Standard, TreatAsFile asFiles = 0x00)
|
||||
{
|
||||
// Add safeguard if file doesn't exist
|
||||
if (!File.Exists(input))
|
||||
return null;
|
||||
|
||||
// Get input information
|
||||
var fileType = GetFileType(input);
|
||||
Stream inputStream = File.OpenRead(input);
|
||||
|
||||
// Try to match the supplied header skipper
|
||||
if (header != null)
|
||||
{
|
||||
var rule = Transform.GetMatchingRule(input, Path.GetFileNameWithoutExtension(header));
|
||||
|
||||
// If there's a match, transform the stream before getting info
|
||||
if (rule.Tests != null && rule.Tests.Count != 0)
|
||||
{
|
||||
// Create the output stream
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
|
||||
// Transform the stream and get the information from it
|
||||
rule.TransformStream(inputStream, outputStream, keepReadOpen: false, keepWriteOpen: true);
|
||||
inputStream = outputStream;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the info in the proper manner
|
||||
BaseFile baseFile;
|
||||
if (fileType == FileType.AaruFormat && !asFiles.HasFlag(TreatAsFile.AaruFormat))
|
||||
baseFile = AaruFormat.Create(inputStream);
|
||||
else if (fileType == FileType.CHD && !asFiles.HasFlag(TreatAsFile.CHD))
|
||||
baseFile = CHDFile.Create(inputStream);
|
||||
else
|
||||
baseFile = GetInfo(inputStream, hashes: hashes, keepReadOpen: false);
|
||||
|
||||
// Dispose of the input stream
|
||||
inputStream?.Dispose();
|
||||
|
||||
// Add unique data from the file
|
||||
baseFile.Filename = Path.GetFileName(input);
|
||||
baseFile.Date = new FileInfo(input).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
return baseFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single file
|
||||
/// </summary>
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.FileTypes.CHD;
|
||||
using SabreTools.Library.IO;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="filename">Filename respresenting the CHD file</param>
|
||||
public static CHDFile Create(string filename)
|
||||
{
|
||||
using (FileStream fs = FileExtensions.TryOpenRead(filename))
|
||||
using (FileStream fs = File.OpenRead(filename))
|
||||
{
|
||||
return Create(fs);
|
||||
}
|
||||
|
||||
@@ -1252,30 +1252,6 @@ namespace SabreTools.Library.FileTypes
|
||||
PPMdVersionIRev1 = 98,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Type of file that is being looked at
|
||||
/// </summary>
|
||||
public enum FileType
|
||||
{
|
||||
// Singleton
|
||||
None = 0,
|
||||
AaruFormat,
|
||||
CHD,
|
||||
|
||||
// Can contain children
|
||||
Folder,
|
||||
SevenZipArchive,
|
||||
GZipArchive,
|
||||
LRZipArchive,
|
||||
LZ4Archive,
|
||||
RarArchive,
|
||||
TapeArchive,
|
||||
XZArchive,
|
||||
ZipArchive,
|
||||
ZPAQArchive,
|
||||
ZstdArchive,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Output format for rebuilt files
|
||||
/// </summary>
|
||||
|
||||
@@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Logging;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
@@ -249,7 +249,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If we had a file, copy that over to the new name
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
{
|
||||
FileExtensions.TryOpenRead(match).CopyTo(ms);
|
||||
File.OpenRead(match).CopyTo(ms);
|
||||
realentry = match;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ namespace SabreTools.Library.FileTypes
|
||||
_children = new List<BaseFile>();
|
||||
foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
BaseFile nf = FileExtensions.GetInfo(file, hashes: this.AvailableHashes);
|
||||
BaseFile nf = GetInfo(file, hashes: this.AvailableHashes);
|
||||
_children.Add(nf);
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||
public virtual bool Write(string inputFile, string outDir, Rom rom)
|
||||
{
|
||||
FileStream fs = FileExtensions.TryOpenRead(inputFile);
|
||||
FileStream fs = File.OpenRead(inputFile);
|
||||
return Write(fs, outDir, rom);
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
|
||||
|
||||
// Overwrite output files by default
|
||||
outputStream = FileExtensions.TryCreate(fileName);
|
||||
outputStream = File.Create(fileName);
|
||||
|
||||
// If the output stream isn't null
|
||||
if (outputStream != null)
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = FileExtensions.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(this.Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
|
||||
@@ -124,7 +124,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -226,7 +226,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (this.AvailableHashes == Hash.CRC)
|
||||
{
|
||||
gzipEntryRom.Filename = gamename;
|
||||
using (BinaryReader br = new BinaryReader(FileExtensions.TryOpenRead(this.Filename)))
|
||||
using (BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)))
|
||||
{
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
gzipEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
@@ -306,7 +306,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the Romba-specific header data
|
||||
BinaryReader br = new BinaryReader(FileExtensions.TryOpenRead(this.Filename));
|
||||
BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
|
||||
byte[] header = br.ReadBytes(12); // Get preamble header for checking
|
||||
br.ReadBytes(16); // headermd5
|
||||
br.ReadBytes(4); // headercrc
|
||||
@@ -371,7 +371,7 @@ namespace SabreTools.Library.FileTypes
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
ulong headersz; // Int64 size
|
||||
BinaryReader br = new BinaryReader(FileExtensions.TryOpenRead(this.Filename));
|
||||
BinaryReader br = new BinaryReader(File.OpenRead(this.Filename));
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
@@ -435,7 +435,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputFile = Path.GetFullPath(inputFile);
|
||||
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -474,7 +474,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (!File.Exists(outfile))
|
||||
{
|
||||
// Compress the input stream
|
||||
FileStream outputStream = FileExtensions.TryCreate(outfile);
|
||||
FileStream outputStream = File.Create(outfile);
|
||||
|
||||
// Open the output file for writing
|
||||
BinaryWriter sw = new BinaryWriter(outputStream);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Rar;
|
||||
using SharpCompress.Readers;
|
||||
@@ -106,7 +106,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -182,7 +182,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
try
|
||||
{
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(FileExtensions.TryOpenRead(this.Filename));
|
||||
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(File.OpenRead(this.Filename));
|
||||
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
|
||||
{
|
||||
// Create a blank item for the entry
|
||||
@@ -284,7 +284,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress;
|
||||
using Compress.SevenZip;
|
||||
@@ -86,7 +86,7 @@ namespace SabreTools.Library.FileTypes
|
||||
continue;
|
||||
}
|
||||
|
||||
FileStream writeStream = FileExtensions.TryCreate(Path.Combine(outDir, zf.Filename(i)));
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.Filename(i)));
|
||||
|
||||
// If the stream is smaller than the buffer, just run one loop through to avoid issues
|
||||
if (streamsize < _bufferSize)
|
||||
@@ -155,7 +155,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -410,7 +410,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -597,7 +597,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
@@ -677,7 +677,7 @@ namespace SabreTools.Library.FileTypes
|
||||
int index = inputIndexMap[key];
|
||||
|
||||
// Open the input file for reading
|
||||
Stream freadStream = FileExtensions.TryOpenRead(inputFiles[index]);
|
||||
Stream freadStream = File.OpenRead(inputFiles[index]);
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
@@ -760,7 +760,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (index < 0)
|
||||
{
|
||||
// Open the input file for reading
|
||||
Stream freadStream = FileExtensions.TryOpenRead(inputFiles[-index - 1]);
|
||||
Stream freadStream = File.OpenRead(inputFiles[-index - 1]);
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
@@ -822,7 +822,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
}
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress.ZipFile;
|
||||
using SharpCompress.Archives;
|
||||
@@ -111,7 +111,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -187,7 +187,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
try
|
||||
{
|
||||
TarArchive ta = TarArchive.Open(FileExtensions.TryOpenRead(this.Filename));
|
||||
TarArchive ta = TarArchive.Open(File.OpenRead(this.Filename));
|
||||
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
|
||||
{
|
||||
// Create a blank item for the entry
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -422,7 +422,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace SabreTools.Library.FileTypes
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
tarFile.AddEntry(roms[index].Name, FileExtensions.TryOpenRead(inputFiles[index]), size: roms[index].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(roms[index].Name, File.OpenRead(inputFiles[index]), size: roms[index].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ namespace SabreTools.Library.FileTypes
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input file to the output
|
||||
tarFile.AddEntry(roms[-index - 1].Name, FileExtensions.TryOpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(roms[-index - 1].Name, File.OpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -597,7 +597,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
}
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = FileExtensions.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
FileStream outstream = File.Create(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
var xz = new XZStream(File.OpenRead(this.Filename));
|
||||
xz.CopyTo(outstream);
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -218,7 +218,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (this.AvailableHashes == Hash.CRC)
|
||||
{
|
||||
xzEntryRom.Filename = gamename;
|
||||
using (BinaryReader br = new BinaryReader(FileExtensions.TryOpenRead(this.Filename)))
|
||||
using (BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)))
|
||||
{
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
@@ -335,7 +335,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputFile = Path.GetFullPath(inputFile);
|
||||
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -374,7 +374,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (!File.Exists(outfile))
|
||||
{
|
||||
// Compress the input stream
|
||||
XZStream outputStream = new XZStream(FileExtensions.TryCreate(outfile));
|
||||
XZStream outputStream = new XZStream(File.Create(outfile));
|
||||
inputStream.CopyTo(outputStream);
|
||||
|
||||
// Dispose of everything
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress;
|
||||
using Compress.ZipFile;
|
||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
||||
continue;
|
||||
}
|
||||
|
||||
FileStream writeStream = FileExtensions.TryCreate(Path.Combine(outDir, zf.Filename(i)));
|
||||
FileStream writeStream = File.Create(Path.Combine(outDir, zf.Filename(i)));
|
||||
|
||||
// If the stream is smaller than the buffer, just run one loop through to avoid issues
|
||||
if (streamsize < _bufferSize)
|
||||
@@ -156,7 +156,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
|
||||
|
||||
// Now open and write the file if possible
|
||||
FileStream fs = FileExtensions.TryCreate(realEntry);
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
@@ -412,7 +412,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -598,7 +598,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
@@ -678,7 +678,7 @@ namespace SabreTools.Library.FileTypes
|
||||
int index = inputIndexMap[key];
|
||||
|
||||
// Open the input file for reading
|
||||
Stream freadStream = FileExtensions.TryOpenRead(inputFiles[index]);
|
||||
Stream freadStream = File.OpenRead(inputFiles[index]);
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
@@ -761,7 +761,7 @@ namespace SabreTools.Library.FileTypes
|
||||
if (index < 0)
|
||||
{
|
||||
// Open the input file for reading
|
||||
Stream freadStream = FileExtensions.TryOpenRead(inputFiles[-index - 1]);
|
||||
Stream freadStream = File.OpenRead(inputFiles[-index - 1]);
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
@@ -824,7 +824,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If the old file exists, delete it and replace
|
||||
if (File.Exists(archiveFileName))
|
||||
{
|
||||
FileExtensions.TryDelete(archiveFileName);
|
||||
File.Delete(archiveFileName);
|
||||
}
|
||||
File.Move(tempFile, archiveFileName);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
|
||||
Reference in New Issue
Block a user