From 9dda52522c00bb96900fc7a0702cf21172c0b838 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Dec 2017 03:03:13 +0000 Subject: [PATCH] REFACTOR: Final cleanup of DiscImageChef.Metadata. --- DiscImageChef.Interop/DetectOS.cs | 78 +++++++++++----------- DiscImageChef.Interop/PlatformID.cs | 74 ++++++++++---------- DiscImageChef.Metadata/DeviceReport.cs | 2 +- DiscImageChef.Metadata/ExtentsConverter.cs | 3 +- DiscImageChef.Metadata/Statistics.cs | 21 +++--- 5 files changed, 90 insertions(+), 88 deletions(-) diff --git a/DiscImageChef.Interop/DetectOS.cs b/DiscImageChef.Interop/DetectOS.cs index 273974d3f..a45bbe5e6 100644 --- a/DiscImageChef.Interop/DetectOS.cs +++ b/DiscImageChef.Interop/DetectOS.cs @@ -45,34 +45,6 @@ namespace DiscImageChef.Interop { public static class DetectOS { - /// - /// POSIX uname structure, size from OSX, big enough to handle extra fields - /// - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - struct utsname - { - /// - /// System name - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string sysname; - /// - /// Node name - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string nodename; - /// - /// Release level - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string release; - /// - /// Version level - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string version; - /// - /// Hardware level - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string machine; - } - [DllImport("libc", SetLastError = true)] static extern int uname(out utsname name); @@ -80,17 +52,17 @@ namespace DiscImageChef.Interop static extern int OSX_sysctlbyname(string name, IntPtr oldp, IntPtr oldlenp, IntPtr newp, uint newlen); /// - /// Gets the real platform ID, not the incomplete .NET framework one + /// Gets the real platform ID, not the incomplete .NET framework one /// /// Platform ID /// Unhandled exception public static PlatformID GetRealPlatformID() { - if((int)Environment.OSVersion.Platform < 4 || (int)Environment.OSVersion.Platform == 5) return (PlatformID)(int)Environment.OSVersion.Platform; + if((int)Environment.OSVersion.Platform < 4 || (int)Environment.OSVersion.Platform == 5) + return (PlatformID)(int)Environment.OSVersion.Platform; int error = uname(out utsname unixname); - if(error != 0) - throw new Exception($"Unhandled exception calling uname: {Marshal.GetLastWin32Error()}"); + if(error != 0) throw new Exception($"Unhandled exception calling uname: {Marshal.GetLastWin32Error()}"); switch(unixname.sysname) { @@ -134,7 +106,8 @@ namespace DiscImageChef.Interop if(machine != null && (machine.StartsWith("iPad", StringComparison.Ordinal) || machine.StartsWith("iPod", StringComparison.Ordinal) || - machine.StartsWith("iPhone", StringComparison.Ordinal))) return PlatformID.iOS; + machine.StartsWith("iPhone", StringComparison.Ordinal))) + return PlatformID.iOS; return PlatformID.MacOSX; } @@ -174,7 +147,7 @@ namespace DiscImageChef.Interop } /// - /// Checks if the underlying runtime runs in 64-bit mode + /// Checks if the underlying runtime runs in 64-bit mode /// public static bool Is64Bit() { @@ -182,7 +155,7 @@ namespace DiscImageChef.Interop } /// - /// Checks if the underlying runtime runs in 32-bit mode + /// Checks if the underlying runtime runs in 32-bit mode /// public static bool Is32Bit() { @@ -190,7 +163,7 @@ namespace DiscImageChef.Interop } /// - /// Gets a string for the current operating system REAL version (handles Darwin 1.4 and Windows 10 falsifying) + /// Gets a string for the current operating system REAL version (handles Darwin 1.4 and Windows 10 falsifying) /// /// Current operating system version public static string GetVersion() @@ -203,7 +176,8 @@ namespace DiscImageChef.Interop if(Environment.OSVersion.Version.Major != 1) return $"10.{Environment.OSVersion.Version.Major - 4}.{Environment.OSVersion.Version.Minor}"; - switch(Environment.OSVersion.Version.Minor) { + switch(Environment.OSVersion.Version.Minor) + { case 3: return "10.0"; case 4: return "10.1"; } @@ -223,7 +197,7 @@ namespace DiscImageChef.Interop } /// - /// From a platform ID and version returns a human-readable version + /// From a platform ID and version returns a human-readable version /// /// Platform ID /// Version number @@ -301,5 +275,33 @@ namespace DiscImageChef.Interop default: return id.ToString(); } } + + /// + /// POSIX uname structure, size from OSX, big enough to handle extra fields + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + struct utsname + { + /// + /// System name + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string sysname; + /// + /// Node name + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string nodename; + /// + /// Release level + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string release; + /// + /// Version level + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string version; + /// + /// Hardware level + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string machine; + } } } \ No newline at end of file diff --git a/DiscImageChef.Interop/PlatformID.cs b/DiscImageChef.Interop/PlatformID.cs index 0ded678bc..5d1650de5 100644 --- a/DiscImageChef.Interop/PlatformID.cs +++ b/DiscImageChef.Interop/PlatformID.cs @@ -39,152 +39,152 @@ namespace DiscImageChef.Interop { /// - /// Contains an arbitrary list of OSes, even if .NET does not run on them + /// Contains an arbitrary list of OSes, even if .NET does not run on them /// public enum PlatformID { /// - /// Win32s + /// Win32s /// Win32S = 0, /// - /// Win32 (Windows 9x) + /// Win32 (Windows 9x) /// Win32Windows = 1, /// - /// Windows NT + /// Windows NT /// Win32NT = 2, /// - /// Windows Mobile + /// Windows Mobile /// WinCE = 3, /// - /// UNIX (do not use, too generic) + /// UNIX (do not use, too generic) /// Unix = 4, /// - /// Xbox 360 + /// Xbox 360 /// Xbox = 5, /// - /// OS X + /// OS X /// MacOSX = 6, /// - /// iOS is not OS X + /// iOS is not OS X /// iOS = 7, /// - /// Linux + /// Linux /// Linux = 8, /// - /// Sun Solaris + /// Sun Solaris /// Solaris = 9, /// - /// NetBSD + /// NetBSD /// NetBSD = 10, /// - /// OpenBSD + /// OpenBSD /// OpenBSD = 11, /// - /// FreeBSD + /// FreeBSD /// FreeBSD = 12, /// - /// DragonFly BSD + /// DragonFly BSD /// DragonFly = 13, /// - /// Nintendo Wii + /// Nintendo Wii /// Wii = 14, /// - /// Nintendo Wii U + /// Nintendo Wii U /// WiiU = 15, /// - /// Sony PlayStation 3 + /// Sony PlayStation 3 /// PlayStation3 = 16, /// - /// Sony Playstation 4 + /// Sony Playstation 4 /// PlayStation4 = 17, /// - /// Google Android + /// Google Android /// Android = 18, /// - /// Samsung Tizen + /// Samsung Tizen /// Tizen = 19, /// - /// Windows Phone + /// Windows Phone /// WindowsPhone = 20, /// - /// GNU/Hurd + /// GNU/Hurd /// Hurd = 21, /// - /// Haiku + /// Haiku /// Haiku = 22, /// - /// HP-UX + /// HP-UX /// HPUX = 23, /// - /// AIX + /// AIX /// AIX = 24, /// - /// OS/400 + /// OS/400 /// OS400 = 25, /// - /// IRIX + /// IRIX /// IRIX = 26, /// - /// Minix + /// Minix /// Minix = 27, /// - /// NonStop + /// NonStop /// NonStop = 28, /// - /// QNX + /// QNX /// QNX = 29, /// - /// SINIX + /// SINIX /// SINIX = 30, /// - /// Tru64 UNIX + /// Tru64 UNIX /// Tru64 = 31, /// - /// Ultrix + /// Ultrix /// Ultrix = 32, /// - /// SCO OpenServer / SCO UNIX + /// SCO OpenServer / SCO UNIX /// OpenServer = 33, /// - /// SCO UnixWare + /// SCO UnixWare /// UnixWare = 34, /// - /// IBM z/OS + /// IBM z/OS /// zOS = 35, Unknown = -1 diff --git a/DiscImageChef.Metadata/DeviceReport.cs b/DiscImageChef.Metadata/DeviceReport.cs index fc29a8dca..3e2a68e1e 100644 --- a/DiscImageChef.Metadata/DeviceReport.cs +++ b/DiscImageChef.Metadata/DeviceReport.cs @@ -31,11 +31,11 @@ // ****************************************************************************/ using System; -using System.Diagnostics.CodeAnalysis; using System.Xml.Serialization; using DiscImageChef.Decoders.ATA; using DiscImageChef.Decoders.SCSI; using DiscImageChef.Decoders.SCSI.MMC; + // ReSharper disable InconsistentNaming // ReSharper disable UnusedAutoPropertyAccessor.Global diff --git a/DiscImageChef.Metadata/ExtentsConverter.cs b/DiscImageChef.Metadata/ExtentsConverter.cs index b48993aad..4f0427413 100644 --- a/DiscImageChef.Metadata/ExtentsConverter.cs +++ b/DiscImageChef.Metadata/ExtentsConverter.cs @@ -57,7 +57,8 @@ namespace DiscImageChef.Metadata { if(extents == null) return null; - List> tuples = extents.Select(extent => new Tuple(extent.Start, extent.End)).ToList(); + List> tuples = + extents.Select(extent => new Tuple(extent.Start, extent.End)).ToList(); return new ExtentsULong(tuples); } diff --git a/DiscImageChef.Metadata/Statistics.cs b/DiscImageChef.Metadata/Statistics.cs index 0c734a6a7..c1b5d0968 100644 --- a/DiscImageChef.Metadata/Statistics.cs +++ b/DiscImageChef.Metadata/Statistics.cs @@ -38,11 +38,11 @@ namespace DiscImageChef.Metadata [XmlRoot("DicStats", Namespace = "", IsNullable = false)] public class Stats { + public CommandsStats Commands; [XmlArrayItem("OperatingSystem")] public List OperatingSystems { get; set; } [XmlArrayItem("Version")] public List Versions { get; set; } - public CommandsStats Commands; [XmlArrayItem("Filesystem")] public List Filesystems { get; set; } [XmlArrayItem("Scheme")] @@ -74,13 +74,13 @@ namespace DiscImageChef.Metadata public long Entropy; public long ExtractFiles; public long Formats; + public long ListDevices; + public long ListEncodings; public long Ls; public long MediaInfo; public long MediaScan; public long PrintHex; public long Verify; - public long ListDevices; - public long ListEncodings; } public class VerifiedItems @@ -97,19 +97,19 @@ namespace DiscImageChef.Metadata public class ScannedSectors { - public long Total; - public long Error; public long Correct; + public long Error; + public long Total; public long Unverifiable; } public class TimeStats { - public long LessThan3ms; public long LessThan10ms; - public long LessThan50ms; public long LessThan150ms; + public long LessThan3ms; public long LessThan500ms; + public long LessThan50ms; public long MoreThan500ms; } @@ -127,12 +127,12 @@ namespace DiscImageChef.Metadata public class BenchmarkStats { + public double All; [XmlElement("Checksum")] public List Checksum; public double Entropy; - public double All; - public double Sequential; public long MaxMemory; public long MinMemory; + public double Sequential; } public class MediaStats @@ -144,12 +144,11 @@ namespace DiscImageChef.Metadata public class DeviceStats { + [XmlIgnore] public bool ManufacturerSpecified; public string Manufacturer { get; set; } public string Model { get; set; } public string Revision { get; set; } public string Bus { get; set; } - - [XmlIgnore] public bool ManufacturerSpecified; } public class NameValueStats