mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Invert if to reduce nesting.
This commit is contained in:
@@ -270,14 +270,13 @@ public class PluginRegister
|
||||
|
||||
var foundFilter = (IFilter)filter.GetType().GetConstructor(Type.EmptyTypes)?.Invoke([]);
|
||||
|
||||
if(foundFilter?.Open(path) == ErrorNumber.NoError)
|
||||
{
|
||||
if(foundFilter?.Open(path) != ErrorNumber.NoError) continue;
|
||||
|
||||
transaction.Finish();
|
||||
|
||||
return foundFilter;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
noFilter = filter;
|
||||
}
|
||||
catch(IOException ex)
|
||||
|
||||
@@ -130,13 +130,12 @@ public partial class LzdStream : Stream
|
||||
break;
|
||||
}
|
||||
|
||||
if(status == LZDStatus.DONE)
|
||||
{
|
||||
if(status != LZDStatus.DONE) continue;
|
||||
|
||||
_eof = true;
|
||||
Debug.WriteLine(">>> SET _eof=true (no more data and already flushed)");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// if OK but no bytes, loop again
|
||||
}
|
||||
|
||||
@@ -1042,16 +1042,16 @@ partial class Dump
|
||||
|
||||
sectorStatus[b] = SectorStatus.Dumped;
|
||||
|
||||
if(inData && _paranoia)
|
||||
{
|
||||
if(!inData || !_paranoia) continue;
|
||||
|
||||
// Check valid sector
|
||||
CdChecksums.CheckCdSector(sector,
|
||||
out bool? correctEccP,
|
||||
out bool? correctEccQ,
|
||||
out bool? correctEdc);
|
||||
|
||||
if(correctEdc != true || correctEccP != true || correctEccQ != true)
|
||||
{
|
||||
if(correctEdc == true && correctEccP == true && correctEccQ == true) continue;
|
||||
|
||||
sectorStatus[b] = SectorStatus.Errored;
|
||||
_resume.BadBlocks.Add(i + (ulong)b);
|
||||
|
||||
@@ -1064,8 +1064,6 @@ partial class Dump
|
||||
if(correctEccQ != true)
|
||||
UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_Q_in_sector_0, i + (ulong)b));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(supportsLongSectors)
|
||||
outputFormat.WriteSectorsLong(data, i, false, blocksToRead, sectorStatus);
|
||||
|
||||
@@ -206,14 +206,13 @@ public sealed partial class MediaScan
|
||||
ibgLog.Write(i, 0);
|
||||
}
|
||||
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
if(accumulatedSpeedMs < 100) continue;
|
||||
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
accumulatedSpeedSectors = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
@@ -341,11 +340,9 @@ public sealed partial class MediaScan
|
||||
ibgLog.Write(currentBlock, 0);
|
||||
}
|
||||
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
currentSpeed = accumulatedSpeedSectors *
|
||||
blockSize /
|
||||
(1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
if(accumulatedSpeedMs < 100) continue;
|
||||
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
|
||||
ScanSpeed?.Invoke(currentBlock, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
@@ -353,7 +350,6 @@ public sealed partial class MediaScan
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
|
||||
@@ -508,14 +508,13 @@ public sealed partial class MediaScan
|
||||
}
|
||||
}
|
||||
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
if(accumulatedSpeedMs < 100) continue;
|
||||
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
accumulatedSpeedSectors = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
@@ -624,14 +623,12 @@ public sealed partial class MediaScan
|
||||
ibgLog.Write(i, 0);
|
||||
}
|
||||
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
if(accumulatedSpeedMs < 100) continue;
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
accumulatedSpeedSectors = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
|
||||
@@ -343,14 +343,13 @@ public sealed partial class MediaScan
|
||||
ibgLog.Write(i, 0);
|
||||
}
|
||||
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
if(accumulatedSpeedMs < 100) continue;
|
||||
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
accumulatedSpeedSectors = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
|
||||
@@ -134,7 +134,7 @@ public static class DI
|
||||
Reserved2 = DIResponse[3]
|
||||
};
|
||||
|
||||
int offset = 4;
|
||||
var offset = 4;
|
||||
List<DiscInformationUnits> 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)
|
||||
{
|
||||
if(unit.FormatDependentContents is null) continue;
|
||||
|
||||
sb.AppendLine(Localization.Blu_ray_DI_Unit_format_dependent_contents_as_hex_follows);
|
||||
|
||||
sb.AppendLine(Markup.Escape(PrintHex.ByteArrayToHexArrayString(unit.FormatDependentContents,
|
||||
color: true)));
|
||||
}
|
||||
sb.AppendLine(Markup.Escape(PrintHex.ByteArrayToHexArrayString(unit.FormatDependentContents, color: true)));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
@@ -106,12 +106,11 @@ public partial class BlockMap : UserControl
|
||||
|
||||
_sectorData = change.GetNewValue<ObservableCollection<(ulong startingSector, double duration)>>();
|
||||
|
||||
if(_sectorData != null)
|
||||
{
|
||||
if(_sectorData == null) return;
|
||||
|
||||
_sectorData.CollectionChanged += OnSectorDataChanged;
|
||||
RedrawAll();
|
||||
}
|
||||
}
|
||||
else if(change.Property == ScanBlockSizeProperty)
|
||||
{
|
||||
_scanBlockSize = change.GetNewValue<uint>();
|
||||
@@ -136,12 +135,13 @@ 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)
|
||||
{
|
||||
if(_bitmap != null && _bitmap.PixelSize.Width == width && _bitmap.PixelSize.Height == height) return;
|
||||
|
||||
_bitmap?.Dispose();
|
||||
|
||||
_bitmap = new WriteableBitmap(new PixelSize(width, height),
|
||||
@@ -149,14 +149,12 @@ public partial class BlockMap : UserControl
|
||||
PixelFormat.Bgra8888,
|
||||
AlphaFormat.Premul);
|
||||
|
||||
if(_image != null)
|
||||
{
|
||||
if(_image == null) return;
|
||||
|
||||
_image.Source = _bitmap;
|
||||
_image.Width = width;
|
||||
_image.Height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RedrawAll()
|
||||
{
|
||||
|
||||
@@ -183,23 +183,21 @@ public partial class DiscSpeedGraph : UserControl
|
||||
{
|
||||
double newZoom = Math.Min(_yZoomLevel + ZOOM_STEP, MAX_ZOOM);
|
||||
|
||||
if(Math.Abs(newZoom - _yZoomLevel) > 0.001)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if(!(Math.Abs(newZoom - _yZoomLevel) > 0.001)) return;
|
||||
|
||||
_yZoomLevel = newZoom;
|
||||
RedrawAll();
|
||||
}
|
||||
}
|
||||
|
||||
void OnPointerWheelChanged(object sender, PointerWheelEventArgs e)
|
||||
{
|
||||
|
||||
@@ -488,8 +488,8 @@ public partial class SpectreTextBlock : TextBlock
|
||||
{
|
||||
i++;
|
||||
|
||||
if(i < text.Length && text[i] == ']')
|
||||
{
|
||||
if(i >= text.Length || text[i] != ']') continue;
|
||||
|
||||
// Found [/], close the most recent tag
|
||||
if(tagStack.Count > 0)
|
||||
{
|
||||
@@ -497,9 +497,6 @@ public partial class SpectreTextBlock : TextBlock
|
||||
int closeTagEnd = i + 1; // After the ']' of [/]
|
||||
result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart));
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -516,13 +513,11 @@ public partial class SpectreTextBlock : TextBlock
|
||||
int openTagEnd = i + 1; // After the ']'
|
||||
tagStack.Push((tagStart, openTagEnd, tagName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -52,10 +52,9 @@ public partial class DeviceView : Window
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
|
||||
if(DataContext is DeviceViewModel vm)
|
||||
{
|
||||
if(DataContext is not DeviceViewModel vm) return;
|
||||
|
||||
Closed += (_, _) => vm?.Closed();
|
||||
vm?.LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -485,8 +485,8 @@ public partial class SpectreTextBlock : TextBlock
|
||||
{
|
||||
i++;
|
||||
|
||||
if(i < text.Length && text[i] == ']')
|
||||
{
|
||||
if(i >= text.Length || text[i] != ']') continue;
|
||||
|
||||
// Found [/], close the most recent tag
|
||||
if(tagStack.Count > 0)
|
||||
{
|
||||
@@ -494,9 +494,6 @@ public partial class SpectreTextBlock : TextBlock
|
||||
int closeTagEnd = i + 1; // After the ']' of [/]
|
||||
result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart));
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -513,13 +510,11 @@ public partial class SpectreTextBlock : TextBlock
|
||||
int openTagEnd = i + 1; // After the ']'
|
||||
tagStack.Push((tagStart, openTagEnd, tagName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -40,15 +40,12 @@ 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))
|
||||
{
|
||||
if(e.Key != Key.Enter) return;
|
||||
if(DataContext is not FileViewViewModel vm || !vm.OpenSelectedFileCommand.CanExecute(null)) return;
|
||||
|
||||
vm.OpenSelectedFileCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
|
||||
@@ -390,11 +390,10 @@ sealed class StatisticsCommand : AsyncCommand<StatisticsCommand.Settings>
|
||||
AaruLogging.WriteLine();
|
||||
}
|
||||
|
||||
if(!thereAreStats)
|
||||
{
|
||||
if(thereAreStats) return (int)ErrorNumber.NoError;
|
||||
|
||||
AaruLogging.WriteLine(UI.There_are_no_statistics);
|
||||
AaruLogging.Information(UI.There_are_no_statistics);
|
||||
}
|
||||
|
||||
return (int)ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
@@ -414,14 +414,13 @@ sealed class LsCommand : Command<LsCommand.Settings>
|
||||
byte[] xattrBuf = [];
|
||||
error = fs.GetXattr(path + "/" + entry.Key, xattr, ref xattrBuf);
|
||||
|
||||
if(error == ErrorNumber.NoError)
|
||||
{
|
||||
if(error != ErrorNumber.NoError) continue;
|
||||
|
||||
table.AddRow("", $"[lime]{xattrBuf.Length}[/]", "", $"[fuchsia]{Markup.Escape(xattr)}[/]");
|
||||
|
||||
AaruLogging.Information($"{xattrBuf.Length} {xattr}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
table.AddRow("", "", "", $"[green]{Markup.Escape(entry.Key)}[/]");
|
||||
|
||||
@@ -1397,16 +1397,13 @@ sealed class ConvertImageCommand : Command<ConvertImageCommand.Settings>
|
||||
return (false, 0, 0, 0);
|
||||
}
|
||||
|
||||
if(!uint.TryParse(geometryPieces[2], out uint sectors) || sectors == 0)
|
||||
{
|
||||
if(uint.TryParse(geometryPieces[2], out uint sectors) && sectors != 0) return (true, cylinders, heads, sectors);
|
||||
|
||||
AaruLogging.Error(UI.Invalid_sectors_per_track_specified);
|
||||
|
||||
return (false, 0, 0, 0);
|
||||
}
|
||||
|
||||
return (true, cylinders, heads, sectors);
|
||||
}
|
||||
|
||||
private (bool success, Metadata sidecar, Resume resume) LoadMetadata(
|
||||
string aaruMetadataPath, string cicmXmlPath, string resumeFilePath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user