consolidate os display name

This commit is contained in:
Luke Pulverenti 2014-11-23 18:10:41 -05:00
parent 1923de72bf
commit 2df4273ee0
13 changed files with 226 additions and 195 deletions

View File

@ -193,6 +193,11 @@ namespace MediaBrowser.Common.Implementations
}
}
public virtual string OperatingSystemDisplayName
{
get { return Environment.OSVersion.VersionString; }
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary>

View File

@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Security
{ "systemid", _appHost.SystemId },
{ "mb2equiv", mb2Equivalent },
{ "ver", version },
{ "platform", Environment.OSVersion.VersionString },
{ "platform", _appHost.OperatingSystemDisplayName },
{ "isservice", _appHost.IsRunningAsService.ToString().ToLower() }
};

View File

@ -13,6 +13,12 @@ namespace MediaBrowser.Common
/// </summary>
public interface IApplicationHost
{
/// <summary>
/// Gets the display name of the operating system.
/// </summary>
/// <value>The display name of the operating system.</value>
string OperatingSystemDisplayName { get; }
/// <summary>
/// Gets the name.
/// </summary>

View File

@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{ "serverid", _applicationHost.SystemId },
{ "deviceid", _applicationHost.SystemId },
{ "ver", _applicationHost.ApplicationVersion.ToString() },
{ "platform", Environment.OSVersion.VersionString },
{ "platform", _applicationHost.OperatingSystemDisplayName },
{ "isservice", _applicationHost.IsRunningAsService.ToString().ToLower()}
};

View File

@ -69,6 +69,7 @@
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="Native\BaseMonoApp.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Native\NativeApp.cs" />

View File

@ -0,0 +1,193 @@
using MediaBrowser.Common.Net;
using MediaBrowser.IsoMounter;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Mono.Networking;
using MediaBrowser.Server.Startup.Common;
using Mono.Unix.Native;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
namespace MediaBrowser.Server.Mono.Native
{
public abstract class BaseMonoApp : INativeApp
{
/// <summary>
/// Shutdowns this instance.
/// </summary>
public abstract void Shutdown();
/// <summary>
/// Restarts this instance.
/// </summary>
public void Restart()
{
}
/// <summary>
/// Determines whether this instance [can self restart].
/// </summary>
/// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns>
public bool CanSelfRestart
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether this instance can self update.
/// </summary>
/// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
public bool CanSelfUpdate
{
get
{
return false;
}
}
public bool SupportsAutoRunAtStartup
{
get { return false; }
}
public void PreventSystemStandby()
{
}
public List<Assembly> GetAssembliesWithParts()
{
var list = new List<Assembly>();
if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux)
{
list.AddRange(GetLinuxAssemblies());
}
list.Add(GetType().Assembly);
return list;
}
private IEnumerable<Assembly> GetLinuxAssemblies()
{
var list = new List<Assembly>();
list.Add(typeof(LinuxIsoManager).Assembly);
return list;
}
public void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int udpPort, string tempDirectory)
{
}
private NativeEnvironment _nativeEnvironment;
public NativeEnvironment Environment
{
get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); }
}
public bool SupportsRunningAsService
{
get
{
return false;
}
}
public bool IsRunningAsService
{
get
{
return false;
}
}
public void ConfigureAutoRun(bool autorun)
{
}
public INetworkManager CreateNetworkManager(ILogger logger)
{
return new NetworkManager(logger);
}
private NativeEnvironment GetEnvironmentInfo()
{
var info = new NativeEnvironment
{
OperatingSystem = Startup.Common.OperatingSystem.Linux
};
var uname = GetUnixName();
var sysName = uname.sysname ?? string.Empty;
if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase))
{
info.OperatingSystem = Startup.Common.OperatingSystem.Osx;
}
else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase))
{
info.OperatingSystem = Startup.Common.OperatingSystem.Linux;
}
else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase))
{
// TODO: How to detect BSD?
info.OperatingSystem = Startup.Common.OperatingSystem.Bsd;
}
var archX86 = new Regex("(i|I)[3-6]86");
if (archX86.IsMatch(uname.machine))
{
info.SystemArchitecture = Architecture.X86;
}
else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase))
{
info.SystemArchitecture = Architecture.X86_X64;
}
else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase))
{
info.SystemArchitecture = Architecture.Arm;
}
info.OperatingSystemVersionString = string.IsNullOrWhiteSpace(sysName) ?
System.Environment.OSVersion.VersionString :
sysName;
return info;
}
private NativeApp.Uname _unixName;
private NativeApp.Uname GetUnixName()
{
if (_unixName == null)
{
var uname = new NativeApp.Uname();
Utsname utsname;
var callResult = Syscall.uname(out utsname);
if (callResult == 0)
{
uname.sysname = utsname.sysname;
uname.machine = utsname.machine;
}
_unixName = uname;
}
return _unixName;
}
public class Uname
{
public string sysname = string.Empty;
public string machine = string.Empty;
}
}
}

