Jackett/src/Jackett.Tray/Program.cs

54 lines
1.8 KiB
C#
Raw Permalink Normal View History

using System;
using System.Diagnostics;
2015-07-19 00:27:41 +00:00
using System.Linq;
using System.Windows.Forms;
2020-02-09 18:08:34 +00:00
using CommandLine;
2015-07-19 00:27:41 +00:00
namespace Jackett.Tray
2015-07-19 00:27:41 +00:00
{
internal static class Program
2015-07-19 00:27:41 +00:00
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private 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();
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);
if (sameAsThisSessionJacketTray.Any())
{
MessageBox.Show("JackettTray is already running");
}
else
{
var 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;
}
});
}
catch (Exception)
{
newVersion = "";
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main(newVersion));
}
2015-07-19 00:27:41 +00:00
}
}
}