mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Loop can be converted into LINQ-expression.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Core;
|
||||
@@ -156,9 +157,7 @@ namespace DiscImageChef.Commands
|
||||
}
|
||||
|
||||
string[] contents = Directory.GetFiles(options.InputFile, "*", SearchOption.TopDirectoryOnly);
|
||||
List<string> files = new List<string>();
|
||||
|
||||
foreach(string file in contents) if(new FileInfo(file).Length % options.BlockSize == 0) files.Add(file);
|
||||
List<string> files = contents.Where(file => new FileInfo(file).Length % options.BlockSize == 0).ToList();
|
||||
|
||||
files.Sort(StringComparer.CurrentCultureIgnoreCase);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiscImageChef.Checksums;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Core;
|
||||
@@ -108,13 +109,7 @@ namespace DiscImageChef.Commands
|
||||
trackSize += (ulong)sector.LongLength;
|
||||
}
|
||||
|
||||
foreach(ulong l in entTable)
|
||||
{
|
||||
#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
double frequency = (double)l / (double)trackSize;
|
||||
#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
entropy += -(frequency * Math.Log(frequency, 2));
|
||||
}
|
||||
entropy += entTable.Select(l => (double)l / (double)trackSize).Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum();
|
||||
|
||||
DicConsole.WriteLine("Entropy for track {0} is {1:F4}.", currentTrack.TrackSequence, entropy);
|
||||
|
||||
@@ -163,13 +158,7 @@ namespace DiscImageChef.Commands
|
||||
diskSize += (ulong)sector.LongLength;
|
||||
}
|
||||
|
||||
foreach(ulong l in entTable)
|
||||
{
|
||||
#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
double frequency = (double)l / (double)diskSize;
|
||||
#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created
|
||||
entropy += -(frequency * Math.Log(frequency, 2));
|
||||
}
|
||||
entropy += entTable.Select(l => (double)l / (double)diskSize).Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum();
|
||||
|
||||
DicConsole.WriteLine();
|
||||
|
||||
|
||||
@@ -46,12 +46,8 @@ namespace DiscImageChef.Commands
|
||||
|
||||
internal static void DoList(ListEncodingsOptions encodingOptions)
|
||||
{
|
||||
List<CommonEncodingInfo> encodings = new List<CommonEncodingInfo>();
|
||||
|
||||
foreach(System.Text.EncodingInfo info in System.Text.Encoding.GetEncodings())
|
||||
encodings.Add(new CommonEncodingInfo {Name = info.Name, DisplayName = info.GetEncoding().EncodingName});
|
||||
foreach(Claunia.Encoding.EncodingInfo info in Claunia.Encoding.Encoding.GetEncodings())
|
||||
encodings.Add(new CommonEncodingInfo {Name = info.Name, DisplayName = info.DisplayName});
|
||||
List<CommonEncodingInfo> encodings = System.Text.Encoding.GetEncodings().Select(info => new CommonEncodingInfo {Name = info.Name, DisplayName = info.GetEncoding().EncodingName}).ToList();
|
||||
encodings.AddRange(Claunia.Encoding.Encoding.GetEncodings().Select(info => new CommonEncodingInfo {Name = info.Name, DisplayName = info.DisplayName}));
|
||||
|
||||
DicConsole.WriteLine("{0,-16} {1,-8}", "Name", "Description");
|
||||
|
||||
|
||||
@@ -216,8 +216,7 @@ namespace DiscImageChef.Commands
|
||||
if(decMode.Value.Header.BlockDescriptors != null && decMode.Value.Header.BlockDescriptors.Length >= 1)
|
||||
scsiDensityCode = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
|
||||
|
||||
foreach(Decoders.SCSI.Modes.ModePage modePage in decMode.Value.Pages)
|
||||
containsFloppyPage |= modePage.Page == 0x05;
|
||||
containsFloppyPage = decMode.Value.Pages.Aggregate(containsFloppyPage, (current, modePage) => current | modePage.Page == 0x05);
|
||||
}
|
||||
|
||||
switch(dev.ScsiType) {
|
||||
|
||||
@@ -152,9 +152,9 @@ namespace DiscImageChef.Commands
|
||||
else if(checkStatus == true && tempStatus == true) checkStatus = true;
|
||||
else checkStatus = null;
|
||||
|
||||
foreach(ulong failLba in tempfailingLbas) failingLbas.Add(failLba);
|
||||
failingLbas.AddRange(tempfailingLbas);
|
||||
|
||||
foreach(ulong unknownLba in tempunknownLbas) unknownLbas.Add(unknownLba);
|
||||
unknownLbas.AddRange(tempunknownLbas);
|
||||
|
||||
if(remainingSectors < 512)
|
||||
{
|
||||
@@ -199,9 +199,9 @@ namespace DiscImageChef.Commands
|
||||
else if(checkStatus == true && tempStatus == true) checkStatus = true;
|
||||
else checkStatus = null;
|
||||
|
||||
foreach(ulong failLba in tempfailingLbas) failingLbas.Add(failLba);
|
||||
failingLbas.AddRange(tempfailingLbas);
|
||||
|
||||
foreach(ulong unknownLba in tempunknownLbas) unknownLbas.Add(unknownLba);
|
||||
unknownLbas.AddRange(tempunknownLbas);
|
||||
|
||||
if(remainingSectors < 512)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user