View File

@ -1,189 +1,17 @@
using MediaBrowser.Common.Net;
using MediaBrowser.IsoMounter;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Mono.Networking;
using MediaBrowser.Server.Startup.Common;
using Mono.Unix.Native;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;

namespace MediaBrowser.Server.Mono.Native
{
/// <summary>
/// Class NativeApp
/// </summary>
public class NativeApp : INativeApp
public class NativeApp : BaseMonoApp
{
/// <summary>
/// Shutdowns this instance.
/// </summary>
public void Shutdown()
public override void Shutdown()
{
MainClass.Shutdown();
}
/// <summary>
/// Restarts this instance.
/// </summary>
public void Restart()
{
}
/// <summary>
/// Determines whether this instance [can self restart].
/// </summary>
/// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns>
public bool CanSelfRestart
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether this instance can self update.
/// </summary>
/// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
public bool CanSelfUpdate
{
get
{
return false;
}
}
public bool SupportsAutoRunAtStartup
{
get { return false; }
}
public void PreventSystemStandby()
{
}
public List<Assembly> GetAssembliesWithParts()
{
var list = new List<Assembly>();
if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux)
{
list.AddRange(GetLinuxAssemblies());
}
list.Add(GetType().Assembly);
return list;
}
private List<Assembly> GetLinuxAssemblies()
{
var list = new List<Assembly>();
list.Add(typeof(LinuxIsoManager).Assembly);
return list;
}
public void AuthorizeServer(int httpServerPort, string httpServerUrlPrefix, int udpPort, string tempDirectory)
{
}
private NativeEnvironment _nativeEnvironment;
public NativeEnvironment Environment
{
get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); }
}
public bool SupportsRunningAsService
{
get
{
return false;
}
}
public bool IsRunningAsService
{
get
{
return false;
}
}
public void ConfigureAutoRun(bool autorun)
{
}
public INetworkManager CreateNetworkManager(ILogger logger)
{
return new NetworkManager(logger);
}
private NativeEnvironment GetEnvironmentInfo()
{
var info = new NativeEnvironment
{
OperatingSystem = Startup.Common.OperatingSystem.Linux
};
var uname = GetUnixName();
var sysName = uname.sysname ?? string.Empty;
if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase))
{
info.OperatingSystem = Startup.Common.OperatingSystem.Osx;
}
else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase))
{
info.OperatingSystem = Startup.Common.OperatingSystem.Linux;
}
else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase))
{
// TODO: How to detect BSD?
info.OperatingSystem = Startup.Common.OperatingSystem.Bsd;
}
var archX86 = new Regex("(i|I)[3-6]86");
if (archX86.IsMatch(uname.machine))
{
info.SystemArchitecture = Architecture.X86;
}
else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase))
{
info.SystemArchitecture = Architecture.X86_X64;
}
else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase))
{
info.SystemArchitecture = Architecture.Arm;
}
return info;
}
private static Uname GetUnixName()
{
var uname = new Uname();
Utsname utsname;
var callResult = Syscall.uname(out utsname);
if (callResult == 0)
{
uname.sysname = utsname.sysname;
uname.machine = utsname.machine;
}
return uname;
}
public class Uname
{
public string sysname = string.Empty;
public string machine = string.Empty;
}
}
}

