Merge branch 'master' into dotnetcore

This commit is contained in:
flightlevel 2018-06-24 11:43:02 +10:00
commit 54c5b66ecf
13 changed files with 177 additions and 240 deletions

View File

@ -26,6 +26,7 @@ OutputBaseFilename={#MyOutputFilename}
SetupIconFile=src\Jackett.Console\jackett.ico
UninstallDisplayIcon={commonappdata}\Jackett\JackettConsole.exe
VersionInfoVersion={#MyAppVersion}
UninstallDisplayName={#MyAppName}
Compression=lzma
SolidCompression=yes
DisableDirPage=yes
@ -38,7 +39,7 @@ Name: "windowsService"; Description: "Install as a Windows Service"
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "{#MySourceFolder}\Jackett\*"; DestDir: "{commonappdata}\Jackett"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#MySourceFolder}\*"; DestDir: "{commonappdata}\Jackett"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
@ -50,13 +51,12 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{commonappdata}\Jackett\{#MyApp
Filename: "{commonappdata}\Jackett\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[Run]
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated;
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--ReserveUrls"; Flags: waituntilterminated;
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--MigrateSettings"; Flags: waituntilterminated;
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Install"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Start"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated runhidden;
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--ReserveUrls"; Flags: waituntilterminated runhidden;
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Install"; Flags: waituntilterminated runhidden; Tasks: windowsService
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Start"; Flags: waituntilterminated runhidden; Tasks: windowsService
[UninstallRun]
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated skipifdoesntexist
Filename: "{commonappdata}\Jackett\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated skipifdoesntexist runhidden

View File

@ -56,7 +56,11 @@ Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
MSBuild("./src/Jackett.sln", settings => settings.SetConfiguration(configuration));
var buildSettings = new MSBuildSettings()
.SetConfiguration(configuration)
.UseToolVersion(MSBuildToolVersion.VS2017);
MSBuild("./src/Jackett.sln", buildSettings);
});
Task("Run-Unit-Tests")
@ -86,7 +90,7 @@ Task("Copy-Files-Full-Framework")
CopyDirectory("./src/Jackett.Console/bin/" + configuration, windowsOutput);
CopyFiles("./src/Jackett.Service/bin/" + configuration + "/JackettService.*", windowsOutput);
CopyFiles("./src/Jackett.Tray/bin/" + configuration + "/JackettTray.*", windowsOutput);
CopyFiles("./src/Jackett.Updater/bin/" + configuration + "/JackettUpdater.*", windowsOutput);
CopyFiles("./src/Jackett.Updater/bin/" + configuration + "/net452" + "/JackettUpdater.*", windowsOutput); //builds against multiple frameworks
CopyFiles("./Upstart.config", windowsOutput);
CopyFiles("./LICENSE", windowsOutput);
CopyFiles("./README.md", windowsOutput);
@ -119,13 +123,13 @@ Task("Package-Windows-Installer-Full-Framework")
.IsDependentOn("Check-Packaging-Platform")
.Does(() =>
{
string sourceFolder = MakeAbsolute(Directory(windowsBuildFullFramework)).ToString();
string sourceFolder = MakeAbsolute(Directory(windowsBuildFullFramework + "/Jackett")).ToString();
InnoSetupSettings settings = new InnoSetupSettings();
settings.OutputDirectory = workingDir + "/" + artifactsDirName;
settings.Defines = new Dictionary<string, string>
{
{ "MyFileForVersion", sourceFolder + "/Jackett/Jackett.Common.dll" },
{ "MyFileForVersion", sourceFolder + "/Jackett.Common.dll" },
{ "MySourceFolder", sourceFolder },
{ "MyOutputFilename", "Jackett.Installer.Windows" },
};
@ -155,7 +159,7 @@ Task("Package-Full-Framework")
.IsDependentOn("Package-Files-Full-Framework-Mono")
.Does(() =>
{
Information("Full Framwork Packaging Completed");
Information("Full Framework Packaging Completed");
});
Task("Experimental-DotNetCore")

View File

@ -34,15 +34,8 @@
page: 1
srcrel: "{{ .Keywords }}"
keywordsfilters:
- name: re_replace
args: ["S[0-9]{2}([^E]|$)", ""] # remove season tag without episode (search doesn't support it)
- name: diacritics
args: replace
# most ITA TV torrents are in XXxYY format, so we search without S/E prefixes and filter later
- name: re_replace
args: ["S0?(\\d{1,2})", " $1 "]
- name: re_replace
args: ["E(\\d{2,3})", " $1 "]
rows:
selector: div.showrelease_tb table tbody tr:not(tr:nth-child(1))
fields:
@ -54,27 +47,9 @@
filters:
- name: split
args: ["=", "-1"]
# inizio prova
- name: re_replace # replace special characters with " " (space)
args: ["[^a-zA-Z0-9]|\\.", " "]
# normalize to SXXEYY format
- name: re_replace
args: ["(\\d{2})x(\\d{2})", "S$1E$2"]
- name: re_replace
args: ["(\\d{1})x(\\d{2})", "S0$1E$2"]
- name: re_replace #Stagione X --> S0X
args: ["Stagione (\\d{0,1}\\s)", "S0$1"]
- name: re_replace #Stagione XX --> SXX
args: ["Stagione (\\d{2}\\s)", "S$1"]
- name: re_replace #/ Episodio [YY-YY --> EYY-YY
args: ["(\\s\\/\\sEpisodio|\\s\\/\\sEpisodi|\\sEpisodio|\\s\\|\\sEpisodio|\\sEpisodi)\\s\\[", "E"]
- name: re_replace #/ Completa [episodi YY-YY --> EYY-YY
args: ["(\\s\\/\\sCompleta\\s\\[episodi\\s)", "E"]
- name: re_replace #remove di YY] | remove /YY]
args: ["(\\sdi\\s\\d{1,2}|\\/\\d{1,2})\\]", " "]
- name: re_replace #remove various
args: ["(Serie completa|Completa|\\[in pausa\\])", ""]
# fine prova
args: ["\\b([s])?(\\d{1,3})[x\\s](\\d{1,3})", "S$2E$3"]
details:
selector: td:nth-child(7) a
attribute: href

View File

@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Services.Interfaces;
@ -14,6 +7,12 @@ using Jackett.Common.Utils.Clients;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Common.Indexers
{
@ -184,10 +183,10 @@ namespace Jackett.Common.Indexers
return false;
}
Version dotNetVersion = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.RuntimeFramework.Version;
bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("core", StringComparison.OrdinalIgnoreCase) >= 0;
bool isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
if (!isWindows && dotNetVersion.Major < 4)
if (!isWindows && runningOnDotNetCore)
{
// 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;
@ -290,7 +289,7 @@ namespace Jackett.Common.Indexers
return false;
if (caps.SupportsImdbSearch && query.IsImdbQuery)
return true;
else if(!caps.SupportsImdbSearch && query.IsImdbQuery && query.QueryType != "TorrentPotato") // potato query should always contain imdb+search term
else if (!caps.SupportsImdbSearch && query.IsImdbQuery && query.QueryType != "TorrentPotato") // potato query should always contain imdb+search term
return false;
if (caps.SearchAvailable && query.IsSearch)
return true;
@ -838,7 +837,6 @@ namespace Jackett.Common.Indexers
public override TorznabCapabilities TorznabCaps { get; protected set; }
private List<CategoryMapping> categoryMapping = new List<CategoryMapping>();
protected WebClient webclient;
protected readonly string downloadUrlBase = "";

View File

@ -23,9 +23,9 @@ namespace Jackett.Common.Indexers
private string LoginUrl { get { return SiteLink + "login.php"; } }
private const int MAXPAGES = 3;
private new ConfigurationDataBasicLogin configData
private new ConfigurationDataRecaptchaLogin configData
{
get { return (ConfigurationDataBasicLogin)base.configData; }
get { return (ConfigurationDataRecaptchaLogin)base.configData; }
set { base.configData = value; }
}
@ -37,7 +37,7 @@ namespace Jackett.Common.Indexers
client: w,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLogin())
configData: new ConfigurationDataRecaptchaLogin())
{
Encoding = Encoding.GetEncoding("windows-1255");
Language = "he-il";
@ -95,9 +95,57 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(76, TorznabCatType.TV, "סדרות");
}
public override async Task<ConfigurationData> GetConfigurationForSetup()
{
var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);
CQ cq = loginPage.Content;
var captcha = cq.Find(".g-recaptcha"); // invisible recaptcha
if (captcha.Any())
{
var result = this.configData;
result.CookieHeader.Value = loginPage.Cookies;
result.Captcha.SiteKey = captcha.Attr("data-sitekey");
result.Captcha.Version = "2";
return result;
}
else
{
var result = new ConfigurationDataBasicLogin();
result.SiteLink.Value = configData.SiteLink.Value;
result.Instructions.Value = configData.Instructions.Value;
result.Username.Value = configData.Username.Value;
result.Password.Value = configData.Password.Value;
result.CookieHeader.Value = loginPage.Cookies;
return result;
}
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
LoadValuesFromJson(configJson);
if (!string.IsNullOrWhiteSpace(configData.Captcha.Cookie))
{
CookieHeader = configData.Captcha.Cookie;
try
{
var results = await PerformQuery(new TorznabQuery());
if (results.Count() == 0)
{
throw new Exception("Your cookie did not work");
}
IsConfigured = true;
SaveConfig();
return IndexerConfigurationStatus.Completed;
}
catch (Exception e)
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
}
var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);
var pairs = new Dictionary<string, string> {

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net452;net461</TargetFrameworks>
<Version>0.0.0</Version>
</PropertyGroup>
@ -121,7 +121,6 @@
<PackageReference Include="CommandLineParser" Version="2.2.1" />
<PackageReference Include="DotNet4.SocksProxy" Version="1.4.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="MimeMapping" Version="1.0.1.12" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NLog" Version="4.5.6" />
@ -189,7 +188,8 @@
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<PackageReference Include="CsQuery" Version="1.3.5-beta5" />
<PackageReference Include="SharpZipLib" Version="0.86.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.2" />

View File

@ -98,6 +98,12 @@ namespace Jackett.Common.Services
return;
}
bool trayIsRunning = false;
if (isWindows)
{
trayIsRunning = Process.GetProcessesByName("JackettTray").Length > 0;
}
try
{
@ -135,7 +141,7 @@ namespace Jackett.Common.Services
var installDir = Path.GetDirectoryName(ExePath());
var updaterPath = Path.Combine(tempDir, "Jackett", "JackettUpdater.exe");
if (updaterPath != null)
StartUpdate(updaterPath, installDir, isWindows, serverConfig.RuntimeSettings.NoRestart);
StartUpdate(updaterPath, installDir, isWindows, serverConfig.RuntimeSettings.NoRestart, trayIsRunning);
}
catch (Exception e)
{
@ -212,7 +218,7 @@ namespace Jackett.Common.Services
private async Task<string> DownloadRelease(List<Asset> assets, bool isWindows, string version)
{
var targetAsset = assets.Where(a => isWindows ? a.Browser_download_url.ToLowerInvariant().EndsWith(".zip") : a.Browser_download_url.ToLowerInvariant().EndsWith(".gz")).FirstOrDefault();
var targetAsset = assets.Where(a => isWindows ? a.Browser_download_url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) : a.Browser_download_url.EndsWith(".gz", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (targetAsset == null)
{
@ -262,7 +268,7 @@ namespace Jackett.Common.Services
return tempDir;
}
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart)
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayWasRunning)
{
var exe = Path.GetFileName(ExePath());
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" +a + "\"" : a )).Replace("\"", "\\\"");
@ -298,7 +304,14 @@ namespace Jackett.Common.Services
}
if (NoRestart)
{
startInfo.Arguments += " --NoRestart";
}
if (trayWasRunning)
{
startInfo.Arguments += " --StartTray";
}
logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}");
var procInfo = Process.Start(startInfo);

