diff --git a/Aaru.Checksums b/Aaru.Checksums index 30cbd81c8..01391f7a7 160000 --- a/Aaru.Checksums +++ b/Aaru.Checksums @@ -1 +1 @@ -Subproject commit 30cbd81c8471af158a6437e3cecaaee06140e031 +Subproject commit 01391f7a76904b1ed0853d3fc30c49001030ac0a diff --git a/Aaru.Core/Devices/Dumping/ATA.cs b/Aaru.Core/Devices/Dumping/ATA.cs index 9f0f68999..2660879df 100644 --- a/Aaru.Core/Devices/Dumping/ATA.cs +++ b/Aaru.Core/Devices/Dumping/ATA.cs @@ -58,7 +58,13 @@ public partial class Dump void Ata() { bool recoveredError; - var outputFormat = _outputPlugin as IWritableImage; + + if(_outputPlugin is not IWritableImage outputFormat) + { + StoppingErrorMessage?.Invoke("Image is not writable, aborting..."); + + return; + } if(_dumpRaw) { diff --git a/Aaru.Core/Devices/Dumping/Metadata.cs b/Aaru.Core/Devices/Dumping/Metadata.cs index c47535df6..1734b2019 100644 --- a/Aaru.Core/Devices/Dumping/Metadata.cs +++ b/Aaru.Core/Devices/Dumping/Metadata.cs @@ -62,8 +62,15 @@ partial class Dump _dumpLog.WriteLine("Creating sidecar."); var filters = new FiltersList(); IFilter filter = filters.GetFilter(_outputPath); - var inputPlugin = ImageFormat.Detect(filter) as IMediaImage; totalChkDuration = 0; + + if(ImageFormat.Detect(filter) is not IMediaImage inputPlugin) + { + StoppingErrorMessage?.Invoke("Could not detect image format."); + + return; + } + ErrorNumber opened = inputPlugin.Open(filter); if(opened != ErrorNumber.NoError) diff --git a/Aaru.Core/Devices/Dumping/MiniDisc.cs b/Aaru.Core/Devices/Dumping/MiniDisc.cs index 09de36201..f907a8008 100644 --- a/Aaru.Core/Devices/Dumping/MiniDisc.cs +++ b/Aaru.Core/Devices/Dumping/MiniDisc.cs @@ -75,7 +75,13 @@ partial class Dump Dictionary mediaTags = new(); byte[] cmdBuf; 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."); var scsiReader = new Reader(_dev, _dev.Timeout, null, _errorLog); diff --git a/Aaru.Core/Devices/Dumping/PlayStationPortable/MemoryStick.cs b/Aaru.Core/Devices/Dumping/PlayStationPortable/MemoryStick.cs index 7c510b8fc..c562bac9d 100644 --- a/Aaru.Core/Devices/Dumping/PlayStationPortable/MemoryStick.cs +++ b/Aaru.Core/Devices/Dumping/PlayStationPortable/MemoryStick.cs @@ -70,7 +70,13 @@ public partial class Dump MediaType dskType; bool sense; 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 _); diff --git a/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs b/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs index 5b39cfc21..56901d50a 100644 --- a/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs +++ b/Aaru.Core/Devices/Dumping/PlayStationPortable/UMD.cs @@ -65,7 +65,13 @@ public partial class Dump DateTime start; DateTime end; 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, _dev.Timeout, out _); diff --git a/Aaru.Core/Devices/Dumping/Sbc/Trim.cs b/Aaru.Core/Devices/Dumping/Sbc/Trim.cs index a23eec5f7..176a4d342 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Trim.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Trim.cs @@ -51,7 +51,13 @@ partial class Dump bool blankCheck; byte[] buffer; 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) { diff --git a/Aaru.Core/Devices/Dumping/XGD.cs b/Aaru.Core/Devices/Dumping/XGD.cs index 31910ac8d..0af215e92 100644 --- a/Aaru.Core/Devices/Dumping/XGD.cs +++ b/Aaru.Core/Devices/Dumping/XGD.cs @@ -72,7 +72,13 @@ partial class Dump double currentSpeed = 0; double maxSpeed = double.MinValue; 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) { diff --git a/Aaru.Core/Statistics.cs b/Aaru.Core/Statistics.cs index 12ccdfe5c..fb9a1317a 100644 --- a/Aaru.Core/Statistics.cs +++ b/Aaru.Core/Statistics.cs @@ -79,435 +79,447 @@ public static class Statistics allStats = (Stats)xs.Deserialize(sr); sr.Close(); - if(allStats.Commands?.Analyze > 0) + if(allStats != null) { - Command command = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info" && c.Synchronized) ?? - 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(allStats.Commands?.Analyze > 0) { - 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 + Command command = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info" && c.Synchronized) ?? + new Command { - Name = nvs.name, + Name = "fs-info", Synchronized = true }; - existing.Count += (ulong)nvs.Value; - ctx.Filters.Update(existing); + command.Count += (ulong)allStats.Commands.Analyze; + ctx.Commands.Update(command); } - if(allStats.Devices != null) - foreach(DeviceStats device in allStats.Devices) + if(allStats.Commands?.Checksum > 0) { - 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 + Command command = + ctx.Commands.FirstOrDefault(c => c.Name == "checksum" && c.Synchronized) ?? new Command { - Type = media.type, - Real = media.real, + Name = "checksum", Synchronized = true }; - existing.Count += (ulong)media.Value; - ctx.Medias.Update(existing); + command.Count += (ulong)allStats.Commands.Checksum; + ctx.Commands.Update(command); } - ctx.SaveChanges(); - File.Delete(Path.Combine(Settings.StatsPath, "Statistics.xml")); - } + 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) || + 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 { // Do not care about it diff --git a/Aaru.Devices/Windows/Usb.cs b/Aaru.Devices/Windows/Usb.cs index 9ff5973c4..bffe2c948 100644 --- a/Aaru.Devices/Windows/Usb.cs +++ b/Aaru.Devices/Windows/Usb.cs @@ -301,7 +301,8 @@ static partial class Usb if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, out _, IntPtr.Zero)) { - hubName = (UsbRootHubName)Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)); + hubName = (UsbRootHubName)(Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)) ?? + default(UsbRootHubName)); root.HubDevicePath = @"\\.\" + hubName.RootHubName; } @@ -428,8 +429,9 @@ static partial class Usb continue; nodeConnection = - (UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection, - typeof(UsbNodeConnectionInformationEx)); + (UsbNodeConnectionInformationEx)(Marshal.PtrToStructure(ptrNodeConnection, + typeof(UsbNodeConnectionInformationEx)) ?? + default(UsbNodeConnectionInformationEx)); // load up the USBPort class var port = new UsbPort @@ -556,7 +558,8 @@ static partial class Usb var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); + (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? + default(UsbStringDescriptor)); device.DeviceManufacturer = stringDesc.bString; } @@ -592,7 +595,8 @@ static partial class Usb var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); + (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? + default(UsbStringDescriptor)); device.DeviceProduct = stringDesc.bString; } @@ -628,7 +632,8 @@ static partial class Usb var ptrStringDesc = IntPtr.Add(ptrRequest, Marshal.SizeOf(request)); var stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)); + (UsbStringDescriptor)(Marshal.PtrToStructure(ptrStringDesc, typeof(UsbStringDescriptor)) ?? + default(UsbStringDescriptor)); 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, nBytes, out nBytesReturned, IntPtr.Zero)) { - driverKey = (UsbNodeConnectionDriverkeyName)Marshal.PtrToStructure(ptrDriverKey, - typeof(UsbNodeConnectionDriverkeyName)); + driverKey = (UsbNodeConnectionDriverkeyName)(Marshal.PtrToStructure(ptrDriverKey, + typeof(UsbNodeConnectionDriverkeyName)) ?? + default(UsbNodeConnectionDriverkeyName)); 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 _, IntPtr.Zero)) { - nodeName = (UsbNodeConnectionName)Marshal.PtrToStructure(ptrNodeName, typeof(UsbNodeConnectionName)); + nodeName = (UsbNodeConnectionName)(Marshal.PtrToStructure(ptrNodeName, typeof(UsbNodeConnectionName)) ?? + default(UsbNodeConnectionName)); 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 _, 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.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; diff --git a/Aaru.Filesystems/CPM/Definitions.cs b/Aaru.Filesystems/CPM/Definitions.cs index 6a05fe291..2793dcdee 100644 --- a/Aaru.Filesystems/CPM/Definitions.cs +++ b/Aaru.Filesystems/CPM/Definitions.cs @@ -56,6 +56,9 @@ public sealed partial class CPM var defsSerializer = new XmlSerializer(typeof(CpmDefinitions)); _definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader); + if(_definitions is null) + return false; + // Patch definitions foreach(CpmDefinition def in _definitions.definitions) { diff --git a/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs b/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs index 87ea4627b..1b5b63cf9 100644 --- a/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs @@ -97,7 +97,7 @@ public sealed class MediaInfoViewModel : ViewModelBase 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(); diff --git a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs index 7fada83d3..d2129b23a 100644 --- a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs @@ -2000,7 +2000,7 @@ public sealed class ImageConvertViewModel : ViewModelBase var sr = new StreamReader(result[0]); var resume = (Resume)sidecarXs.Deserialize(sr); - if(resume.Tries?.Any() == false) + if(resume?.Tries?.Any() == false) { _dumpHardware = resume.Tries; ResumeFileText = result[0]; diff --git a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs index 3afbd349d..62fe862a2 100644 --- a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs @@ -136,6 +136,9 @@ public sealed class MainWindowViewModel : ViewModelBase break; } + if(_assets == null) + return; + _genericHddIcon = 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 = 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 = - 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 = 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 @@ -168,7 +174,7 @@ public sealed class MainWindowViewModel : ViewModelBase } public bool NativeMenuSupported => - NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as + NativeMenu.GetIsNativeMenuExported((Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow); [NotNull] @@ -480,7 +486,7 @@ public sealed class MainWindowViewModel : ViewModelBase } internal void ExecuteExitCommand() => - (Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown(); + (Application.Current?.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown(); void ExecuteConsoleCommand() { diff --git a/Aaru.Helpers b/Aaru.Helpers index 0462eaac5..af338014d 160000 --- a/Aaru.Helpers +++ b/Aaru.Helpers @@ -1 +1 @@ -Subproject commit 0462eaac5ef31084ca7c031858caeae358adcb42 +Subproject commit af338014d5ccc4c008de4bfc927aa78952dda752 diff --git a/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs b/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs index 4757275cc..554c8a9be 100644 --- a/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs +++ b/Aaru.Tests/Filesystems/ReadOnlyFilesystemTest.cs @@ -161,6 +161,10 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest var filtersList = new FiltersList(); IFilter inputFilter = filtersList.GetFilter(testFile); var image = ImageFormat.Detect(inputFilter) as IMediaImage; + + if(image is null) + continue; + ErrorNumber opened = image.Open(inputFilter); if(opened != ErrorNumber.NoError) diff --git a/Aaru/Commands/Filesystem/ExtractFiles.cs b/Aaru/Commands/Filesystem/ExtractFiles.cs index 45d1aca36..853a8eda7 100644 --- a/Aaru/Commands/Filesystem/ExtractFiles.cs +++ b/Aaru/Commands/Filesystem/ExtractFiles.cs @@ -337,6 +337,9 @@ sealed class ExtractFilesCommand : Command var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?. Invoke(Array.Empty()); + if(fs is null) + continue; + Spectre.ProgressSingleSpinner(ctx => { ctx.AddTask("Mounting filesystem...").IsIndeterminate(); @@ -370,6 +373,9 @@ sealed class ExtractFilesCommand : Command var fs = (IReadOnlyFilesystem)plugin.GetType().GetConstructor(Type.EmptyTypes)?. Invoke(Array.Empty()); + if(fs is null) + continue; + Spectre.ProgressSingleSpinner(ctx => { ctx.AddTask("Mounting filesystem...").IsIndeterminate(); diff --git a/Aaru/Commands/Image/Print.cs b/Aaru/Commands/Image/Print.cs index 17d617d44..893fc846a 100644 --- a/Aaru/Commands/Image/Print.cs +++ b/Aaru/Commands/Image/Print.cs @@ -214,7 +214,12 @@ sealed class PrintHexCommand : Command else 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);