-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArchiveFactoryUtilities.cs
45 lines (32 loc) · 1.5 KB
/
ArchiveFactoryUtilities.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
using Gsemac.Reflection;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Gsemac.IO.Compression {
internal class ArchiveFactoryUtilities {
// Internal members
internal static string GetProgramExecutablePath(string directoryName, string fileName) {
// Scan all program files directories on all drives to find the given directory, and look for the given filename inside.
IEnumerable<string> driveDirectoryPaths = DriveInfo.GetDrives()
.Select(info => info.RootDirectory.FullName);
IEnumerable<string> programDirectoryPaths = new[] {
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
@"Program Files",
@"Program Files (x86)",
}
.Distinct()
.Where(path => !string.IsNullOrWhiteSpace(path))
.Select(path => Path.Combine(path, directoryName))
.SelectMany(path => driveDirectoryPaths.Select(drivePath => Path.Combine(drivePath, path)))
.Distinct();
IFileSystemAssemblyResolver resolver = new FileSystemAssemblyResolver() {
AddExtension = false,
};
foreach (string probingPath in programDirectoryPaths)
resolver.ProbingPaths.Add(probingPath);
return resolver.GetAssemblyPath(fileName);
}
}
}