General code refactor and reformat.

This commit is contained in:
2018-12-31 13:17:27 +00:00
parent 6b12cd1a8e
commit f2caa8c40f
413 changed files with 3554 additions and 6549 deletions

View File

@@ -35,6 +35,7 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
namespace DiscImageChef.CommonTypes.Enums
{
public enum DeviceType

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<byte, byte>[] ToArray()
{
return backend.ToArray();
}
public Tuple<byte, byte>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<int, int>[] ToArray()
{
return backend.ToArray();
}
public Tuple<int, int>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<long, long>[] ToArray()
{
return backend.ToArray();
}
public Tuple<long, long>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<sbyte, sbyte>[] ToArray()
{
return backend.ToArray();
}
public Tuple<sbyte, sbyte>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<short, short>[] ToArray()
{
return backend.ToArray();
}
public Tuple<short, short>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<uint, uint>[] ToArray()
{
return backend.ToArray();
}
public Tuple<uint, uint>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<ulong, ulong>[] ToArray()
{
return backend.ToArray();
}
public Tuple<ulong, ulong>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -228,10 +228,7 @@ namespace DiscImageChef.CommonTypes.Extents
/// last element
/// </summary>
/// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<ushort, ushort>[] ToArray()
{
return backend.ToArray();
}
public Tuple<ushort, ushort>[] ToArray() => backend.ToArray();
/// <summary>
/// Gets the first element of the extent that contains the specified item

View File

@@ -106,9 +106,6 @@ namespace DiscImageChef.CommonTypes
/// Gets all known filters
/// </summary>
/// <returns>Known filters</returns>
public SortedDictionary<string, IFilter> GetFiltersList()
{
return Filters;
}
public SortedDictionary<string, IFilter> GetFiltersList() => Filters;
}
}

View File

@@ -117,21 +117,18 @@ namespace DiscImageChef.CommonTypes
public static MediaType GetMediaType(
(ushort cylinders, byte heads, ushort sectorsPerTrack, uint bytesPerSector, MediaEncoding encoding, bool
variableSectorsPerTrack) geometry)
{
return (from geom in KnownGeometries
where geom.cylinders == geometry.cylinders && geom.heads == geometry.heads &&
geom.sectorsPerTrack == geometry.sectorsPerTrack &&
geom.bytesPerSector == geometry.bytesPerSector &&
geom.encoding == geometry.encoding &&
geom.variableSectorsPerTrack == geometry.variableSectorsPerTrack
select geom.type).FirstOrDefault();
}
variableSectorsPerTrack) geometry) =>
(from geom in KnownGeometries
where geom.cylinders == geometry.cylinders &&
geom.heads == geometry.heads &&
geom.sectorsPerTrack == geometry.sectorsPerTrack &&
geom.bytesPerSector == geometry.bytesPerSector &&
geom.encoding == geometry.encoding &&
geom.variableSectorsPerTrack == geometry.variableSectorsPerTrack
select geom.type).FirstOrDefault();
public static (ushort cylinders, byte heads, ushort sectorsPerTrack, uint bytesPerSector, MediaEncoding encoding
, bool variableSectorsPerTrack, MediaType type) GetGeometry(MediaType mediaType)
{
return (from geom in KnownGeometries where geom.type == mediaType select geom).FirstOrDefault();
}
, bool variableSectorsPerTrack, MediaType type) GetGeometry(MediaType mediaType) =>
(from geom in KnownGeometries where geom.type == mediaType select geom).FirstOrDefault();
}
}

View File

