-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstalledBuilds.cs
63 lines (53 loc) · 2.6 KB
/
InstalledBuilds.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
using Microsoft.Win32;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Switch_Trados_Studios_Environment
{
public class InstalledBuilds
{
public List<InstalledBuildInformation> listOfInstalledBuilds = new List<InstalledBuildInformation>();
public Dictionary<int, string> studioBuildTypeDictionary = new Dictionary<int, string>();
public int nrOfInstalledBuilds;
public InstalledBuilds()
{
listOfInstalledBuilds = PopulateListOfInstalledBuilds();
studioBuildTypeDictionary = PopulateStudioDictionaries();
nrOfInstalledBuilds = studioBuildTypeDictionary.Count();
}
private List<InstalledBuildInformation> PopulateListOfInstalledBuilds()
{
RegistryKey SdlInstallRegistry = Registry.LocalMachine.OpenSubKey(Constants.Trados32bit);
List<string> installedBuilds = new List<string>();
List<InstalledBuildInformation> installedBuildsInformation = new List<InstalledBuildInformation>();
if (SdlInstallRegistry != null)
{
var installedStudioBuilds = SdlInstallRegistry.GetSubKeyNames()
.Where<string>(val => val.StartsWith("Studio1") && !val.Contains("License") && !val.Contains("MTStudio")).ToList();
installedBuilds.AddRange(installedStudioBuilds);
}
foreach(var buildName in installedBuilds)
{
RegistryKey tradosInstallInformation = Registry.LocalMachine.OpenSubKey(Path.Combine(Constants.Trados32bit, buildName));
installedBuildsInformation.Add(new InstalledBuildInformation
{
DisplayName = (string)tradosInstallInformation.GetValue("DisplayName"),
DisplayVersion = (string)tradosInstallInformation.GetValue("DisplayVersion"),
InstallLocation = tradosInstallInformation.GetValue("DisplayIcon").ToString().Substring(0, tradosInstallInformation.GetValue("DisplayIcon").ToString().LastIndexOf('\\'))
});
}
return installedBuildsInformation;
}
private Dictionary<int, string> PopulateStudioDictionaries()
{
int Key = 0;
Dictionary<int, string> buildTypeDictionary = new Dictionary<int, string>();
foreach (var build in listOfInstalledBuilds)
{
buildTypeDictionary.Add(Key, $"{build.DisplayName} {build.DisplayVersion}");
Key++;
}
return buildTypeDictionary;
}
}
}