mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Use System.Text.Json to serialize lsar output.
This commit is contained in:
96
RomRepoMgr.Core/Models/lsar.cs
Normal file
96
RomRepoMgr.Core/Models/lsar.cs
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace RomRepoMgr.Core.Models;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(lsar))]
|
||||||
|
public partial class lsarJsonContext : JsonSerializerContext {}
|
||||||
|
|
||||||
|
public class lsar
|
||||||
|
{
|
||||||
|
public int lsarFormatVersion { get; set; }
|
||||||
|
public string lsarEncoding { get; set; }
|
||||||
|
public int lsarConfidence { get; set; }
|
||||||
|
public string lsarFormatName { get; set; }
|
||||||
|
public lsarProperties lsarProperties { get; set; }
|
||||||
|
public lsarContents[] lsarContents { get; set; }
|
||||||
|
public int lsarError { get; set; }
|
||||||
|
public string lsarInnerFormatName { get; set; }
|
||||||
|
public lsarProperties lsarInnerProperties { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class lsarProperties
|
||||||
|
{
|
||||||
|
public string[] XADVolumes { get; set; }
|
||||||
|
public string XADComment { get; set; }
|
||||||
|
public string XADArchiveName { get; set; }
|
||||||
|
public bool XADIsSolid { get; set; }
|
||||||
|
public DateTime XADCreationDate { get; set; }
|
||||||
|
public DateTime XADLastModificationDate { get; set; }
|
||||||
|
public string ARJOriginalArchiveName { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class lsarContents
|
||||||
|
{
|
||||||
|
public long XADCompressedSize { get; set; }
|
||||||
|
public long XADDataLength { get; set; }
|
||||||
|
public short ZipFlags { get; set; }
|
||||||
|
public short ZipFileAttributes { get; set; }
|
||||||
|
public long XADDataOffset { get; set; }
|
||||||
|
public long XADIndex { get; set; }
|
||||||
|
public string ZipOSName { get; set; }
|
||||||
|
public short XADPosixPermissions { get; set; }
|
||||||
|
public uint ZipCRC32 { get; set; }
|
||||||
|
public int ZipLocalDate { get; set; }
|
||||||
|
public short ZipOS { get; set; }
|
||||||
|
public short ZipCompressionMethod { get; set; }
|
||||||
|
public string XADCompressionName { get; set; }
|
||||||
|
public short ZipExtractVersion { get; set; }
|
||||||
|
public string XADFileName { get; set; }
|
||||||
|
public DateTime XADLastModificationDate { get; set; }
|
||||||
|
public short XADDOSFileAttributes { get; set; }
|
||||||
|
public long XADFileSize { get; set; }
|
||||||
|
public bool TARIsSparseFile { get; set; }
|
||||||
|
public long XADFirstSolidEntry { get; set; }
|
||||||
|
public string XADSolidObject { get; set; }
|
||||||
|
public long XADFirstSolidIndex { get; set; }
|
||||||
|
public short XADPosixUser { get; set; }
|
||||||
|
public short XADPosixGroup { get; set; }
|
||||||
|
public bool XADIsSolid { get; set; }
|
||||||
|
public DateTime XADLastAccessDate { get; set; }
|
||||||
|
public int ARJCRC32 { get; set; }
|
||||||
|
public int ARJMethod { get; set; }
|
||||||
|
public int ARJMinimumVersion { get; set; }
|
||||||
|
public int ARJFileType { get; set; }
|
||||||
|
public int ARJFlags { get; set; }
|
||||||
|
public string ARJOSName { get; set; }
|
||||||
|
public int ARJOS { get; set; }
|
||||||
|
public int ARJVersion { get; set; }
|
||||||
|
public int GzipExtraFlags { get; set; }
|
||||||
|
public string GzipFilename { get; set; }
|
||||||
|
public int GzipOS { get; set; }
|
||||||
|
public short LHAHeaderLevel { get; set; }
|
||||||
|
public string LHAExtFileNameData { get; set; }
|
||||||
|
public short LHACRC16 { get; set; }
|
||||||
|
public string LHAOSName { get; set; }
|
||||||
|
public int LHAOS { get; set; }
|
||||||
|
public string RAR5OSName { get; set; }
|
||||||
|
public int RAR5Attributes { get; set; }
|
||||||
|
public long RAR5DataLength { get; set; }
|
||||||
|
public long RAR5CompressionMethod { get; set; }
|
||||||
|
public long RAR5DictionarySize { get; set; }
|
||||||
|
public uint RAR5CRC32 { get; set; }
|
||||||
|
public int RAR5Flags { get; set; }
|
||||||
|
public int RAR5DataOffset { get; set; }
|
||||||
|
public int RAR5CompressionVersion { get; set; }
|
||||||
|
public int RAR5CompressionInformation { get; set; }
|
||||||
|
public int RAR5OS { get; set; }
|
||||||
|
public RAR5InputParts[] RAR5InputParts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RAR5InputParts
|
||||||
|
{
|
||||||
|
public uint CRC32 { get; set; }
|
||||||
|
public long InputLength { get; set; }
|
||||||
|
public long Offset { get; set; }
|
||||||
|
}
|
||||||
@@ -461,8 +461,8 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
Dictionary<ChecksumType, string> checksums = checksumWorker.End();
|
Dictionary<ChecksumType, string> checksums = checksumWorker.End();
|
||||||
|
|
||||||
var uSize = (ulong)inFs.Length;
|
ulong uSize = (ulong)inFs.Length;
|
||||||
var fileInDb = true;
|
bool fileInDb = true;
|
||||||
|
|
||||||
bool knownFile = _pendingFiles.TryGetValue(checksums[ChecksumType.Sha512], out DbFile dbFile);
|
bool knownFile = _pendingFiles.TryGetValue(checksums[ChecksumType.Sha512], out DbFile dbFile);
|
||||||
|
|
||||||
@@ -505,10 +505,10 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(!knownFile) _pendingFiles[checksums[ChecksumType.Sha512]] = dbFile;
|
if(!knownFile) _pendingFiles[checksums[ChecksumType.Sha512]] = dbFile;
|
||||||
|
|
||||||
var sha384Bytes = new byte[48];
|
byte[] sha384Bytes = new byte[48];
|
||||||
string sha384 = checksums[ChecksumType.Sha384];
|
string sha384 = checksums[ChecksumType.Sha384];
|
||||||
|
|
||||||
for(var i = 0; i < 48; i++)
|
for(int i = 0; i < 48; i++)
|
||||||
{
|
{
|
||||||
if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39)
|
if(sha384[i * 2] >= 0x30 && sha384[i * 2] <= 0x39)
|
||||||
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10);
|
sha384Bytes[i] = (byte)((sha384[i * 2] - 0x30) * 0x10);
|
||||||
@@ -696,9 +696,9 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(chd.MD5 != null)
|
if(chd.MD5 != null)
|
||||||
{
|
{
|
||||||
var chdArray = new char[32];
|
char[] chdArray = new char[32];
|
||||||
|
|
||||||
for(var i = 0; i < 16; i++)
|
for(int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
int nibble1 = chd.MD5[i] >> 4;
|
int nibble1 = chd.MD5[i] >> 4;
|
||||||
int nibble2 = chd.MD5[i] & 0xF;
|
int nibble2 = chd.MD5[i] & 0xF;
|
||||||
@@ -715,9 +715,9 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(chd.SHA1 != null)
|
if(chd.SHA1 != null)
|
||||||
{
|
{
|
||||||
var chdArray = new char[40];
|
char[] chdArray = new char[40];
|
||||||
|
|
||||||
for(var i = 0; i < 20; i++)
|
for(int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
int nibble1 = chd.SHA1[i] >> 4;
|
int nibble1 = chd.SHA1[i] >> 4;
|
||||||
int nibble2 = chd.SHA1[i] & 0xF;
|
int nibble2 = chd.SHA1[i] & 0xF;
|
||||||
@@ -732,11 +732,11 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
sha1 = new string(chdArray);
|
sha1 = new string(chdArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
var uSize = (ulong)inFs.Length;
|
ulong uSize = (ulong)inFs.Length;
|
||||||
var diskInDb = true;
|
bool diskInDb = true;
|
||||||
DbDisk dbDisk = null;
|
DbDisk dbDisk = null;
|
||||||
var knownDisk = false;
|
bool knownDisk = false;
|
||||||
var knownDiskWasBigger = false;
|
bool knownDiskWasBigger = false;
|
||||||
|
|
||||||
if(sha1 != null) knownDisk = _pendingDisksBySha1.TryGetValue(sha1, out dbDisk);
|
if(sha1 != null) knownDisk = _pendingDisksBySha1.TryGetValue(sha1, out dbDisk);
|
||||||
|
|
||||||
@@ -887,7 +887,7 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
Message = Localization.CopyingFile
|
Message = Localization.CopyingFile
|
||||||
});
|
});
|
||||||
|
|
||||||
var buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
|
|
||||||
while(inFs.Position + BUFFER_SIZE <= inFs.Length)
|
while(inFs.Position + BUFFER_SIZE <= inFs.Length)
|
||||||
{
|
{
|
||||||
@@ -978,9 +978,9 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(aif.MD5 != null)
|
if(aif.MD5 != null)
|
||||||
{
|
{
|
||||||
var chdArray = new char[32];
|
char[] chdArray = new char[32];
|
||||||
|
|
||||||
for(var i = 0; i < 16; i++)
|
for(int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
int nibble1 = aif.MD5[i] >> 4;
|
int nibble1 = aif.MD5[i] >> 4;
|
||||||
int nibble2 = aif.MD5[i] & 0xF;
|
int nibble2 = aif.MD5[i] & 0xF;
|
||||||
@@ -997,9 +997,9 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(aif.SHA1 != null)
|
if(aif.SHA1 != null)
|
||||||
{
|
{
|
||||||
var chdArray = new char[40];
|
char[] chdArray = new char[40];
|
||||||
|
|
||||||
for(var i = 0; i < 20; i++)
|
for(int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
int nibble1 = aif.SHA1[i] >> 4;
|
int nibble1 = aif.SHA1[i] >> 4;
|
||||||
int nibble2 = aif.SHA1[i] & 0xF;
|
int nibble2 = aif.SHA1[i] & 0xF;
|
||||||
@@ -1016,9 +1016,9 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
|
|
||||||
if(aif.SHA256 != null)
|
if(aif.SHA256 != null)
|
||||||
{
|
{
|
||||||
var chdArray = new char[64];
|
char[] chdArray = new char[64];
|
||||||
|
|
||||||
for(var i = 0; i < 32; i++)
|
for(int i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
int nibble1 = aif.SHA256[i] >> 4;
|
int nibble1 = aif.SHA256[i] >> 4;
|
||||||
int nibble2 = aif.SHA256[i] & 0xF;
|
int nibble2 = aif.SHA256[i] & 0xF;
|
||||||
@@ -1033,11 +1033,11 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
sha256 = new string(chdArray);
|
sha256 = new string(chdArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
var uSize = (ulong)inFs.Length;
|
ulong uSize = (ulong)inFs.Length;
|
||||||
var mediaInDb = true;
|
bool mediaInDb = true;
|
||||||
DbMedia dbMedia = null;
|
DbMedia dbMedia = null;
|
||||||
var knownMedia = false;
|
bool knownMedia = false;
|
||||||
var knownMediaWasBigger = false;
|
bool knownMediaWasBigger = false;
|
||||||
|
|
||||||
if(sha256 != null) knownMedia = _pendingMediasBySha256.TryGetValue(sha256, out dbMedia);
|
if(sha256 != null) knownMedia = _pendingMediasBySha256.TryGetValue(sha256, out dbMedia);
|
||||||
|
|
||||||
@@ -1229,7 +1229,7 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
Message = Localization.CopyingFile
|
Message = Localization.CopyingFile
|
||||||
});
|
});
|
||||||
|
|
||||||
var buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
|
|
||||||
while(inFs.Position + BUFFER_SIZE <= inFs.Length)
|
while(inFs.Position + BUFFER_SIZE <= inFs.Length)
|
||||||
{
|
{
|
||||||
@@ -1351,28 +1351,19 @@ public sealed class FileImporter(bool onlyKnown, bool deleteAfterImport)
|
|||||||
lsarProcess.Start();
|
lsarProcess.Start();
|
||||||
string lsarOutput = lsarProcess.StandardOutput.ReadToEnd();
|
string lsarOutput = lsarProcess.StandardOutput.ReadToEnd();
|
||||||
lsarProcess.WaitForExit();
|
lsarProcess.WaitForExit();
|
||||||
string format = null;
|
|
||||||
var jsReader = new JsonTextReader(new StringReader(lsarOutput));
|
|
||||||
|
|
||||||
while(jsReader.Read())
|
lsar lsar = JsonConvert.DeserializeObject<lsar>(lsarOutput);
|
||||||
|
|
||||||
|
if(lsar is null)
|
||||||
{
|
{
|
||||||
switch(jsReader.TokenType)
|
counter = 0;
|
||||||
{
|
|
||||||
case JsonToken.PropertyName when jsReader.Value?.ToString() == "XADFileName":
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
break;
|
return null;
|
||||||
case JsonToken.PropertyName when jsReader.Value?.ToString() == "lsarFormatName":
|
|
||||||
jsReader.Read();
|
|
||||||
|
|
||||||
if(jsReader.TokenType == JsonToken.String && jsReader.Value != null)
|
|
||||||
format = jsReader.Value.ToString();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return counter == 0 ? null : format;
|
counter = lsar.lsarContents.Length;
|
||||||
|
|
||||||
|
return lsar.lsarFormatName;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user