2018-06-26 09:44:12 +00:00
|
|
|
|
using CommandLine;
|
|
|
|
|
using System;
|
2017-12-01 09:28:19 +00:00
|
|
|
|
using System.Diagnostics;
|
2015-07-19 00:27:41 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
|
namespace Jackett.Tray
|
2015-07-19 00:27:41 +00:00
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
2018-06-26 09:44:12 +00:00
|
|
|
|
static void Main(string[] args)
|
2015-07-19 00:27:41 +00:00
|
|
|
|
{
|
2017-12-01 09:39:50 +00:00
|
|
|
|
var JacketTrayProcess = Process.GetCurrentProcess();
|
2017-12-01 09:28:19 +00:00
|
|
|
|
var runningProcesses = Process.GetProcesses();
|
|
|
|
|
var currentSessionID = Process.GetCurrentProcess().SessionId;
|
|
|
|
|
var sameAsThisSession = runningProcesses.Where(p => p.SessionId == currentSessionID);
|
2017-12-01 09:39:50 +00:00
|
|
|
|
var sameAsThisSessionJacketTray = sameAsThisSession.Where(p => p.ProcessName == JacketTrayProcess.ProcessName && p.Id != JacketTrayProcess.Id);
|
2017-12-01 09:28:19 +00:00
|
|
|
|
if (sameAsThisSessionJacketTray.Any())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("JackettTray is already running");
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-06-26 09:44:12 +00:00
|
|
|
|
{
|
|
|
|
|
string newVersion = "";
|
|
|
|
|
var commandLineParser = new Parser(settings => settings.CaseSensitive = false);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var optionsResult = commandLineParser.ParseArguments<TrayConsoleOptions>(args);
|
|
|
|
|
optionsResult.WithParsed(options =>
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(options.UpdatedVersion))
|
|
|
|
|
{
|
|
|
|
|
newVersion = options.UpdatedVersion;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-07-22 12:03:04 +00:00
|
|
|
|
catch (Exception)
|
2018-06-26 09:44:12 +00:00
|
|
|
|
{
|
|
|
|
|
newVersion = "";
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 09:28:19 +00:00
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2018-06-26 09:44:12 +00:00
|
|
|
|
Application.Run(new Main(newVersion));
|
2017-12-01 09:28:19 +00:00
|
|
|
|
}
|
2015-07-19 00:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|