Add null reference checks.

This commit is contained in:
2022-03-17 00:46:26 +00:00
parent f6245f954d
commit b05dc45d09
18 changed files with 528 additions and 441 deletions

View File

@@ -58,7 +58,13 @@ public partial class Dump
void Ata() void Ata()
{ {
bool recoveredError; bool recoveredError;
var outputFormat = _outputPlugin as IWritableImage;
if(_outputPlugin is not IWritableImage outputFormat)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
if(_dumpRaw) if(_dumpRaw)
{ {

View File

@@ -62,8 +62,15 @@ partial class Dump
_dumpLog.WriteLine("Creating sidecar."); _dumpLog.WriteLine("Creating sidecar.");
var filters = new FiltersList(); var filters = new FiltersList();
IFilter filter = filters.GetFilter(_outputPath); IFilter filter = filters.GetFilter(_outputPath);
var inputPlugin = ImageFormat.Detect(filter) as IMediaImage;
totalChkDuration = 0; totalChkDuration = 0;
if(ImageFormat.Detect(filter) is not IMediaImage inputPlugin)
{
StoppingErrorMessage?.Invoke("Could not detect image format.");
return;
}
ErrorNumber opened = inputPlugin.Open(filter); ErrorNumber opened = inputPlugin.Open(filter);
if(opened != ErrorNumber.NoError) if(opened != ErrorNumber.NoError)

View File

@@ -75,7 +75,13 @@ partial class Dump
Dictionary<MediaTagType, byte[]> mediaTags = new(); Dictionary<MediaTagType, byte[]> mediaTags = new();
byte[] cmdBuf; byte[] cmdBuf;
bool ret; bool ret;
var outputFormat = _outputPlugin as IWritableImage;
if(_outputPlugin is not IWritableImage outputFormat)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
_dumpLog.WriteLine("Initializing reader."); _dumpLog.WriteLine("Initializing reader.");
var scsiReader = new Reader(_dev, _dev.Timeout, null, _errorLog); var scsiReader = new Reader(_dev, _dev.Timeout, null, _errorLog);

View File

@@ -70,7 +70,13 @@ public partial class Dump
MediaType dskType; MediaType dskType;
bool sense; bool sense;
byte[] senseBuf; byte[] senseBuf;
var outputFormat = _outputPlugin as IWritableImage;
if(_outputPlugin is not IWritableImage outputFormat)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
sense = _dev.ReadCapacity(out byte[] readBuffer, out _, _dev.Timeout, out _); sense = _dev.ReadCapacity(out byte[] readBuffer, out _, _dev.Timeout, out _);

View File

@@ -65,7 +65,13 @@ public partial class Dump
DateTime start; DateTime start;
DateTime end; DateTime end;
byte[] senseBuf; byte[] senseBuf;
var outputOptical = _outputPlugin as IWritableOpticalImage;
if(_outputPlugin is not IWritableOpticalImage outputOptical)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
bool sense = _dev.Read12(out byte[] readBuffer, out _, 0, false, true, false, false, 0, 512, 0, 1, false, bool sense = _dev.Read12(out byte[] readBuffer, out _, 0, false, true, false, false, 0, 512, 0, 1, false,
_dev.Timeout, out _); _dev.Timeout, out _);

View File

@@ -51,7 +51,13 @@ partial class Dump
bool blankCheck; bool blankCheck;
byte[] buffer; byte[] buffer;
var newBlank = false; var newBlank = false;
var outputFormat = _outputPlugin as IWritableImage;
if(_outputPlugin is not IWritableImage outputFormat)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
foreach(ulong badSector in tmpArray) foreach(ulong badSector in tmpArray)
{ {

View File

@@ -72,7 +72,13 @@ partial class Dump
double currentSpeed = 0; double currentSpeed = 0;
double maxSpeed = double.MinValue; double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue; double minSpeed = double.MaxValue;
var outputFormat = _outputPlugin as IWritableImage;
if(_outputPlugin is not IWritableImage outputFormat)
{
StoppingErrorMessage?.Invoke("Image is not writable, aborting...");
return;
}
if(DetectOS.GetRealPlatformID() != PlatformID.Win32NT) if(DetectOS.GetRealPlatformID() != PlatformID.Win32NT)
{ {

View File

@@ -79,435 +79,447 @@ public static class Statistics
allStats = (Stats)xs.Deserialize(sr); allStats = (Stats)xs.Deserialize(sr);
sr.Close(); sr.Close();
if(allStats.Commands?.Analyze > 0) if(allStats != null)
{ {
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info" && c.Synchronized) ?? if(allStats.Commands?.Analyze > 0)
new Command
{
Name = "fs-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Analyze;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Checksum > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "checksum" && c.Synchronized) ??
new Command
{
Name = "checksum",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Checksum;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Compare > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "compare" && c.Synchronized) ??
new Command
{
Name = "compare",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Compare;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ConvertImage > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "convert-image" && c.Synchronized) ?? new Command
{
Name = "convert-image",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ConvertImage;
ctx.Commands.Update(command);
}
if(allStats.Commands?.CreateSidecar > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar" && c.Synchronized) ??
new Command
{
Name = "create-sidecar",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.CreateSidecar;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Decode > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "decode" && c.Synchronized) ??
new Command
{
Name = "decode",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Decode;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DeviceInfo > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "device-info" && c.Synchronized) ??
new Command
{
Name = "device-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DeviceInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DeviceReport > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "device-report" && c.Synchronized) ?? new Command
{
Name = "device-report",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DeviceReport;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DumpMedia > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media" && c.Synchronized) ??
new Command
{
Name = "dump-media",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DumpMedia;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Entropy > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "entropy" && c.Synchronized) ??
new Command
{
Name = "entropy",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Entropy;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ExtractFiles > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "extract-files" && c.Synchronized) ?? new Command
{
Name = "extract-files",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ExtractFiles;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Formats > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "formats" && c.Synchronized) ??
new Command
{
Name = "formats",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Formats;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ImageInfo > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "image-info" && c.Synchronized) ??
new Command
{
Name = "image-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ImageInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ListDevices > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "list-devices" && c.Synchronized) ?? new Command
{
Name = "list-devices",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ListDevices;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ListEncodings > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings" && c.Synchronized) ??
new Command
{
Name = "list-encodings",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ListEncodings;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Ls > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "ls" && c.Synchronized) ??
new Command
{
Name = "ls",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Ls;
ctx.Commands.Update(command);
}
if(allStats.Commands?.MediaInfo > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "media-info" && c.Synchronized) ??
new Command
{
Name = "media-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.MediaInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.MediaScan > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan" && c.Synchronized) ??
new Command
{
Name = "media-scan",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.MediaScan;
ctx.Commands.Update(command);
}
if(allStats.Commands?.PrintHex > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "printhex" && c.Synchronized) ??
new Command
{
Name = "printhex",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.PrintHex;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Verify > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "verify" && c.Synchronized) ??
new Command
{
Name = "verify",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Verify;
ctx.Commands.Update(command);
}
if(allStats.OperatingSystems != null)
foreach(OsStats operatingSystem in allStats.OperatingSystems)
{ {
if(string.IsNullOrWhiteSpace(operatingSystem.name) || Command command = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info" && c.Synchronized) ??
string.IsNullOrWhiteSpace(operatingSystem.version)) new Command
continue;
OperatingSystem existing =
ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name &&
c.Version == operatingSystem.version &&
c.Synchronized) ?? new OperatingSystem
{
Name = operatingSystem.name,
Version = operatingSystem.version,
Synchronized = true
};
existing.Count += (ulong)operatingSystem.Value;
ctx.OperatingSystems.Update(existing);
}
if(allStats.Versions != null)
foreach(NameValueStats nvs in allStats.Versions)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Version existing = ctx.Versions.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Version
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Versions.Update(existing);
}
if(allStats.Filesystems != null)
foreach(NameValueStats nvs in allStats.Filesystems)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filesystem existing =
ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Filesystem
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Filesystems.Update(existing);
}
if(allStats.Partitions != null)
foreach(NameValueStats nvs in allStats.Partitions)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Partition existing =
ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Partition
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Partitions.Update(existing);
}
if(allStats.Filesystems != null)
foreach(NameValueStats nvs in allStats.Filesystems)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filesystem existing =
ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Filesystem
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Filesystems.Update(existing);
}
if(allStats.MediaImages != null)
foreach(NameValueStats nvs in allStats.MediaImages)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
MediaFormat existing =
ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new MediaFormat
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.MediaFormats.Update(existing);
}
if(allStats.Filters != null)
foreach(NameValueStats nvs in allStats.Filters)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Filter
{ {
Name = nvs.name, Name = "fs-info",
Synchronized = true Synchronized = true
}; };
existing.Count += (ulong)nvs.Value; command.Count += (ulong)allStats.Commands.Analyze;
ctx.Filters.Update(existing); ctx.Commands.Update(command);
} }
if(allStats.Devices != null) if(allStats.Commands?.Checksum > 0)
foreach(DeviceStats device in allStats.Devices)
{ {
if(ctx.SeenDevices.Any(d => d.Manufacturer == device.Manufacturer && Command command =
d.Model == device.Model && d.Revision == device.Revision && ctx.Commands.FirstOrDefault(c => c.Name == "checksum" && c.Synchronized) ?? new Command
d.Bus == device.Bus))
continue;
ctx.SeenDevices.Add(new DeviceStat
{
Bus = device.Bus,
Manufacturer = device.Manufacturer,
Model = device.Model,
Revision = device.Revision,
Synchronized = true
});
}
if(allStats.Medias != null)
foreach(MediaStats media in allStats.Medias)
{
if(string.IsNullOrWhiteSpace(media.type))
continue;
Database.Models.Media existing =
ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real &&
c.Synchronized) ?? new Database.Models.Media
{ {
Type = media.type, Name = "checksum",
Real = media.real,
Synchronized = true Synchronized = true
}; };
existing.Count += (ulong)media.Value; command.Count += (ulong)allStats.Commands.Checksum;
ctx.Medias.Update(existing); ctx.Commands.Update(command);
} }
ctx.SaveChanges(); if(allStats.Commands?.Compare > 0)
File.Delete(Path.Combine(Settings.StatsPath, "Statistics.xml")); {
} Command command = ctx.Commands.FirstOrDefault(c => c.Name == "compare" && c.Synchronized) ??
new Command
{
Name = "compare",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Compare;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ConvertImage > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "convert-image" && c.Synchronized) ??
new Command
{
Name = "convert-image",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ConvertImage;
ctx.Commands.Update(command);
}
if(allStats.Commands?.CreateSidecar > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar" && c.Synchronized) ??
new Command
{
Name = "create-sidecar",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.CreateSidecar;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Decode > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "decode" && c.Synchronized) ??
new Command
{
Name = "decode",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Decode;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DeviceInfo > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "device-info" && c.Synchronized) ??
new Command
{
Name = "device-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DeviceInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DeviceReport > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "device-report" && c.Synchronized) ??
new Command
{
Name = "device-report",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DeviceReport;
ctx.Commands.Update(command);
}
if(allStats.Commands?.DumpMedia > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "dump-media" && c.Synchronized) ??
new Command
{
Name = "dump-media",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.DumpMedia;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Entropy > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "entropy" && c.Synchronized) ??
new Command
{
Name = "entropy",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Entropy;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ExtractFiles > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "extract-files" && c.Synchronized) ??
new Command
{
Name = "extract-files",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ExtractFiles;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Formats > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "formats" && c.Synchronized) ??
new Command
{
Name = "formats",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Formats;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ImageInfo > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "image-info" && c.Synchronized) ??
new Command
{
Name = "image-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ImageInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ListDevices > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "list-devices" && c.Synchronized) ??
new Command
{
Name = "list-devices",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ListDevices;
ctx.Commands.Update(command);
}
if(allStats.Commands?.ListEncodings > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings" && c.Synchronized) ??
new Command
{
Name = "list-encodings",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.ListEncodings;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Ls > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "ls" && c.Synchronized) ??
new Command
{
Name = "ls",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Ls;
ctx.Commands.Update(command);
}
if(allStats.Commands?.MediaInfo > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "media-info" && c.Synchronized) ??
new Command
{
Name = "media-info",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.MediaInfo;
ctx.Commands.Update(command);
}
if(allStats.Commands?.MediaScan > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "media-scan" && c.Synchronized) ??
new Command
{
Name = "media-scan",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.MediaScan;
ctx.Commands.Update(command);
}
if(allStats.Commands?.PrintHex > 0)
{
Command command =
ctx.Commands.FirstOrDefault(c => c.Name == "printhex" && c.Synchronized) ?? new Command
{
Name = "printhex",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.PrintHex;
ctx.Commands.Update(command);
}
if(allStats.Commands?.Verify > 0)
{
Command command = ctx.Commands.FirstOrDefault(c => c.Name == "verify" && c.Synchronized) ??
new Command
{
Name = "verify",
Synchronized = true
};
command.Count += (ulong)allStats.Commands.Verify;
ctx.Commands.Update(command);
}
if(allStats.OperatingSystems != null)
foreach(OsStats operatingSystem in allStats.OperatingSystems)
{
if(string.IsNullOrWhiteSpace(operatingSystem.name) ||
string.IsNullOrWhiteSpace(operatingSystem.version))
continue;
OperatingSystem existing =
ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name &&
c.Version == operatingSystem.version &&
c.Synchronized) ?? new OperatingSystem
{
Name = operatingSystem.name,
Version = operatingSystem.version,
Synchronized = true
};
existing.Count += (ulong)operatingSystem.Value;
ctx.OperatingSystems.Update(existing);
}
if(allStats.Versions != null)
foreach(NameValueStats nvs in allStats.Versions)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Version existing =
ctx.Versions.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Version
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Versions.Update(existing);
}
if(allStats.Filesystems != null)
foreach(NameValueStats nvs in allStats.Filesystems)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filesystem existing =
ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Filesystem
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Filesystems.Update(existing);
}
if(allStats.Partitions != null)
foreach(NameValueStats nvs in allStats.Partitions)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Partition existing =
ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Partition
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Partitions.Update(existing);
}
if(allStats.Filesystems != null)
foreach(NameValueStats nvs in allStats.Filesystems)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filesystem existing =
ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new Filesystem
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Filesystems.Update(existing);
}
if(allStats.MediaImages != null)
foreach(NameValueStats nvs in allStats.MediaImages)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
MediaFormat existing =
ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ??
new MediaFormat
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.MediaFormats.Update(existing);
}
if(allStats.Filters != null)
foreach(NameValueStats nvs in allStats.Filters)
{
if(string.IsNullOrWhiteSpace(nvs.name))
continue;
Filter existing =
ctx.Filters.FirstOrDefault(c => c.Name == nvs.name && c.Synchronized) ?? new Filter
{
Name = nvs.name,
Synchronized = true
};
existing.Count += (ulong)nvs.Value;
ctx.Filters.Update(existing);
}
if(allStats.Devices != null)
foreach(DeviceStats device in allStats.Devices)
{
if(ctx.SeenDevices.Any(d => d.Manufacturer == device.Manufacturer &&
d.Model == device.Model && d.Revision == device.Revision &&
d.Bus == device.Bus))
continue;
ctx.SeenDevices.Add(new DeviceStat
{
Bus = device.Bus,
Manufacturer = device.Manufacturer,
Model = device.Model,
Revision = device.Revision,
Synchronized = true
});
}
if(allStats.Medias != null)
foreach(MediaStats media in allStats.Medias)
{
if(string.IsNullOrWhiteSpace(media.type))
continue;
Database.Models.Media existing =
ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real &&
c.Synchronized) ?? new Database.Models.Media
{
Type = media.type,
Real = media.real,
Synchronized = true
};
existing.Count += (ulong)media.Value;
ctx.Medias.Update(existing);
}
ctx.SaveChanges();
File.Delete(Path.Combine(Settings.StatsPath, "Statistics.xml"));
} }
catch catch
{ {
// Do not care about it // Do not care about it

View File

@@ -301,7 +301,8 @@ static partial class Usb
if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, out _, if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, out _,
IntPtr.Zero)) IntPtr.Zero))
{ {
hubName = (UsbRootHubName)Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)); hubName = (UsbRootHubName)(Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)) ??
default(UsbRootHubName));
root.HubDevicePath = @"\\.\" + hubName.RootHubName; root.HubDevicePath = @"\\.\" + hubName.RootHubName;
} }
@@ -428,8 +429,9 @@ static partial class Usb
continue; continue;
nodeConnection = nodeConnection =
(UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection, (UsbNodeConnectionInformationEx)(Marshal.PtrToStructure(ptrNodeConnection,
typeof(UsbNodeConnectionInformationEx)); typeof(UsbNodeConnectionInformationEx)) ??
default(UsbNodeConnectionInformationEx));
// load up the USBPort class // load up the USBPort class
var port = new UsbPort var port = new UsbPort
@@ -556,7 +558,8 @@ static partial class Usb
var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request));
var stringDesc = var stringDesc =
(UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ??
default(UsbStringDescriptor));
device.DeviceManufacturer = stringDesc.bString; device.DeviceManufacturer = stringDesc.bString;
} }
@@ -592,7 +595,8 @@ static partial class Usb
var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request));
var stringDesc = var stringDesc =
(UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ??
default(UsbStringDescriptor));
device.DeviceProduct = stringDesc.bString; device.DeviceProduct = stringDesc.bString;
} }
@@ -628,7 +632,8 @@ static partial class Usb
var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request));
var stringDesc = var stringDesc =
(UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ??
default(UsbStringDescriptor));
device.DeviceSerialNumber = stringDesc.bString; device.DeviceSerialNumber = stringDesc.bString;
} }
@@ -678,8 +683,9 @@ static partial class Usb
if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, ptrDriverKey, nBytes, ptrDriverKey, if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, ptrDriverKey, nBytes, ptrDriverKey,
nBytes, out nBytesReturned, IntPtr.Zero)) nBytes, out nBytesReturned, IntPtr.Zero))
{ {
driverKey = (UsbNodeConnectionDriverkeyName)Marshal.PtrToStructure(ptrDriverKey, driverKey = (UsbNodeConnectionDriverkeyName)(Marshal.PtrToStructure(ptrDriverKey,
typeof(UsbNodeConnectionDriverkeyName)); typeof(UsbNodeConnectionDriverkeyName)) ??
default(UsbNodeConnectionDriverkeyName));
device.DeviceDriverKey = driverKey.DriverKeyName; device.DeviceDriverKey = driverKey.DriverKeyName;
@@ -727,7 +733,8 @@ static partial class Usb
if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, out _, if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, out _,
IntPtr.Zero)) IntPtr.Zero))
{ {
nodeName = (UsbNodeConnectionName)Marshal.PtrToStructure(ptrNodeName, typeof(UsbNodeConnectionName)); nodeName = (UsbNodeConnectionName)(Marshal.PtrToStructure(ptrNodeName, typeof(UsbNodeConnectionName)) ??
default(UsbNodeConnectionName));
hub.HubDevicePath = @"\\.\" + nodeName.NodeName; hub.HubDevicePath = @"\\.\" + nodeName.NodeName;
} }
@@ -751,7 +758,8 @@ static partial class Usb
if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out _, if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out _,
IntPtr.Zero)) IntPtr.Zero))
{ {
nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, typeof(UsbNodeInformation)); nodeInfo = (UsbNodeInformation)(Marshal.PtrToStructure(ptrNodeInfo, typeof(UsbNodeInformation)) ??
default(UsbNodeInformation));
hub.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); hub.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered);
hub.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; hub.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts;