View File

@ -266,6 +266,11 @@ namespace MediaBrowser.Server.Startup.Common
}
}
public override string OperatingSystemDisplayName
{
get { return NativeApp.Environment.OperatingSystemVersionString; }
}
public override bool IsRunningAsService
{
get { return NativeApp.IsRunningAsService; }
@ -531,7 +536,7 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task.</returns>
private async Task RegisterMediaEncoder(IProgress<double> progress)
{
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager)
var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment)
.GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false);
new FFmpegValidator(Logger, ApplicationPaths).Validate(info);
@ -909,7 +914,7 @@ namespace MediaBrowser.Server.Startup.Common
CachePath = ApplicationPaths.CachePath,
MacAddress = GetMacAddress(),
HttpServerPortNumber = HttpServerPort,
OperatingSystem = Environment.OSVersion.ToString(),
OperatingSystem = OperatingSystemDisplayName,
CanSelfRestart = CanSelfRestart,
CanSelfUpdate = CanSelfUpdate,
WanAddress = ConnectManager.WanApiAddress,

View File

@ -22,19 +22,21 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
private readonly ILogger _logger;
private readonly IZipClient _zipClient;
private readonly IFileSystem _fileSystem;
private readonly NativeEnvironment _environment;
private readonly string[] _fontUrls =
{
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z"
};
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem)
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment)
{
_logger = logger;
_appPaths = appPaths;
_httpClient = httpClient;
_zipClient = zipClient;
_fileSystem = fileSystem;
_environment = environment;
}
public async Task<FFMpegInfo> GetFFMpegInfo(NativeEnvironment environment, StartupOptions options, IProgress<double> progress)
@ -240,7 +242,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
private void SetFilePermissions(string targetFolder, string file)
{
// Linux: File permission to 666, and user's execute bit
if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
if (_environment.OperatingSystem == OperatingSystem.Bsd || _environment.OperatingSystem == OperatingSystem.Linux || _environment.OperatingSystem == OperatingSystem.Osx)
{
Syscall.chmod(Path.Combine(targetFolder, Path.GetFileName(file)), FilePermissions.DEFFILEMODE | FilePermissions.S_IXUSR);
}

View File

@ -1,5 +1,4 @@
using System;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System.Collections.Generic;
using System.Reflection;

View File

@ -5,6 +5,7 @@ namespace MediaBrowser.Server.Startup.Common
{
public OperatingSystem OperatingSystem { get; set; }
public Architecture SystemArchitecture { get; set; }
public string OperatingSystemVersionString { get; set; }
}
public enum OperatingSystem

View File

@ -49,7 +49,7 @@ namespace MediaBrowser.ServerApplication
var logger = _logger = logManager.GetLogger("Main");
BeginLog(logger, appPaths);
ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
// Install directly
if (options.ContainsOption("-installservice"))
@ -188,16 +188,6 @@ namespace MediaBrowser.ServerApplication
}
}
/// <summary>
/// Begins the log.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="appPaths">The app paths.</param>
private static void BeginLog(ILogger logger, IApplicationPaths appPaths)
{
ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
}
private static readonly TaskCompletionSource<bool> ApplicationTaskCompletionSource = new TaskCompletionSource<bool>();
/// <summary>

View File

@ -33,7 +33,8 @@ namespace MediaBrowser.ServerApplication.Native
return new NativeEnvironment
{
OperatingSystem = OperatingSystem.Windows,
SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X86_X64 : Architecture.X86
SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X86_X64 : Architecture.X86,
OperatingSystemVersionString = System.Environment.OSVersion.VersionString
};
}
}