/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Helpers/Environment/SoftwareHelpers.cs
59 строк
1 KB
Filippo Ferrario
Feature: Added an option to change the default IDE (#16730)
26 фев 2025, 23:51
Не верифицирован
26 фев 2025, 23:51
bc3572b
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Microsoft.Win32; using System.Security; namespace Files.App.Helpers { internal static class SoftwareHelpers { private const string UninstallRegistryKey = @"Software\Microsoft\Windows\CurrentVersion\Uninstall"; private const string VsCodeName = "Microsoft Visual Studio Code"; public static bool IsVSCodeInstalled() { try { return ContainsName(Registry.CurrentUser.OpenSubKey(UninstallRegistryKey), VsCodeName) || ContainsName(Registry.LocalMachine.OpenSubKey(UninstallRegistryKey), VsCodeName); } catch (SecurityException) { // Handle edge case where OpenSubKey results in SecurityException return false; } } private static bool ContainsName(RegistryKey? key, string find) { if (key is null) return false; try { 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; } catch (SecurityException) { // Handle edge case where OpenSubKey results in SecurityException return false; } } } }