@@ -44,55 +44,55 @@ namespace DiscImageChef.CommonTypes.Interfaces
public interface IPluginRegister
{
/// <summary>
/// Gets all checksum plugins
/// Gets all checksum plugins
/// </summary>
/// <returns>List of checksum plugins</returns>
List<Type> GetAllChecksumPlugins();
/// <summary>
/// Gets all filesystem plugins
/// Gets all filesystem plugins
/// </summary>
/// <returns>List of filesystem plugins</returns>
List<Type> GetAllFilesystemPlugins();
/// <summary>
/// Gets all filter plugins
/// Gets all filter plugins
/// </summary>
/// <returns>List of filter plugins</returns>
List<Type> GetAllFilterPlugins();
/// <summary>
/// Gets all floppy image plugins
/// Gets all floppy image plugins
/// </summary>
/// <returns>List of floppy image plugins</returns>
List<Type> GetAllFloppyImagePlugins();
/// <summary>
/// Gets all media image plugins
/// Gets all media image plugins
/// </summary>
/// <returns>List of media image plugins</returns>
List<Type> GetAllMediaImagePlugins();
/// <summary>
/// Gets all partition plugins
/// Gets all partition plugins
/// </summary>
/// <returns>List of partition plugins</returns>
List<Type> GetAllPartitionPlugins();
/// <summary>
/// Gets all read-only filesystem plugins
/// Gets all read-only filesystem plugins
/// </summary>
/// <returns>List of read-only filesystem plugins</returns>
List<Type> GetAllReadOnlyFilesystemPlugins();
/// <summary>
/// Gets all writable floppy image plugins
/// Gets all writable floppy image plugins
/// </summary>
/// <returns>List of writable floppy image plugins</returns>
List<Type> GetAllWritableFloppyImagePlugins();
/// <summary>
/// Gets all writable media image plugins
/// Gets all writable media image plugins
/// </summary>
/// <returns>List of writable media image plugins</returns>
List<Type> GetAllWritableImagePlugins();

View File

@@ -63,6 +63,28 @@ namespace DiscImageChef.CommonTypes.Interop
GetRealPlatformID() == PlatformID.Win32Windows || GetRealPlatformID() == PlatformID.WinCE ||
GetRealPlatformID() == PlatformID.WindowsPhone || GetRealPlatformID() == PlatformID.Xbox;
public static bool IsAdmin
{
get
{
if(!IsWindows) return Environment.UserName == "root";
bool isAdmin;
WindowsIdentity user = null;
try
{
user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch(UnauthorizedAccessException ex) { isAdmin = false; }
catch(Exception ex) { isAdmin = false; }
finally { user?.Dispose(); }
return isAdmin;
}
}
[DllImport("libc", SetLastError = true)]
static extern int uname(out utsname name);
@@ -276,28 +298,6 @@ namespace DiscImageChef.CommonTypes.Interop
}
}
public static bool IsAdmin
{
get
{
if(!IsWindows) return Environment.UserName == "root";
bool isAdmin;
WindowsIdentity user = null;
try
{
user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch(UnauthorizedAccessException ex) { isAdmin = false; }
catch(Exception ex) { isAdmin = false; }
finally { user?.Dispose(); }
return isAdmin;
}
}
/// <summary>
/// POSIX uname structure, size from OSX, big enough to handle extra fields
/// </summary>

View File

@@ -48,10 +48,7 @@ namespace DiscImageChef.CommonTypes.Interop
/// Gets version string
/// </summary>
/// <returns>Version</returns>
public static string GetVersion()
{
return typeof(Version).Assembly.GetName().Version.ToString();
}
public static string GetVersion() => typeof(Version).Assembly.GetName().Version.ToString();
public static string GetNetCoreVersion()
{

View File

@@ -269,7 +269,7 @@ namespace DiscImageChef.CommonTypes
/// <summary>Sega/Yamaha recordable Gigabyte Disc</summary>
GDR = 153,
SegaCard = 154,
MilCD = 155,
MilCD = 155,
#endregion Sega game media, types 150 to 169
#region Other game media, types 170 to 179

View File

@@ -68,15 +68,15 @@ namespace DiscImageChef.CommonTypes.Metadata
public class StatsDto
{
public List<NameValueStats> Commands { get; set; }
public List<OsStats> OperatingSystems { get; set; }
public List<NameValueStats> Versions { get; set; }
public List<NameValueStats> Filesystems { get; set; }
public List<NameValueStats> Partitions { get; set; }
public List<NameValueStats> MediaFormats { get; set; }
public List<NameValueStats> Filters { get; set; }
public List<DeviceStats> Devices { get; set; }
public List<MediaStats> Medias { get; set; }
public List<NameValueStats> Commands { get; set; }
public List<OsStats> OperatingSystems { get; set; }
public List<NameValueStats> Versions { get; set; }
public List<NameValueStats> Filesystems { get; set; }
public List<NameValueStats> Partitions { get; set; }
public List<NameValueStats> MediaFormats { get; set; }
public List<NameValueStats> Filters { get; set; }
public List<DeviceStats> Devices { get; set; }
public List<MediaStats> Medias { get; set; }
}
public class CommandsStats

View File

@@ -47,14 +47,12 @@ namespace DiscImageChef.CommonTypes.Metadata
/// Gets XML software type for the running version
/// </summary>
/// <returns>XML software type</returns>
public static SoftwareType GetSoftwareType()
{
return new SoftwareType
public static SoftwareType GetSoftwareType() =>
new SoftwareType
{
Name = "DiscImageChef",
OperatingSystem = DetectOS.GetRealPlatformID().ToString(),
Version = typeof(Version).Assembly.GetName().Version.ToString()
};
}
}
}

