mirror of https://github.com/Jackett/Jackett
Merge branch 'master' into dotnetcore
This commit is contained in:
commit
cd65ec7a71
|
@ -9,6 +9,7 @@
|
|||
- https://ilcorsaronero.info/
|
||||
certificates:
|
||||
- aa7c40aa360a1cec8a9687312fd50402b912e618 # incomplete CA chain
|
||||
- 83174ec1f92fa13cdef9d51888ea1dfba2166e17 # incomplete CA chain
|
||||
|
||||
caps:
|
||||
categorymappings:
|
||||
|
|
|
@ -31,33 +31,32 @@
|
|||
- {id: 61, cat: Books, desc: "Audiolibri"}
|
||||
# Games
|
||||
- {id: 47, cat: PC/Games, desc: "Games PC"}
|
||||
- {id: 22, cat: Console/Other, desc: "Nintendo"}
|
||||
- {id: 40, cat: Console/Other, desc: "Nintendo"}
|
||||
- {id: 13, cat: Console/PS4, desc: "Sony PS"}
|
||||
- {id: 20, cat: Console/Xbox, desc: "XboX"}
|
||||
- {id: 33, cat: Console/Xbox, desc: "XboX"}
|
||||
- {id: 14, cat: Console/Wii, desc: "Wii"}
|
||||
# Music
|
||||
- {id: 54, cat: Audio/MP3, desc: "MP3"}
|
||||
- {id: 55, cat: Audio/Lossless, desc: "Flac"}
|
||||
# Movies
|
||||
- {id: 17, cat: Movies/SD, desc: "Cine News"}
|
||||
- {id: 23, cat: Movies/SD, desc: "BDRip"}
|
||||
- {id: 43, cat: Movies/SD, desc: "BDRip"}
|
||||
- {id: 16, cat: Movies/SD, desc: "DivX"}
|
||||
- {id: 32, cat: Movies/SD, desc: "DVDRip"}
|
||||
- {id: 11, cat: Movies/DVD, desc: "DVD"}
|
||||
- {id: 29, cat: Movies/HD, desc: "720p"}
|
||||
- {id: 30, cat: Movies/HD, desc: "1080p"}
|
||||
- {id: 35, cat: Movies/BluRay, desc: "Blu Ray Disk"}
|
||||
- {id: 40, cat: Movies/HD, desc: "H-265"}
|
||||
- {id: 56, cat: Movies/3D, desc: "FullHD-3D"}
|
||||
- {id: 27, cat: TV/SD, desc: "SerieTV"}
|
||||
- {id: 20, cat: Movies/SD, desc: "DVDRip"}
|
||||
- {id: 21, cat: Movies/DVD, desc: "DVD"}
|
||||
- {id: 25, cat: Movies/HD, desc: "720p"}
|
||||
- {id: 24, cat: Movies/HD, desc: "1080p"}
|
||||
- {id: 27, cat: Movies/BluRay, desc: "Blu Ray Disk"}
|
||||
- {id: 23, cat: Movies/HD, desc: "H-265"}
|
||||
- {id: 26, cat: Movies/3D, desc: "3D-FullHD"}
|
||||
- {id: 31, cat: TV/SD, desc: "SerieTV"}
|
||||
- {id: 45, cat: TV/HD, desc: "Serie Tv HD"}
|
||||
- {id: 44, cat: Movies/UHD, desc: "4K Ultra HD"}
|
||||
- {id: 22, cat: Movies/UHD, desc: "4K-Ultra-HD"}
|
||||
- {id: 49, cat: TV/Documentary, desc: "Documentari"}
|
||||
- {id: 50, cat: TV/Other, desc: "Programmi TV"}
|
||||
- {id: 51, cat: Movies/Other, desc: "Mp4"}
|
||||
|
||||
- {id: 5, cat: TV/Anime, desc: "Anime"}
|
||||
- {id: 31, cat: TV/Anime, desc: "Cartoni Animati"}
|
||||
|
||||
modes:
|
||||
search: [q]
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
<PackageReference Include="CsQuery" Version="1.3.5-beta5" />
|
||||
<PackageReference Include="SharpZipLib" Version="0.86.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.2" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
|
@ -208,6 +209,9 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities">
|
||||
<Version>2.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController">
|
||||
<Version>4.5.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
using Jackett.Common.Services.Interfaces;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
|
||||
namespace Jackett.Common.Services
|
||||
{
|
||||
public class WindowsServiceConfigService : IServiceConfigService
|
||||
{
|
||||
private const string NAME = "Jackett";
|
||||
private const string DESCRIPTION = "API Support for your favorite torrent trackers";
|
||||
private const string SERVICEEXE = "JackettService.exe";
|
||||
|
||||
private IProcessService processService;
|
||||
private Logger logger;
|
||||
|
||||
public WindowsServiceConfigService(IProcessService p, Logger l)
|
||||
{
|
||||
processService = p;
|
||||
logger = l;
|
||||
}
|
||||
|
||||
public bool ServiceExists()
|
||||
{
|
||||
return GetService(NAME) != null;
|
||||
}
|
||||
|
||||
public bool ServiceRunning()
|
||||
{
|
||||
var service = GetService(NAME);
|
||||
if (service == null)
|
||||
return false;
|
||||
return service.Status == ServiceControllerStatus.Running;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var service = GetService(NAME);
|
||||
service.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
var service = GetService(NAME);
|
||||
service.Stop();
|
||||
}
|
||||
|
||||
public ServiceController GetService(string serviceName)
|
||||
{
|
||||
return ServiceController.GetServices().FirstOrDefault(c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public void Install()
|
||||
{
|
||||
if (ServiceExists())
|
||||
{
|
||||
logger.Warn("The service is already installed!");
|
||||
}
|
||||
else
|
||||
{
|
||||
string applicationFolder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
|
||||
|
||||
var exePath = Path.Combine(applicationFolder, SERVICEEXE);
|
||||
if (!File.Exists(exePath) && Debugger.IsAttached)
|
||||
{
|
||||
exePath = Path.Combine(applicationFolder, "..\\..\\..\\Jackett.Service\\bin\\Debug", SERVICEEXE);
|
||||
}
|
||||
|
||||
string arg = $"create {NAME} start= auto binpath= \"{exePath}\" DisplayName= {NAME}";
|
||||
|
||||
processService.StartProcessAndLog("sc.exe", arg, true);
|
||||
|
||||
processService.StartProcessAndLog("sc.exe", $"description {NAME} \"{DESCRIPTION}\"", true);
|
||||
}
|
||||
}
|
||||
|
||||
public void Uninstall()
|
||||
{
|
||||
RemoveService();
|
||||
|
||||
processService.StartProcessAndLog("sc.exe", $"delete {NAME}", true);
|
||||
|
||||
logger.Info("The service was uninstalled.");
|
||||
}
|
||||
|
||||
public void RemoveService()
|
||||
{
|
||||
var service = GetService(NAME);
|
||||
if (service == null)
|
||||
{
|
||||
logger.Warn("The service is already uninstalled");
|
||||
return;
|
||||
}
|
||||
if (service.Status != ServiceControllerStatus.Stopped)
|
||||
{
|
||||
service.Stop();
|
||||
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
|
||||
|
||||
service.Refresh();
|
||||
if (service.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
logger.Info("Service stopped.");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Failed to stop the service");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn("The service was already stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Common.Services;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using System.IO;
|
||||
|
||||
namespace Jackett.Common.Utils
|
||||
{
|
||||
public static class LoggingSetup
|
||||
{
|
||||
public static LoggingConfiguration GetLoggingConfiguration(RuntimeSettings settings, bool fileOnly = false)
|
||||
{
|
||||
var logFileName = settings.CustomLogFileName ?? "log.txt";
|
||||
var logLevel = settings.TracingEnabled ? NLog.LogLevel.Debug : NLog.LogLevel.Info;
|
||||
// Add custom date time format renderer as the default is too long
|
||||
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("simpledatetime", typeof(SimpleDateTimeRenderer));
|
||||
|
||||
var logConfig = new LoggingConfiguration();
|
||||
var logFile = new FileTarget();
|
||||
logConfig.AddTarget("file", logFile);
|
||||
logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
|
||||
logFile.FileName = Path.Combine(settings.DataFolder, logFileName);
|
||||
logFile.ArchiveFileName = Path.Combine(settings.DataFolder, logFileName + ".{#####}.txt");
|
||||
logFile.ArchiveAboveSize = 500000;
|
||||
logFile.MaxArchiveFiles = 5;
|
||||
logFile.KeepFileOpen = false;
|
||||
logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence;
|
||||
var logFileRule = new LoggingRule("*", logLevel, logFile);
|
||||
logConfig.LoggingRules.Add(logFileRule);
|
||||
|
||||
if (!fileOnly)
|
||||
{
|
||||
var logConsole = new ColoredConsoleTarget();
|
||||
logConfig.AddTarget("console", logConsole);
|
||||
|
||||
logConsole.Layout = "${simpledatetime} ${level} ${message} ${exception:format=ToString}";
|
||||
var logConsoleRule = new LoggingRule("*", logLevel, logConsole);
|
||||
logConfig.LoggingRules.Add(logConsoleRule);
|
||||
|
||||
var logService = new LogCacheService();
|
||||
logConfig.AddTarget("service", logService);
|
||||
var serviceRule = new LoggingRule("*", logLevel, logService);
|
||||
logConfig.LoggingRules.Add(serviceRule);
|
||||
}
|
||||
|
||||
return logConfig;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -14,6 +14,7 @@
|
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
|
||||
<RuntimeIdentifier>win</RuntimeIdentifier>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -88,11 +89,6 @@
|
|||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="jackett.ico" />
|
||||
</ItemGroup>
|
||||
|
@ -101,10 +97,6 @@
|
|||
<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>
|
||||
<COMReference Include="IWshRuntimeLibrary">
|
||||
|
|
|
@ -60,51 +60,51 @@
|
|||
this.toolStripMenuItemAutoStart,
|
||||
this.toolStripMenuItemShutdown});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(292, 148);
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(296, 126);
|
||||
this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening);
|
||||
//
|
||||
// toolStripMenuItemWebUI
|
||||
//
|
||||
this.toolStripMenuItemWebUI.Name = "toolStripMenuItemWebUI";
|
||||
this.toolStripMenuItemWebUI.Size = new System.Drawing.Size(291, 22);
|
||||
this.toolStripMenuItemWebUI.Size = new System.Drawing.Size(295, 22);
|
||||
this.toolStripMenuItemWebUI.Text = "Open Web UI";
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(288, 6);
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(292, 6);
|
||||
//
|
||||
// backgroundMenuItem
|
||||
//
|
||||
this.backgroundMenuItem.Enabled = false;
|
||||
this.backgroundMenuItem.Name = "backgroundMenuItem";
|
||||
this.backgroundMenuItem.Size = new System.Drawing.Size(291, 22);
|
||||
this.backgroundMenuItem.Text = "Jacket is running as a background service";
|
||||
this.backgroundMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
this.backgroundMenuItem.Text = "Jackett is running as a background service";
|
||||
//
|
||||
// serviceControlMenuItem
|
||||
//
|
||||
this.serviceControlMenuItem.Name = "serviceControlMenuItem";
|
||||
this.serviceControlMenuItem.Size = new System.Drawing.Size(291, 22);
|
||||
this.serviceControlMenuItem.Size = new System.Drawing.Size(295, 22);
|
||||
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);
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(292, 6);
|
||||
//
|
||||
// toolStripMenuItemAutoStart
|
||||
//
|
||||
this.toolStripMenuItemAutoStart.CheckOnClick = true;
|
||||
this.toolStripMenuItemAutoStart.Name = "toolStripMenuItemAutoStart";
|
||||
this.toolStripMenuItemAutoStart.Size = new System.Drawing.Size(291, 22);
|
||||
this.toolStripMenuItemAutoStart.Size = new System.Drawing.Size(295, 22);
|
||||
this.toolStripMenuItemAutoStart.Text = "Auto-start on boot";
|
||||
this.toolStripMenuItemAutoStart.Visible = false;
|
||||
//
|
||||
// toolStripMenuItemShutdown
|
||||
//
|
||||
this.toolStripMenuItemShutdown.Name = "toolStripMenuItemShutdown";
|
||||
this.toolStripMenuItemShutdown.Size = new System.Drawing.Size(291, 22);
|
||||
this.toolStripMenuItemShutdown.Size = new System.Drawing.Size(295, 22);
|
||||
this.toolStripMenuItemShutdown.Text = "Shutdown";
|
||||
//
|
||||
// Main
|
||||
|
|
|
@ -1,32 +1,52 @@
|
|||
using System;
|
||||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Common.Services;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
using Jackett.Common.Utils;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Jackett.Common;
|
||||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Common.Utils;
|
||||
using Microsoft.Win32;
|
||||
using Jackett;
|
||||
using Jackett.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Jackett.Tray
|
||||
{
|
||||
public partial class Main : Form
|
||||
{
|
||||
private IProcessService processService;
|
||||
private IServiceConfigService windowsService;
|
||||
private ITrayLockService trayLockService;
|
||||
private ISerializeService serializeService;
|
||||
private IConfigurationService configurationService;
|
||||
private ServerConfig serverConfig;
|
||||
private Process consoleProcess;
|
||||
private Logger logger;
|
||||
private bool closeApplicationInitiated;
|
||||
|
||||
public Main()
|
||||
{
|
||||
Hide();
|
||||
InitializeComponent();
|
||||
|
||||
RuntimeSettings runtimeSettings = new RuntimeSettings()
|
||||
{
|
||||
CustomLogFileName = "TrayLog.txt"
|
||||
};
|
||||
|
||||
LogManager.Configuration = LoggingSetup.GetLoggingConfiguration(runtimeSettings);
|
||||
logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
logger.Info("Starting Jackett Tray v" + EnvironmentUtil.JackettVersion);
|
||||
|
||||
processService = new ProcessService(logger);
|
||||
windowsService = new WindowsServiceConfigService(processService, logger);
|
||||
trayLockService = new TrayLockService();
|
||||
serializeService = new SerializeService();
|
||||
configurationService = new ConfigurationService(serializeService, processService, logger, runtimeSettings);
|
||||
serverConfig = configurationService.BuildServerConfig(runtimeSettings);
|
||||
|
||||
toolStripMenuItemAutoStart.Checked = AutoStart;
|
||||
toolStripMenuItemAutoStart.CheckedChanged += toolStripMenuItemAutoStart_CheckedChanged;
|
||||
|
||||
|
@ -34,18 +54,15 @@ namespace Jackett.Tray
|
|||
toolStripMenuItemShutdown.Click += toolStripMenuItemShutdown_Click;
|
||||
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
{
|
||||
{
|
||||
toolStripMenuItemAutoStart.Visible = true;
|
||||
}
|
||||
|
||||
Engine.BuildContainer(new RuntimeSettings(),new WebApi2Module());
|
||||
Engine.Server.Initalize();
|
||||
|
||||
if (!Engine.ServiceConfig.ServiceExists())
|
||||
if (!windowsService.ServiceExists())
|
||||
{
|
||||
// We are not installed as a service so just the web server too and run from the tray.
|
||||
Engine.Logger.Info("Starting server from tray");
|
||||
Engine.Server.Start();
|
||||
// We are not installed as a service so just start the web server via JackettConsole and run from the tray.
|
||||
logger.Info("Starting server from tray");
|
||||
StartConsoleApplication();
|
||||
}
|
||||
|
||||
Task.Factory.StartNew(WaitForEvent);
|
||||
|
@ -53,26 +70,26 @@ namespace Jackett.Tray
|
|||
|
||||
private void WaitForEvent()
|
||||
{
|
||||
Engine.LockService.WaitForSignal();
|
||||
Application.Exit();
|
||||
trayLockService.WaitForSignal();
|
||||
CloseTrayApplication();
|
||||
}
|
||||
|
||||
void toolStripMenuItemWebUI_Click(object sender, EventArgs e)
|
||||
private void toolStripMenuItemWebUI_Click(object sender, EventArgs e)
|
||||
{
|
||||
Process.Start("http://127.0.0.1:" + Engine.ServerConfig.Port);
|
||||
Process.Start("http://127.0.0.1:" + serverConfig.Port);
|
||||
}
|
||||
|
||||
void toolStripMenuItemShutdown_Click(object sender, EventArgs e)
|
||||
private void toolStripMenuItemShutdown_Click(object sender, EventArgs e)
|
||||
{
|
||||
Process.GetCurrentProcess().Kill();
|
||||
CloseTrayApplication();
|
||||
}
|
||||
|
||||
void toolStripMenuItemAutoStart_CheckedChanged(object sender, EventArgs e)
|
||||
private void toolStripMenuItemAutoStart_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
AutoStart = toolStripMenuItemAutoStart.Checked;
|
||||
}
|
||||
|
||||
string ProgramTitle
|
||||
private string ProgramTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -80,7 +97,7 @@ namespace Jackett.Tray
|
|||
}
|
||||
}
|
||||
|
||||
bool AutoStart
|
||||
private bool AutoStart
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -122,22 +139,29 @@ namespace Jackett.Tray
|
|||
|
||||
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
|
||||
{
|
||||
if (Engine.ServiceConfig.ServiceExists())
|
||||
if (windowsService.ServiceExists())
|
||||
{
|
||||
backgroundMenuItem.Visible = true;
|
||||
serviceControlMenuItem.Visible = true;
|
||||
toolStripSeparator1.Visible = true;
|
||||
toolStripSeparator2.Visible = true;
|
||||
if (Engine.ServiceConfig.ServiceRunning())
|
||||
|
||||
if (windowsService.ServiceRunning())
|
||||
{
|
||||
serviceControlMenuItem.Text = "Stop background service";
|
||||
} else
|
||||
backgroundMenuItem.Text = "Jackett is running as a background service";
|
||||
toolStripMenuItemWebUI.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceControlMenuItem.Text = "Start background service";
|
||||
backgroundMenuItem.Text = "Jackett will run as a background service";
|
||||
toolStripMenuItemWebUI.Enabled = false;
|
||||
}
|
||||
|
||||
toolStripMenuItemShutdown.Text = "Close tray icon";
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundMenuItem.Visible = false;
|
||||
serviceControlMenuItem.Visible = false;
|
||||
|
@ -151,17 +175,17 @@ namespace Jackett.Tray
|
|||
{
|
||||
var consolePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "JackettConsole.exe");
|
||||
|
||||
if (Engine.ServiceConfig.ServiceRunning())
|
||||
if (windowsService.ServiceRunning())
|
||||
{
|
||||
if (ServerUtil.IsUserAdministrator())
|
||||
{
|
||||
Engine.ServiceConfig.Stop();
|
||||
|
||||
} else
|
||||
windowsService.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Engine.ProcessService.StartProcessAndLog(consolePath, "--Stop", true);
|
||||
processService.StartProcessAndLog(consolePath, "--Stop", true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -173,13 +197,13 @@ namespace Jackett.Tray
|
|||
{
|
||||
if (ServerUtil.IsUserAdministrator())
|
||||
{
|
||||
Engine.ServiceConfig.Start();
|
||||
windowsService.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Engine.ProcessService.StartProcessAndLog(consolePath, "--Start", true);
|
||||
processService.StartProcessAndLog(consolePath, "--Start", true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -188,5 +212,65 @@ namespace Jackett.Tray
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseTrayApplication()
|
||||
{
|
||||
closeApplicationInitiated = true;
|
||||
|
||||
logger.Info("Close of tray application initiated");
|
||||
|
||||
//Clears notify icon, otherwise icon will still appear on taskbar until you hover the mouse over
|
||||
notifyIcon1.Icon = null;
|
||||
notifyIcon1.Dispose();
|
||||
Application.DoEvents();
|
||||
|
||||
if (consoleProcess != null && !consoleProcess.HasExited)
|
||||
{
|
||||
consoleProcess.StandardInput.Close();
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
if (consoleProcess != null && !consoleProcess.HasExited)
|
||||
{
|
||||
consoleProcess.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void StartConsoleApplication()
|
||||
{
|
||||
string applicationFolder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
|
||||
|
||||
var exePath = Path.Combine(applicationFolder, "JackettConsole.exe");
|
||||
|
||||
var startInfo = new ProcessStartInfo()
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
FileName = exePath,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardError = true
|
||||
};
|
||||
|
||||
consoleProcess = Process.Start(startInfo);
|
||||
consoleProcess.EnableRaisingEvents = true;
|
||||
consoleProcess.Exited += ProcessExited;
|
||||
consoleProcess.ErrorDataReceived += ProcessErrorDataReceived;
|
||||
}
|
||||
|
||||
private void ProcessErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
logger.Error(e.Data);
|
||||
}
|
||||
|
||||
private void ProcessExited(object sender, EventArgs e)
|
||||
{
|
||||
logger.Info("Tray icon not responsible for process exit");
|
||||
|
||||
if (!closeApplicationInitiated)
|
||||
{
|
||||
CloseTrayApplication();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,7 @@ namespace Jackett.Tray.Properties {
|
|||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
|
Loading…
Reference in New Issue