diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs
index 20aca661..8d18ef8b 100644
--- a/SabreTools.Library/DatFiles/DatFile.cs
+++ b/SabreTools.Library/DatFiles/DatFile.cs
@@ -31,22 +31,22 @@ namespace SabreTools.Library.DatFiles
/// Represents a format-agnostic DAT
///
///
- /// TODO: Make output standard width (HTML, without making the entire thing a table)
- /// TODO: Multithreading? Either StringBuilder or locking
+ /// TODO: Make stats output standard width (HTML, without making the entire thing a table)
+ /// TODO: Stats multithreading? Either StringBuilder or locking
///
public partial class DatFile
{
#region Private instance variables
// Internal DatHeader values
- private DatHeader _datHeader = new DatHeader();
+ internal DatHeader _datHeader = new DatHeader();
// DatItems dictionary
- private SortedDictionary> _items = new SortedDictionary>();
- private SortedBy _sortedBy;
+ internal SortedDictionary> _items = new SortedDictionary>();
+ internal SortedBy _sortedBy;
// Internal statistical data
- DatStats _datStats = new DatStats();
+ internal DatStats _datStats = new DatStats();
#endregion
@@ -2962,55 +2962,55 @@ namespace SabreTools.Library.DatFiles
switch (FileTools.GetDatFormat(filename))
{
case DatFormat.AttractMode:
- (this as AttractMode).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new AttractMode(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.ClrMamePro:
- (this as ClrMamePro).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new ClrMamePro(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.CSV:
- (this as SeparatedValue).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode);
+ new SeparatedValue(this).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode);
break;
case DatFormat.DOSCenter:
- (this as DosCenter).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new DosCenter(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.Listroms:
- (this as Listroms).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new Listroms(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.Logiqx:
- (this as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new Logiqx(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.OfflineList:
- (this as OfflineList).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new OfflineList(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.RedumpMD5:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.MD5, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.MD5, clean, remUnicode);
break;
case DatFormat.RedumpSFV:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.CRC, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.CRC, clean, remUnicode);
break;
case DatFormat.RedumpSHA1:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA1, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.SHA1, clean, remUnicode);
break;
case DatFormat.RedumpSHA256:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA256, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.SHA256, clean, remUnicode);
break;
case DatFormat.RedumpSHA384:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA384, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.SHA384, clean, remUnicode);
break;
case DatFormat.RedumpSHA512:
- (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA512, clean, remUnicode);
+ new Hashfile(this).Parse(filename, sysid, srcid, Hash.SHA512, clean, remUnicode);
break;
case DatFormat.RomCenter:
- (this as RomCenter).Parse(filename, sysid, srcid, clean, remUnicode);
+ new RomCenter(this).Parse(filename, sysid, srcid, clean, remUnicode);
break;
case DatFormat.SabreDat:
- (this as SabreDat).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new SabreDat(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.SoftwareList:
- (this as SoftwareList).Parse(filename, sysid, srcid, keep, clean, remUnicode);
+ new SoftwareList(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break;
case DatFormat.TSV:
- (this as SeparatedValue).Parse(filename, sysid, srcid, '\t', keep, clean, remUnicode);
+ new SeparatedValue(this).Parse(filename, sysid, srcid, '\t', keep, clean, remUnicode);
break;
default:
return;
@@ -5564,63 +5564,71 @@ namespace SabreTools.Library.DatFiles
Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat =>
{
string outfile = outfiles[datFormat];
- switch (datFormat)
+ try
{
- case DatFormat.AttractMode:
- (this as AttractMode).WriteToFile(outfile);
- break;
- case DatFormat.ClrMamePro:
- (this as ClrMamePro).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.CSV:
- (this as SeparatedValue).WriteToFile(outfile, ',', ignoreblanks);
- break;
- case DatFormat.DOSCenter:
- (this as DosCenter).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.Listroms:
- (this as Listroms).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.Logiqx:
- (this as Logiqx).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.MissFile:
- (this as Missfile).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.OfflineList:
- (this as OfflineList).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.RedumpMD5:
- (this as Hashfile).WriteToFile(outfile, Hash.MD5, ignoreblanks);
- break;
- case DatFormat.RedumpSFV:
- (this as Hashfile).WriteToFile(outfile, Hash.CRC, ignoreblanks);
- break;
- case DatFormat.RedumpSHA1:
- (this as Hashfile).WriteToFile(outfile, Hash.SHA1, ignoreblanks);
- break;
- case DatFormat.RedumpSHA256:
- (this as Hashfile).WriteToFile(outfile, Hash.SHA256, ignoreblanks);
- break;
- case DatFormat.RedumpSHA384:
- (this as Hashfile).WriteToFile(outfile, Hash.SHA384, ignoreblanks);
- break;
- case DatFormat.RedumpSHA512:
- (this as Hashfile).WriteToFile(outfile, Hash.SHA512, ignoreblanks);
- break;
- case DatFormat.RomCenter:
- (this as RomCenter).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.SabreDat:
- (this as SabreDat).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.SoftwareList:
- (this as SoftwareList).WriteToFile(outfile, ignoreblanks);
- break;
- case DatFormat.TSV:
- (this as SeparatedValue).WriteToFile(outfile, '\t', ignoreblanks);
- break;
+ switch (datFormat)
+ {
+ case DatFormat.AttractMode:
+ new AttractMode(this).WriteToFile(outfile);
+ break;
+ case DatFormat.ClrMamePro:
+ new ClrMamePro(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.CSV:
+ new SeparatedValue(this).WriteToFile(outfile, ',', ignoreblanks);
+ break;
+ case DatFormat.DOSCenter:
+ new DosCenter(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.Listroms:
+ new Listroms(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.Logiqx:
+ new Logiqx(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.MissFile:
+ new Missfile(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.OfflineList:
+ new OfflineList(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.RedumpMD5:
+ new Hashfile(this).WriteToFile(outfile, Hash.MD5, ignoreblanks);
+ break;
+ case DatFormat.RedumpSFV:
+ new Hashfile(this).WriteToFile(outfile, Hash.CRC, ignoreblanks);
+ break;
+ case DatFormat.RedumpSHA1:
+ new Hashfile(this).WriteToFile(outfile, Hash.SHA1, ignoreblanks);
+ break;
+ case DatFormat.RedumpSHA256:
+ new Hashfile(this).WriteToFile(outfile, Hash.SHA256, ignoreblanks);
+ break;
+ case DatFormat.RedumpSHA384:
+ new Hashfile(this).WriteToFile(outfile, Hash.SHA384, ignoreblanks);
+ break;
+ case DatFormat.RedumpSHA512:
+ new Hashfile(this).WriteToFile(outfile, Hash.SHA512, ignoreblanks);
+ break;
+ case DatFormat.RomCenter:
+ new RomCenter(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.SabreDat:
+ new SabreDat(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.SoftwareList:
+ new SoftwareList(this).WriteToFile(outfile, ignoreblanks);
+ break;
+ case DatFormat.TSV:
+ new SeparatedValue(this).WriteToFile(outfile, '\t', ignoreblanks);
+ break;
+ }
}
+ catch (Exception ex)
+ {
+ Globals.Logger.Error("Datfile {0} could not be written out: {1}", outfile, ex.ToString());
+ }
+
});
}
catch (Exception ex)
diff --git a/SabreTools.Library/Tools/ArchiveTools.cs b/SabreTools.Library/Tools/ArchiveTools.cs
index 33c3ee6c..9ebe54df 100644
--- a/SabreTools.Library/Tools/ArchiveTools.cs
+++ b/SabreTools.Library/Tools/ArchiveTools.cs
@@ -815,45 +815,17 @@ namespace SabreTools.Library.Tools
MachineName = gamename,
});
}
- // Otherwise, extract to a stream
+ // Otherwise, use the stream directly
else
{
- MemoryStream entryStream = new MemoryStream();
-
- // If the stream is smaller than the buffer, just run one loop through to avoid issues
- if (streamsize < _bufferSize)
- {
- byte[] ibuffer = new byte[streamsize];
- int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
- entryStream.Write(ibuffer, 0, ilen);
- entryStream.Flush();
- }
- // Otherwise, we do the normal loop
- else
- {
- byte[] ibuffer = new byte[_bufferSize];
- int ilen;
- while (streamsize > _bufferSize)
- {
- ilen = readStream.Read(ibuffer, 0, _bufferSize);
- entryStream.Write(ibuffer, 0, ilen);
- entryStream.Flush();
- streamsize -= _bufferSize;
- }
-
- ilen = readStream.Read(ibuffer, 0, (int)streamsize);
- entryStream.Write(ibuffer, 0, ilen);
- entryStream.Flush();
- }
- zr = zf.CloseReadStream();
-
// Get and add the extended Rom information
- Rom zipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan);
+ Rom zipEntryRom = FileTools.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
zipEntryRom.Name = zf.Entries[i].FileName;
zipEntryRom.MachineName = gamename;
string convertedDate = Style.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = (date ? convertedDate : null);
found.Add(zipEntryRom);
+ zr = zf.CloseReadStream();
}
}
diff --git a/SabreTools.Library/Tools/FileTools.cs b/SabreTools.Library/Tools/FileTools.cs
index caca3a76..a9cd5490 100644
--- a/SabreTools.Library/Tools/FileTools.cs
+++ b/SabreTools.Library/Tools/FileTools.cs
@@ -758,13 +758,20 @@ namespace SabreTools.Library.Tools
xxHash.Init();
// Seek to the starting position, if one is set
- if (offset < 0)
+ try
{
- input.Seek(offset, SeekOrigin.End);
+ if (offset < 0)
+ {
+ input.Seek(offset, SeekOrigin.End);
+ }
+ else if (offset > 0)
+ {
+ input.Seek(offset, SeekOrigin.Begin);
+ }
}
- else
+ catch (NotImplementedException)
{
- input.Seek(offset, SeekOrigin.Begin);
+ Globals.Logger.Warning("Stream does not support seeking. Stream position not changed");
}
byte[] buffer = new byte[8 * 1024];
@@ -845,8 +852,15 @@ namespace SabreTools.Library.Tools
}
finally
{
- // Seek to the beginning of the stream
- input.Seek(0, SeekOrigin.Begin);
+ // Seek to the beginning of the stream if possible
+ try
+ {
+ input.Seek(0, SeekOrigin.Begin);
+ }
+ catch (NotImplementedException)
+ {
+ Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");
+ }
if (!keepReadOpen)
{