mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add back date support (fixes #17)
This commit is contained in:
@@ -5796,7 +5796,7 @@ namespace SabreTools.Library.DatFiles
|
||||
}
|
||||
if ((DatFormat & DatFormat.EverdriveSMDB) != 0
|
||||
&& ((DatFormat & DatFormat.AttractMode) != 0
|
||||
|| (DatFormat & DatFormat.Listrom) != 0)
|
||||
|| (DatFormat & DatFormat.Listrom) != 0
|
||||
|| (DatFormat & DatFormat.MissFile) != 0))
|
||||
{
|
||||
outfileNames.Add(DatFormat.SoftwareList, CreateOutfileNamesHelper(outDir, ".smdb.txt", overwrite));
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Compress
|
||||
void ZipFileClose();
|
||||
|
||||
ZipReturn ZipFileOpenReadStream(int index, out Stream stream, out ulong streamSize);
|
||||
ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream);
|
||||
ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, uint? datetime, out Stream stream);
|
||||
ZipReturn ZipFileCloseReadStream();
|
||||
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace Compress.ZipFile
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream)
|
||||
public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, uint? datetime, out Stream stream)
|
||||
{
|
||||
stream = null;
|
||||
if (ZipOpen != ZipOpenType.OpenWrite)
|
||||
@@ -225,7 +225,7 @@ namespace Compress.ZipFile
|
||||
return ZipReturn.ZipWritingToInputFile;
|
||||
}
|
||||
|
||||
LocalFile lf = new LocalFile(filename);
|
||||
LocalFile lf = new LocalFile(filename, datetime);
|
||||
|
||||
ZipReturn retVal = lf.LocalFileOpenWriteStream(_zipFs, raw, trrntzip, uncompressedSize, compressionMethod, out stream);
|
||||
|
||||
@@ -863,7 +863,7 @@ namespace Compress.ZipFile
|
||||
return zRet;
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileAddFake(string filename, ulong fileOffset, ulong uncompressedSize, ulong compressedSize, byte[] crc32, out byte[] localHeader)
|
||||
public ZipReturn ZipFileAddFake(string filename, ulong fileOffset, ulong uncompressedSize, ulong compressedSize, byte[] crc32, uint? datetime, out byte[] localHeader)
|
||||
{
|
||||
localHeader = null;
|
||||
|
||||
@@ -872,7 +872,7 @@ namespace Compress.ZipFile
|
||||
return ZipReturn.ZipWritingToInputFile;
|
||||
}
|
||||
|
||||
LocalFile lf = new LocalFile(filename);
|
||||
LocalFile lf = new LocalFile(filename, datetime);
|
||||
_localFiles.Add(lf);
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -1087,6 +1087,7 @@ namespace Compress.ZipFile
|
||||
private ushort _compressionMethod;
|
||||
private ushort _lastModFileTime;
|
||||
private ushort _lastModFileDate;
|
||||
private uint? _lastModFileDateTime;
|
||||
private ulong _compressedSize;
|
||||
public ulong RelativeOffsetOfLocalHeader; // only in centeral directory
|
||||
|
||||
@@ -1098,13 +1099,20 @@ namespace Compress.ZipFile
|
||||
{
|
||||
}
|
||||
|
||||
public LocalFile(string filename)
|
||||
public LocalFile(string filename, uint? datetime)
|
||||
{
|
||||
Zip64 = false;
|
||||
GeneralPurposeBitFlag = 2; // Maximum Compression Deflating
|
||||
_compressionMethod = 8; // Compression Method Deflate
|
||||
if (datetime == null)
|
||||
{
|
||||
_lastModFileTime = 48128;
|
||||
_lastModFileDate = 8600;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastModFileDateTime = datetime;
|
||||
}
|
||||
|
||||
FileName = filename;
|
||||
}
|
||||
@@ -1120,6 +1128,8 @@ namespace Compress.ZipFile
|
||||
public DateTime DateTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_lastModFileDateTime == null)
|
||||
{
|
||||
int second = (_lastModFileTime & 0x1f) * 2;
|
||||
int minute = (_lastModFileTime >> 5) & 0x3f;
|
||||
@@ -1131,6 +1141,11 @@ namespace Compress.ZipFile
|
||||
|
||||
return new DateTime(year, month, day, hour, minute, second);
|
||||
}
|
||||
else
|
||||
{
|
||||
return SabreTools.Library.Tools.Utilities.ConvertMsDosTimeFormatToDateTime(_lastModFileDateTime.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ulong LocalFilePos
|
||||
@@ -1329,8 +1344,15 @@ namespace Compress.ZipFile
|
||||
bw.Write(versionNeededToExtract);
|
||||
bw.Write(GeneralPurposeBitFlag);
|
||||
bw.Write(_compressionMethod);
|
||||
if (_lastModFileDateTime == null)
|
||||
{
|
||||
bw.Write(_lastModFileTime);
|
||||
bw.Write(_lastModFileDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(_lastModFileDateTime.Value);
|
||||
}
|
||||
bw.Write(CRC[3]);
|
||||
bw.Write(CRC[2]);
|
||||
bw.Write(CRC[1]);
|
||||
@@ -1636,8 +1658,15 @@ namespace Compress.ZipFile
|
||||
bw.Write(versionNeededToExtract);
|
||||
bw.Write(GeneralPurposeBitFlag);
|
||||
bw.Write(_compressionMethod);
|
||||
if (_lastModFileDateTime == null)
|
||||
{
|
||||
bw.Write(_lastModFileTime);
|
||||
bw.Write(_lastModFileDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(_lastModFileDateTime.Value);
|
||||
}
|
||||
|
||||
_crc32Location = (ulong)zipFs.Position;
|
||||
|
||||
@@ -1690,8 +1719,15 @@ namespace Compress.ZipFile
|
||||
bw.Write(versionNeededToExtract);
|
||||
bw.Write(GeneralPurposeBitFlag);
|
||||
bw.Write(_compressionMethod);
|
||||
if (_lastModFileDateTime == null)
|
||||
{
|
||||
bw.Write(_lastModFileTime);
|
||||
bw.Write(_lastModFileDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(_lastModFileDateTime.Value);
|
||||
}
|
||||
|
||||
uint tCompressedSize;
|
||||
uint tUncompressedSize;
|
||||
|
||||
@@ -495,11 +495,11 @@ namespace SabreTools.Library.FileTypes
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -570,11 +570,11 @@ namespace SabreTools.Library.FileTypes
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -595,7 +595,8 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(oldZipFile.LastModified(index));
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
@@ -720,11 +721,11 @@ namespace SabreTools.Library.FileTypes
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -803,11 +804,11 @@ namespace SabreTools.Library.FileTypes
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -827,7 +828,8 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Instantiate the streams
|
||||
oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream);
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(oldZipFile.LastModified(index));
|
||||
zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
|
||||
// Copy the input stream to the output
|
||||
byte[] ibuffer = new byte[_bufferSize];
|
||||
|
||||
Reference in New Issue
Block a user