parent
ea5ad24944
commit
aef89160e2
@ -0,0 +1,30 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test.Http
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class UserAgentBuilderFixture : TestBase<UserAgentBuilder>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_get_user_agent_if_os_version_is_null()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IOsInfo>().SetupGet(c => c.Version).Returns((string)null);
|
||||||
|
Mocker.GetMock<IOsInfo>().SetupGet(c => c.Name).Returns("TestOS");
|
||||||
|
|
||||||
|
Subject.GetUserAgent(false).Should().NotBeNullOrWhiteSpace();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_get_use_os_family_if_name_is_null()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IOsInfo>().SetupGet(c => c.Version).Returns((string)null);
|
||||||
|
Mocker.GetMock<IOsInfo>().SetupGet(c => c.Name).Returns((string)null);
|
||||||
|
|
||||||
|
Subject.GetUserAgent(false).Should().NotBeNullOrWhiteSpace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
{
|
||||||
|
public interface IOperatingSystemVersionInfo
|
||||||
|
{
|
||||||
|
string Version { get; }
|
||||||
|
string Name { get; }
|
||||||
|
string FullName { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public interface IOsVersionAdapter
|
||||||
|
{
|
||||||
|
bool Enabled { get; }
|
||||||
|
OsVersionModel Read();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public enum PlatformType
|
||||||
|
{
|
||||||
|
DotNet = 0,
|
||||||
|
Mono = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IPlatformInfo
|
||||||
|
{
|
||||||
|
Version Version { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class PlatformInfo : IPlatformInfo
|
||||||
|
{
|
||||||
|
static PlatformInfo()
|
||||||
|
{
|
||||||
|
if (Type.GetType("Mono.Runtime") != null)
|
||||||
|
{
|
||||||
|
Platform = PlatformType.Mono;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Platform = PlatformType.DotNet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlatformType Platform { get; }
|
||||||
|
public static bool IsMono => Platform == PlatformType.Mono;
|
||||||
|
public static bool IsDotNet => Platform == PlatformType.DotNet;
|
||||||
|
|
||||||
|
public static string PlatformName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsDotNet)
|
||||||
|
{
|
||||||
|
return ".NET";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Mono";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Version Version { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
{
|
||||||
|
public class OsVersionModel
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public OsVersionModel(string name, string version, string fullName = null)
|
||||||
|
{
|
||||||
|
Name = Trim(name);
|
||||||
|
Version = Trim(version);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(fullName))
|
||||||
|
{
|
||||||
|
fullName = $"{Name} {Version}";
|
||||||
|
}
|
||||||
|
|
||||||
|
FullName = Trim(fullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Trim(string source)
|
||||||
|
{
|
||||||
|
return source.Trim().Trim('"', '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; }
|
||||||
|
public string FullName { get; }
|
||||||
|
public string Version { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
using System;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
|
|
||||||
namespace NzbDrone.Common.Exceptron
|
|
||||||
{
|
|
||||||
public static class ExceptionExtentions
|
|
||||||
{
|
|
||||||
private const string IGNORE_FLAG = "exceptron_ignore";
|
|
||||||
|
|
||||||
public static Exception ExceptronIgnoreOnMono(this Exception exception)
|
|
||||||
{
|
|
||||||
if (OsInfo.IsNotWindows)
|
|
||||||
{
|
|
||||||
exception.ExceptronIgnore();
|
|
||||||
}
|
|
||||||
|
|
||||||
return exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Exception ExceptronIgnore(this Exception exception)
|
|
||||||
{
|
|
||||||
exception.Data.Add(IGNORE_FLAG, true);
|
|
||||||
return exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ExceptronShouldIgnore(this Exception exception)
|
|
||||||
{
|
|
||||||
return exception.Data.Contains(IGNORE_FLAG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Mono.EnvironmentInfo;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.Test.EnvironmentInfo
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[Platform("Mono")]
|
||||||
|
public class MonoPlatformInfoFixture : TestBase<MonoPlatformInfo>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_get_framework_version()
|
||||||
|
{
|
||||||
|
Subject.Version.Major.Should().BeOneOf(4, 5);
|
||||||
|
if (Subject.Version.Major == 4)
|
||||||
|
{
|
||||||
|
Subject.Version.Minor.Should().BeOneOf(0, 5, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Mono.Disk;
|
||||||
|
using NzbDrone.Mono.EnvironmentInfo.VersionAdapters;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.Test.EnvironmentInfo
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[Platform("Mono")]
|
||||||
|
public class ReleaseFileVersionAdapterFixture : TestBase<ReleaseFileVersionAdapter>
|
||||||
|
{
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
Mocker.SetConstant<IDiskProvider>(Mocker.Resolve<DiskProvider>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_get_version_info()
|
||||||
|
{
|
||||||
|
var info = Subject.Read();
|
||||||
|
info.FullName.Should().NotBeNullOrWhiteSpace();
|
||||||
|
info.Name.Should().NotBeNullOrWhiteSpace();
|
||||||
|
info.Version.Should().NotBeNullOrWhiteSpace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Mono.EnvironmentInfo.VersionAdapters;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class MacOsVersionAdapterFixture : TestBase<MacOsVersionAdapter>
|
||||||
|
{
|
||||||
|
[TestCase("10.8.0")]
|
||||||
|
[TestCase("10.8")]
|
||||||
|
[TestCase("10.8.1")]
|
||||||
|
[TestCase("10.11.20")]
|
||||||
|
public void should_get_version_info(string versionString)
|
||||||
|
{
|
||||||
|
var fileContent = File.ReadAllText(GetTestPath("Files/macOS/SystemVersion.plist")).Replace("10.0.0", versionString);
|
||||||
|
|
||||||
|
const string plistPath = "/System/Library/CoreServices/SystemVersion.plist";
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly))
|
||||||
|
.Returns(new[] { plistPath });
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.ReadAllText(plistPath))
|
||||||
|
.Returns(fileContent);
|
||||||
|
|
||||||
|
var versionName = Subject.Read();
|
||||||
|
versionName.Version.Should().Be(versionString);
|
||||||
|
versionName.Name.Should().Be("macOS");
|
||||||
|
versionName.FullName.Should().Be("macOS " + versionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void should_detect_server()
|
||||||
|
{
|
||||||
|
var fileContent = File.ReadAllText(GetTestPath("Files/macOS/SystemVersion.plist"));
|
||||||
|
|
||||||
|
const string plistPath = "/System/Library/CoreServices/ServerVersion.plist";
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly))
|
||||||
|
.Returns(new[] { plistPath });
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.ReadAllText(plistPath))
|
||||||
|
.Returns(fileContent);
|
||||||
|
|
||||||
|
var versionName = Subject.Read();
|
||||||
|
versionName.Name.Should().Be("macOS Server");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void should_return_null_if_folder_doesnt_exist()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(false);
|
||||||
|
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Verify(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly), Times.Never());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
using System.IO;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Mono.Disk;
|
||||||
|
using NzbDrone.Mono.EnvironmentInfo.VersionAdapters;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Test.Common.Categories;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ReleaseFileVersionAdapterFixture : TestBase<ReleaseFileVersionAdapter>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[IntegrationTest]
|
||||||
|
[Platform("Mono")]
|
||||||
|
public void should_get_version_info_from_actual_linux()
|
||||||
|
{
|
||||||
|
Mocker.SetConstant<IDiskProvider>(Mocker.Resolve<DiskProvider>());
|
||||||
|
var info = Subject.Read();
|
||||||
|
info.FullName.Should().NotBeNullOrWhiteSpace();
|
||||||
|
info.Name.Should().NotBeNullOrWhiteSpace();
|
||||||
|
info.Version.Should().NotBeNullOrWhiteSpace();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_null_if_etc_doestn_exist()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(false);
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Verify(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly), Times.Never());
|
||||||
|
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_null_if_release_file_doestn_exist()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(true);
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(new string[0]);
|
||||||
|
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_detect_version()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists("/etc/")).Returns(true);
|
||||||
|
Subject.Read().Should().BeNull();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(new[]
|
||||||
|
{
|
||||||
|
"/etc/lsb-release",
|
||||||
|
"/etc/os-release"
|
||||||
|
});
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.ReadAllText("/etc/lsb-release"))
|
||||||
|
.Returns(File.ReadAllText(GetTestPath("Files/linux/lsb-release")));
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>()
|
||||||
|
.Setup(c => c.ReadAllText("/etc/os-release"))
|
||||||
|
.Returns(File.ReadAllText(GetTestPath("Files/linux/os-release")));
|
||||||
|
|
||||||
|
var version = Subject.Read();
|
||||||
|
version.Should().NotBeNull();
|
||||||
|
version.Name.Should().Be("ubuntu");
|
||||||
|
version.Version.Should().Be("14.04");
|
||||||
|
version.FullName.Should().Be("Ubuntu 14.04.5 LTS");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
DISTRIB_ID=Ubuntu
|
||||||
|
DISTRIB_RELEASE=14.04
|
||||||
|
DISTRIB_CODENAME=trusty
|
||||||
|
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
|
@ -0,0 +1,9 @@
|
|||||||
|
NAME="Ubuntu"
|
||||||
|
VERSION="14.04.5 LTS, Trusty Tahr"
|
||||||
|
ID=ubuntu
|
||||||
|
ID_LIKE=debian
|
||||||
|
PRETTY_NAME="Ubuntu 14.04.5 LTS"
|
||||||
|
VERSION_ID="14.04"
|
||||||
|
HOME_URL="http://www.ubuntu.com/"
|
||||||
|
SUPPORT_URL="http://help.ubuntu.com/"
|
||||||
|
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>ProductBuildVersion</key>
|
||||||
|
<string>16C68</string>
|
||||||
|
<key>ProductCopyright</key>
|
||||||
|
<string>1983-2016 Apple Inc.</string>
|
||||||
|
<key>ProductName</key>
|
||||||
|
<string>Mac OS X</string>
|
||||||
|
<key>ProductUserVisibleVersion</key>
|
||||||
|
<string>10.0.0</string>
|
||||||
|
<key>ProductVersion</key>
|
||||||
|
<string>10.0.0</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -0,0 +1,8 @@
|
|||||||
|
majorversion="6"
|
||||||
|
minorversion="0"
|
||||||
|
productversion="6.0.2"
|
||||||
|
buildphase="hotfix"
|
||||||
|
buildnumber="8451"
|
||||||
|
smallfixnumber="7"
|
||||||
|
builddate="2016/12/20"
|
||||||
|
buildtime="05:11:44"
|
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.EnvironmentInfo
|
||||||
|
{
|
||||||
|
public class MonoPlatformInfo : PlatformInfo
|
||||||
|
{
|
||||||
|
private static readonly Regex VersionRegex = new Regex(@"(?<=\W|^)(?<version>\d+\.\d+(\.\d+)?(\.\d+)?)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
public override Version Version { get; }
|
||||||
|
|
||||||
|
public MonoPlatformInfo(Logger logger)
|
||||||
|
{
|
||||||
|
var runTimeVersion = new Version();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var type = Type.GetType("Mono.Runtime");
|
||||||
|
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
var displayNameMethod = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
if (displayNameMethod != null)
|
||||||
|
{
|
||||||
|
var displayName = displayNameMethod.Invoke(null, null).ToString();
|
||||||
|
var versionMatch = VersionRegex.Match(displayName);
|
||||||
|
|
||||||
|
if (versionMatch.Success)
|
||||||
|
{
|
||||||
|
runTimeVersion = new Version(versionMatch.Groups["version"].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error(ex, "Unable to get mono version");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Version = runTimeVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
public class IssueFileVersionAdapter : IOsVersionAdapter
|
||||||
|
{
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
|
||||||
|
public IssueFileVersionAdapter(IDiskProvider diskProvider)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsVersionModel Read()
|
||||||
|
{
|
||||||
|
if (!_diskProvider.FolderExists("/etc/"))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var issueFile = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("/issue"));
|
||||||
|
|
||||||
|
if (issueFile == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileContent = _diskProvider.ReadAllText(issueFile);
|
||||||
|
|
||||||
|
|
||||||
|
// Ubuntu 14.04.5 LTS \n \l
|
||||||
|
// Ubuntu 16.04.1 LTS \n \l
|
||||||
|
|
||||||
|
// Fedora/Centos
|
||||||
|
// Kernel \r on an \m (\l)
|
||||||
|
|
||||||
|
// Arch Linux \r (\l)
|
||||||
|
// Debian GNU/Linux 8 \n \l
|
||||||
|
if (fileContent.Contains("Arch Linux"))
|
||||||
|
{
|
||||||
|
return new OsVersionModel("Arch", "1.0", "Arch Linux");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enabled => OsInfo.IsLinux;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
public class MacOsVersionAdapter : IOsVersionAdapter
|
||||||
|
{
|
||||||
|
private static readonly Regex DarwinVersionRegex = new Regex("<string>(?<version>10\\.\\d{1,2}\\.?\\d{0,2}?)<\\/string>",
|
||||||
|
RegexOptions.Compiled |
|
||||||
|
RegexOptions.IgnoreCase
|
||||||
|
);
|
||||||
|
|
||||||
|
private const string PLIST_DIR = "/System/Library/CoreServices/";
|
||||||
|
|
||||||
|
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public MacOsVersionAdapter(IDiskProvider diskProvider, Logger logger)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsVersionModel Read()
|
||||||
|
{
|
||||||
|
var version = "10.0";
|
||||||
|
|
||||||
|
if (!_diskProvider.FolderExists(PLIST_DIR))
|
||||||
|
{
|
||||||
|
_logger.Debug("Directory {0} doesn't exist", PLIST_DIR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var allFiles = _diskProvider.GetFiles(PLIST_DIR, SearchOption.TopDirectoryOnly);
|
||||||
|
|
||||||
|
var versionFile = allFiles.SingleOrDefault(c =>
|
||||||
|
c.EndsWith("SystemVersion.plist") ||
|
||||||
|
c.EndsWith("ServerVersion.plist")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(versionFile))
|
||||||
|
{
|
||||||
|
_logger.Debug("Couldn't find version plist file in {0}", PLIST_DIR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = _diskProvider.ReadAllText(versionFile);
|
||||||
|
var match = DarwinVersionRegex.Match(text);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
version = match.Groups["version"].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = versionFile.Contains("Server") ? "macOS Server" : "macOS";
|
||||||
|
|
||||||
|
return new OsVersionModel(name, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enabled => OsInfo.IsOsx;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
public class ReleaseFileVersionAdapter : IOsVersionAdapter
|
||||||
|
{
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
|
||||||
|
public ReleaseFileVersionAdapter(IDiskProvider diskProvider)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsVersionModel Read()
|
||||||
|
{
|
||||||
|
if (!_diskProvider.FolderExists("/etc/"))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var releaseFiles = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).Where(c => c.EndsWith("release")).ToList();
|
||||||
|
|
||||||
|
var name = "Linux";
|
||||||
|
var fullName = "";
|
||||||
|
var version = "";
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
foreach (var releaseFile in releaseFiles)
|
||||||
|
{
|
||||||
|
var fileContent = _diskProvider.ReadAllText(releaseFile);
|
||||||
|
var lines = Regex.Split(fileContent, "\r\n|\r|\n"); ;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var parts = line.Split('=');
|
||||||
|
if (parts.Length >= 2)
|
||||||
|
{
|
||||||
|
var key = parts[0];
|
||||||
|
var value = parts[1];
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case "ID":
|
||||||
|
success = true;
|
||||||
|
name = value;
|
||||||
|
break;
|
||||||
|
case "PRETTY_NAME":
|
||||||
|
success = true;
|
||||||
|
fullName = value;
|
||||||
|
break;
|
||||||
|
case "VERSION_ID":
|
||||||
|
success = true;
|
||||||
|
version = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OsVersionModel(name, version, fullName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enabled => OsInfo.IsLinux;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters
|
||||||
|
{
|
||||||
|
public class SynologyVersionAdapter : IOsVersionAdapter
|
||||||
|
{
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private const string NAME = "DSM";
|
||||||
|
private const string FULL_NAME = "Synology DSM";
|
||||||
|
|
||||||
|
|
||||||
|
public SynologyVersionAdapter(IDiskProvider diskProvider)
|
||||||
|
{
|
||||||
|
_diskProvider = diskProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsVersionModel Read()
|
||||||
|
{
|
||||||
|
if (!_diskProvider.FolderExists("/etc.defaults/"))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var versionFile = _diskProvider.GetFiles("/etc.defaults/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("VERSION"));
|
||||||
|
|
||||||
|
if (versionFile == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var version = "";
|
||||||
|
var major = "";
|
||||||
|
var minor = "0";
|
||||||
|
|
||||||
|
var fileContent = _diskProvider.ReadAllText(versionFile);
|
||||||
|
var lines = Regex.Split(fileContent, "\r\n|\r|\n"); ;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var parts = line.Split('=');
|
||||||
|
if (parts.Length >= 2)
|
||||||
|
{
|
||||||
|
var key = parts[0];
|
||||||
|
var value = parts[1].Trim('"');
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case "productversion":
|
||||||
|
version = value;
|
||||||
|
break;
|
||||||
|
case "majorversion":
|
||||||
|
major = value;
|
||||||
|
break;
|
||||||
|
case "minorversion":
|
||||||
|
minor = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(version) && !string.IsNullOrWhiteSpace(major))
|
||||||
|
{
|
||||||
|
version = $"{major}.{minor}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OsVersionModel(NAME, version, $"{FULL_NAME} {version}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enabled => OsInfo.IsLinux;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
@ -0,0 +1,19 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Windows.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Windows.Test.EnvironmentInfo
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[Platform("Win")]
|
||||||
|
public class DotNetPlatformInfoFixture : TestBase<DotNetPlatformInfo>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_get_framework_version()
|
||||||
|
{
|
||||||
|
Subject.Version.Major.Should().Be(4);
|
||||||
|
Subject.Version.Minor.Should().BeOneOf(0, 5, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Windows.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Windows.Test.EnvironmentInfo
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[Platform("Win")]
|
||||||
|
public class WindowsVersionInfoFixture : TestBase<WindowsVersionInfo>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_get_windows_version()
|
||||||
|
{
|
||||||
|
var info = Subject.Read();
|
||||||
|
info.Version.Should().NotBeNullOrWhiteSpace();
|
||||||
|
info.Name.Should().Contain("Windows");
|
||||||
|
info.FullName.Should().Contain("Windows");
|
||||||
|
info.FullName.Should().Contain("NT");
|
||||||
|
info.FullName.Should().Contain(info.Version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Windows.EnvironmentInfo
|
||||||
|
{
|
||||||
|
public class DotNetPlatformInfo : PlatformInfo
|
||||||
|
{
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public DotNetPlatformInfo(Logger logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
var version = GetFrameworkVersion();
|
||||||
|
Environment.SetEnvironmentVariable("RUNTIME_VERSION", version.ToString());
|
||||||
|
Version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Version Version { get; }
|
||||||
|
|
||||||
|
private Version GetFrameworkVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
|
||||||
|
using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
|
||||||
|
{
|
||||||
|
if (ndpKey == null)
|
||||||
|
{
|
||||||
|
return new Version(4, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
var releaseKey = (int)ndpKey.GetValue("Release");
|
||||||
|
|
||||||
|
if (releaseKey >= 394802)
|
||||||
|
{
|
||||||
|
return new Version(4, 6, 2);
|
||||||
|
}
|
||||||
|
if (releaseKey >= 394254)
|
||||||
|
{
|
||||||
|
return new Version(4, 6, 1);
|
||||||
|
}
|
||||||
|
if (releaseKey >= 393295)
|
||||||
|
{
|
||||||
|
return new Version(4, 6);
|
||||||
|
}
|
||||||
|
if (releaseKey >= 379893)
|
||||||
|
{
|
||||||
|
return new Version(4, 5, 2);
|
||||||
|
}
|
||||||
|
if (releaseKey >= 378675)
|
||||||
|
{
|
||||||
|
return new Version(4, 5, 1);
|
||||||
|
}
|
||||||
|
if (releaseKey >= 378389)
|
||||||
|
{
|
||||||
|
return new Version(4, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(e, "Couldnt get .NET framework version");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Version(4, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Windows.EnvironmentInfo
|
||||||
|
{
|
||||||
|
public class WindowsVersionInfo : IOsVersionAdapter
|
||||||
|
{
|
||||||
|
private readonly Logger _logger;
|
||||||
|
public bool Enabled => OsInfo.IsWindows;
|
||||||
|
|
||||||
|
public WindowsVersionInfo(Logger logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsVersionModel Read()
|
||||||
|
{
|
||||||
|
var windowsServer = IsServer();
|
||||||
|
var osName = windowsServer ? "Windows Server" : "Windows";
|
||||||
|
return new OsVersionModel(osName, Environment.OSVersion.Version.ToString(), Environment.OSVersion.VersionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsServer()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const string subkey = @"Software\Microsoft\Windows NT\CurrentVersion";
|
||||||
|
var openSubKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey);
|
||||||
|
if (openSubKey != null)
|
||||||
|
{
|
||||||
|
var productName = openSubKey.GetValue("ProductName").ToString();
|
||||||
|
|
||||||
|
if (productName.ToLower().Contains("server"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(e, "Couldn't detect if running Windows Server");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
@ -0,0 +1,4 @@
|
|||||||
|
[ViewState]
|
||||||
|
Mode=
|
||||||
|
Vid=
|
||||||
|
FolderType=Documents
|
Loading…
Reference in new issue