OS X and linux can be treated separately

pull/4/head
Mark McDowall 10 years ago
parent 9d74693bb7
commit 8885bbb60f

@ -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();

@ -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));
}

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

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

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

@ -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;
}
}

@ -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();
}

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

@ -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;
}

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

@ -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;

@ -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));
}

@ -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);

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

@ -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);
}

@ -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;
}

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

@ -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] == ':')
{

@ -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");
}

@ -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" />

@ -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);
}

@ -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}}
Loading…
Cancel
Save