blob: 6de79a85cd3f006cb6c8725d2d447d2830d2b16c (
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
|
using System;
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Toolkit.Framework;
namespace StardewModdingAPI.Toolkit.Utilities
{
/// <summary>Provides methods for fetching environment information.</summary>
public static class EnvironmentUtility
{
/*********
** Fields
*********/
/// <summary>The cached platform.</summary>
private static Platform? CachedPlatform;
/*********
** Public methods
*********/
/// <summary>Detect the current OS.</summary>
public static Platform DetectPlatform()
{
Platform? platform = EnvironmentUtility.CachedPlatform;
if (platform == null)
{
string rawPlatform = LowLevelEnvironmentUtility.DetectPlatform();
EnvironmentUtility.CachedPlatform = platform = (Platform)Enum.Parse(typeof(Platform), rawPlatform, ignoreCase: true);
}
return platform.Value;
}
/// <summary>Get the human-readable OS name and version.</summary>
/// <param name="platform">The current platform.</param>
[SuppressMessage("ReSharper", "EmptyGeneralCatchClause", Justification = "Error suppressed deliberately to fallback to default behaviour.")]
public static string GetFriendlyPlatformName(Platform platform)
{
return LowLevelEnvironmentUtility.GetFriendlyPlatformName(platform.ToString());
}
/// <summary>Get the name of the Stardew Valley executable.</summary>
/// <param name="platform">The current platform.</param>
public static string GetExecutableName(Platform platform)
{
return LowLevelEnvironmentUtility.GetExecutableName(platform.ToString());
}
/// <summary>Get whether an executable is 64-bit.</summary>
/// <param name="path">The absolute path to the assembly file.</param>
public static bool Is64BitAssembly(string path)
{
return LowLevelEnvironmentUtility.Is64BitAssembly(path);
}
}
}
|