Skip to content

Commit

Permalink
Fix: Fixed issue where the System version of VS Code wasn't detected (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo authored Jun 29, 2023
1 parent 431cc4d commit b3736d8
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/Files.App/Helpers/SoftwareHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,35 @@ internal static class SoftwareHelpers
public static bool IsVSCodeInstalled()
{
string registryKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
string vsCodeName = "Microsoft Visual Studio Code";

var key = Registry.CurrentUser.OpenSubKey(registryKey);
return
ContainsName(Registry.CurrentUser.OpenSubKey(registryKey), vsCodeName) ||
ContainsName(Registry.LocalMachine.OpenSubKey(registryKey), vsCodeName);
}

public static bool IsVSInstalled()
{
string registryKey = @"SOFTWARE\Microsoft\VisualStudio";

var key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key is null)
return false;

string? displayName;
key.Close();

return true;
}

private static bool ContainsName(RegistryKey? key, string find)
{
if (key is null)
return false;

foreach (var subKey in key.GetSubKeyNames().Select(key.OpenSubKey))
{
displayName = subKey?.GetValue("DisplayName") as string;
if (!string.IsNullOrWhiteSpace(displayName) && displayName.StartsWith("Microsoft Visual Studio Code"))
var displayName = subKey?.GetValue("DisplayName") as string;
if (!string.IsNullOrWhiteSpace(displayName) && displayName.StartsWith(find))
{
key.Close();

Expand All @@ -32,18 +50,5 @@ public static bool IsVSCodeInstalled()

return false;
}

public static bool IsVSInstalled()
{
string registryKey = @"SOFTWARE\Microsoft\VisualStudio";

var key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key is null)
return false;

key.Close();

return true;
}
}
}

0 comments on commit b3736d8

Please sign in to comment.