EnvironmentInfo.cs 4.4 KB

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