EnvironmentInfo.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 OperatingSystem
  13. {
  14. get
  15. {
  16. #if NET46
  17. switch (Environment.OSVersion.Platform)
  18. {
  19. case PlatformID.MacOSX:
  20. return MediaBrowser.Model.System.OperatingSystem.OSX;
  21. case PlatformID.Win32NT:
  22. return MediaBrowser.Model.System.OperatingSystem.Windows;
  23. case PlatformID.Unix:
  24. return MediaBrowser.Model.System.OperatingSystem.Linux;
  25. }
  26. #elif NETSTANDARD1_6
  27. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  28. {
  29. return OperatingSystem.OSX;
  30. }
  31. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  32. {
  33. return OperatingSystem.Windows;
  34. }
  35. if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  36. {
  37. return OperatingSystem.Linux;
  38. }
  39. #endif
  40. return MediaBrowser.Model.System.OperatingSystem.Windows;
  41. }
  42. }
  43. public string OperatingSystemName
  44. {
  45. get
  46. {
  47. #if NET46
  48. return Environment.OSVersion.Platform.ToString();
  49. #elif NETSTANDARD1_6
  50. return System.Runtime.InteropServices.RuntimeInformation.OSDescription;
  51. #endif
  52. return "Operating System";
  53. }
  54. }
  55. public string OperatingSystemVersion
  56. {
  57. get
  58. {
  59. #if NET46
  60. return Environment.OSVersion.Version.ToString() + " " + Environment.OSVersion.ServicePack.ToString();
  61. #elif NETSTANDARD1_6
  62. return System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
  63. #endif
  64. return "1.0";
  65. }
  66. }
  67. public MediaBrowser.Model.System.Architecture SystemArchitecture
  68. {
  69. get
  70. {
  71. if (CustomArchitecture.HasValue)
  72. {
  73. return CustomArchitecture.Value;
  74. }
  75. #if NET46
  76. return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86;
  77. #elif NETSTANDARD1_6
  78. switch(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture)
  79. {
  80. case System.Runtime.InteropServices.Architecture.Arm:
  81. return MediaBrowser.Model.System.Architecture.Arm;
  82. case System.Runtime.InteropServices.Architecture.Arm64:
  83. return MediaBrowser.Model.System.Architecture.Arm64;
  84. case System.Runtime.InteropServices.Architecture.X64:
  85. return MediaBrowser.Model.System.Architecture.X64;
  86. case System.Runtime.InteropServices.Architecture.X86:
  87. return MediaBrowser.Model.System.Architecture.X86;
  88. }
  89. #endif
  90. return MediaBrowser.Model.System.Architecture.X64;
  91. }
  92. }
  93. }
  94. }