summaryrefslogtreecommitdiff
path: root/modules/mono/editor/GodotTools
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-11-10 17:10:38 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-11-13 21:41:11 +0100
commitde7c2ad21b4cc2d889a5aeda64ead962036d2aa4 (patch)
tree4229e2596bff84d556ec42587918c4b60221b7e1 /modules/mono/editor/GodotTools
parent14e52f7aeea449dc6cfa8861657b2e23cc34c560 (diff)
Mono/C#: WebAssembly support
Diffstat (limited to 'modules/mono/editor/GodotTools')
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs211
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs11
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs197
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs2
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs6
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs76
8 files changed, 272 insertions, 235 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
index eb2c2dd77c..b7e773ee88 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
@@ -91,7 +91,7 @@ namespace GodotTools.Build
{
var result = new List<string>();
- if (OS.IsOSX())
+ if (OS.IsOSX)
{
result.Add("/Library/Frameworks/Mono.framework/Versions/Current/bin/");
result.Add("/usr/local/var/homebrew/linked/mono/bin/");
diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
new file mode 100644
index 0000000000..6b8b1a3cee
--- /dev/null
+++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
@@ -0,0 +1,211 @@
+using Godot;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using GodotTools.Core;
+using GodotTools.Internals;
+using Directory = GodotTools.Utils.Directory;
+using File = GodotTools.Utils.File;
+using OS = GodotTools.Utils.OS;
+using Path = System.IO.Path;
+
+namespace GodotTools.Export
+{
+ public class ExportPlugin : EditorExportPlugin
+ {
+ private void AddFile(string srcPath, string dstPath, bool remap = false)
+ {
+ AddFile(dstPath, File.ReadAllBytes(srcPath), remap);
+ }
+
+ public override void _ExportFile(string path, string type, string[] features)
+ {
+ base._ExportFile(path, type, features);
+
+ if (type != Internal.CSharpLanguageType)
+ return;
+
+ if (Path.GetExtension(path) != $".{Internal.CSharpLanguageExtension}")
+ throw new ArgumentException($"Resource of type {Internal.CSharpLanguageType} has an invalid file extension: {path}", nameof(path));
+
+ // TODO What if the source file is not part of the game's C# project
+
+ bool includeScriptsContent = (bool) ProjectSettings.GetSetting("mono/export/include_scripts_content");
+
+ if (!includeScriptsContent)
+ {
+ // We don't want to include the source code on exported games
+ AddFile(path, new byte[] { }, remap: false);
+ Skip();
+ }
+ }
+
+ public override void _ExportBegin(string[] features, bool isDebug, string path, int flags)
+ {
+ base._ExportBegin(features, isDebug, path, flags);
+
+ try
+ {
+ _ExportBeginImpl(features, isDebug, path, flags);
+ // TODO: Handle _ExportBeginImpl return value. Do something on error once _ExportBegin supports failing.
+ }
+ catch (Exception e)
+ {
+ GD.PushError($"Failed to export project: {e.Message}");
+ Console.Error.WriteLine(e);
+ // TODO: Do something on error once _ExportBegin supports failing.
+ }
+ }
+
+ private bool _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
+ {
+ if (!File.Exists(GodotSharpDirs.ProjectSlnPath))
+ return true;
+
+ string platform = DeterminePlatformFromFeatures(features);
+
+ if (platform == null)
+ throw new NotSupportedException("Target platform not supported");
+
+ // TODO Right now there is no way to stop the export process with an error
+
+ string buildConfig = isDebug ? "Debug" : "Release";
+
+ string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");
+ CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);
+
+ AddFile(scriptsMetadataPath, scriptsMetadataPath);
+
+ // Turn export features into defines
+ var godotDefines = features;
+
+ if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines))
+ {
+ GD.PushError("Failed to build project");
+ return false;
+ }
+
+ // Add dependency assemblies
+
+ var dependencies = new Godot.Collections.Dictionary<string, string>();
+
+ var projectDllName = (string) ProjectSettings.GetSetting("application/config/name");
+ if (projectDllName.Empty())
+ {
+ projectDllName = "UnnamedProject";
+ }
+
+ string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
+ string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");
+
+ dependencies[projectDllName] = projectDllSrcPath;
+
+ {
+ string templatesDir = Internal.FullTemplatesDir;
+ string platformBclDir = Path.Combine(templatesDir, $"{platform}-bcl", platform);
+
+ string customBclDir = Directory.Exists(platformBclDir) ? platformBclDir : string.Empty;
+
+ internal_GetExportedAssemblyDependencies(projectDllName, projectDllSrcPath, buildConfig, customBclDir, dependencies);
+ }
+
+ string apiConfig = isDebug ? "Debug" : "Release";
+ string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig);
+
+ foreach (var dependency in dependencies)
+ {
+ string dependSrcPath = dependency.Value;
+ string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile());
+ AddFile(dependSrcPath, dependDstPath);
+ }
+
+ // Mono specific export template extras (data dir)
+ ExportDataDirectory(features, platform, isDebug, path);
+
+ return true;
+ }
+
+ private static void ExportDataDirectory(ICollection<string> features, string platform, bool debug, string path)
+ {
+ if (!PlatformHasTemplateDir(platform))
+ return;
+
+ string bits = features.Contains("64") ? "64" : "32";
+ string target = debug ? "release_debug" : "release";
+
+ string TemplateDirName() => $"data.mono.{platform}.{bits}.{target}";
+
+ string templateDirPath = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());
+
+ if (!Directory.Exists(templateDirPath))
+ {
+ templateDirPath = null;
+
+ if (debug)
+ {
+ target = "debug"; // Support both 'release_debug' and 'debug' for the template data directory name
+ templateDirPath = Path.Combine(Internal.FullTemplatesDir, TemplateDirName());
+
+ if (!Directory.Exists(templateDirPath))
+ templateDirPath = null;
+ }
+ }
+
+ if (templateDirPath == null)
+ throw new FileNotFoundException("Data template directory not found");
+
+ string outputDir = new FileInfo(path).Directory?.FullName ??
+ throw new FileNotFoundException("Base directory not found");
+
+ string outputDataDir = Path.Combine(outputDir, DataDirName);
+
+ if (Directory.Exists(outputDataDir))
+ Directory.Delete(outputDataDir, recursive: true); // Clean first
+
+ Directory.CreateDirectory(outputDataDir);
+
+ foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
+ {
+ Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
+ }
+
+ foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
+ {
+ File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
+ }
+ }
+
+ private static bool PlatformHasTemplateDir(string platform)
+ {
+ // OSX export templates are contained in a zip, so we place our custom template inside it and let Godot do the rest.
+ return !new[] {OS.Platforms.OSX, OS.Platforms.Android, OS.Platforms.HTML5}.Contains(platform);
+ }
+
+ private static string DeterminePlatformFromFeatures(IEnumerable<string> features)
+ {
+ foreach (var feature in features)
+ {
+ if (OS.PlatformNameMap.TryGetValue(feature, out string platform))
+ return platform;
+ }
+
+ return null;
+ }
+
+ private static string DataDirName
+ {
+ get
+ {
+ var appName = (string) ProjectSettings.GetSetting("application/config/name");
+ string appNameSafe = appName.ToSafeDirName(allowDirSeparator: false);
+ return $"data_{appNameSafe}";
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ private static extern void internal_GetExportedAssemblyDependencies(string projectDllName, string projectDllSrcPath,
+ string buildConfig, string customBclDir, Godot.Collections.Dictionary<string, string> dependencies);
+ }
+}
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
index 12edd651df..3ef23761a7 100644
--- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs
@@ -1,4 +1,5 @@
using Godot;
+using GodotTools.Export;
using GodotTools.Utils;
using System;
using System.Collections.Generic;
@@ -225,7 +226,7 @@ namespace GodotTools
bool osxAppBundleInstalled = false;
- if (OS.IsOSX())
+ if (OS.IsOSX)
{
// The package path is '/Applications/Visual Studio Code.app'
const string vscodeBundleId = "com.microsoft.VSCode";
@@ -265,7 +266,7 @@ namespace GodotTools
string command;
- if (OS.IsOSX())
+ if (OS.IsOSX)
{
if (!osxAppBundleInstalled && _vsCodePath.Empty())
{
@@ -420,7 +421,7 @@ namespace GodotTools
settingsHintStr += $",MonoDevelop:{(int) ExternalEditorId.MonoDevelop}" +
$",Visual Studio Code:{(int) ExternalEditorId.VsCode}";
}
- else if (OS.IsOSX())
+ else if (OS.IsOSX)
{
settingsHintStr += $",Visual Studio:{(int) ExternalEditorId.VisualStudioForMac}" +
$",MonoDevelop:{(int) ExternalEditorId.MonoDevelop}" +
@@ -441,7 +442,7 @@ namespace GodotTools
});
// Export plugin
- var exportPlugin = new GodotSharpExport();
+ var exportPlugin = new ExportPlugin();
AddExportPlugin(exportPlugin);
exportPluginWeak = WeakRef(exportPlugin);
@@ -461,7 +462,7 @@ namespace GodotTools
// Otherwise, if the GC disposes it at a later time, EditorExportPlatformAndroid
// will be freed after EditorSettings already was, and its device polling thread
// will try to access the EditorSettings singleton, resulting in null dereferencing.
- (exportPluginWeak.GetRef() as GodotSharpExport)?.Dispose();
+ (exportPluginWeak.GetRef() as ExportPlugin)?.Dispose();
exportPluginWeak.Dispose();
}
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs
deleted file mode 100644
index 4f93ef8530..0000000000
--- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpExport.cs
+++ /dev/null
@@ -1,197 +0,0 @@
-using Godot;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using GodotTools.Core;
-using GodotTools.Internals;
-using Directory = GodotTools.Utils.Directory;
-using File = GodotTools.Utils.File;
-using Path = System.IO.Path;
-
-namespace GodotTools
-{
- public class GodotSharpExport : EditorExportPlugin
- {
- private void AddFile(string srcPath, string dstPath, bool remap = false)
- {
- AddFile(dstPath.Replace("\\", "/"), File.ReadAllBytes(srcPath), remap);
- }
-
- public override void _ExportFile(string path, string type, string[] features)
- {
- base._ExportFile(path, type, features);
-
- if (type != Internal.CSharpLanguageType)
- return;
-
- if (Path.GetExtension(path) != $".{Internal.CSharpLanguageExtension}")
- throw new ArgumentException($"Resource of type {Internal.CSharpLanguageType} has an invalid file extension: {path}", nameof(path));
-
- // TODO What if the source file is not part of the game's C# project
-
- bool includeScriptsContent = (bool) ProjectSettings.GetSetting("mono/export/include_scripts_content");
-
- if (!includeScriptsContent)
- {
- // We don't want to include the source code on exported games
- AddFile(path, new byte[] { }, remap: false);
- Skip();
- }
- }
-
- public override void _ExportBegin(string[] features, bool isDebug, string path, int flags)
- {
- base._ExportBegin(features, isDebug, path, flags);
-
- try
- {
- _ExportBeginImpl(features, isDebug, path, flags);
- }
- catch (Exception e)
- {
- GD.PushError($"Failed to export project. Exception message: {e.Message}");
- Console.Error.WriteLine(e);
- }
- }
-
- public void _ExportBeginImpl(string[] features, bool isDebug, string path, int flags)
- {
- // TODO Right now there is no way to stop the export process with an error
-
- if (File.Exists(GodotSharpDirs.ProjectSlnPath))
- {
- string buildConfig = isDebug ? "Debug" : "Release";
-
- string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}");
- CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath);
-
- AddFile(scriptsMetadataPath, scriptsMetadataPath);
-
- // Turn export features into defines
- var godotDefines = features;
-
- if (!BuildManager.BuildProjectBlocking(buildConfig, godotDefines))
- {
- GD.PushError("Failed to build project");
- return;
- }
-
- // Add dependency assemblies
-
- var dependencies = new Godot.Collections.Dictionary<string, string>();
-
- var projectDllName = (string) ProjectSettings.GetSetting("application/config/name");
- if (projectDllName.Empty())
- {
- projectDllName = "UnnamedProject";
- }
-
- string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
- string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");
-
- dependencies[projectDllName] = projectDllSrcPath;
-
- {
- string templatesDir = Internal.FullTemplatesDir;
- string androidBclDir = Path.Combine(templatesDir, "android-bcl");
-
- string customLibDir = features.Contains("Android") && Directory.Exists(androidBclDir) ? androidBclDir : string.Empty;
-
- GetExportedAssemblyDependencies(projectDllName, projectDllSrcPath, buildConfig, customLibDir, dependencies);
- }
-
- string apiConfig = isDebug ? "Debug" : "Release";
- string resAssembliesDir = Path.Combine(GodotSharpDirs.ResAssembliesBaseDir, apiConfig);
-
- foreach (var dependency in dependencies)
- {
- string dependSrcPath = dependency.Value;
- string dependDstPath = Path.Combine(resAssembliesDir, dependSrcPath.GetFile());
- AddFile(dependSrcPath, dependDstPath);
- }
- }
-
- // Mono specific export template extras (data dir)
- ExportDataDirectory(features, isDebug, path);
- }
-
- private static void ExportDataDirectory(IEnumerable<string> features, bool debug, string path)
- {
- var featureSet = new HashSet<string>(features);
-
- if (!PlatformHasTemplateDir(featureSet))
- return;
-
- string templateDirName = "data.mono";
-
- if (featureSet.Contains("Windows"))
- {
- templateDirName += ".windows";
- templateDirName += featureSet.Contains("64") ? ".64" : ".32";
- }
- else if (featureSet.Contains("X11"))
- {
- templateDirName += ".x11";
- templateDirName += featureSet.Contains("64") ? ".64" : ".32";
- }
- else
- {
- throw new NotSupportedException("Target platform not supported");
- }
-
- templateDirName += debug ? ".release_debug" : ".release";
-
- string templateDirPath = Path.Combine(Internal.FullTemplatesDir, templateDirName);
-
- if (!Directory.Exists(templateDirPath))
- throw new FileNotFoundException("Data template directory not found");
-
- string outputDir = new FileInfo(path).Directory?.FullName ??
- throw new FileNotFoundException("Base directory not found");
-
- string outputDataDir = Path.Combine(outputDir, DataDirName);
-
- if (Directory.Exists(outputDataDir))
- Directory.Delete(outputDataDir, recursive: true); // Clean first
-
- Directory.CreateDirectory(outputDataDir);
-
- foreach (string dir in Directory.GetDirectories(templateDirPath, "*", SearchOption.AllDirectories))
- {
- Directory.CreateDirectory(Path.Combine(outputDataDir, dir.Substring(templateDirPath.Length + 1)));
- }
-
- foreach (string file in Directory.GetFiles(templateDirPath, "*", SearchOption.AllDirectories))
- {
- File.Copy(file, Path.Combine(outputDataDir, file.Substring(templateDirPath.Length + 1)));
- }
- }
-
- private static bool PlatformHasTemplateDir(IEnumerable<string> featureSet)
- {
- // OSX export templates are contained in a zip, so we place
- // our custom template inside it and let Godot do the rest.
- return !featureSet.Any(f => new[] {"OSX", "Android"}.Contains(f));
- }
-
- private static string DataDirName
- {
- get
- {
- var appName = (string) ProjectSettings.GetSetting("application/config/name");
- string appNameSafe = appName.ToSafeDirName(allowDirSeparator: false);
- return $"data_{appNameSafe}";
- }
- }
-
- private static void GetExportedAssemblyDependencies(string projectDllName, string projectDllSrcPath,
- string buildConfig, string customLibDir, Godot.Collections.Dictionary<string, string> dependencies) =>
- internal_GetExportedAssemblyDependencies(projectDllName, projectDllSrcPath, buildConfig, customLibDir, dependencies);
-
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void internal_GetExportedAssemblyDependencies(string projectDllName, string projectDllSrcPath,
- string buildConfig, string customLibDir, Godot.Collections.Dictionary<string, string> dependencies);
- }
-}
diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj
index 3c57900873..d0c78d095b 100644
--- a/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj
+++ b/modules/mono/editor/GodotTools/GodotTools/GodotTools.csproj
@@ -40,6 +40,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Build\MsBuildFinder.cs" />
+ <Compile Include="Export\ExportPlugin.cs" />
<Compile Include="ExternalEditorId.cs" />
<Compile Include="Ides\GodotIdeManager.cs" />
<Compile Include="Ides\GodotIdeServer.cs" />
@@ -63,7 +64,6 @@
<Compile Include="BuildInfo.cs" />
<Compile Include="BuildTab.cs" />
<Compile Include="BottomPanel.cs" />
- <Compile Include="GodotSharpExport.cs" />
<Compile Include="CsProjOperations.cs" />
<Compile Include="Utils\CollectionExtensions.cs" />
</ItemGroup>
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
index 01aa0d0ab1..f94d6f998c 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/GodotIdeManager.cs
@@ -79,7 +79,7 @@ namespace GodotTools.Ides
{
MonoDevelop.Instance GetMonoDevelopInstance(string solutionPath)
{
- if (Utils.OS.IsOSX() && editor == ExternalEditorId.VisualStudioForMac)
+ if (Utils.OS.IsOSX && editor == ExternalEditorId.VisualStudioForMac)
{
vsForMacInstance = vsForMacInstance ??
new MonoDevelop.Instance(solutionPath, MonoDevelop.EditorId.VisualStudioForMac);
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
index 1fdccf5bbd..2d9734c5ed 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/MonoDevelop/Instance.cs
@@ -24,7 +24,7 @@ namespace GodotTools.Ides.MonoDevelop
string command;
- if (OS.IsOSX())
+ if (OS.IsOSX)
{
string bundleId = BundleIds[editorId];
@@ -81,7 +81,7 @@ namespace GodotTools.Ides.MonoDevelop
public Instance(string solutionFile, EditorId editorId)
{
- if (editorId == EditorId.VisualStudioForMac && !OS.IsOSX())
+ if (editorId == EditorId.VisualStudioForMac && !OS.IsOSX)
throw new InvalidOperationException($"{nameof(EditorId.VisualStudioForMac)} not supported on this platform");
this.solutionFile = solutionFile;
@@ -93,7 +93,7 @@ namespace GodotTools.Ides.MonoDevelop
static Instance()
{
- if (OS.IsOSX())
+ if (OS.IsOSX)
{
ExecutableNames = new Dictionary<EditorId, string>
{
diff --git a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
index e48b1115db..f0cb8200e5 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
@@ -1,56 +1,78 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
namespace GodotTools.Utils
{
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
public static class OS
{
[MethodImpl(MethodImplOptions.InternalCall)]
- extern static string GetPlatformName();
+ static extern string GetPlatformName();
- const string HaikuName = "Haiku";
- const string OSXName = "OSX";
- const string ServerName = "Server";
- const string UWPName = "UWP";
- const string WindowsName = "Windows";
- const string X11Name = "X11";
-
- public static bool IsHaiku()
+ public static class Names
{
- return HaikuName.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
+ public const string Windows = "Windows";
+ public const string OSX = "OSX";
+ public const string X11 = "X11";
+ public const string Server = "Server";
+ public const string UWP = "UWP";
+ public const string Haiku = "Haiku";
+ public const string Android = "Android";
+ public const string HTML5 = "HTML5";
}
- public static bool IsOSX()
+ public static class Platforms
{
- return OSXName.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
+ public const string Windows = "windows";
+ public const string OSX = "osx";
+ public const string X11 = "x11";
+ public const string Server = "server";
+ public const string UWP = "uwp";
+ public const string Haiku = "haiku";
+ public const string Android = "android";
+ public const string HTML5 = "javascript";
}
- public static bool IsServer()
+ public static readonly Dictionary<string, string> PlatformNameMap = new Dictionary<string, string>
{
- return ServerName.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
- }
-
- public static bool IsUWP()
+ [Names.Windows] = Platforms.Windows,
+ [Names.OSX] = Platforms.OSX,
+ [Names.X11] = Platforms.X11,
+ [Names.Server] = Platforms.Server,
+ [Names.UWP] = Platforms.UWP,
+ [Names.Haiku] = Platforms.Haiku,
+ [Names.Android] = Platforms.Android,
+ [Names.HTML5] = Platforms.HTML5
+ };
+
+ private static bool IsOS(string name)
{
- return UWPName.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
+ return name.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
}
- public static bool IsWindows()
- {
- return WindowsName.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
- }
+ public static bool IsWindows() => IsOS(Names.Windows);
- public static bool IsX11()
- {
- return X11Name.Equals(GetPlatformName(), StringComparison.OrdinalIgnoreCase);
- }
+ public static bool IsOSX => IsOS(Names.OSX);
+
+ public static bool IsX11 => IsOS(Names.X11);
+
+ public static bool IsServer => IsOS(Names.Server);
+
+ public static bool IsUWP => IsOS(Names.UWP);
+
+ public static bool IsHaiku => IsOS(Names.Haiku);
+
+ public static bool IsAndroid => IsOS(Names.Android);
+
+ public static bool IsHTML5 => IsOS(Names.HTML5);
private static bool? _isUnixCache;
- private static readonly string[] UnixPlatforms = {HaikuName, OSXName, ServerName, X11Name};
+ private static readonly string[] UnixPlatforms = {Names.OSX, Names.X11, Names.Server, Names.Haiku, Names.Android};
public static bool IsUnix()
{