Fix compilation under mono #117. Allow explicit web client selection. Init curl at application start.

This commit is contained in:
KZ 2015-07-30 18:50:46 +01:00
parent c76137a70c
commit 922583ea5d
21 changed files with 139 additions and 59 deletions

View File

@ -1,21 +1,32 @@
rmdir /s /q build
rmdir /s /q build.windows
rmdir /s /q build.mono
rmdir /s /q Output
cd src
Msbuild Jackett.sln /t:Clean,Build /p:Configuration=Release
Msbuild Jackett.sln /t:Clean,Build /p:Configuration=Release /verbosity:minimal
cd ..
xcopy src\Jackett.Console\bin\Release Build\ /e /y
copy /Y src\Jackett.Service\bin\Release\JackettService.exe build\JackettService.exe
copy /Y src\Jackett.Service\bin\Release\JackettService.exe.config build\JackettService.exe.config
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe build\JackettTray.exe
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe.config build\JackettTray.exe.config
copy /Y LICENSE build\LICENSE
copy /Y README.md build\README.md
cd build
del *.pdb
del *.xml
xcopy src\Jackett.Console\bin\Release Build.windows\ /e /y
copy /Y src\Jackett.Service\bin\Release\JackettService.exe build.windows\JackettService.exe
copy /Y src\Jackett.Service\bin\Release\JackettService.exe.config build.windows\JackettService.exe.config
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe build.windows\JackettTray.exe
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe.config build.windows\JackettTray.exe.config
copy /Y LICENSE build.windows\LICENSE
copy /Y README.md build.windows\README.md
cd src
Msbuild Jackett.sln /t:Clean
call "C:\Program Files (x86)\Mono\bin\xbuild.bat" Jackett.sln /t:Build /p:Configuration=Release /verbosity:minimal
cd ..
xcopy src\Jackett.Console\bin\Release Build.mono\ /e /y
copy /Y src\Jackett.Service\bin\Release\JackettService.exe build.mono\JackettService.exe
copy /Y src\Jackett.Service\bin\Release\JackettService.exe.config build.mono\JackettService.exe.config
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe build.mono\JackettTray.exe
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe.config build.mono\JackettTray.exe.config
copy /Y LICENSE build.mono\LICENSE
copy /Y README.md build.mono\README.md
iscc Installer.iss

View File

@ -36,8 +36,8 @@ Name: "windowsService"; Description: "Install as a Windows Service"
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "Build\JackettTray.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "Build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "Build.windows\JackettTray.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "Build.windows\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]

View File

@ -24,8 +24,8 @@ namespace Jackett.Console
[Option('t', "Tracing", HelpText = "Enable tracing")]
public bool Tracing { get; set; }
[Option('c', "UseCurlExec", HelpText = "Execute curl rather than libcurl for all outgoing requests.")]
public bool UseCurlExec { get; set; }
[Option('c', "UseClient", HelpText = "Override web client selection. Automatic(Default)/libcurl/safecurl/httpclient ")]
public string Client { get; set; }
[Option('s', "Start", HelpText = "Start the Jacket Windows service (Must be admin)")]
public bool StartService { get; set; }

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
@ -34,11 +35,14 @@ namespace JackettConsole
}
else
{
/* ====== Options ===== */
// Use curl
if (options.UseCurlExec)
Startup.CurlSafe = true;
if (options.Client!=null)
Startup.ClientOverride = options.Client.ToLowerInvariant();
// Logging
if (options.Logging)
@ -50,9 +54,6 @@ namespace JackettConsole
// Log after the fact as using the logger will cause the options above to be used
if (options.UseCurlExec)
Engine.Logger.Info("Safe curl enabled.");
if (options.Logging)
Engine.Logger.Info("Logging enabled.");

View File

@ -31,5 +31,10 @@ namespace JackettTest
{
return Task.FromResult<WebClientStringResult>(stringCallbacks.Where(r => r.Key.Equals(request)).First().Value.Invoke(request));
}
public void Init()
{
}
}
}

View File

