// Copyright (c) 2012-2020 Flax Engine. All rights reserved. using System.IO; using Flax.Build.Platforms; namespace Flax.Build.Projects.VisualStudioCode { /// /// The Visual Studio Code instance utility. /// public sealed class VisualStudioCodeInstance { private static VisualStudioCodeInstance _instance; /// /// The install directory path. /// public string Path; /// /// Determines whether any version of the IDE is installed. /// /// true if any version is installed; otherwise, false. public static bool HasIDE() { return GetInstance() != null; } /// /// Gets the installed Visual Studio instance. /// /// The install location. 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; } } }