mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
broke up EnvironmentProvider into different services
This commit is contained in:
parent
4d874829e8
commit
6b0a24e28e
54 changed files with 549 additions and 560 deletions
65
NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs
Normal file
65
NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Principal;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
|
||||
public interface IRuntimeInfo
|
||||
{
|
||||
bool IsUserInteractive { get; }
|
||||
bool IsAdmin { get; }
|
||||
}
|
||||
|
||||
public class RuntimeInfo : IRuntimeInfo
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RuntimeInfo(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool IsUserInteractive
|
||||
{
|
||||
get { return Environment.UserInteractive; }
|
||||
}
|
||||
|
||||
public bool IsAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.WarnException("Error checking if the current user is an administrator.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string ProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
|
||||
|
||||
public static bool IsProduction
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BuildInfo.IsDebug || Debugger.IsAttached) return false;
|
||||
if (BuildInfo.Version.Revision > 10000) return false; //Official builds will never have such a high revision
|
||||
|
||||
var lowerProcessName = ProcessName.ToLower();
|
||||
if (lowerProcessName.Contains("vshost")) return false;
|
||||
if (lowerProcessName.Contains("nunit")) return false;
|
||||
if (lowerProcessName.Contains("jetbrain")) return false;
|
||||
if (lowerProcessName.Contains("resharper")) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue