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 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 @@ namespace NzbDrone.Api.System
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 @@ namespace NzbDrone.Api.System
SqliteVersion = _database.Version,
UrlBase = _configFileProvider.UrlBase
}.AsResponse();
}
private Response GetRoutes()
{
return _routeCacheProvider.GetCache().Values.AsResponse();

View File

@ -100,7 +100,7 @@ namespace NzbDrone.Common.EnsureThat
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));
}

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
namespace NzbDrone.Common.EnvironmentInfo
{
@ -7,34 +8,80 @@ namespace NzbDrone.Common.EnvironmentInfo
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
}
}

View File

@ -78,7 +78,7 @@ namespace NzbDrone.Common.EnvironmentInfo
return (OsInfo.IsWindows &&
IsUserInteractive &&
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
{
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();
}

View File

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

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
return false;
}
if (OsInfo.IsLinux)
if (OsInfo.IsMono)
{
return path.StartsWith(Path.DirectorySeparatorChar.ToString());
}
@ -97,7 +97,7 @@ namespace NzbDrone.Common
public static string GetActualCasing(this string path)
{
if (OsInfo.IsLinux || path.StartsWith("\\"))
if (OsInfo.IsMono || path.StartsWith("\\"))
{
return path;
}

View File

@ -48,7 +48,7 @@ namespace NzbDrone.Core.Lifecycle
{
_logger.Info("Restart requested.");
if (OsInfo.IsLinux)
if (OsInfo.IsMono)
{
_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 (OsInfo.IsLinux)
if (OsInfo.IsMono)
{
_logger.Trace("{0} is still being unpacked", localEpisode.Path);
return false;

View File

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

View File

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

View File

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

View File

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

View File

@ -106,12 +106,12 @@ namespace NzbDrone.Host
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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