Attempt to handle not found System.Runtime.InteropServices.RuntimeInformation

https://github.com/Jackett/Jackett/issues/3816
This commit is contained in:
flightlevel
2018-09-24 19:24:17 +10:00
parent 2f378210d9
commit f9b4b5a76c
5 changed files with 35 additions and 14 deletions

View File

@@ -10,7 +10,6 @@ using NLog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Jackett.Common.Models.IndexerConfig.ConfigurationData; using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
@@ -177,10 +176,9 @@ namespace Jackett.Common.Indexers
//TODO: Remove this section once users have moved off DPAPI //TODO: Remove this section once users have moved off DPAPI
private bool MigratedFromDPAPI(JToken jsonConfig) private bool MigratedFromDPAPI(JToken jsonConfig)
{ {
bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("core", StringComparison.OrdinalIgnoreCase) >= 0;
bool isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; bool isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
if (!isWindows && runningOnDotNetCore) if (!isWindows && DotNetCoreUtil.IsRunningOnDotNetCore)
{ {
// User isn't running Windows, but is running on .NET Core framework, no access to the DPAPI, so don't bother trying to migrate // User isn't running Windows, but is running on .NET Core framework, no access to the DPAPI, so don't bother trying to migrate
return false; return false;

View File

@@ -0,0 +1,28 @@
using System;
using System.Runtime.InteropServices;
namespace Jackett.Common.Utils
{
public static class DotNetCoreUtil
{
public static bool IsRunningOnDotNetCore
{
get
{
bool runningOnDotNetCore = false;
try
{
runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("core", StringComparison.OrdinalIgnoreCase) >= 0;
}
catch
{
//Issue only appears to occur for small number of users on Mono
runningOnDotNetCore = false;
}
return runningOnDotNetCore;
}
}
}
}

View File

@@ -4,8 +4,6 @@ using Jackett.Common.Utils;
using Jackett.Server.Services; using Jackett.Server.Services;
using NLog; using NLog;
using System; using System;
using System.Linq;
using System.Runtime.InteropServices;
namespace Jackett.Server namespace Jackett.Server
{ {
@@ -113,8 +111,8 @@ namespace Jackett.Server
{ {
logger.Info("Overriding port to " + consoleOptions.Port); logger.Info("Overriding port to " + consoleOptions.Port);
serverConfig.Port = consoleOptions.Port; serverConfig.Port = consoleOptions.Port;
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (isWindows) if (EnvironmentUtil.IsWindows)
{ {
if (ServerUtil.IsUserAdministrator()) if (ServerUtil.IsUserAdministrator())
{ {
@@ -137,7 +135,7 @@ namespace Jackett.Server
{ {
logger.Info("Overriding external access to " + consoleOptions.ListenPublic); logger.Info("Overriding external access to " + consoleOptions.ListenPublic);
serverConfig.AllowExternal = consoleOptions.ListenPublic; serverConfig.AllowExternal = consoleOptions.ListenPublic;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (EnvironmentUtil.IsWindows)
{ {
if (ServerUtil.IsUserAdministrator()) if (ServerUtil.IsUserAdministrator())
{ {

View File

@@ -47,9 +47,7 @@ namespace Jackett.Server
{ {
if (string.IsNullOrEmpty(options.Client)) if (string.IsNullOrEmpty(options.Client))
{ {
bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("Core", StringComparison.OrdinalIgnoreCase) >= 0; if (DotNetCoreUtil.IsRunningOnDotNetCore)
if (runningOnDotNetCore)
{ {
options.Client = "httpclientnetcore"; options.Client = "httpclientnetcore";
} }

View File

@@ -1,5 +1,6 @@
using Jackett.Common.Models.Config; using Jackett.Common.Models.Config;
using Jackett.Common.Services.Interfaces; using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities; using Microsoft.AspNetCore.WebUtilities;
using NLog; using NLog;
@@ -121,10 +122,8 @@ namespace Jackett.Server.Services
logger.Error(e, "Error while reading the issue file"); logger.Error(e, "Error while reading the issue file");
} }
bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("Core", StringComparison.OrdinalIgnoreCase) >= 0;
Type monotype = Type.GetType("Mono.Runtime"); Type monotype = Type.GetType("Mono.Runtime");
if (monotype != null && !runningOnDotNetCore) if (monotype != null && !DotNetCoreUtil.IsRunningOnDotNetCore)
{ {
MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
var monoVersion = "unknown"; var monoVersion = "unknown";