From 4f73de67aa0b673214ba1ce7755cee66d8597cb6 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Fri, 17 Feb 2017 15:48:44 +0100 Subject: [PATCH] make HttpWebClient the default for mono >= 4.8 --- src/Jackett/JackettModule.cs | 30 +++++++++++++++++++++++++-- src/Jackett/Services/ServerService.cs | 28 +++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index 988b61238..4e40c81b0 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -10,10 +10,11 @@ using Jackett.Utils; using Jackett.Utils.Clients; using AutoMapper; using Jackett.Models; +using System.Reflection; namespace Jackett { - public class JackettModule : Module + public class JackettModule : Autofac.Module { protected override void Load(ContainerBuilder builder) { @@ -39,7 +40,32 @@ namespace Jackett default: if (System.Environment.OSVersion.Platform == PlatformID.Unix) { - builder.RegisterType().As(); + var usehttpclient = false; + try { + Type monotype = Type.GetType("Mono.Runtime"); + if (monotype != null) + { + MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); + if (displayName != null) + { + var monoVersion = displayName.Invoke(null, null).ToString(); + var monoVersionO = new Version(monoVersion.Split(' ')[0]); + if (monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) + { + usehttpclient = true; + } + } + } + } + catch (Exception e) + { + Console.Out.WriteLine("Error while deciding which HttpWebClient to use: " + e); + } + + if (usehttpclient) + builder.RegisterType().As(); + else + builder.RegisterType().As(); } else { diff --git a/src/Jackett/Services/ServerService.cs b/src/Jackett/Services/ServerService.cs index 2171b19d4..4a4f7b97f 100644 --- a/src/Jackett/Services/ServerService.cs +++ b/src/Jackett/Services/ServerService.cs @@ -198,12 +198,14 @@ namespace Jackett.Services monoVersion = displayName.Invoke(null, null).ToString(); logger.Info("mono version: " + monoVersion); - if (monoVersion.StartsWith("3.")) + var monoVersionO = new Version(monoVersion.Split(' ')[0]); + + if (monoVersionO.Major < 4) { logger.Error("Your mono version is to old (mono 3 is no longer supported). Please update to the latest version from http://www.mono-project.com/download/"); Environment.Exit(2); } - else if (monoVersion.StartsWith("4.2.")) + else if (monoVersionO.Major == 4 && monoVersionO.Minor == 2) { logger.Error("mono version 4.2.* is known to cause problems with Jackett. If you experience any problems please try updating to the latest mono version from http://www.mono-project.com/download/ first."); } @@ -223,6 +225,28 @@ namespace Jackett.Services logger.Error(e, "Error while checking for mono-devel"); } + try + { + // Check for ca-certificates-mono + var mono_cert_file = Path.Combine(runtimedir, "cert-sync.exe"); + if (!File.Exists(mono_cert_file)) + { + if (monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) + { + logger.Error("The ca-certificates-mono package is not installed, HTTPS trackers won't work. Please install it."); + } + else + { + logger.Info("The ca-certificates-mono package is not installed, it will become mandatory once mono >= 4.8 is used."); + } + + } + } + catch (Exception e) + { + logger.Error(e, "Error while checking for ca-certificates-mono"); + } + try { Encoding.GetEncoding("windows-1255");