public RegistryData()
        {
            const string REGISTRY_KEY = @"SOFTWARE\Microsoft";

            MsMachineKey = Registry.LocalMachine.OpenSubKey(REGISTRY_KEY);

            if (MsMachineKey == null)
            {
                NoVisualStudio = true;
                return;
            }

            var vsKeyNames = MsMachineKey
                             .GetSubKeyNames()
                             .Where(sk => sk.StartsWith("VisualStudio", StringComparison.Ordinal))
                             .ToArray();

            if (vsKeyNames.Length == 0)
            {
                NoVisualStudio = true;
                return;
            }

            VsPre2017MachineKey = MsMachineKey.OpenSubKey("VisualStudio");
            VsPre2017KeyNames   = VsPre2017MachineKey?.GetSubKeyNames() ?? new string[0];

            VsPost2015Data = vsKeyNames
                             .Where(kn => kn.StartsWith("VisualStudio_"))
                             .Select(kn => new VsPost2017Data(MsMachineKey.OpenSubKey(kn)))
                             .ToArray();
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            MsMachineKey?.Dispose();
            VsPre2017MachineKey?.Dispose();

            foreach (var vsPost2015DataItem in VsPost2015Data)
            {
                vsPost2015DataItem.Dispose();
            }
        }
Exemplo n.º 3
0
        private void PopulatePre2017InstallPath(
            Visualizer visualizer,
            ICollection <Visualizer> targetVisualizers)
        {
            var pre2017Key = VsPre2017KeyNames
                             .FirstOrDefault(name => name == visualizer.VsFullVersionNumber);

            if (pre2017Key == null)
            {
                return;
            }

            var vsSubKey    = VsPre2017MachineKey.OpenSubKey(pre2017Key);
            var installPath = vsSubKey?.GetValue("InstallDir") as string;

            if (string.IsNullOrWhiteSpace(installPath) || !Directory.Exists(installPath))
            {
                return;
            }

            targetVisualizers.Add(visualizer.With(vsSubKey, installPath));
        }
Exemplo n.º 4
0
        public RegistryData(FileVersionInfo thisAssemblyVersion)
        {
            _thisAssemblyVersion = thisAssemblyVersion;
            const string REGISTRY_KEY = @"SOFTWARE\Microsoft";

            MsMachineKey = Registry.LocalMachine.OpenSubKey(REGISTRY_KEY);

            if (MsMachineKey == null)
            {
                ErrorMessage   = $"Unable to open the '{REGISTRY_KEY}' registry key";
                NoVisualStudio = true;
                return;
            }

            var vsKeyNames = MsMachineKey
                             .GetSubKeyNames()
                             .Where(sk => sk.StartsWith("VisualStudio", StringComparison.Ordinal))
                             .ToArray();

            if (vsKeyNames.Length == 0)
            {
                ErrorMessage   = $@"Unable to find any '{REGISTRY_KEY}\VisualStudio' registry keys from which to determine your Visual Studio install paths";
                NoVisualStudio = true;
                return;
            }

            VsPre2017MachineKey = MsMachineKey.OpenSubKey("VisualStudio");
            VsPre2017KeyNames   = VsPre2017MachineKey?.GetSubKeyNames() ?? new string[0];

            VsPost2015Data = vsKeyNames
                             .Where(kn => kn.StartsWith("VisualStudio_"))
                             .Select(kn => new VsPost2017Data(MsMachineKey.OpenSubKey(kn)))
                             .GroupBy(d => d.InstallPath)
                             .Select(grp => grp.First())
                             .ToArray();
        }