forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoftwareHelpers.cs
55 lines (43 loc) · 1.2 KB
/
SoftwareHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.
using Microsoft.Win32;
using System.IO;
namespace Files.App.Helpers
{
internal static class SoftwareHelpers
{
public static bool IsVSCodeInstalled()
{
string registryKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
string vsCodeName = "Microsoft Visual Studio Code";
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;
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))
{
var displayName = subKey?.GetValue("DisplayName") as string;
if (!string.IsNullOrWhiteSpace(displayName) && displayName.StartsWith(find))
{
key.Close();
return true;
}
}
key.Close();
return false;
}
}
}