mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Loop can be converted into LINQ-expression.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.DiscImages;
|
||||
@@ -68,19 +69,15 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
ulong counter = 0;
|
||||
|
||||
foreach(DECPartition entry in table.pt_part)
|
||||
foreach(Partition part in table.pt_part.Select(entry => new Partition
|
||||
{
|
||||
Partition part = new Partition
|
||||
{
|
||||
Start = entry.pi_blkoff,
|
||||
Offset = (ulong)(entry.pi_blkoff * sector.Length),
|
||||
Size = (ulong)entry.pi_nblocks,
|
||||
Length = (ulong)(entry.pi_nblocks * sector.Length),
|
||||
Sequence = counter,
|
||||
Scheme = Name
|
||||
};
|
||||
if(part.Size <= 0) continue;
|
||||
|
||||
Start = entry.pi_blkoff,
|
||||
Offset = (ulong)(entry.pi_blkoff * sector.Length),
|
||||
Size = (ulong)entry.pi_nblocks,
|
||||
Length = (ulong)(entry.pi_nblocks * sector.Length),
|
||||
Sequence = counter,
|
||||
Scheme = Name
|
||||
}).Where(part => part.Size > 0)) {
|
||||
partitions.Add(part);
|
||||
counter++;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.Console;
|
||||
|
||||
@@ -150,34 +151,32 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
ulong pseq = 0;
|
||||
|
||||
foreach(GptEntry entry in entries)
|
||||
if(entry.partitionType != Guid.Empty && entry.partitionId != Guid.Empty)
|
||||
foreach(GptEntry entry in entries.Where(entry => entry.partitionType != Guid.Empty && entry.partitionId != Guid.Empty)) {
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.partitionType = {0}", entry.partitionType);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.partitionId = {0}", entry.partitionId);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.startLBA = {0}", entry.startLBA);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.endLBA = {0}", entry.endLBA);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.attributes = 0x{0:X16}", entry.attributes);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.name = {0}", entry.name);
|
||||
|
||||
if(entry.startLBA / divisor > imagePlugin.GetSectors() ||
|
||||
entry.endLBA / divisor > imagePlugin.GetSectors()) return false;
|
||||
|
||||
CommonTypes.Partition part = new CommonTypes.Partition
|
||||
{
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.partitionType = {0}", entry.partitionType);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.partitionId = {0}", entry.partitionId);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.startLBA = {0}", entry.startLBA);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.endLBA = {0}", entry.endLBA);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.attributes = 0x{0:X16}", entry.attributes);
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "entry.name = {0}", entry.name);
|
||||
|
||||
if(entry.startLBA / divisor > imagePlugin.GetSectors() ||
|
||||
entry.endLBA / divisor > imagePlugin.GetSectors()) return false;
|
||||
|
||||
CommonTypes.Partition part = new CommonTypes.Partition
|
||||
{
|
||||
Description = string.Format("ID: {0}", entry.partitionId),
|
||||
Size = (entry.endLBA - entry.startLBA + 1) * sectorSize,
|
||||
Name = entry.name,
|
||||
Length = (entry.endLBA - entry.startLBA + 1) / divisor,
|
||||
Sequence = pseq++,
|
||||
Offset = entry.startLBA * sectorSize,
|
||||
Start = entry.startLBA / divisor,
|
||||
Type = GetGuidTypeName(entry.partitionType),
|
||||
Scheme = Name
|
||||
};
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "part.PartitionType = {0}", part.Type);
|
||||
partitions.Add(part);
|
||||
}
|
||||
Description = string.Format("ID: {0}", entry.partitionId),
|
||||
Size = (entry.endLBA - entry.startLBA + 1) * sectorSize,
|
||||
Name = entry.name,
|
||||
Length = (entry.endLBA - entry.startLBA + 1) / divisor,
|
||||
Sequence = pseq++,
|
||||
Offset = entry.startLBA * sectorSize,
|
||||
Start = entry.startLBA / divisor,
|
||||
Type = GetGuidTypeName(entry.partitionType),
|
||||
Scheme = Name
|
||||
};
|
||||
DicConsole.DebugWriteLine("GPT Plugin", "part.PartitionType = {0}", part.Type);
|
||||
partitions.Add(part);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using DiscImageChef.Console;
|
||||
@@ -76,10 +77,7 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
ulong label_position = 0;
|
||||
|
||||
foreach(ulong i in new ulong[] {0, 4, 15, 16})
|
||||
{
|
||||
if(i + sectorOffset >= imagePlugin.GetSectors()) break;
|
||||
|
||||
foreach(ulong i in new ulong[] {0, 4, 15, 16}.TakeWhile(i => i + sectorOffset < imagePlugin.GetSectors())) {
|
||||
label_sector = imagePlugin.ReadSector(i + sectorOffset);
|
||||
magic = BigEndianBitConverter.ToUInt32(label_sector, 0x00);
|
||||
if(magic != NEXT_MAGIC1 && magic != NEXT_MAGIC2 && magic != NEXT_MAGIC3) continue;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiscImageChef.CommonTypes;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
@@ -60,14 +61,7 @@ namespace DiscImageChef.Partitions
|
||||
// While all of Plan9 is supposedly UTF-8, it uses ASCII strcmp for reading its partition table
|
||||
string[] really = StringHandlers.CToString(sector).Split(new[] {'\n'});
|
||||
|
||||
foreach(string part in really)
|
||||
{
|
||||
if(part.Length < 5 || part.Substring(0, 5) != "part ") break;
|
||||
|
||||
string[] tokens = part.Split(new[] {' '});
|
||||
|
||||
if(tokens.Length != 4) break;
|
||||
|
||||
foreach(string[] tokens in really.TakeWhile(part => part.Length >= 5 && part.Substring(0, 5) == "part ").Select(part => part.Split(new[] {' '})).TakeWhile(tokens => tokens.Length == 4)) {
|
||||
if(!ulong.TryParse(tokens[2], out ulong start) || !ulong.TryParse(tokens[3], out ulong end)) break;
|
||||
|
||||
Partition _part = new Partition
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.Console;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
@@ -1317,8 +1319,7 @@ namespace DiscImageChef.Partitions
|
||||
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.priority = {0}", fshd.Dnode.Priority);
|
||||
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.startup = {0}", fshd.Dnode.Startup);
|
||||
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.seglist_ptr = {0}", fshd.Dnode.SeglistPtr);
|
||||
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.global_vec = 0x{0:X8}",
|
||||
fshd.Dnode.GlobalVec);
|
||||
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.global_vec = 0x{0:X8}", fshd.Dnode.GlobalVec);
|
||||
|
||||
nextBlock = fshd.Dnode.SeglistPtr;
|
||||
bool thereAreLoadSegments = false;
|
||||
@@ -1370,24 +1371,24 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
|
||||
ulong sequence = 0;
|
||||
foreach(PartitionEntry rdbEntry in partitionEntries)
|
||||
foreach(Partition entry in partitionEntries.Select(rdbEntry => new CommonTypes.Partition
|
||||
{
|
||||
Description = AmigaDosTypeToDescriptionString(rdbEntry.DosEnvVec.DosType),
|
||||
Name = rdbEntry.DriveName,
|
||||
Sequence = sequence,
|
||||
Length =
|
||||
(rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) *
|
||||
rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt,
|
||||
Start = rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt +
|
||||
sectorOffset,
|
||||
Type = AmigaDosTypeToString(rdbEntry.DosEnvVec.DosType),
|
||||
Scheme = Name,
|
||||
Offset = (rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt +
|
||||
sectorOffset) * rdb.BlockSize,
|
||||
Size = ((rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) *
|
||||
rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt) * rdb.BlockSize
|
||||
}))
|
||||
{
|
||||
CommonTypes.Partition entry = new CommonTypes.Partition
|
||||
{
|
||||
Description = AmigaDosTypeToDescriptionString(rdbEntry.DosEnvVec.DosType),
|
||||
Name = rdbEntry.DriveName,
|
||||
Sequence = sequence,
|
||||
Length =
|
||||
(rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) *
|
||||
rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt,
|
||||
Start = rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt +
|
||||
sectorOffset,
|
||||
Type = AmigaDosTypeToString(rdbEntry.DosEnvVec.DosType),
|
||||
Scheme = Name
|
||||
};
|
||||
entry.Offset = entry.Start * rdb.BlockSize;
|
||||
entry.Size = entry.Length * rdb.BlockSize;
|
||||
|
||||
partitions.Add(entry);
|
||||
sequence++;
|
||||
}
|
||||
@@ -1425,9 +1426,12 @@ namespace DiscImageChef.Partitions
|
||||
case TYPEID_FFS_MUSER: return "Amiga Fast File System with multi-user patches";
|
||||
case TYPEID_OFS_INTL_MUSER:
|
||||
return "Amiga Original File System with international characters and multi-user patches";
|
||||
case TYPEID_FFS_INTL_MUSER: return "Amiga Fast File System with international characters and multi-user patches";
|
||||
case TYPEID_OFS_CACHE_MUSER: return "Amiga Original File System with directory cache and multi-user patches";
|
||||
case TYPEID_FFS_CACHE_MUSER: return "Amiga Fast File System with directory cache and multi-user patches";
|
||||
case TYPEID_FFS_INTL_MUSER:
|
||||
return "Amiga Fast File System with international characters and multi-user patches";
|
||||
case TYPEID_OFS_CACHE_MUSER:
|
||||
return "Amiga Original File System with directory cache and multi-user patches";
|
||||
case TYPEID_FFS_CACHE_MUSER:
|
||||
return "Amiga Fast File System with directory cache and multi-user patches";
|
||||
case TYPEID_OLD_BSD_UNUSED: return "BSD unused";
|
||||
case TYPEID_OLD_BSD_SWAP: return "BSD swap";
|
||||
case TYPEID_OLD_BSD42_FFS: return "BSD 4.2 FFS";
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.DiscImages;
|
||||
@@ -66,20 +67,16 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
ulong counter = 0;
|
||||
|
||||
foreach(RioKarmaEntry entry in table.entries)
|
||||
foreach(Partition part in from entry in table.entries let part = new Partition
|
||||
{
|
||||
Partition part = new Partition
|
||||
{
|
||||
Start = entry.offset,
|
||||
Offset = (ulong)(entry.offset * sector.Length),
|
||||
Size = entry.size,
|
||||
Length = (ulong)(entry.size * sector.Length),
|
||||
Type = "Rio Karma",
|
||||
Sequence = counter,
|
||||
Scheme = Name
|
||||
};
|
||||
if(entry.type != ENTRY_MAGIC) continue;
|
||||
|
||||
Start = entry.offset,
|
||||
Offset = (ulong)(entry.offset * sector.Length),
|
||||
Size = entry.size,
|
||||
Length = (ulong)(entry.size * sector.Length),
|
||||
Type = "Rio Karma",
|
||||
Sequence = counter,
|
||||
Scheme = Name
|
||||
} where entry.type == ENTRY_MAGIC select part) {
|
||||
partitions.Add(part);
|
||||
counter++;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.Console;
|
||||
@@ -64,10 +65,7 @@ namespace DiscImageChef.Partitions
|
||||
bool magic_found = false;
|
||||
bool absolute = false;
|
||||
|
||||
foreach(ulong i in new ulong[] {0, 1, 8, 29})
|
||||
{
|
||||
if(i + sectorOffset >= imagePlugin.GetSectors()) break;
|
||||
|
||||
foreach(ulong i in new ulong[] {0, 1, 8, 29}.TakeWhile(i => i + sectorOffset < imagePlugin.GetSectors())) {
|
||||
pdsector = imagePlugin.ReadSector(i + sectorOffset);
|
||||
magic = BitConverter.ToUInt32(pdsector, 4);
|
||||
DicConsole.DebugWriteLine("VTOC plugin", "sanity at {0} is 0x{1:X8} (should be 0x{2:X8} or 0x{3:X8})",
|
||||
|
||||
Reference in New Issue
Block a user