-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddInsManager.cs
More file actions
74 lines (61 loc) · 3.04 KB
/
Copy pathAddInsManager.cs
File metadata and controls
74 lines (61 loc) · 3.04 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
using AddinManagerWpf.Entities;
using System.Collections.ObjectModel;
using System.IO;
namespace AddinManagerWpf
{
public static class AddInsManager
{
public static ObservableCollection<RevitVersionInfo> AvailableVersions { get; private set; } = [];
/// <summary>
/// Only directories that exist
/// </summary>
public static List<string> AvailableBasePaths { get; private set; } = [];
private static readonly List<string> PossibleBasePaths =
[
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Autodesk", "Revit", "Addins"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Autodesk", "ApplicationPlugins"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Autodesk", "Revit", "Addins"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Autodesk", "ApplicationPlugins")
];
public static List<string> RefreshBasePaths()
{
AvailableBasePaths = [.. PossibleBasePaths.Where(Directory.Exists)];
return AvailableBasePaths;
}
/// <summary>
/// Refreshes the collection of available Base Paths & Revit versions and their associated add-ins
/// </summary>
public static void RefreshAvailableVersions()
{
AvailableVersions.Clear();
// Track versions we've already added, so there aren't duplicate "version" entries and addins are merged.
Dictionary<string, RevitVersionInfo> versionDict = [];
List<string> basePaths = RefreshBasePaths();
foreach (string basePath in basePaths)
{
foreach (string versionDir in Directory.EnumerateDirectories(basePath))
{
string version = Path.GetFileName(versionDir);
if (!versionDict.TryGetValue(version, out RevitVersionInfo? revitVersionInfo))
{
revitVersionInfo = new(version);
// Skip non-version folders
if (!revitVersionInfo.ValidateVersion())
continue;
versionDict[version] = revitVersionInfo;
}
revitVersionInfo.AddIns.AddRange(AddInLoader.LoadAddInsFromDirectory(versionDir));
}
}
// Only load versions that have addins
AvailableVersions = new(versionDict.Values.Where(revitVersionInfo => revitVersionInfo.AddIns.Count != 0));
RevitVersionInfo allVersion = new("ALL")
{
AddIns = [.. AvailableVersions.SelectMany(v => v.AddIns)]
};
// Add "ALL" first
AvailableVersions.Insert(0, allVersion);
}
static AddInsManager() => RefreshAvailableVersions();
}
}