View File

@ -32,17 +32,7 @@ namespace Jackett.Common.Utils
try
{
var currentAssembly = Assembly.GetExecutingAssembly();
bool aspNetCorePresent = new StackTrace().GetFrames()
.Select(x => x.GetMethod().ReflectedType.Assembly).Distinct()
.Where(x => x.GetReferencedAssemblies().Any(y => y.FullName == currentAssembly.FullName))
.Where(x => x.ManifestModule.Name == "JackettConsole.exe").Select(x => x.CustomAttributes)
.FirstOrDefault()
.Where(x => x.AttributeType.Assembly.FullName.StartsWith("Microsoft.AspNetCore", StringComparison.OrdinalIgnoreCase))
.Any();
runningOwin = !aspNetCorePresent;
runningOwin = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.StartsWith("Jackett, ")).Any();
}
catch
{

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>

View File

@ -1,88 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A61E311A-6F8B-4497-B5E4-2EA8994C7BD8}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Jackett.Updater</RootNamespace>
<AssemblyName>JackettUpdater</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<RuntimeIdentifier>win</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net461;netcoreapp2.1</TargetFrameworks>
<ApplicationIcon>jackett.ico</ApplicationIcon>
<AssemblyName>JackettUpdater</AssemblyName>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\Jackett.Common\Jackett.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdaterConsoleOptions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jackett.Common\Jackett.Common.csproj">
<Project>{6B854A1B-9A90-49C0-BC37-9A35C75BCA73}</Project>
<Name>Jackett.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Jackett\Jackett.csproj">
<Project>{e636d5f8-68b4-4903-b4ed-ccfd9c9e899f}</Project>
<Name>Jackett</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="jackett.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,34 +1,51 @@
using CommandLine;
using CommandLine.Text;
using Jackett.Common.Models.Config;
using Jackett.Services;
using Jackett.Common.Services;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using NLog;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Web;
using Jackett.Common;
namespace Jackett.Updater
{
class Program
public class Program
{
static void Main(string[] args)
private IProcessService processService;
private IServiceConfigService windowsService;
private Logger logger;
public static void Main(string[] args)
{
new Program().Run(args);
}
private void Run(string[] args)
{
Engine.BuildContainer(new RuntimeSettings()
RuntimeSettings runtimeSettings = new RuntimeSettings()
{
CustomLogFileName = "updater.txt"
});
Engine.Logger.Info("Jackett Updater v" + GetCurrentVersion());
Engine.Logger.Info("Options \"" + string.Join("\" \"", args) + "\"");
try {
var optionsResult = Parser.Default.ParseArguments<UpdaterConsoleOptions>(args);
};
LogManager.Configuration = LoggingSetup.GetLoggingConfiguration(runtimeSettings);
logger = LogManager.GetCurrentClassLogger();
logger.Info("Jackett Updater v" + GetCurrentVersion());
logger.Info("Options \"" + string.Join("\" \"", args) + "\"");
processService = new ProcessService(logger);
windowsService = new WindowsServiceConfigService(processService, logger);
var commandLineParser = new Parser(settings => settings.CaseSensitive = false);
try
{
var optionsResult = commandLineParser.ParseArguments<UpdaterConsoleOptions>(args);
optionsResult.WithParsed(options =>
{
ProcessUpdate(options);
@ -36,14 +53,14 @@ namespace Jackett.Updater
);
optionsResult.WithNotParsed(errors =>
{
Engine.Logger.Error(HelpText.AutoBuild(optionsResult));
Engine.Logger.Error("Failed to process update arguments!");
logger.Error(HelpText.AutoBuild(optionsResult));
logger.Error("Failed to process update arguments!");
Console.ReadKey();
});
}
catch (Exception e)
{
Engine.Logger.Error(e, "Exception applying update!");
logger.Error(e, "Exception applying update!");
}
}
@ -61,21 +78,20 @@ namespace Jackett.Updater
try
{
var proc = Process.GetProcessById(pid);
Engine.Logger.Info("Killing process " + proc.Id);
logger.Info("Killing process " + proc.Id);
proc.Kill();
var exited = proc.WaitForExit(5000);
if (!exited)
Engine.Logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds");
logger.Info("Process " + pid.ToString() + " didn't exit within 5 seconds");
}
catch (ArgumentException)
{
Engine.Logger.Info("Process " + pid.ToString() + " is already dead");
logger.Info("Process " + pid.ToString() + " is already dead");
}
catch (Exception e)
{
Engine.Logger.Info("Error killing process " + pid.ToString());
Engine.Logger.Info(e);
logger.Info("Error killing process " + pid.ToString());
logger.Info(e);
}
}
}
@ -83,7 +99,7 @@ namespace Jackett.Updater
private void ProcessUpdate(UpdaterConsoleOptions options)
{
var updateLocation = GetUpdateLocation();
if(!(updateLocation.EndsWith("\\") || updateLocation.EndsWith("/")))
if (!(updateLocation.EndsWith("\\") || updateLocation.EndsWith("/")))
{
updateLocation += Path.DirectorySeparatorChar;
}
@ -95,18 +111,18 @@ namespace Jackett.Updater
pids = Array.ConvertAll(pidsStr, pid => int.Parse(pid));
}
var isWindows = System.Environment.OSVersion.Platform != PlatformID.Unix;
var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
var trayRunning = false;
var trayProcesses = Process.GetProcessesByName("JackettTray");
if (isWindows)
{
if (trayProcesses.Count() > 0)
{
{
foreach (var proc in trayProcesses)
{
try
{
Engine.Logger.Info("Killing tray process " + proc.Id);
logger.Info("Killing tray process " + proc.Id);
proc.Kill();
trayRunning = true;
}
@ -118,9 +134,9 @@ namespace Jackett.Updater
// On unix we kill the PIDs after the update so e.g. systemd can automatically restart the process
KillPids(pids);
}
Engine.Logger.Info("Finding files in: " + updateLocation);
logger.Info("Finding files in: " + updateLocation);
var files = Directory.GetFiles(updateLocation, "*.*", SearchOption.AllDirectories);
foreach(var file in files)
foreach (var file in files)
{
var fileName = Path.GetFileName(file).ToLowerInvariant();
@ -130,20 +146,21 @@ namespace Jackett.Updater
{
continue;
}
try {
Engine.Logger.Info("Copying " + fileName);
try
{
logger.Info("Copying " + fileName);
var dest = Path.Combine(options.Path, file.Substring(updateLocation.Length));
var destDir = Path.GetDirectoryName(dest);
if (!Directory.Exists(destDir))
{
Engine.Logger.Info("Creating directory " + destDir);
logger.Info("Creating directory " + destDir);
Directory.CreateDirectory(destDir);
}
File.Copy(file, dest, true);
}
catch(Exception e)
catch (Exception e)
{
Engine.Logger.Error(e);
logger.Error(e);
}
}
@ -157,17 +174,16 @@ namespace Jackett.Updater
var deleteDir = Path.Combine(options.Path, oldDir);
if (Directory.Exists(deleteDir))
{
Engine.Logger.Info("Deleting directory " + deleteDir);
logger.Info("Deleting directory " + deleteDir);
Directory.Delete(deleteDir, true);
}
}
catch (Exception e)
{
Engine.Logger.Error(e);
logger.Error(e);
}
}
// delete old files
string[] oldFiles = new string[] {
"Content/css/jquery.dataTables.css",
@ -209,20 +225,20 @@ namespace Jackett.Updater
"Definitions/torrentwtf.yml",
};
foreach (var oldFIle in oldFiles)
foreach (var oldFile in oldFiles)
{
try
{
var deleteFile = Path.Combine(options.Path, oldFIle);
var deleteFile = Path.Combine(options.Path, oldFile);
if (File.Exists(deleteFile))
{
Engine.Logger.Info("Deleting file " + deleteFile);
logger.Info("Deleting file " + deleteFile);
File.Delete(deleteFile);
}
}
catch (Exception e)
{
Engine.Logger.Error(e);
logger.Error(e);
}
}
@ -232,7 +248,7 @@ namespace Jackett.Updater
if (options.NoRestart == false)
{
if (trayRunning)
if (trayRunning || options.StartTray)
{
var startInfo = new ProcessStartInfo()
{
@ -242,16 +258,22 @@ namespace Jackett.Updater
};
Process.Start(startInfo);
if (!windowsService.ServiceExists())
{
//User was running the tray icon, but not using the Windows service, starting Tray icon will start JackettConsole as well
return;
}
}
if(string.Equals(options.Type, "JackettService.exe", StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(options.Type, "JackettService.exe", StringComparison.InvariantCultureIgnoreCase))
{
var serviceHelper = new ServiceConfigService(null, null);
if (serviceHelper.ServiceExists())
if (windowsService.ServiceExists())
{
serviceHelper.Start();
windowsService.Start();
}
} else
}
else
{
var startInfo = new ProcessStartInfo()
{
@ -266,7 +288,7 @@ namespace Jackett.Updater
startInfo.FileName = "mono";
}
Engine.Logger.Info("Starting Jackett: " + startInfo.FileName + " " + startInfo.Arguments);
logger.Info("Starting Jackett: " + startInfo.FileName + " " + startInfo.Arguments);
Process.Start(startInfo);
}
}
@ -275,7 +297,7 @@ namespace Jackett.Updater
private string GetUpdateLocation()
{
var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
return new FileInfo(HttpUtility.UrlDecode(location.AbsolutePath)).DirectoryName;
return new FileInfo(WebUtility.UrlDecode(location.AbsolutePath)).DirectoryName;
}
}
}

View File

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Jackett.Updater")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Jackett.Updater")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a61e311a-6f8b-4497-b5e4-2ea8994c7bd8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]

View File

@ -18,5 +18,8 @@ namespace Jackett.Updater
[Option("KillPids", HelpText = "PIDs which will be killed before (Windows) or after (Unix) the update")]
public string KillPids { get; set; }
[Option("StartTray", HelpText = "Indicates that the updater should start the tray icon")]
public bool StartTray { get; set; }
}
}