diff --git a/Aaru.CommonTypes/PluginRegister.cs b/Aaru.CommonTypes/PluginRegister.cs index 7fe4135ca..5075761e7 100644 --- a/Aaru.CommonTypes/PluginRegister.cs +++ b/Aaru.CommonTypes/PluginRegister.cs @@ -270,15 +270,14 @@ public class PluginRegister var foundFilter = (IFilter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke([]); - if(foundFilter?.Open(path) == ErrorNumber.NoError) - { - transaction.Finish(); + if(foundFilter?.Open(path) != ErrorNumber.NoError) continue; - return foundFilter; - } + transaction.Finish(); + + return foundFilter; } - else - noFilter = filter; + + noFilter = filter; } catch(IOException ex) { diff --git a/Aaru.Compression/LzdStream.cs b/Aaru.Compression/LzdStream.cs index 6b556abb4..5e0b4b3b1 100644 --- a/Aaru.Compression/LzdStream.cs +++ b/Aaru.Compression/LzdStream.cs @@ -130,13 +130,12 @@ public partial class LzdStream : Stream break; } - if(status == LZDStatus.DONE) - { - _eof = true; - Debug.WriteLine(">>> SET _eof=true (no more data and already flushed)"); + if(status != LZDStatus.DONE) continue; - break; - } + _eof = true; + Debug.WriteLine(">>> SET _eof=true (no more data and already flushed)"); + + break; // if OK but no bytes, loop again } diff --git a/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs b/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs index 3aefe3275..2d0776bf7 100644 --- a/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs +++ b/Aaru.Core/Devices/Dumping/CompactDisc/Data.cs @@ -1042,29 +1042,27 @@ partial class Dump sectorStatus[b] = SectorStatus.Dumped; - if(inData && _paranoia) - { - // Check valid sector - CdChecksums.CheckCdSector(sector, - out bool? correctEccP, - out bool? correctEccQ, - out bool? correctEdc); + if(!inData || !_paranoia) continue; - if(correctEdc != true || correctEccP != true || correctEccQ != true) - { - sectorStatus[b] = SectorStatus.Errored; - _resume.BadBlocks.Add(i + (ulong)b); + // Check valid sector + CdChecksums.CheckCdSector(sector, + out bool? correctEccP, + out bool? correctEccQ, + out bool? correctEdc); - if(correctEdc != true) - UpdateStatus?.Invoke(string.Format(UI.Incorrect_EDC_in_sector_0, i + (ulong)b)); + if(correctEdc == true && correctEccP == true && correctEccQ == true) continue; - if(correctEccP != true) - UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_P_in_sector_0, i + (ulong)b)); + sectorStatus[b] = SectorStatus.Errored; + _resume.BadBlocks.Add(i + (ulong)b); - if(correctEccQ != true) - UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_Q_in_sector_0, i + (ulong)b)); - } - } + if(correctEdc != true) + UpdateStatus?.Invoke(string.Format(UI.Incorrect_EDC_in_sector_0, i + (ulong)b)); + + if(correctEccP != true) + UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_P_in_sector_0, i + (ulong)b)); + + if(correctEccQ != true) + UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_Q_in_sector_0, i + (ulong)b)); } if(supportsLongSectors) diff --git a/Aaru.Core/Devices/Scanning/ATA.cs b/Aaru.Core/Devices/Scanning/ATA.cs index 97d95af8f..50b1f98cc 100644 --- a/Aaru.Core/Devices/Scanning/ATA.cs +++ b/Aaru.Core/Devices/Scanning/ATA.cs @@ -206,13 +206,12 @@ public sealed partial class MediaScan ibgLog.Write(i, 0); } - if(accumulatedSpeedMs >= 100) - { - currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); - ScanSpeed?.Invoke(i, currentSpeed * 1024); - accumulatedSpeedMs = 0; - accumulatedSpeedSectors = 0; - } + if(accumulatedSpeedMs < 100) continue; + + currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); + ScanSpeed?.Invoke(i, currentSpeed * 1024); + accumulatedSpeedMs = 0; + accumulatedSpeedSectors = 0; } _speedStopwatch.Stop(); @@ -341,16 +340,13 @@ public sealed partial class MediaScan ibgLog.Write(currentBlock, 0); } - if(accumulatedSpeedMs >= 100) - { - currentSpeed = accumulatedSpeedSectors * - blockSize / - (1048576 * (accumulatedSpeedMs / 1000.0)); + if(accumulatedSpeedMs < 100) continue; - ScanSpeed?.Invoke(currentBlock, currentSpeed * 1024); - accumulatedSpeedMs = 0; - accumulatedSpeedSectors = 0; - } + currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); + + ScanSpeed?.Invoke(currentBlock, currentSpeed * 1024); + accumulatedSpeedMs = 0; + accumulatedSpeedSectors = 0; } } } diff --git a/Aaru.Core/Devices/Scanning/SCSI.cs b/Aaru.Core/Devices/Scanning/SCSI.cs index db2ae6c63..745690469 100644 --- a/Aaru.Core/Devices/Scanning/SCSI.cs +++ b/Aaru.Core/Devices/Scanning/SCSI.cs @@ -508,13 +508,12 @@ public sealed partial class MediaScan } } - if(accumulatedSpeedMs >= 100) - { - currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); - ScanSpeed?.Invoke(i, currentSpeed * 1024); - accumulatedSpeedMs = 0; - accumulatedSpeedSectors = 0; - } + if(accumulatedSpeedMs < 100) continue; + + currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); + ScanSpeed?.Invoke(i, currentSpeed * 1024); + accumulatedSpeedMs = 0; + accumulatedSpeedSectors = 0; } _scanStopwatch.Stop(); @@ -624,13 +623,11 @@ public sealed partial class MediaScan ibgLog.Write(i, 0); } - if(accumulatedSpeedMs >= 100) - { - currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); - ScanSpeed?.Invoke(i, currentSpeed * 1024); - accumulatedSpeedMs = 0; - accumulatedSpeedSectors = 0; - } + if(accumulatedSpeedMs < 100) continue; + currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); + ScanSpeed?.Invoke(i, currentSpeed * 1024); + accumulatedSpeedMs = 0; + accumulatedSpeedSectors = 0; } _scanStopwatch.Stop(); diff --git a/Aaru.Core/Devices/Scanning/SecureDigital.cs b/Aaru.Core/Devices/Scanning/SecureDigital.cs index 12175b44b..0c69a42eb 100644 --- a/Aaru.Core/Devices/Scanning/SecureDigital.cs +++ b/Aaru.Core/Devices/Scanning/SecureDigital.cs @@ -343,13 +343,12 @@ public sealed partial class MediaScan ibgLog.Write(i, 0); } - if(accumulatedSpeedMs >= 100) - { - currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); - ScanSpeed?.Invoke(i, currentSpeed * 1024); - accumulatedSpeedMs = 0; - accumulatedSpeedSectors = 0; - } + if(accumulatedSpeedMs < 100) continue; + + currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0)); + ScanSpeed?.Invoke(i, currentSpeed * 1024); + accumulatedSpeedMs = 0; + accumulatedSpeedSectors = 0; } _scanStopwatch.Stop(); diff --git a/Aaru.Decoders/Bluray/DI.cs b/Aaru.Decoders/Bluray/DI.cs index bbde4f0d5..906c9b4a2 100644 --- a/Aaru.Decoders/Bluray/DI.cs +++ b/Aaru.Decoders/Bluray/DI.cs @@ -134,7 +134,7 @@ public static class DI Reserved2 = DIResponse[3] }; - int offset = 4; + var offset = 4; List units = []; while(true) @@ -232,7 +232,7 @@ public static class DI decoded.Units = new DiscInformationUnits[units.Count]; - for(int i = 0; i < units.Count; i++) decoded.Units[i] = units[i]; + for(var i = 0; i < units.Count; i++) decoded.Units[i] = units[i]; return decoded; } @@ -425,13 +425,11 @@ public static class DI sb.AppendFormat(Localization.Disc_product_revision_number_0, unit.ProductRevisionNumber).AppendLine(); } - if(unit.FormatDependentContents is not null) - { - sb.AppendLine(Localization.Blu_ray_DI_Unit_format_dependent_contents_as_hex_follows); + if(unit.FormatDependentContents is null) continue; - sb.AppendLine(Markup.Escape(PrintHex.ByteArrayToHexArrayString(unit.FormatDependentContents, - color: true))); - } + sb.AppendLine(Localization.Blu_ray_DI_Unit_format_dependent_contents_as_hex_follows); + + sb.AppendLine(Markup.Escape(PrintHex.ByteArrayToHexArrayString(unit.FormatDependentContents, color: true))); } return sb.ToString(); diff --git a/Aaru.Gui/Controls/BlockMap.axaml.cs b/Aaru.Gui/Controls/BlockMap.axaml.cs index ab1e94ff4..a565cd657 100644 --- a/Aaru.Gui/Controls/BlockMap.axaml.cs +++ b/Aaru.Gui/Controls/BlockMap.axaml.cs @@ -106,11 +106,10 @@ public partial class BlockMap : UserControl _sectorData = change.GetNewValue>(); - if(_sectorData != null) - { - _sectorData.CollectionChanged += OnSectorDataChanged; - RedrawAll(); - } + if(_sectorData == null) return; + + _sectorData.CollectionChanged += OnSectorDataChanged; + RedrawAll(); } else if(change.Property == ScanBlockSizeProperty) { @@ -136,26 +135,25 @@ public partial class BlockMap : UserControl void EnsureBitmap() { if(_blocksPerRow <= 0 || _rows <= 0) return; + int blockWithSpacing = BlockSize + BlockSpacing; int width = _blocksPerRow * blockWithSpacing; int height = _rows * blockWithSpacing; - if(_bitmap == null || _bitmap.PixelSize.Width != width || _bitmap.PixelSize.Height != height) - { - _bitmap?.Dispose(); + if(_bitmap != null && _bitmap.PixelSize.Width == width && _bitmap.PixelSize.Height == height) return; - _bitmap = new WriteableBitmap(new PixelSize(width, height), - new Vector(96, 96), - PixelFormat.Bgra8888, - AlphaFormat.Premul); + _bitmap?.Dispose(); - if(_image != null) - { - _image.Source = _bitmap; - _image.Width = width; - _image.Height = height; - } - } + _bitmap = new WriteableBitmap(new PixelSize(width, height), + new Vector(96, 96), + PixelFormat.Bgra8888, + AlphaFormat.Premul); + + if(_image == null) return; + + _image.Source = _bitmap; + _image.Width = width; + _image.Height = height; } private void RedrawAll() diff --git a/Aaru.Gui/Controls/DiscSpeedGraph.axaml.cs b/Aaru.Gui/Controls/DiscSpeedGraph.axaml.cs index 825683a19..77fb52ba9 100644 --- a/Aaru.Gui/Controls/DiscSpeedGraph.axaml.cs +++ b/Aaru.Gui/Controls/DiscSpeedGraph.axaml.cs @@ -183,22 +183,20 @@ public partial class DiscSpeedGraph : UserControl { double newZoom = Math.Min(_yZoomLevel + ZOOM_STEP, MAX_ZOOM); - if(Math.Abs(newZoom - _yZoomLevel) > 0.001) - { - _yZoomLevel = newZoom; - RedrawAll(); - } + if(!(Math.Abs(newZoom - _yZoomLevel) > 0.001)) return; + + _yZoomLevel = newZoom; + RedrawAll(); } void ZoomOut() { double newZoom = Math.Max(_yZoomLevel - ZOOM_STEP, MIN_ZOOM); - if(Math.Abs(newZoom - _yZoomLevel) > 0.001) - { - _yZoomLevel = newZoom; - RedrawAll(); - } + if(!(Math.Abs(newZoom - _yZoomLevel) > 0.001)) return; + + _yZoomLevel = newZoom; + RedrawAll(); } void OnPointerWheelChanged(object sender, PointerWheelEventArgs e) diff --git a/Aaru.Gui/Controls/SpectreTextBlock.cs b/Aaru.Gui/Controls/SpectreTextBlock.cs index efa42d705..0b950cbce 100644 --- a/Aaru.Gui/Controls/SpectreTextBlock.cs +++ b/Aaru.Gui/Controls/SpectreTextBlock.cs @@ -488,17 +488,14 @@ public partial class SpectreTextBlock : TextBlock { i++; - if(i < text.Length && text[i] == ']') - { - // Found [/], close the most recent tag - if(tagStack.Count > 0) - { - (int openStart, int openTagEnd, string tag) = tagStack.Pop(); - int closeTagEnd = i + 1; // After the ']' of [/] - result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart)); - } + if(i >= text.Length || text[i] != ']') continue; - i++; + // Found [/], close the most recent tag + if(tagStack.Count > 0) + { + (int openStart, int openTagEnd, string tag) = tagStack.Pop(); + int closeTagEnd = i + 1; // After the ']' of [/] + result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart)); } } else @@ -516,12 +513,10 @@ public partial class SpectreTextBlock : TextBlock int openTagEnd = i + 1; // After the ']' tagStack.Push((tagStart, openTagEnd, tagName)); } - - i++; } } - else - i++; + + i++; } return result; diff --git a/Aaru.Gui/Views/Windows/DeviceView.axaml.cs b/Aaru.Gui/Views/Windows/DeviceView.axaml.cs index 85686786c..97b3d5dff 100644 --- a/Aaru.Gui/Views/Windows/DeviceView.axaml.cs +++ b/Aaru.Gui/Views/Windows/DeviceView.axaml.cs @@ -52,10 +52,9 @@ public partial class DeviceView : Window { base.OnDataContextChanged(e); - if(DataContext is DeviceViewModel vm) - { - Closed += (_, _) => vm?.Closed(); - vm?.LoadData(); - } + if(DataContext is not DeviceViewModel vm) return; + + Closed += (_, _) => vm?.Closed(); + vm?.LoadData(); } } \ No newline at end of file diff --git a/Aaru.Tui/Controls/SpectreTextBlock.cs b/Aaru.Tui/Controls/SpectreTextBlock.cs index 8875dba4b..fd86973b0 100644 --- a/Aaru.Tui/Controls/SpectreTextBlock.cs +++ b/Aaru.Tui/Controls/SpectreTextBlock.cs @@ -485,17 +485,14 @@ public partial class SpectreTextBlock : TextBlock { i++; - if(i < text.Length && text[i] == ']') - { - // Found [/], close the most recent tag - if(tagStack.Count > 0) - { - (int openStart, int openTagEnd, string tag) = tagStack.Pop(); - int closeTagEnd = i + 1; // After the ']' of [/] - result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart)); - } + if(i >= text.Length || text[i] != ']') continue; - i++; + // Found [/], close the most recent tag + if(tagStack.Count > 0) + { + (int openStart, int openTagEnd, string tag) = tagStack.Pop(); + int closeTagEnd = i + 1; // After the ']' of [/] + result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart)); } } else @@ -513,12 +510,10 @@ public partial class SpectreTextBlock : TextBlock int openTagEnd = i + 1; // After the ']' tagStack.Push((tagStart, openTagEnd, tagName)); } - - i++; } } - else - i++; + + i++; } return result; diff --git a/Aaru.Tui/Views/Windows/FileView.axaml.cs b/Aaru.Tui/Views/Windows/FileView.axaml.cs index b0ea35f2e..bfa93db22 100644 --- a/Aaru.Tui/Views/Windows/FileView.axaml.cs +++ b/Aaru.Tui/Views/Windows/FileView.axaml.cs @@ -40,14 +40,11 @@ public partial class FileView : UserControl private void ListBox_OnKeyDown(object sender, KeyEventArgs e) { - if(e.Key == Key.Enter) - { - if(DataContext is FileViewViewModel vm && vm.OpenSelectedFileCommand.CanExecute(null)) - { - vm.OpenSelectedFileCommand.Execute(null); - e.Handled = true; - } - } + if(e.Key != Key.Enter) return; + if(DataContext is not FileViewViewModel vm || !vm.OpenSelectedFileCommand.CanExecute(null)) return; + + vm.OpenSelectedFileCommand.Execute(null); + e.Handled = true; } /// diff --git a/Aaru/Commands/Database/Statistics.cs b/Aaru/Commands/Database/Statistics.cs index 39e4f61a2..7bc7cbfb7 100644 --- a/Aaru/Commands/Database/Statistics.cs +++ b/Aaru/Commands/Database/Statistics.cs @@ -390,11 +390,10 @@ sealed class StatisticsCommand : AsyncCommand AaruLogging.WriteLine(); } - if(!thereAreStats) - { - AaruLogging.WriteLine(UI.There_are_no_statistics); - AaruLogging.Information(UI.There_are_no_statistics); - } + if(thereAreStats) return (int)ErrorNumber.NoError; + + AaruLogging.WriteLine(UI.There_are_no_statistics); + AaruLogging.Information(UI.There_are_no_statistics); return (int)ErrorNumber.NoError; } diff --git a/Aaru/Commands/Filesystem/Ls.cs b/Aaru/Commands/Filesystem/Ls.cs index 055378f7c..b799fd470 100644 --- a/Aaru/Commands/Filesystem/Ls.cs +++ b/Aaru/Commands/Filesystem/Ls.cs @@ -414,12 +414,11 @@ sealed class LsCommand : Command byte[] xattrBuf = []; error = fs.GetXattr(path + "/" + entry.Key, xattr, ref xattrBuf); - if(error == ErrorNumber.NoError) - { - table.AddRow("", $"[lime]{xattrBuf.Length}[/]", "", $"[fuchsia]{Markup.Escape(xattr)}[/]"); + if(error != ErrorNumber.NoError) continue; - AaruLogging.Information($"{xattrBuf.Length} {xattr}"); - } + table.AddRow("", $"[lime]{xattrBuf.Length}[/]", "", $"[fuchsia]{Markup.Escape(xattr)}[/]"); + + AaruLogging.Information($"{xattrBuf.Length} {xattr}"); } } else diff --git a/Aaru/Commands/Image/Convert.cs b/Aaru/Commands/Image/Convert.cs index 99020b27b..e32b022c6 100644 --- a/Aaru/Commands/Image/Convert.cs +++ b/Aaru/Commands/Image/Convert.cs @@ -1397,14 +1397,11 @@ sealed class ConvertImageCommand : Command return (false, 0, 0, 0); } - if(!uint.TryParse(geometryPieces[2], out uint sectors) || sectors == 0) - { - AaruLogging.Error(UI.Invalid_sectors_per_track_specified); + if(uint.TryParse(geometryPieces[2], out uint sectors) && sectors != 0) return (true, cylinders, heads, sectors); - return (false, 0, 0, 0); - } + AaruLogging.Error(UI.Invalid_sectors_per_track_specified); - return (true, cylinders, heads, sectors); + return (false, 0, 0, 0); } private (bool success, Metadata sidecar, Resume resume) LoadMetadata(