2013-06-28 02:04:52 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2013-07-26 08:11:55 +02:00
|
|
|
|
using System.IO;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
using System.Security.Principal;
|
2013-08-14 05:48:50 +02:00
|
|
|
|
using System.ServiceProcess;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 08:11:55 +02:00
|
|
|
|
static RuntimeInfo()
|
|
|
|
|
{
|
|
|
|
|
IsProduction = InternalIsProduction();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 02:04:52 +02:00
|
|
|
|
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();
|
|
|
|
|
|
2013-07-26 08:11:55 +02:00
|
|
|
|
public static bool IsProduction { get; private set; }
|
|
|
|
|
|
|
|
|
|
private static bool InternalIsProduction()
|
2013-06-28 02:04:52 +02:00
|
|
|
|
{
|
2013-07-26 08:11:55 +02:00
|
|
|
|
if (BuildInfo.IsDebug || Debugger.IsAttached) return false;
|
|
|
|
|
if (BuildInfo.Version.Revision > 10000) return false; //Official builds will never have such a high revision
|
2013-06-28 02:04:52 +02:00
|
|
|
|
|
2013-07-26 08:11:55 +02:00
|
|
|
|
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;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
|
2013-07-26 08:11:55 +02:00
|
|
|
|
if (Directory.GetCurrentDirectory().ToLower().Contains("teamcity")) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|