forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.cs
More file actions
131 lines (105 loc) · 5.08 KB
/
Env.cs
File metadata and controls
131 lines (105 loc) · 5.08 KB
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
//Copyright (c) Service Stack LLC. All Rights Reserved.
//License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
using System;
using System.Globalization;
using System.IO;
namespace ServiceStack.Text
{
public static class Env
{
static Env()
{
if (PclExport.Instance == null)
throw new ArgumentException("PclExport.Instance needs to be initialized");
var platformName = PclExport.Instance.PlatformName;
if (platformName != PclExport.Platforms.WindowsStore)
{
IsMono = AssemblyUtils.FindType("Mono.Runtime") != null;
IsMonoTouch = AssemblyUtils.FindType("MonoTouch.Foundation.NSObject") != null
|| AssemblyUtils.FindType("Foundation.NSObject") != null;
IsAndroid = AssemblyUtils.FindType("Android.Manifest") != null;
//Throws unhandled exception if not called from the main thread
//IsWinRT = AssemblyUtils.FindType("Windows.ApplicationModel") != null;
IsWindowsPhone = AssemblyUtils.FindType("Microsoft.Phone.Info.DeviceStatus") != null;
IsSilverlight = AssemblyUtils.FindType("System.Windows.Interop.SilverlightHost") != null;
}
else
{
IsWindowsStore = true;
}
#if PCL || NETSTANDARD1_1
IsUnix = IsMono;
#else
var platform = (int)Environment.OSVersion.Platform;
IsUnix = (platform == 4) || (platform == 6) || (platform == 128);
#endif
ServerUserAgent = "ServiceStack/" +
ServiceStackVersion + " "
+ platformName
+ (IsMono ? "/Mono" : "/.NET");
VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);
__releaseDate = new DateTime(2001,01,01);
}
public static string VersionString { get; set; }
public static decimal ServiceStackVersion = 4.00m;
public static bool IsUnix { get; set; }
public static bool IsMono { get; set; }
public static bool IsMonoTouch { get; set; }
public static bool IsAndroid { get; set; }
public static bool IsWindowsStore { get; set; }
public static bool IsSilverlight { get; set; }
public static bool IsWindowsPhone { get; set; }
public static bool SupportsExpressions { get; set; }
public static bool SupportsEmit { get; set; }
public static string ServerUserAgent { get; set; }
private static readonly DateTime __releaseDate;
public static DateTime GetReleaseDate()
{
return __releaseDate;
}
private static string referenceAssembyPath;
public static string ReferenceAssembyPath
{
get
{
#if !SL5
if (!IsMono && referenceAssembyPath == null)
{
var programFilesPath = PclExport.Instance.GetEnvironmentVariable("ProgramFiles(x86)") ?? @"C:\Program Files (x86)";
var netFxReferenceBasePath = programFilesPath + @"\Reference Assemblies\Microsoft\Framework\.NETFramework\";
if ((netFxReferenceBasePath + @"v4.5.2\").DirectoryExists())
referenceAssembyPath = netFxReferenceBasePath + @"v4.5.2\";
else if ((netFxReferenceBasePath + @"v4.5.1\").DirectoryExists())
referenceAssembyPath = netFxReferenceBasePath + @"v4.5.1\";
else if ((netFxReferenceBasePath + @"v4.5\").DirectoryExists())
referenceAssembyPath = netFxReferenceBasePath + @"v4.5\";
else if ((netFxReferenceBasePath + @"v4.0\").DirectoryExists())
referenceAssembyPath = netFxReferenceBasePath + @"v4.0\";
else
{
var v4Dirs = PclExport.Instance.GetDirectoryNames(netFxReferenceBasePath, "v4*");
if (v4Dirs.Length == 0)
{
var winPath = PclExport.Instance.GetEnvironmentVariable("SYSTEMROOT") ?? @"C:\Windows";
var gacPath = winPath + @"\Microsoft.NET\Framework\";
v4Dirs = PclExport.Instance.GetDirectoryNames(gacPath, "v4*");
}
if (v4Dirs.Length > 0)
{
referenceAssembyPath = v4Dirs[v4Dirs.Length - 1] + @"\"; //latest v4
}
else
{
throw new FileNotFoundException(
"Could not infer .NET Reference Assemblies path, e.g '{0}'.\n".Fmt(netFxReferenceBasePath + @"v4.0\") +
"Provide path manually 'Env.ReferenceAssembyPath'.");
}
}
}
#endif
return referenceAssembyPath;
}
set { referenceAssembyPath = value; }
}
}
}