View File

@@ -56,6 +56,9 @@ public sealed partial class CPM
var defsSerializer = new XmlSerializer(typeof(CpmDefinitions)); var defsSerializer = new XmlSerializer(typeof(CpmDefinitions));
_definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader); _definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader);
if(_definitions is null)
return false;
// Patch definitions // Patch definitions
foreach(CpmDefinition def in _definitions.definitions) foreach(CpmDefinition def in _definitions.definitions)
{ {

View File

@@ -97,7 +97,7 @@ public sealed class MediaInfoViewModel : ViewModelBase
var mediaResource = new Uri($"avares://Aaru.Gui/Assets/Logos/Media/{scsiInfo.MediaType}.png"); var mediaResource = new Uri($"avares://Aaru.Gui/Assets/Logos/Media/{scsiInfo.MediaType}.png");
MediaLogo = assets.Exists(mediaResource) ? new Bitmap(assets.Open(mediaResource)) : null; MediaLogo = assets?.Exists(mediaResource) == true ? new Bitmap(assets.Open(mediaResource)) : null;
MediaType = scsiInfo.MediaType.ToString(); MediaType = scsiInfo.MediaType.ToString();

View File

@@ -2000,7 +2000,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
var sr = new StreamReader(result[0]); var sr = new StreamReader(result[0]);
var resume = (Resume)sidecarXs.Deserialize(sr); var resume = (Resume)sidecarXs.Deserialize(sr);
if(resume.Tries?.Any() == false) if(resume?.Tries?.Any() == false)
{ {
_dumpHardware = resume.Tries; _dumpHardware = resume.Tries;
ResumeFileText = result[0]; ResumeFileText = result[0];

View File

@@ -136,6 +136,9 @@ public sealed class MainWindowViewModel : ViewModelBase
break; break;
} }
if(_assets == null)
return;
_genericHddIcon = _genericHddIcon =
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-harddisk.png"))); new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-harddisk.png")));
@@ -150,15 +153,18 @@ public sealed class MainWindowViewModel : ViewModelBase
_usbIcon = _usbIcon =
new new
Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media-usb.png"))); Bitmap(_assets.Open(new
Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media-usb.png")));
_removableIcon = _removableIcon =
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media.png"))); new
Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/drive-removable-media.png")));
_sdIcon = _sdIcon =
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-flash-sd-mmc.png"))); new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-flash-sd-mmc.png")));
_ejectIcon = new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-eject.png"))); _ejectIcon =
new Bitmap(_assets.Open(new Uri("avares://Aaru.Gui/Assets/Icons/oxygen/32x32/media-eject.png")));
} }
public bool DevicesSupported public bool DevicesSupported
@@ -168,7 +174,7 @@ public sealed class MainWindowViewModel : ViewModelBase
} }
public bool NativeMenuSupported => public bool NativeMenuSupported =>
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as NativeMenu.GetIsNativeMenuExported((Application.Current?.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow); IClassicDesktopStyleApplicationLifetime)?.MainWindow);
[NotNull] [NotNull]
@@ -480,7 +486,7 @@ public sealed class MainWindowViewModel : ViewModelBase
} }
internal void ExecuteExitCommand() => internal void ExecuteExitCommand() =>
(Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown(); (Application.Current?.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown();
void ExecuteConsoleCommand() void ExecuteConsoleCommand()
{ {

View File

@@ -161,6 +161,10 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
var filtersList = new FiltersList(); var filtersList = new FiltersList();
IFilter inputFilter = filtersList.GetFilter(testFile); IFilter inputFilter = filtersList.GetFilter(testFile);
var image = ImageFormat.Detect(inputFilter) as IMediaImage; var image = ImageFormat.Detect(inputFilter) as IMediaImage;
if(image is null)
continue;
ErrorNumber opened = image.Open(inputFilter); ErrorNumber opened = image.Open(inputFilter);
if(opened != ErrorNumber.NoError) if(opened != ErrorNumber.NoError)

View File

@@ -337,6 +337,9 @@ sealed class ExtractFilesCommand : Command
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?. var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
Invoke(Array.Empty<object>()); Invoke(Array.Empty<object>());
if(fs is null)
continue;
Spectre.ProgressSingleSpinner(ctx => Spectre.ProgressSingleSpinner(ctx =>
{ {
ctx.AddTask("Mounting filesystem...").IsIndeterminate(); ctx.AddTask("Mounting filesystem...").IsIndeterminate();
@@ -370,6 +373,9 @@ sealed class ExtractFilesCommand : Command
var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?. var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?.
Invoke(Array.Empty<object>()); Invoke(Array.Empty<object>());
if(fs is null)
continue;
Spectre.ProgressSingleSpinner(ctx => Spectre.ProgressSingleSpinner(ctx =>
{ {
ctx.AddTask("Mounting filesystem...").IsIndeterminate(); ctx.AddTask("Mounting filesystem...").IsIndeterminate();

View File

@@ -214,7 +214,12 @@ sealed class PrintHexCommand : Command
else else
for(ulong i = 0; i < length; i++) for(ulong i = 0; i < length; i++)
{ {
var blockImage = inputFormat as IMediaImage; if(inputFormat is not IMediaImage blockImage)
{
AaruConsole.ErrorWriteLine("Cannot open image file, aborting...");
break;
}
AaruConsole.WriteLine("[bold][italic]Sector {0}[/][/]", start + i); AaruConsole.WriteLine("[bold][italic]Sector {0}[/][/]", start + i);