OS X and linux can be treated separately

This commit is contained in:
Mark McDowall 2014-03-08 21:28:40 -08:00
parent 9d74693bb7
commit 8885bbb60f
22 changed files with 101 additions and 50 deletions

View File

@ -16,7 +16,11 @@ namespace NzbDrone.Api.System
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
private readonly IDatabase _database; 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") : base("system")
{ {
_appFolderInfo = appFolderInfo; _appFolderInfo = appFolderInfo;
@ -41,8 +45,10 @@ namespace NzbDrone.Api.System
StartupPath = _appFolderInfo.StartUpFolder, StartupPath = _appFolderInfo.StartUpFolder,
AppData = _appFolderInfo.GetAppDataPath(), AppData = _appFolderInfo.GetAppDataPath(),
OsVersion = OsInfo.Version.ToString(), OsVersion = OsInfo.Version.ToString(),
IsMonoRuntime = OsInfo.IsMono,
IsMono = OsInfo.IsMono, IsMono = OsInfo.IsMono,
IsLinux = OsInfo.IsLinux, IsLinux = OsInfo.IsMono,
IsOsx = OsInfo.IsOsx,
IsWindows = OsInfo.IsWindows, IsWindows = OsInfo.IsWindows,
Branch = _configFileProvider.Branch, Branch = _configFileProvider.Branch,
Authentication = _configFileProvider.AuthenticationEnabled, Authentication = _configFileProvider.AuthenticationEnabled,
@ -50,10 +56,8 @@ namespace NzbDrone.Api.System
SqliteVersion = _database.Version, SqliteVersion = _database.Version,
UrlBase = _configFileProvider.UrlBase UrlBase = _configFileProvider.UrlBase
}.AsResponse(); }.AsResponse();
} }
private Response GetRoutes() private Response GetRoutes()
{ {
return _routeCacheProvider.GetCache().Values.AsResponse(); return _routeCacheProvider.GetCache().Values.AsResponse();

View File

@ -100,7 +100,7 @@ namespace NzbDrone.Common.EnsureThat
if (param.Value.IsPathValid()) return 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)); throw ExceptionFactory.CreateForParamValidation(param.Name, string.Format("value [{0}] is not a valid *nix path. paths must start with /", param.Value));
} }

View File

@ -32,7 +32,7 @@ namespace NzbDrone.Common.EnvironmentInfo
{ {
_diskProvider.EnsureFolder(_appFolderInfo.AppDataFolder); _diskProvider.EnsureFolder(_appFolderInfo.AppDataFolder);
if (!OsInfo.IsLinux) if (!OsInfo.IsMono)
{ {
SetPermissions(); SetPermissions();
} }

View File

@ -17,7 +17,7 @@ namespace NzbDrone.Common.EnvironmentInfo
public AppFolderInfo(IStartupContext startupContext) public AppFolderInfo(IStartupContext startupContext)
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData; DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData;
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.InteropServices;
namespace NzbDrone.Common.EnvironmentInfo namespace NzbDrone.Common.EnvironmentInfo
{ {
@ -7,34 +8,80 @@ namespace NzbDrone.Common.EnvironmentInfo
static OsInfo() static OsInfo()
{ {
var platform = (int)Environment.OSVersion.Platform;
Version = Environment.OSVersion.Version; Version = Environment.OSVersion.Version;
IsMono = Type.GetType("Mono.Runtime") != null;
int platform = (int)Environment.OSVersion.Platform; IsMonoRuntime = Type.GetType("Mono.Runtime") != null;
IsLinux = (platform == 4) || (platform == 6) || (platform == 128); 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 Version Version { get; private set; }
public static bool IsMonoRuntime { get; private set; }
public static bool IsMono { get; private set; } public static bool IsMono { get; private set; }
public static bool IsLinux { 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 //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);
static bool IsRunningOnMac()
{ {
get var buf = IntPtr.Zero;
try
{ {
return !IsLinux; 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);
} }
} }
public static DayOfWeek FirstDayOfWeek return false;
}
}
public enum Os
{ {
get Windows,
{ Linux,
return DateTime.Today.GetFirstDayOfWeek().DayOfWeek; Osx
}
}
} }
} }

View File

@ -78,7 +78,7 @@ namespace NzbDrone.Common.EnvironmentInfo
return (OsInfo.IsWindows && return (OsInfo.IsWindows &&
IsUserInteractive && IsUserInteractive &&
ProcessName.Equals(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME, StringComparison.InvariantCultureIgnoreCase)) || ProcessName.Equals(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME, StringComparison.InvariantCultureIgnoreCase)) ||
OsInfo.IsLinux; OsInfo.IsMono;
} }
} }

