forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageObject.cs
More file actions
98 lines (79 loc) · 3.17 KB
/
PackageObject.cs
File metadata and controls
98 lines (79 loc) · 3.17 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using NuGet;
using ScriptCs.Contracts;
namespace ScriptCs.Hosting.Package
{
internal class PackageObject : IPackageObject
{
private const string Dll = ".dll";
private const string Exe = ".exe";
private readonly IPackage _package;
public PackageObject(IPackage package, FrameworkName frameworkName)
{
_package = package;
FrameworkName = frameworkName;
Id = package.Id;
Version = package.Version.Version;
TextVersion = package.Version.ToString();
FrameworkAssemblies = package.FrameworkAssemblies
.Where(x => x.SupportedFrameworks.Any(y => y == frameworkName))
.Select(x => x.AssemblyName);
var dependencies = _package.GetCompatiblePackageDependencies(frameworkName);
if (dependencies != null)
{
Dependencies = dependencies.Select(i => new PackageObject(i.Id) { FrameworkName = frameworkName });
}
}
public PackageObject(string packageId)
{
Id = packageId;
}
public IEnumerable<string> FrameworkAssemblies { get; private set; }
public string Id { get; private set; }
public string TextVersion { get; private set; }
public Version Version { get; private set; }
public FrameworkName FrameworkName { get; private set; }
public IEnumerable<IPackageObject> Dependencies { get; set; }
public string FullName
{
get { return Id + "." + TextVersion; }
}
public IEnumerable<string> GetCompatibleDlls(FrameworkName frameworkName)
{
var dlls = _package.GetLibFiles().Where(i => i.EffectivePath.EndsWith(Dll) || i.EffectivePath.EndsWith(Exe));
IEnumerable<IPackageFile> compatibleFiles;
VersionUtility.TryGetCompatibleItems(frameworkName, dlls, out compatibleFiles);
// HACK: Delete unnecessary temporary NuGet files
List<string> tempDirectories = new List<string>();
foreach (PhysicalPackageFile file in dlls)
{
var match = Regex.Match(((PhysicalPackageFile)dlls.First()).SourcePath, "(" + Path.Combine(Path.GetTempPath(), "nuget").Replace("\\", "\\\\") + "\\\\[^\\\\]+?)\\\\");
if (match.Success && match.Groups.Count > 1)
{
tempDirectories.Add(match.Groups[1].Value);
}
}
foreach (string directory in tempDirectories.Distinct())
{
if (Directory.Exists(directory))
{
Directory.Delete(directory, true);
}
}
// /HACK
return compatibleFiles != null ? compatibleFiles.Select(i => i.Path) : null;
}
public IEnumerable<string> GetContentFiles()
{
foreach (var file in _package.GetContentFiles())
{
yield return file.Path;
}
}
}
}