Repository navigation
Expand file tree
/
Copy pathProgramDetector.cs
More file actions
196 lines (187 loc) · 9.06 KB
/
Copy pathProgramDetector.cs
File metadata and controls
196 lines (187 loc) · 9.06 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using VoukoderManager.Core.Models;
namespace VoukoderManager.Core
{
/// <summary>
/// Class for detecting installed programs on your operating system
/// </summary>
public static class ProgramDetector
{
private static readonly string _premierePluginsDir = @"SOFTWARE\Adobe\Premiere Pro\";
private static readonly string _afterEffectsPluginsDir = @"SOFTWARE\Adobe\After Effects\";
private static readonly string _vegasPluginsDir = @"SOFTWARE\Sony Creative Software\VEGAS Pro\";
private static readonly string _movieStudioPluginsDir = @"SOFTWARE\Sony Creative Software\Movie Studio\";
public static readonly List<string> ProgramSearchValues = new List<string>() { "Premiere", "Media Encoder", "AfterEffects", "VEGAS" };
public static readonly List<string> VoukoderSearchValues = new List<string>() { "Premiere", "AfterEffects", "VEGAS" };
/// <summary>
/// Returns a list which contains all installed programs where voukoder components are available for
/// </summary>
/// <param name="includeConnector">include the connector if installed</param>
/// <param name="onlyNewestVersion">only the newest version of each program</param>
/// <returns></returns>
public static List<IProgramEntry> GetInstalledPrograms(bool includeConnector, bool onlyNewestVersion)
{
var programs = RegistryHelper.GetPrograms();
Log.Debug("Received registry program list for GetInstalledPrograms");
List<IProgramEntry> list = new List<IProgramEntry>();
IProgramEntry pro;
foreach (RegistryEntry pr in programs)
{
var displayname = pr.DisplayName;
foreach (var v in ProgramSearchValues)
{
if (displayname.Contains(v) && !displayname.Contains("connector"))
{
var parsed = Enum.TryParse(v.Replace(" ", ""), out ProgramType result);
Log.Debug($"Enum parsing successed: {parsed}");
ConvertFromRegistryEntry(out pro, pr, result);
if (includeConnector)
FillComponent(ref pro);
list.Add(pro);
Log.Debug($"Adding: {pro.Name} to list");
}
}
}
void FillComponent(ref IProgramEntry entry)
{
entry.SubComponent = GetVoukoderComponent(entry.ComponentType);
if (entry.SubComponent != null)
{
Log.Debug($"Adding subcomponent: {entry.SubComponent.Name} to entry");
entry.SubComponent.SubComponent = GetVoukoderComponent(ProgramType.VoukoderCore);
}
}
if (onlyNewestVersion)
{
var enumlengh = Enum.GetNames(typeof(ProgramType)).Length;
//Check for multiple installed versions of each program
for (int i = 0; i < enumlengh; i++)
{
var items = list.Where(x => (int)x.ComponentType == i);
//if more than one version of the same program is installed
if (items.Count() > 2)
{
Log.Debug("Removing older versions of same program from list");
//search for the newest version of the same program
var ii = items.Aggregate((i1, i2) => i1.Version.Major > i2.Version.Major ? i1 : i2);
//remove older versions from the list
list.RemoveAll(x => x.Version.Major != ii.Version.Major && x.ComponentType == ii.ComponentType);
}
}
}
return list;
}
private static void ConvertFromRegistryEntry(out IProgramEntry entry, RegistryEntry regEntry, ProgramType type)
{
entry = new VKProgramEntry(regEntry.DisplayName, new Models.Version(regEntry.DisplayVersion, regEntry.PreRelease));
entry.ComponentType = type;
entry.InstallationDate = regEntry.InstallationDate;
entry.InstallationPath = regEntry.InstallationPath;
entry.ModifyPath = regEntry.ModifyPath;
entry.Publisher = regEntry.Publisher;
entry.UninstallString = regEntry.UninstallString;
entry.WindowsInstaller = regEntry.WindowsInstaller;
if (entry.ComponentType == ProgramType.MediaEncoder)
entry.Hide = true;
}
/// <summary>
/// Returns the connector for the given type if installed on the system
/// </summary>
/// <param name="connectorType"></param>
/// <returns></returns>
public static IProgramEntry GetVoukoderComponent(ProgramType connectorType)
{
var programs = RegistryHelper.GetPrograms();
Log.Debug("Received registry program list for GetVoukoderComponent");
IProgramEntry entry = null;
List<RegistryEntry> vComponents = null;
foreach (RegistryEntry e in programs)
{
var displayname = e.DisplayName;
if (displayname.Contains("Voukoder"))
{
if (vComponents == null)
vComponents = new List<RegistryEntry>();
vComponents.Add(e);
}
}
if (vComponents == null)
return null;
try
{
var ad = vComponents.Single(x => x.DisplayName.Any(char.IsDigit));
ConvertFromRegistryEntry(out entry, ad, ProgramType.VoukoderCore);
}
catch (InvalidOperationException ex) { }
try
{
var re = vComponents.Single(x => x.DisplayName.Contains(connectorType.ToString()));
ConvertFromRegistryEntry(out entry, re, connectorType);
}
catch (InvalidOperationException ex) { }
if (entry != null && connectorType == entry.ComponentType)
return entry;
Log.Debug("No match for searching voukoder component");
return null;
}
/// <summary>
/// Returns a list which contains all installed Voukoder components
/// </summary>
/// <returns></returns>
public static List<IProgramEntry> GetInstalledVoukoderComponents()
{
var programs = RegistryHelper.GetPrograms();
Log.Debug("Received registry program list for GetInstalledVoukoderComponents");
List<IProgramEntry> list = new List<IProgramEntry>();
IProgramEntry entry;
foreach (RegistryEntry e in programs)
{
var displayname = e.DisplayName;
if (displayname.Contains("Voukoder"))
{
foreach (var v in VoukoderSearchValues)
{
if (displayname.Contains(v))
{
Enum.TryParse(v, out ProgramType result);
ConvertFromRegistryEntry(out entry, e, result);
}
else
ConvertFromRegistryEntry(out entry, e, ProgramType.VoukoderCore);
list.Add(entry);
}
}
}
return list;
}
public static bool IsVoukoderComponentInstalled(IEntry entry)
{
var cpn = GetInstalledVoukoderComponents();
foreach (var v in cpn)
{
if (v.ComponentType == entry.ComponentType)
{
return true;
}
}
return false;
}
public static string GetPluginsDir(IEntry program)
{
if ((program.ComponentType == ProgramType.Premiere || program.ComponentType == ProgramType.MediaEncoder) && program.Version.Major > 6)
return RegistryHelper.GetHKEYLocalValue(_premierePluginsDir + program.Version.Major + ".0", "CommonPluginInstallPath");
//If CS6 is installed we have to use a different registry path
else if ((program.ComponentType == ProgramType.Premiere) && program.Version.Major <= 6)
return RegistryHelper.GetHKEYLocalValue(_premierePluginsDir + "CurrentVersion", "Plug-InsDir");
else if (program.ComponentType == ProgramType.AfterEffects)
return RegistryHelper.GetHKEYLocalValue(_afterEffectsPluginsDir + program.Version.Major + ".0", "CommonPluginInstallPath");
else if (program.ComponentType == ProgramType.MovieStudio)
return RegistryHelper.GetHKEYLocalValue(_movieStudioPluginsDir + program.Version.Major + ".0", "InstallPath");
else
return RegistryHelper.GetHKEYLocalValue(_vegasPluginsDir + program.Version.Major + ".0", "InstallPath");
}
}
}