From 987ab9641945f5cec6483567bc0ca7f45c959958 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 3 Nov 2024 16:12:56 +0100 Subject: [PATCH] feature: support Visual Studio external tool on Windows --- README.md | 1 + src/Models/ExternalTool.cs | 5 +++++ src/Native/Windows.cs | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 52383670..44ed5917 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ This app supports open repository in external tools listed in the table below. | JetBrains Fleet | YES | YES | YES | FLEET | | Sublime Text | YES | YES | YES | SUBLIME_TEXT | | Zed | NO | YES | YES | ZED | +| Visual Studio | YES | YES | YES | VISUALSTUDIO | > [!NOTE] > This app will try to find those tools based on some pre-defined or expected locations automatically. If you are using one portable version of these tools, it will not be detected by this app. diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index b26a9a90..50691081 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -154,6 +154,11 @@ namespace SourceGit.Models TryAdd("Zed", "zed", "\"{0}\"", "ZED", platformFinder); } + public void VisualStudio(Func platformFinder) + { + TryAdd("Visual Studio", "vs", "\"{0}\"", "VISUALSTUDIO", platformFinder); + } + public void FindJetBrainsFromToolbox(Func platformFinder) { var exclude = new List { "fleet", "dotmemory", "dottrace", "resharper-u", "androidstudio" }; diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 6ca0bbb0..0563644c 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -134,6 +134,7 @@ namespace SourceGit.Native finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Programs\\Fleet\\Fleet.exe"); finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\JetBrains\\Toolbox"); finder.SublimeText(FindSublimeText); + finder.VisualStudio(FindVisualStudio); return finder.Founded; } @@ -313,6 +314,25 @@ namespace SourceGit.Native return string.Empty; } + + private string FindVisualStudio() + { + var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey( + Microsoft.Win32.RegistryHive.LocalMachine, + Microsoft.Win32.RegistryView.Registry64); + + // Get default class for VisualStudio.Launcher.sln - the handler for *.sln files + if (localMachine.OpenSubKey(@"SOFTWARE\Classes\VisualStudio.Launcher.sln\CLSID") is Microsoft.Win32.RegistryKey launcher) + { + // Get actual path to the executable + if (launcher.GetValue(string.Empty) is string CLSID && localMachine.OpenSubKey(@$"SOFTWARE\Classes\CLSID\{CLSID}\LocalServer32") is Microsoft.Win32.RegistryKey devenv && devenv.GetValue(string.Empty) is string localServer32) + { + return localServer32!.Trim('\"'); + } + } + + return string.Empty; + } #endregion private void OpenFolderAndSelectFile(string folderPath)