[DatFile, ArchiveTools, FileTools] Fix DFD

This commit is contained in:
Matt Nadareski
2017-10-16 14:02:41 -07:00
parent a9d0483a17
commit 89489a10d0
3 changed files with 109 additions and 115 deletions

View File

@@ -31,22 +31,22 @@ namespace SabreTools.Library.DatFiles
/// Represents a format-agnostic DAT /// Represents a format-agnostic DAT
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// TODO: Make output standard width (HTML, without making the entire thing a table) /// TODO: Make stats output standard width (HTML, without making the entire thing a table)
/// TODO: Multithreading? Either StringBuilder or locking /// TODO: Stats multithreading? Either StringBuilder or locking
/// </remarks> /// </remarks>
public partial class DatFile public partial class DatFile
{ {
#region Private instance variables #region Private instance variables
// Internal DatHeader values // Internal DatHeader values
private DatHeader _datHeader = new DatHeader(); internal DatHeader _datHeader = new DatHeader();
// DatItems dictionary // DatItems dictionary
private SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>(); internal SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>();
private SortedBy _sortedBy; internal SortedBy _sortedBy;
// Internal statistical data // Internal statistical data
DatStats _datStats = new DatStats(); internal DatStats _datStats = new DatStats();
#endregion #endregion
@@ -2962,55 +2962,55 @@ namespace SabreTools.Library.DatFiles
switch (FileTools.GetDatFormat(filename)) switch (FileTools.GetDatFormat(filename))
{ {
case DatFormat.AttractMode: case DatFormat.AttractMode:
(this as AttractMode).Parse(filename, sysid, srcid, keep, clean, remUnicode); new AttractMode(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.ClrMamePro: case DatFormat.ClrMamePro:
(this as ClrMamePro).Parse(filename, sysid, srcid, keep, clean, remUnicode); new ClrMamePro(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.CSV: case DatFormat.CSV:
(this as SeparatedValue).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode); new SeparatedValue(this).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode);
break; break;
case DatFormat.DOSCenter: case DatFormat.DOSCenter:
(this as DosCenter).Parse(filename, sysid, srcid, keep, clean, remUnicode); new DosCenter(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.Listroms: case DatFormat.Listroms:
(this as Listroms).Parse(filename, sysid, srcid, keep, clean, remUnicode); new Listroms(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.Logiqx: case DatFormat.Logiqx:
(this as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode); new Logiqx(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.OfflineList: case DatFormat.OfflineList:
(this as OfflineList).Parse(filename, sysid, srcid, keep, clean, remUnicode); new OfflineList(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.RedumpMD5: 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; break;
case DatFormat.RedumpSFV: 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; break;
case DatFormat.RedumpSHA1: 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; break;
case DatFormat.RedumpSHA256: 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; break;
case DatFormat.RedumpSHA384: 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; break;
case DatFormat.RedumpSHA512: 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; break;
case DatFormat.RomCenter: case DatFormat.RomCenter:
(this as RomCenter).Parse(filename, sysid, srcid, clean, remUnicode); new RomCenter(this).Parse(filename, sysid, srcid, clean, remUnicode);
break; break;
case DatFormat.SabreDat: case DatFormat.SabreDat:
(this as SabreDat).Parse(filename, sysid, srcid, keep, clean, remUnicode); new SabreDat(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.SoftwareList: case DatFormat.SoftwareList:
(this as SoftwareList).Parse(filename, sysid, srcid, keep, clean, remUnicode); new SoftwareList(this).Parse(filename, sysid, srcid, keep, clean, remUnicode);
break; break;
case DatFormat.TSV: 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; break;
default: default:
return; return;
@@ -5564,63 +5564,71 @@ namespace SabreTools.Library.DatFiles
Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat => Parallel.ForEach(outfiles.Keys, Globals.ParallelOptions, datFormat =>
{ {
string outfile = outfiles[datFormat]; string outfile = outfiles[datFormat];
switch (datFormat) try
{ {
case DatFormat.AttractMode: switch (datFormat)
(this as AttractMode).WriteToFile(outfile); {
break; case DatFormat.AttractMode:
case DatFormat.ClrMamePro: new AttractMode(this).WriteToFile(outfile);
(this as ClrMamePro).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.ClrMamePro:
case DatFormat.CSV: new ClrMamePro(this).WriteToFile(outfile, ignoreblanks);
(this as SeparatedValue).WriteToFile(outfile, ',', ignoreblanks); break;
break; case DatFormat.CSV:
case DatFormat.DOSCenter: new SeparatedValue(this).WriteToFile(outfile, ',', ignoreblanks);
(this as DosCenter).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.DOSCenter:
case DatFormat.Listroms: new DosCenter(this).WriteToFile(outfile, ignoreblanks);
(this as Listroms).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.Listroms:
case DatFormat.Logiqx: new Listroms(this).WriteToFile(outfile, ignoreblanks);
(this as Logiqx).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.Logiqx:
case DatFormat.MissFile: new Logiqx(this).WriteToFile(outfile, ignoreblanks);
(this as Missfile).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.MissFile:
case DatFormat.OfflineList: new Missfile(this).WriteToFile(outfile, ignoreblanks);
(this as OfflineList).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.OfflineList:
case DatFormat.RedumpMD5: new OfflineList(this).WriteToFile(outfile, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.MD5, ignoreblanks); break;
break; case DatFormat.RedumpMD5:
case DatFormat.RedumpSFV: new Hashfile(this).WriteToFile(outfile, Hash.MD5, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.CRC, ignoreblanks); break;
break; case DatFormat.RedumpSFV:
case DatFormat.RedumpSHA1: new Hashfile(this).WriteToFile(outfile, Hash.CRC, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.SHA1, ignoreblanks); break;
break; case DatFormat.RedumpSHA1:
case DatFormat.RedumpSHA256: new Hashfile(this).WriteToFile(outfile, Hash.SHA1, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.SHA256, ignoreblanks); break;
break; case DatFormat.RedumpSHA256:
case DatFormat.RedumpSHA384: new Hashfile(this).WriteToFile(outfile, Hash.SHA256, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.SHA384, ignoreblanks); break;
break; case DatFormat.RedumpSHA384:
case DatFormat.RedumpSHA512: new Hashfile(this).WriteToFile(outfile, Hash.SHA384, ignoreblanks);
(this as Hashfile).WriteToFile(outfile, Hash.SHA512, ignoreblanks); break;
break; case DatFormat.RedumpSHA512:
case DatFormat.RomCenter: new Hashfile(this).WriteToFile(outfile, Hash.SHA512, ignoreblanks);
(this as RomCenter).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.RomCenter:
case DatFormat.SabreDat: new RomCenter(this).WriteToFile(outfile, ignoreblanks);
(this as SabreDat).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.SabreDat:
case DatFormat.SoftwareList: new SabreDat(this).WriteToFile(outfile, ignoreblanks);
(this as SoftwareList).WriteToFile(outfile, ignoreblanks); break;
break; case DatFormat.SoftwareList:
case DatFormat.TSV: new SoftwareList(this).WriteToFile(outfile, ignoreblanks);
(this as SeparatedValue).WriteToFile(outfile, '\t', ignoreblanks); break;
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) catch (Exception ex)

View File

@@ -815,45 +815,17 @@ namespace SabreTools.Library.Tools
MachineName = gamename, MachineName = gamename,
}); });
} }
// Otherwise, extract to a stream // Otherwise, use the stream directly
else 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 // 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.Name = zf.Entries[i].FileName;
zipEntryRom.MachineName = gamename; zipEntryRom.MachineName = gamename;
string convertedDate = Style.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss"); string convertedDate = Style.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = (date ? convertedDate : null); zipEntryRom.Date = (date ? convertedDate : null);
found.Add(zipEntryRom); found.Add(zipEntryRom);
zr = zf.CloseReadStream();
} }
} }

View File

@@ -758,13 +758,20 @@ namespace SabreTools.Library.Tools
xxHash.Init(); xxHash.Init();
// Seek to the starting position, if one is set // 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]; byte[] buffer = new byte[8 * 1024];
@@ -845,8 +852,15 @@ namespace SabreTools.Library.Tools
} }
finally finally
{ {
// Seek to the beginning of the stream // Seek to the beginning of the stream if possible
input.Seek(0, SeekOrigin.Begin); try
{
input.Seek(0, SeekOrigin.Begin);
}
catch (NotImplementedException)
{
Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");
}
if (!keepReadOpen) if (!keepReadOpen)
{ {