Moved some environment version detections to Interop.

This commit is contained in:
2018-04-11 07:16:45 +01:00
parent 0dd475f520
commit a2be2dcf51
4 changed files with 117 additions and 96 deletions

View File

@@ -36,6 +36,10 @@
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using System;
using System.Reflection;
using System.Runtime;
namespace DiscImageChef.Interop
{
public static class Version
@@ -48,5 +52,28 @@ namespace DiscImageChef.Interop
{
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;
}
}
}