View File

@@ -71,20 +71,11 @@ namespace DiscImageChef.CommonTypes
/// </summary>
/// <param name="other">Partition to compare with</param>
/// <returns>0 if both partitions start and end at the same sector</returns>
public bool Equals(Partition other)
{
return Start == other.Start && Length == other.Length;
}
public bool Equals(Partition other) => Start == other.Start && Length == other.Length;
public override bool Equals(object obj)
{
return obj is Partition partition && Equals(partition);
}
public override bool Equals(object obj) => obj is Partition partition && Equals(partition);
public override int GetHashCode()
{
return Start.GetHashCode() + End.GetHashCode();
}
public override int GetHashCode() => Start.GetHashCode() + End.GetHashCode();
/// <summary>
/// Compares this partition with another and returns an integer that indicates whether the current partition precedes,
@@ -102,39 +93,21 @@ namespace DiscImageChef.CommonTypes
}
// Define the equality operator.
public static bool operator ==(Partition operand1, Partition operand2)
{
return operand1.Equals(operand2);
}
public static bool operator ==(Partition operand1, Partition operand2) => operand1.Equals(operand2);
// Define the inequality operator.
public static bool operator !=(Partition operand1, Partition operand2)
{
return !operand1.Equals(operand2);
}
public static bool operator !=(Partition operand1, Partition operand2) => !operand1.Equals(operand2);
// Define the is greater than operator.
public static bool operator >(Partition operand1, Partition operand2)
{
return operand1.CompareTo(operand2) == 1;
}
public static bool operator >(Partition operand1, Partition operand2) => operand1.CompareTo(operand2) == 1;
// Define the is less than operator.
public static bool operator <(Partition operand1, Partition operand2)
{
return operand1.CompareTo(operand2) == -1;
}
public static bool operator <(Partition operand1, Partition operand2) => operand1.CompareTo(operand2) == -1;
// Define the is greater than or equal to operator.
public static bool operator >=(Partition operand1, Partition operand2)
{
return operand1.CompareTo(operand2) >= 0;
}
public static bool operator >=(Partition operand1, Partition operand2) => operand1.CompareTo(operand2) >= 0;
// Define the is less than or equal to operator.
public static bool operator <=(Partition operand1, Partition operand2)
{
return operand1.CompareTo(operand2) <= 0;
}
public static bool operator <=(Partition operand1, Partition operand2) => operand1.CompareTo(operand2) <= 0;
}
}