View File

@ -31,7 +31,7 @@ namespace NzbDrone.Common.Instrumentation
} }
else 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(); RegisterConsole();
} }

View File

@ -20,7 +20,7 @@ namespace NzbDrone.Common
public int GetHashCode(string obj) public int GetHashCode(string obj)
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
return obj.CleanFilePath().GetHashCode(); return obj.CleanFilePath().GetHashCode();
} }

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Common
var info = new FileInfo(path.Trim()); var info = new FileInfo(path.Trim());
if (!OsInfo.IsLinux && info.FullName.StartsWith(@"\\")) //UNC if (!OsInfo.IsMono && info.FullName.StartsWith(@"\\")) //UNC
{ {
return info.FullName.TrimEnd('/', '\\', ' '); return info.FullName.TrimEnd('/', '\\', ' ');
} }
@ -39,7 +39,7 @@ namespace NzbDrone.Common
public static bool PathEquals(this string firstPath, string secondPath) public static bool PathEquals(this string firstPath, string secondPath)
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
if (firstPath.Equals(secondPath)) return true; if (firstPath.Equals(secondPath)) return true;
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath()); return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath());
@ -58,7 +58,7 @@ namespace NzbDrone.Common
return false; return false;
} }
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
return path.StartsWith(Path.DirectorySeparatorChar.ToString()); return path.StartsWith(Path.DirectorySeparatorChar.ToString());
} }
@ -97,7 +97,7 @@ namespace NzbDrone.Common
public static string GetActualCasing(this string path) public static string GetActualCasing(this string path)
{ {
if (OsInfo.IsLinux || path.StartsWith("\\")) if (OsInfo.IsMono || path.StartsWith("\\"))
{ {
return path; return path;
} }

View File

@ -48,7 +48,7 @@ namespace NzbDrone.Core.Lifecycle
{ {
_logger.Info("Restart requested."); _logger.Info("Restart requested.");
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
_processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--terminateexisting --nobrowser"); _processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--terminateexisting --nobrowser");
} }

View File

@ -36,7 +36,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
{ {
if (Directory.GetParent(localEpisode.Path).Name.StartsWith(workingFolder)) if (Directory.GetParent(localEpisode.Path).Name.StartsWith(workingFolder))
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
_logger.Trace("{0} is still being unpacked", localEpisode.Path); _logger.Trace("{0} is still being unpacked", localEpisode.Path);
return false; return false;

View File

@ -73,7 +73,7 @@ namespace NzbDrone.Core.MediaFiles
{ {
logger.Info("Recycling Bin has not been configured, deleting permanently."); logger.Info("Recycling Bin has not been configured, deleting permanently.");
if (!OsInfo.IsLinux) if (!OsInfo.IsMono)
{ {
logger.Trace(_diskProvider.GetFileAttributes(path)); logger.Trace(_diskProvider.GetFileAttributes(path));
} }

View File

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Update
public UpdatePackage AvailableUpdate() public UpdatePackage AvailableUpdate()
{ {
if (OsInfo.IsLinux) return null; if (OsInfo.IsMono) return null;
var latestAvailable = _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version); var latestAvailable = _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version);

View File

@ -90,7 +90,7 @@ namespace NzbDrone.Host.AccessControl
private bool IsFirewallEnabled() private bool IsFirewallEnabled()
{ {
if (OsInfo.IsLinux) return false; if (OsInfo.IsMono) return false;
try try
{ {

View File

@ -53,7 +53,7 @@ namespace NzbDrone.Host
public void Start() public void Start()
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
Console.CancelKeyPress += (sender, eventArgs) => _processProvider.Kill(_processProvider.GetCurrentProcess().Id); Console.CancelKeyPress += (sender, eventArgs) => _processProvider.Kill(_processProvider.GetCurrentProcess().Id);
} }
@ -90,7 +90,7 @@ namespace NzbDrone.Host
public void Handle(ApplicationShutdownRequested message) public void Handle(ApplicationShutdownRequested message)
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
_processProvider.Kill(_processProvider.GetCurrentProcess().Id); _processProvider.Kill(_processProvider.GetCurrentProcess().Id);
} }

View File

@ -106,12 +106,12 @@ namespace NzbDrone.Host
return ApplicationModes.Help; return ApplicationModes.Help;
} }
if (!OsInfo.IsLinux && startupContext.InstallService) if (!OsInfo.IsMono && startupContext.InstallService)
{ {
return ApplicationModes.InstallService; return ApplicationModes.InstallService;
} }
if (!OsInfo.IsLinux && startupContext.UninstallService) if (!OsInfo.IsMono && startupContext.UninstallService)
{ {
return ApplicationModes.UninstallService; return ApplicationModes.UninstallService;
} }

View File

@ -173,7 +173,7 @@ namespace NzbDrone.Test.Common.AutoMoq
{ {
var assemblyName = "NzbDrone.Windows"; var assemblyName = "NzbDrone.Windows";
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
assemblyName = "NzbDrone.Mono"; assemblyName = "NzbDrone.Mono";
} }

View File

@ -7,7 +7,7 @@ namespace NzbDrone.Test.Common
{ {
public static string AsOsAgnostic(this string path) public static string AsOsAgnostic(this string path)
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
if (path.Length > 2 && path[1] == ':') if (path.Length > 2 && path[1] == ':')
{ {

View File

@ -124,7 +124,7 @@ namespace NzbDrone.Test.Common
protected void WindowsOnly() protected void WindowsOnly()
{ {
if (OsInfo.IsLinux) if (OsInfo.IsMono)
{ {
throw new IgnoreException("windows specific test"); throw new IgnoreException("windows specific test");
} }
@ -133,7 +133,7 @@ namespace NzbDrone.Test.Common
protected void LinuxOnly() protected void LinuxOnly()
{ {
if (!OsInfo.IsLinux) if (!OsInfo.IsMono)
{ {
throw new IgnoreException("linux specific test"); throw new IgnoreException("linux specific test");
} }

View File

@ -8,16 +8,16 @@
<option es3="false" /> <option es3="false" />
<option forin="true" /> <option forin="true" />
<option immed="true" /> <option immed="true" />
<option latedef="true" />
<option newcap="true" /> <option newcap="true" />
<option noarg="true" /> <option noarg="true" />
<option noempty="false" /> <option noempty="false" />
<option nonew="true" /> <option nonew="true" />
<option plusplus="false" /> <option plusplus="false" />
<option undef="true" /> <option undef="true" />
<option unused="true" />
<option strict="true" /> <option strict="true" />
<option trailing="false" /> <option trailing="false" />
<option latedef="true" />
<option unused="true" />
<option quotmark="single" /> <option quotmark="single" />
<option maxdepth="3" /> <option maxdepth="3" />
<option asi="false" /> <option asi="false" />

View File

@ -15,8 +15,8 @@ define(
return options.inverse(this); return options.inverse(this);
}); });
Handlebars.registerHelper('if_linux', function(options) { Handlebars.registerHelper('if_mono', function(options) {
if (StatusModel.get('isLinux')) if (StatusModel.get('isMono'))
{ {
return options.fn(this); return options.fn(this);
} }

View File

@ -1,4 +1,4 @@
{{#if_linux}} {{#if_mono}}
<fieldset class="advanced-setting"> <fieldset class="advanced-setting">
<legend>Permissions</legend> <legend>Permissions</legend>
@ -67,4 +67,4 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
{{/if_linux}} {{/if_mono}}