mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-03-05 13:20:20 -05:00
Build Sonarr on Net6
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,6 @@ namespace NzbDrone.Common.Processes
|
||||
{
|
||||
public interface IProcessProvider
|
||||
{
|
||||
int GetCurrentProcessId();
|
||||
ProcessInfo GetCurrentProcess();
|
||||
ProcessInfo GetProcessById(int id);
|
||||
List<ProcessInfo> FindProcessByName(string name);
|
||||
@@ -43,9 +42,9 @@ namespace NzbDrone.Common.Processes
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public int GetCurrentProcessId()
|
||||
public static int GetCurrentProcessId()
|
||||
{
|
||||
return Process.GetCurrentProcess().Id;
|
||||
return Environment.ProcessId;
|
||||
}
|
||||
|
||||
public ProcessInfo GetCurrentProcess()
|
||||
@@ -156,7 +155,10 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
process.OutputDataReceived += (sender, eventArgs) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.Debug(eventArgs.Data);
|
||||
|
||||
@@ -168,7 +170,10 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
process.ErrorDataReceived += (sender, eventArgs) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
||||
if (string.IsNullOrWhiteSpace(eventArgs.Data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.Error(eventArgs.Data);
|
||||
|
||||
@@ -209,8 +214,11 @@ namespace NzbDrone.Common.Processes
|
||||
public ProcessOutput StartAndCapture(string path, string args = null, StringDictionary environmentVariables = null)
|
||||
{
|
||||
var output = new ProcessOutput();
|
||||
var process = Start(path, args, environmentVariables, s => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Standard, s)),
|
||||
error => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Error, error)));
|
||||
var process = Start(path,
|
||||
args,
|
||||
environmentVariables,
|
||||
s => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Standard, s)),
|
||||
error => output.Lines.Add(new ProcessOutputLine(ProcessOutputLevel.Error, error)));
|
||||
|
||||
process.WaitForExit();
|
||||
output.ExitCode = process.ExitCode;
|
||||
@@ -249,7 +257,7 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
process.Refresh();
|
||||
|
||||
if (process.Id != Process.GetCurrentProcess().Id && process.HasExited)
|
||||
if (process.Id != GetCurrentProcessId() && process.HasExited)
|
||||
{
|
||||
_logger.Debug("Process has already exited");
|
||||
return;
|
||||
@@ -270,7 +278,7 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
foreach (var processInfo in processes)
|
||||
{
|
||||
if (processInfo.Id == Process.GetCurrentProcess().Id)
|
||||
if (processInfo.Id == GetCurrentProcessId())
|
||||
{
|
||||
_logger.Debug("Tried killing own process, skipping: {0} [{1}]", processInfo.Id, processInfo.ProcessName);
|
||||
continue;
|
||||
@@ -283,7 +291,10 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
private ProcessInfo ConvertToProcessInfo(Process process)
|
||||
{
|
||||
if (process == null) return null;
|
||||
if (process == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
process.Refresh();
|
||||
|
||||
@@ -291,14 +302,17 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
try
|
||||
{
|
||||
if (process.Id <= 0) return null;
|
||||
if (process.Id <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
processInfo = new ProcessInfo();
|
||||
processInfo.Id = process.Id;
|
||||
processInfo.Name = process.ProcessName;
|
||||
processInfo.StartPath = GetExeFileName(process);
|
||||
|
||||
if (process.Id != Process.GetCurrentProcess().Id && process.HasExited)
|
||||
if (process.Id != GetCurrentProcessId() && process.HasExited)
|
||||
{
|
||||
processInfo = null;
|
||||
}
|
||||
@@ -324,17 +338,7 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
private List<Process> GetProcessesByName(string name)
|
||||
{
|
||||
//TODO: move this to an OS specific class
|
||||
|
||||
var monoProcesses = Process.GetProcessesByName("mono")
|
||||
.Union(Process.GetProcessesByName("mono-sgen"))
|
||||
.Where(process =>
|
||||
process.Modules.Cast<ProcessModule>()
|
||||
.Any(module =>
|
||||
module.ModuleName.ToLower() == name.ToLower() + ".exe"));
|
||||
|
||||
var processes = Process.GetProcessesByName(name)
|
||||
.Union(monoProcesses).ToList();
|
||||
var processes = Process.GetProcessesByName(name).ToList();
|
||||
|
||||
_logger.Debug("Found {0} processes with the name: {1}", processes.Count, name);
|
||||
|
||||
@@ -355,15 +359,6 @@ namespace NzbDrone.Common.Processes
|
||||
|
||||
private (string Path, string Args) GetPathAndArgs(string path, string args)
|
||||
{
|
||||
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return ("mono", $"--debug {path} {args}");
|
||||
}
|
||||
if (OsInfo.IsOsx && path.EndsWith(".app", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return ("/usr/bin/open", $"--new {path} --args {args}");
|
||||
}
|
||||
|
||||
if (OsInfo.IsWindows && path.EndsWith(".bat", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return ("cmd.exe", $"/c {path} {args}");
|
||||
|
||||
Reference in New Issue
Block a user