aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/EnvironmentInfo/EnvironmentInfo.cs
blob: ad6e35700b625d6e6226d3886af68f56c895b8cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using MediaBrowser.Model.System;

namespace Emby.Common.Implementations.EnvironmentInfo
{
    public class EnvironmentInfo : IEnvironmentInfo
    {
        public MediaBrowser.Model.System.Architecture? CustomArchitecture { get; set; }
        public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; }

        public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem
        {
            get
            {
                if (CustomOperatingSystem.HasValue)
                {
                    return CustomOperatingSystem.Value;
                }

#if NET46
                switch (Environment.OSVersion.Platform)
                {
                    case PlatformID.MacOSX:
                        return MediaBrowser.Model.System.OperatingSystem.OSX;
                    case PlatformID.Win32NT:
                        return MediaBrowser.Model.System.OperatingSystem.Windows;
                    case PlatformID.Unix:
                        return MediaBrowser.Model.System.OperatingSystem.Linux;
                }
#elif NETSTANDARD1_6
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    return OperatingSystem.OSX;
                }
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    return OperatingSystem.Windows;
                }
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    return OperatingSystem.Linux;
                }
#endif
                return MediaBrowser.Model.System.OperatingSystem.Windows;
            }
        }

        public string OperatingSystemName
        {
            get
            {
#if NET46
                return Environment.OSVersion.Platform.ToString();
#elif NETSTANDARD1_6
            return System.Runtime.InteropServices.RuntimeInformation.OSDescription;
#endif
                return "Operating System";
            }
        }

        public string OperatingSystemVersion
        {
            get
            {
#if NET46
                return Environment.OSVersion.Version.ToString() + " " + Environment.OSVersion.ServicePack.ToString();
#elif NETSTANDARD1_6
            return System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
#endif
                return "1.0";
            }
        }

        public char PathSeparator
        {
            get
            {
                return Path.PathSeparator;
            }
        }

        public MediaBrowser.Model.System.Architecture SystemArchitecture
        {
            get
            {
                if (CustomArchitecture.HasValue)
                {
                    return CustomArchitecture.Value;
                }
#if NET46
                return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86;
#elif NETSTANDARD1_6
                switch(System.Runtime.InteropServices.RuntimeInformation.OSArchitecture)
                {
                    case System.Runtime.InteropServices.Architecture.Arm:
                        return MediaBrowser.Model.System.Architecture.Arm;
                    case System.Runtime.InteropServices.Architecture.Arm64:
                        return MediaBrowser.Model.System.Architecture.Arm64;
                    case System.Runtime.InteropServices.Architecture.X64:
                        return MediaBrowser.Model.System.Architecture.X64;
                    case System.Runtime.InteropServices.Architecture.X86:
                        return MediaBrowser.Model.System.Architecture.X86;
                }
#endif
                return MediaBrowser.Model.System.Architecture.X64;
            }
        }

        public string GetEnvironmentVariable(string name)
        {
            return Environment.GetEnvironmentVariable(name);
        }

        public virtual string GetUserId()
        {
            return null;
        }

        public string StackTrace
        {
            get { return Environment.StackTrace; }
        }

        public void SetProcessEnvironmentVariable(string name, string value)
        {
            Environment.SetEnvironmentVariable(name, value);
        }
    }
}