mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Moved some environment version detections to Interop.
This commit is contained in:
@@ -62,19 +62,12 @@ namespace DiscImageChef.Core.Logging
|
|||||||
|
|
||||||
PlatformID platId = DetectOS.GetRealPlatformID();
|
PlatformID platId = DetectOS.GetRealPlatformID();
|
||||||
string platVer = DetectOS.GetVersion();
|
string platVer = DetectOS.GetVersion();
|
||||||
Type monoRunType = Type.GetType("Mono.Runtime");
|
|
||||||
|
|
||||||
logSw.WriteLine("################# System information #################");
|
logSw.WriteLine("################# System information #################");
|
||||||
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
|
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
|
||||||
Environment.Is64BitOperatingSystem ? 64 : 32);
|
Environment.Is64BitOperatingSystem ? 64 : 32);
|
||||||
if(monoRunType != null)
|
if(DetectOS.IsMono)
|
||||||
{
|
logSw.WriteLine("Mono {0}", Version.GetMonoVersion());
|
||||||
string monoVer = "unknown version";
|
|
||||||
MethodInfo monoDisplayName =
|
|
||||||
monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
|
||||||
if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null);
|
|
||||||
logSw.WriteLine("Mono {0}", monoVer);
|
|
||||||
}
|
|
||||||
else logSw.WriteLine(".NET Framework {0}", Environment.Version);
|
else logSw.WriteLine(".NET Framework {0}", Environment.Version);
|
||||||
|
|
||||||
logSw.WriteLine();
|
logSw.WriteLine();
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
IntPtr buf = Marshal.AllocHGlobal(4096);
|
IntPtr buf = Marshal.AllocHGlobal(4096);
|
||||||
int resultSize;
|
int resultSize;
|
||||||
|
|
||||||
if(DetectOS.Is64Bit())
|
if(DetectOS.Is64Bit)
|
||||||
{
|
{
|
||||||
long result64 = Extern.readlink64(path, buf, 4096);
|
long result64 = Extern.readlink64(path, buf, 4096);
|
||||||
if(result64 <= 0) return null;
|
if(result64 <= 0) return null;
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ namespace DiscImageChef.Interop
|
|||||||
{
|
{
|
||||||
public static class DetectOS
|
public static class DetectOS
|
||||||
{
|
{
|
||||||
|
public static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the underlying runtime runs in 64-bit mode
|
||||||
|
/// </summary>
|
||||||
|
public static readonly bool Is64Bit = IntPtr.Size == 8;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the underlying runtime runs in 32-bit mode
|
||||||
|
/// </summary>
|
||||||
|
public static readonly bool Is32Bit = IntPtr.Size == 4;
|
||||||
|
|
||||||
[DllImport("libc", SetLastError = true)]
|
[DllImport("libc", SetLastError = true)]
|
||||||
static extern int uname(out utsname name);
|
static extern int uname(out utsname name);
|
||||||
|
|
||||||
@@ -69,11 +81,11 @@ namespace DiscImageChef.Interop
|
|||||||
// TODO: Differentiate Linux, Android, Tizen
|
// TODO: Differentiate Linux, Android, Tizen
|
||||||
case "Linux":
|
case "Linux":
|
||||||
{
|
{
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
return PlatformID.Android;
|
return PlatformID.Android;
|
||||||
#else
|
#else
|
||||||
return PlatformID.Linux;
|
return PlatformID.Linux;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
case "Darwin":
|
case "Darwin":
|
||||||
{
|
{
|
||||||
@@ -146,22 +158,6 @@ namespace DiscImageChef.Interop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the underlying runtime runs in 64-bit mode
|
|
||||||
/// </summary>
|
|
||||||
public static bool Is64Bit()
|
|
||||||
{
|
|
||||||
return IntPtr.Size == 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the underlying runtime runs in 32-bit mode
|
|
||||||
/// </summary>
|
|
||||||
public static bool Is32Bit()
|
|
||||||
{
|
|
||||||
return IntPtr.Size == 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -285,23 +281,28 @@ namespace DiscImageChef.Interop
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// System name
|
/// System name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string sysname;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string sysname;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Node name
|
/// Node name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string nodename;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string nodename;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Release level
|
/// Release level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string release;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string release;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version level
|
/// Version level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string version;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string version;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hardware level
|
/// Hardware level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string machine;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||||
|
public string machine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,10 @@
|
|||||||
// Copyright © 2011-2018 Natalia Portillo
|
// Copyright © 2011-2018 Natalia Portillo
|
||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime;
|
||||||
|
|
||||||
namespace DiscImageChef.Interop
|
namespace DiscImageChef.Interop
|
||||||
{
|
{
|
||||||
public static class Version
|
public static class Version
|
||||||
@@ -48,5 +52,28 @@ namespace DiscImageChef.Interop
|
|||||||
{
|
{
|
||||||
return typeof(Version).Assembly.GetName().Version.ToString();
|
return typeof(Version).Assembly.GetName().Version.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetNetCoreVersion()
|
||||||
|
{
|
||||||
|
Assembly assembly = typeof(GCSettings).Assembly;
|
||||||
|
string[] assemblyPath =
|
||||||
|
assembly.CodeBase.Split(new[] {'/', '\\'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
|
||||||
|
if(netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
|
||||||
|
return assemblyPath[netCoreAppIndex + 1];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetMonoVersion()
|
||||||
|
{
|
||||||
|
if(!DetectOS.IsMono) return null;
|
||||||
|
|
||||||
|
MethodInfo monoDisplayName = Type.GetType("Mono.Runtime")
|
||||||
|
?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
if(monoDisplayName != null) return (string)monoDisplayName.Invoke(null, null);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user