diff --git a/src/NzbDrone.Api/System/SystemModule.cs b/src/NzbDrone.Api/System/SystemModule.cs index 5acd4d881f..b56f1d14b6 100644 --- a/src/NzbDrone.Api/System/SystemModule.cs +++ b/src/NzbDrone.Api/System/SystemModule.cs @@ -16,7 +16,11 @@ public class SystemModule : NzbDroneApiModule private readonly IConfigFileProvider _configFileProvider; private readonly IDatabase _database; - public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider, IConfigFileProvider configFileProvider, IDatabase database) + public SystemModule(IAppFolderInfo appFolderInfo, + IRuntimeInfo runtimeInfo, + IRouteCacheProvider routeCacheProvider, + IConfigFileProvider configFileProvider, + IDatabase database) : base("system") { _appFolderInfo = appFolderInfo; @@ -41,8 +45,10 @@ private Response GetStatus() StartupPath = _appFolderInfo.StartUpFolder, AppData = _appFolderInfo.GetAppDataPath(), OsVersion = OsInfo.Version.ToString(), + IsMonoRuntime = OsInfo.IsMono, IsMono = OsInfo.IsMono, - IsLinux = OsInfo.IsLinux, + IsLinux = OsInfo.IsMono, + IsOsx = OsInfo.IsOsx, IsWindows = OsInfo.IsWindows, Branch = _configFileProvider.Branch, Authentication = _configFileProvider.AuthenticationEnabled, @@ -50,10 +56,8 @@ private Response GetStatus() SqliteVersion = _database.Version, UrlBase = _configFileProvider.UrlBase }.AsResponse(); - } - private Response GetRoutes() { return _routeCacheProvider.GetCache().Values.AsResponse(); diff --git a/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs b/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs index ede83ca40c..d8bade8cfa 100644 --- a/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs +++ b/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs @@ -100,7 +100,7 @@ public static Param IsValidPath(this Param param) if (param.Value.IsPathValid()) return param; - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid *nix path. paths must start with /", param.Value)); } diff --git a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs index c49d4864b8..d45f4269fa 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs @@ -32,7 +32,7 @@ public void Register() { _diskProvider.EnsureFolder(_appFolderInfo.AppDataFolder); - if (!OsInfo.IsLinux) + if (!OsInfo.IsMono) { SetPermissions(); } diff --git a/src/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs index 3a5bcd0191..da1e7cfaad 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs @@ -17,7 +17,7 @@ public class AppFolderInfo : IAppFolderInfo public AppFolderInfo(IStartupContext startupContext) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData; } diff --git a/src/NzbDrone.Common/EnvironmentInfo/OsInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/OsInfo.cs index 3b769bfeaa..16894f00c1 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/OsInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/OsInfo.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; namespace NzbDrone.Common.EnvironmentInfo { @@ -7,34 +8,80 @@ public static class OsInfo static OsInfo() { - Version = Environment.OSVersion.Version; - IsMono = Type.GetType("Mono.Runtime") != null; + var platform = (int)Environment.OSVersion.Platform; - int platform = (int)Environment.OSVersion.Platform; - IsLinux = (platform == 4) || (platform == 6) || (platform == 128); - + Version = Environment.OSVersion.Version; + + IsMonoRuntime = Type.GetType("Mono.Runtime") != null; + IsMono = (platform == 4) || (platform == 6) || (platform == 128); + IsOsx = IsRunningOnMac(); + IsLinux = IsMono && !IsOsx; + IsWindows = !IsMono; + + FirstDayOfWeek = DateTime.Today.GetFirstDayOfWeek().DayOfWeek; + + if (!IsMono) + { + Os = Os.Windows; + } + + else + { + Os = IsOsx ? Os.Osx : Os.Linux; + } } public static Version Version { get; private set; } - + public static bool IsMonoRuntime { get; private set; } public static bool IsMono { get; private set; } - public static bool IsLinux { get; private set; } + public static bool IsOsx { get; private set; } + public static bool IsWindows { get; private set; } + public static Os Os { get; private set; } + public static DayOfWeek FirstDayOfWeek { get; private set; } - public static bool IsWindows - { - get - { - return !IsLinux; - } - } + //Borrowed from: https://github.com/jpobst/Pinta/blob/master/Pinta.Core/Managers/SystemManager.cs + //From Managed.Windows.Forms/XplatUI + [DllImport("libc")] + static extern int uname(IntPtr buf); - public static DayOfWeek FirstDayOfWeek + static bool IsRunningOnMac() { - get + var buf = IntPtr.Zero; + + try { - return DateTime.Today.GetFirstDayOfWeek().DayOfWeek; + buf = Marshal.AllocHGlobal(8192); + // This is a hacktastic way of getting sysname from uname () + if (uname(buf) == 0) + { + var os = Marshal.PtrToStringAnsi(buf); + + if (os == "Darwin") + { + return true; + } + } } + catch + { + } + finally + { + if (buf != IntPtr.Zero) + { + Marshal.FreeHGlobal(buf); + } + } + + return false; } } + + public enum Os + { + Windows, + Linux, + Osx + } } \ No newline at end of file diff --git a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs index 82369c35b5..8cef57af69 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/RuntimeInfo.cs @@ -78,7 +78,7 @@ public bool IsConsole return (OsInfo.IsWindows && IsUserInteractive && ProcessName.Equals(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME, StringComparison.InvariantCultureIgnoreCase)) || - OsInfo.IsLinux; + OsInfo.IsMono; } } diff --git a/src/NzbDrone.Common/Instrumentation/LogTargets.cs b/src/NzbDrone.Common/Instrumentation/LogTargets.cs index f44ce456c8..67e8f69d3f 100644 --- a/src/NzbDrone.Common/Instrumentation/LogTargets.cs +++ b/src/NzbDrone.Common/Instrumentation/LogTargets.cs @@ -31,7 +31,7 @@ public static void Register(IStartupContext startupContext, bool updateApp, bool } else { - if (inConsole && (OsInfo.IsLinux || new RuntimeInfo(null, new ServiceProvider(new ProcessProvider())).IsUserInteractive)) + if (inConsole && (OsInfo.IsMono || new RuntimeInfo(null, new ServiceProvider(new ProcessProvider())).IsUserInteractive)) { RegisterConsole(); } diff --git a/src/NzbDrone.Common/PathEqualityComparer.cs b/src/NzbDrone.Common/PathEqualityComparer.cs index ce55c50e8b..88df4b480e 100644 --- a/src/NzbDrone.Common/PathEqualityComparer.cs +++ b/src/NzbDrone.Common/PathEqualityComparer.cs @@ -20,7 +20,7 @@ public bool Equals(string x, string y) public int GetHashCode(string obj) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { return obj.CleanFilePath().GetHashCode(); } diff --git a/src/NzbDrone.Common/PathExtensions.cs b/src/NzbDrone.Common/PathExtensions.cs index c08770fc85..16a9bddd1a 100644 --- a/src/NzbDrone.Common/PathExtensions.cs +++ b/src/NzbDrone.Common/PathExtensions.cs @@ -29,7 +29,7 @@ public static string CleanFilePath(this string path) var info = new FileInfo(path.Trim()); - if (!OsInfo.IsLinux && info.FullName.StartsWith(@"\\")) //UNC + if (!OsInfo.IsMono && info.FullName.StartsWith(@"\\")) //UNC { return info.FullName.TrimEnd('/', '\\', ' '); } @@ -39,7 +39,7 @@ public static string CleanFilePath(this string path) public static bool PathEquals(this string firstPath, string secondPath) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { if (firstPath.Equals(secondPath)) return true; return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath()); @@ -58,7 +58,7 @@ public static bool IsPathValid(this string path) return false; } - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { return path.StartsWith(Path.DirectorySeparatorChar.ToString()); } @@ -97,7 +97,7 @@ private static string GetProperCapitalization(DirectoryInfo dirInfo) public static string GetActualCasing(this string path) { - if (OsInfo.IsLinux || path.StartsWith("\\")) + if (OsInfo.IsMono || path.StartsWith("\\")) { return path; } diff --git a/src/NzbDrone.Core/Lifecycle/LifecycleService.cs b/src/NzbDrone.Core/Lifecycle/LifecycleService.cs index 25199b49f5..8b2f3a21e8 100644 --- a/src/NzbDrone.Core/Lifecycle/LifecycleService.cs +++ b/src/NzbDrone.Core/Lifecycle/LifecycleService.cs @@ -48,7 +48,7 @@ public void Execute(RestartCommand message) { _logger.Info("Restart requested."); - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { _processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--terminateexisting --nobrowser"); } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecification.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecification.cs index 50279a4e2e..c5ebd44ec2 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecification.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecification.cs @@ -36,7 +36,7 @@ public bool IsSatisfiedBy(LocalEpisode localEpisode) { if (Directory.GetParent(localEpisode.Path).Name.StartsWith(workingFolder)) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { _logger.Trace("{0} is still being unpacked", localEpisode.Path); return false; diff --git a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 4c5140c9a4..0dc62b613d 100644 --- a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -73,7 +73,7 @@ public void DeleteFile(string path) { logger.Info("Recycling Bin has not been configured, deleting permanently."); - if (!OsInfo.IsLinux) + if (!OsInfo.IsMono) { logger.Trace(_diskProvider.GetFileAttributes(path)); } diff --git a/src/NzbDrone.Core/Update/UpdateCheckService.cs b/src/NzbDrone.Core/Update/UpdateCheckService.cs index 32cb64be29..e8d8533052 100644 --- a/src/NzbDrone.Core/Update/UpdateCheckService.cs +++ b/src/NzbDrone.Core/Update/UpdateCheckService.cs @@ -27,7 +27,7 @@ public CheckUpdateService(IUpdatePackageProvider updatePackageProvider, IConfigF public UpdatePackage AvailableUpdate() { - if (OsInfo.IsLinux) return null; + if (OsInfo.IsMono) return null; var latestAvailable = _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version); diff --git a/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs b/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs index c252e3e9ee..556f47baf3 100644 --- a/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs +++ b/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs @@ -90,7 +90,7 @@ private void OpenFirewallPort(int portNumber) private bool IsFirewallEnabled() { - if (OsInfo.IsLinux) return false; + if (OsInfo.IsMono) return false; try { diff --git a/src/NzbDrone.Host/ApplicationServer.cs b/src/NzbDrone.Host/ApplicationServer.cs index 946334ec6a..1e6a5f7133 100644 --- a/src/NzbDrone.Host/ApplicationServer.cs +++ b/src/NzbDrone.Host/ApplicationServer.cs @@ -53,7 +53,7 @@ protected override void OnStart(string[] args) public void Start() { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { Console.CancelKeyPress += (sender, eventArgs) => _processProvider.Kill(_processProvider.GetCurrentProcess().Id); } @@ -90,7 +90,7 @@ private void Shutdown() public void Handle(ApplicationShutdownRequested message) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { _processProvider.Kill(_processProvider.GetCurrentProcess().Id); } diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index 1b0d9fa700..7a4ef8ff57 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -106,12 +106,12 @@ private static ApplicationModes GetApplicationMode(StartupContext startupContext return ApplicationModes.Help; } - if (!OsInfo.IsLinux && startupContext.InstallService) + if (!OsInfo.IsMono && startupContext.InstallService) { return ApplicationModes.InstallService; } - if (!OsInfo.IsLinux && startupContext.UninstallService) + if (!OsInfo.IsMono && startupContext.UninstallService) { return ApplicationModes.UninstallService; } diff --git a/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs b/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs index 2c7e4b4f75..437a9bde49 100644 --- a/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs +++ b/src/NzbDrone.Test.Common/AutoMoq/AutoMoqer.cs @@ -173,7 +173,7 @@ private void RegisterPlatformLibrary(IUnityContainer container) { var assemblyName = "NzbDrone.Windows"; - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { assemblyName = "NzbDrone.Mono"; } diff --git a/src/NzbDrone.Test.Common/StringExtensions.cs b/src/NzbDrone.Test.Common/StringExtensions.cs index 7ec3f46980..09b9b5b2dd 100644 --- a/src/NzbDrone.Test.Common/StringExtensions.cs +++ b/src/NzbDrone.Test.Common/StringExtensions.cs @@ -7,7 +7,7 @@ public static class StringExtensions { public static string AsOsAgnostic(this string path) { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { if (path.Length > 2 && path[1] == ':') { diff --git a/src/NzbDrone.Test.Common/TestBase.cs b/src/NzbDrone.Test.Common/TestBase.cs index 470cba8e1b..c42fca8a99 100644 --- a/src/NzbDrone.Test.Common/TestBase.cs +++ b/src/NzbDrone.Test.Common/TestBase.cs @@ -124,7 +124,7 @@ public void TestBaseTearDown() protected void WindowsOnly() { - if (OsInfo.IsLinux) + if (OsInfo.IsMono) { throw new IgnoreException("windows specific test"); } @@ -133,7 +133,7 @@ protected void WindowsOnly() protected void LinuxOnly() { - if (!OsInfo.IsLinux) + if (!OsInfo.IsMono) { throw new IgnoreException("linux specific test"); } diff --git a/src/UI/.idea/jsLinters/jshint.xml b/src/UI/.idea/jsLinters/jshint.xml index 4e0df49ad5..e85398a55f 100644 --- a/src/UI/.idea/jsLinters/jshint.xml +++ b/src/UI/.idea/jsLinters/jshint.xml @@ -8,16 +8,16 @@