-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstalledVersions.cs
64 lines (55 loc) · 1.89 KB
/
InstalledVersions.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
56
57
58
59
60
61
62
63
64
//
// @(#) InstalledVersions.cs
//
// Project: usis.Data.LocalDb
// System: Microsoft Visual Studio 2022
// Author: Udo Schäfer
//
// Copyright (c) 2018-2023 usis GmbH. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Win32;
namespace usis.Data.LocalDb
{
// -----------------------
// InstalledVersions class
// -----------------------
internal static class InstalledVersions
{
// -------------------
// FromRegistry method
// -------------------
internal static IDictionary<Version, string> FromRegistry()
{
var dictionary = new SortedDictionary<Version, string>();
ForEach((name, key) => dictionary.Add(new Version(name), key.GetValue(Constants.RegistryValueName) as string));
return dictionary;
}
// --------------
// ForEach method
// --------------
public static void ForEach(Action<string, RegistryKey> action)
{
ForEachName((parentKey, name) =>
{
using var versionKey = parentKey.OpenSubKey(name);
action.Invoke(name, versionKey);
});
}
// ------------------
// ForEachName method
// ------------------
private static void ForEachName(Action<RegistryKey, string> action)
{
using var registryKey = Registry.LocalMachine.OpenSubKey(Constants.ProductRegistryKeyPath);
if (registryKey == null) return;
using var subKey = registryKey.OpenSubKey(Constants.RegistrySubKeyName);
if (subKey == null) return;
foreach (var name in subKey.GetSubKeyNames())
{
action.Invoke(subKey, name);
}
}
}
}
// eof "InstalledVersions.cs"