EnvironmentInfo.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Model.System;
  7. namespace Emby.Common.Implementations.EnvironmentInfo
  8. {
  9. public class EnvironmentInfo : IEnvironmentInfo
  10. {
  11. public MediaBrowser.Model.System.Architecture? CustomArchitecture { get; set; }
  12. public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; }
  13. public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem
  14. {
  15. get
  16. {
  17. if (CustomOperatingSystem.HasValue)
  18. {
  19. return CustomOperatingSystem.Value;
  20. }
  21. #if NET46
  22. switch (Environment.OSVersion.Platform)
  23. {
  24. case PlatformID.MacOSX:
  25. return MediaBrowser.Model.System.OperatingSystem.OSX;
  26. case PlatformID.Win32NT:
  27. return MediaBrowser.Model.System.OperatingSystem.Windows;
  28. case PlatformID.Unix:
  29. return MediaBrowser.Model.System.OperatingSystem.Linux;
  30. }
  31. #elif NETSTANDARD1_6
  32. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  33. {
  34. return OperatingSystem.OSX;
  35. }
  36. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  37. {
  38. return OperatingSystem.Windows;
  39. }
  40. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  41. {
  42. return OperatingSystem.Linux;
  43. }
  44. #endif
  45. return MediaBrowser.Model.System.OperatingSystem.Windows;
  46. }
  47. }
  48. public string OperatingSystemName
  49. {
  50. get
  51. {
  52. #if NET46
  53. return Environment.OSVersion.Platform.ToString();
  54. #elif NETSTANDARD1_6
  55. return System.Runtime.InteropServices.RuntimeInformation.OSDescription;
  56. #endif
  57. return "Operating System";
  58. }
  59. }
  60. public string OperatingSystemVersion
  61. {
  62. get
  63. {
  64. #if NET46
  65. return Environment.OSVersion.Version.ToString() + " " + Environment.OSVersion.ServicePack.ToString();
  66. #elif NETSTANDARD1_6
  67. return System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
  68. #endif
  69. return "1.0";
  70. }
  71. }
  72. public MediaBrowser.Model.System.Architecture SystemArchitecture
  73. {
  74. get
  75. {
  76. if (CustomArchitecture.HasValue)
  77. {
  78. return CustomArchitecture.Value;
  79. }
  80. #if NET46
  81. return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86;
  82. #elif NETSTANDARD1_6
  83. switch(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture)
  84. {
  85. case System.Runtime.InteropServices.Architecture.Arm:
  86. return MediaBrowser.Model.System.Architecture.Arm;
  87. case System.Runtime.InteropServices.Architecture.Arm64:
  88. return MediaBrowser.Model.System.Architecture.Arm64;
  89. case System.Runtime.InteropServices.Architecture.X64:
  90. return MediaBrowser.Model.System.Architecture.X64;
  91. case System.Runtime.InteropServices.Architecture.X86:
  92. return MediaBrowser.Model.System.Architecture.X86;
  93. }
  94. #endif
  95. return MediaBrowser.Model.System.Architecture.X64;
  96. }
  97. }
  98. public string GetEnvironmentVariable(string name)
  99. {
  100. return Environment.GetEnvironmentVariable(name);
  101. }
  102. public virtual string GetUserId()
  103. {
  104. return null;
  105. }
  106. public string StackTrace
  107. {
  108. get { return Environment.StackTrace; }
  109. }
  110. public void SetProcessEnvironmentVariable(string name, string value)
  111. {
  112. Environment.SetEnvironmentVariable(name, value);
  113. }
  114. }
  115. }