@ -55,6 +55,14 @@
<HintPath>..\packages\Autofac.WebApi2.Owin.3.2.0\lib\net45\Autofac.Integration.WebApi.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
@ -146,7 +154,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -190,6 +200,7 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<Import Project="..\packages\AutoMapper.3.3.1\tools\AutoMapper.targets" Condition="Exists('..\packages\AutoMapper.3.3.1\tools\AutoMapper.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -36,9 +36,9 @@
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.backgroundMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.serviceControlMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItemAutoStart = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemShutdown = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -88,12 +88,18 @@
this.serviceControlMenuItem.Text = "Start Service";
this.serviceControlMenuItem.Click += new System.EventHandler(this.serviceControlMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(288, 6);
//
// toolStripMenuItemAutoStart
//
this.toolStripMenuItemAutoStart.CheckOnClick = true;
this.toolStripMenuItemAutoStart.Name = "toolStripMenuItemAutoStart";
this.toolStripMenuItemAutoStart.Size = new System.Drawing.Size(291, 22);
this.toolStripMenuItemAutoStart.Text = "Auto-start on boot";
this.toolStripMenuItemAutoStart.Visible = false;
//
// toolStripMenuItemShutdown
//
@ -101,11 +107,6 @@
this.toolStripMenuItemShutdown.Size = new System.Drawing.Size(291, 22);
this.toolStripMenuItemShutdown.Text = "Shutdown";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(288, 6);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -28,6 +28,11 @@ namespace JackettTray
toolStripMenuItemWebUI.Click += toolStripMenuItemWebUI_Click;
toolStripMenuItemShutdown.Click += toolStripMenuItemShutdown_Click;
#if __MonoCS__
// No shortcuts on linux
#else
toolStripMenuItemAutoStart.Visible = true;
#endif
Engine.Server.Initalize();
@ -91,13 +96,16 @@ namespace JackettTray
private void CreateShortcut()
{
#if __MonoCS__
// No shortcuts on linux
#else
var appPath = Assembly.GetExecutingAssembly().Location;
var shell = new IWshRuntimeLibrary.WshShell();
var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutPath);
shortcut.Description = Assembly.GetExecutingAssembly().GetName().Name;
shortcut.TargetPath = appPath;
shortcut.Save();
#endif
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)

View File

@ -4,6 +4,7 @@
<package id="Autofac.Owin" version="3.1.0" targetFramework="net45" />
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net45" />
<package id="Autofac.WebApi2.Owin" version="3.2.0" targetFramework="net45" />
<package id="AutoMapper" version="3.3.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net45" />

View File

