You're breathtaking!
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2012-2020 Flax Engine. All rights reserved.
|
||||
|
||||
using System.IO;
|
||||
using Flax.Build.Platforms;
|
||||
|
||||
namespace Flax.Build.Projects.VisualStudioCode
|
||||
{
|
||||
/// <summary>
|
||||
/// The Visual Studio Code instance utility.
|
||||
/// </summary>
|
||||
public sealed class VisualStudioCodeInstance
|
||||
{
|
||||
private static VisualStudioCodeInstance _instance;
|
||||
|
||||
/// <summary>
|
||||
/// The install directory path.
|
||||
/// </summary>
|
||||
public string Path;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether any version of the IDE is installed.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if any version is installed; otherwise, <c>false</c>.</returns>
|
||||
public static bool HasIDE()
|
||||
{
|
||||
return GetInstance() != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the installed Visual Studio instance.
|
||||
/// </summary>
|
||||
/// <returns>The install location.</returns>
|
||||
public static VisualStudioCodeInstance GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
switch (Platform.BuildPlatform.Target)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
{
|
||||
if (!WindowsPlatformBase.TryReadDirRegistryKey("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command", string.Empty, out var cmd))
|
||||
{
|
||||
if (!WindowsPlatformBase.TryReadDirRegistryKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Applications\\Code.exe\\shell\\open\\command", string.Empty, out cmd))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var path = cmd.Substring(1, cmd.Length - "\" \"%1\"".Length - 1);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
_instance = new VisualStudioCodeInstance
|
||||
{
|
||||
Path = path,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Linux:
|
||||
{
|
||||
var path = "/usr/bin/code";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
_instance = new VisualStudioCodeInstance
|
||||
{
|
||||
Path = path,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_instance != null)
|
||||
Log.Verbose($"Found VS Code at {_instance.Path}");
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user