@ -16,12 +16,6 @@ namespace Jackett
{
private static readonly object instance = new object();
static CurlHelper()
{
Engine.Logger.Debug("LibCurl init" + Curl.GlobalInit(CurlInitFlag.All).ToString());
Engine.Logger.Debug("LibCurl version " + Curl.Version);
}
public class CurlRequest
{

View File

@ -178,15 +178,30 @@ namespace Jackett.Indexers
public async virtual Task<byte[]> Download(Uri link)
{
var response = await webclient.GetBytes(new Utils.Clients.WebRequest()
{
Url = link.ToString(),
Cookies = cookieHeader
});
var response = await RequestBytesWithCookiesAndRetry(link.ToString());
return response.Content;
}
protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null)
{
Exception lastException = null;
for (int i = 0; i < 3; i++)
{
try
{
return await RequestBytesWithCookies(url, cookieOverride);
}
catch (Exception e)
{
logger.Error(string.Format("On attempt {0} downloading from {1}: {2}", (i + 1), DisplayName, e.Message));
lastException = e;
await Task.Delay(500);
}
}
throw lastException;
}
protected async Task<WebClientStringResult> RequestStringWithCookies(string url, string cookieOverride = null, string referer = null)
{
var request = new Utils.Clients.WebRequest()

View File

@ -115,6 +115,8 @@ namespace Jackett.Indexers
var release = new ReleaseInfo();
var qRow = row.Cq();
release.Title = qRow.Find(".tooltip-content div").First().Text();
if (string.IsNullOrWhiteSpace(release.Title))
continue;
release.Description = qRow.Find(".tooltip-content div").Get(1).InnerText.Trim();
var qLink = row.Cq().Find("td:eq(2) a:eq(1)");

View File

@ -70,7 +70,7 @@ namespace Jackett.Indexers
{
var releases = new List<ReleaseInfo>();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var results = await PostDataWithCookies(SearchUrl, GetSearchFormData(searchString));
var results = await PostDataWithCookiesAndRetry(SearchUrl, GetSearchFormData(searchString));
try
{

View File

@ -264,7 +264,7 @@
<Compile Include="Utils\WebApiRootRedirectMiddleware.cs" />
<Compile Include="Utils\WebAPIRequestLogger.cs" />
<Compile Include="Utils\WebAPIToNLogTracer.cs" />
<Compile Include="Utils\Clients\WindowsWebClient.cs" />
<Compile Include="Utils\Clients\HttpWebClient.cs" />
<Compile Include="WebAPIExceptionLogger.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -22,18 +22,29 @@ namespace Jackett
builder.RegisterAssemblyTypes(thisAssembly).Except<IIndexer>().AsImplementedInterfaces().SingleInstance();
builder.RegisterApiControllers(thisAssembly).InstancePerRequest();
// Register the best web client for the platform or exec curl as a safe option
if (Startup.CurlSafe)
// Register the best web client for the platform or the override
switch (Startup.ClientOverride)
{
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
}
else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
{
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
}
else
{
builder.RegisterType<WindowsWebClient>().As<IWebClient>();
case "httpclient":
builder.RegisterType<HttpWebClient>().As<IWebClient>();
break;
case "safecurl":
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
break;
case "libcurl":
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
break;
case "automatic":
default:
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
{
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
}
else
{
builder.RegisterType<HttpWebClient>().As<IWebClient>();
}
break;
}
// Register indexers

View File

@ -1,6 +1,7 @@
using Autofac;
using Jackett.Models.Config;
using Jackett.Services;
using Jackett.Utils.Clients;
using Microsoft.Owin.Hosting;
using Newtonsoft.Json.Linq;
using NLog;
@ -41,14 +42,16 @@ namespace Jackett.Services
private ISerializeService serializeService;
private IConfigurationService configService;
private Logger logger;
private IWebClient client;
public ServerService(IIndexerManagerService i, IProcessService p, ISerializeService s, IConfigurationService c, Logger l)
public ServerService(IIndexerManagerService i, IProcessService p, ISerializeService s, IConfigurationService c, Logger l, IWebClient w)
{
indexerService = i;
processService = p;
serializeService = s;
configService = c;
logger = l;
client = w;
LoadConfig();
}
@ -105,9 +108,9 @@ namespace Jackett.Services
{
logger.Info("Starting Jackett " + configService.GetVersion());
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Load indexers
indexerService.InitIndexers();
client.Init();
}
public void Start()

View File

@ -34,7 +34,7 @@ namespace Jackett
set;
}
public static bool CurlSafe
public static string ClientOverride
{
get;
set;

View File

@ -11,15 +11,20 @@ using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
class WindowsWebClient : IWebClient
class HttpWebClient : IWebClient
{
private Logger logger;
public WindowsWebClient(Logger l)
public HttpWebClient(Logger l)
{
logger = l;
}
public void Init()
{
}
public async Task<WebClientByteResult> GetBytes(WebRequest request)
{
logger.Debug(string.Format("WindowsWebClient:GetBytes(Url:{0})", request.Url));

View File

@ -11,5 +11,6 @@ namespace Jackett.Utils.Clients
{
Task<WebClientStringResult> GetString(WebRequest request);
Task<WebClientByteResult> GetBytes(WebRequest request);
void Init();
}
}

View File

@ -1,4 +1,5 @@
using AutoMapper;
using CurlSharp;
using Jackett.Models;
using Jackett.Services;
using NLog;
@ -38,6 +39,12 @@ namespace Jackett.Utils.Clients
return Mapper.Map<WebClientStringResult>(result);
}
public void Init()
{
Engine.Logger.Info("LibCurl init " + Curl.GlobalInit(CurlInitFlag.All).ToString());
Engine.Logger.Info("LibCurl version " + Curl.Version);
}
private async Task<WebClientByteResult> Run(WebRequest request)
{
Jackett.CurlHelper.CurlResponse response;

View File

@ -24,6 +24,10 @@ namespace Jackett.Utils.Clients
logger = l;
}
public void Init()
{
}
public async Task<WebClientByteResult> GetBytes(WebRequest request)
{
logger.Debug(string.Format("UnixSafeCurlWebClient:GetBytes(Url:{0})", request.Url));