-
Notifications
You must be signed in to change notification settings - Fork 840
Expand file tree
/
Copy pathPowerShell7.cs
More file actions
162 lines (144 loc) · 5.91 KB
/
Copy pathPowerShell7.cs
File metadata and controls
162 lines (144 loc) · 5.91 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
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Classes.Manager;
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;
using UniGetUI.PackageEngine.Managers.Chocolatey;
using UniGetUI.PackageEngine.Managers.PowerShellManager;
using UniGetUI.PackageEngine.PackageClasses;
namespace UniGetUI.PackageEngine.Managers.PowerShell7Manager
{
public class PowerShell7 : BaseNuGet
{
public PowerShell7()
{
Capabilities = new ManagerCapabilities
{
CanRunAsAdmin = true,
SupportsCustomVersions = true,
SupportsCustomScopes = true,
SupportsCustomSources = true,
SupportsPreRelease = true,
CanDownloadInstaller = true,
CanListDependencies = true,
SupportsCustomPackageIcons = true,
CanUninstallPreviousVersionsAfterUpdate = true,
Sources = new SourceCapabilities
{
KnowsPackageCount = false,
KnowsUpdateDate = false,
},
SupportsProxy = ProxySupport.Partially,
SupportsProxyAuth = true
};
Properties = new ManagerProperties
{
Name = "PowerShell7",
DisplayName = "PowerShell 7.x",
Description = CoreTools.Translate("PowerShell's package manager. Find libraries and scripts to expand PowerShell capabilities<br>Contains: <b>Modules, Scripts, Cmdlets</b>"),
IconId = IconType.PowerShell,
ColorIconId = "powershell_color",
ExecutableFriendlyName = "pwsh.exe",
InstallVerb = "Install-PSResource",
UninstallVerb = "Uninstall-PSResource",
UpdateVerb = "Update-PSResource",
KnownSources = [new ManagerSource(this, "PSGallery", new Uri("https://www.powershellgallery.com/api/v2")),
new ManagerSource(this, "PoshTestGallery", new Uri("https://www.poshtestgallery.com/api/v2"))],
DefaultSource = new ManagerSource(this, "PSGallery", new Uri("https://www.powershellgallery.com/api/v2")),
};
DetailsHelper = new PowerShell7DetailsHelper(this);
SourcesHelper = new PowerShell7SourceHelper(this);
OperationHelper = new PowerShell7PkgOperationHelper(this);
}
protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
{
using Process p = new()
{
StartInfo = new ProcessStartInfo
{
FileName = Status.ExecutablePath,
Arguments = Status.ExecutableCallArgs + " \"Get-InstalledPSResource | Format-Table -Property Name,Version,Repository\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8
}
};
IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.ListInstalledPackages, p);
p.Start();
string? line;
List<Package> Packages = [];
bool DashesPassed = false;
while ((line = p.StandardOutput.ReadLine()) is not null)
{
logger.AddToStdOut(line);
if (!DashesPassed)
{
if (line.Contains("-----"))
{
DashesPassed = true;
}
}
else
{
string[] elements = Regex.Replace(line, " {2,}", " ").Split(' ');
if (elements.Length < 3)
{
continue;
}
for (int i = 0; i < elements.Length; i++)
{
elements[i] = elements[i].Trim();
}
Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1],
SourcesHelper.Factory.GetSourceOrDefault(elements[2]), this));
}
}
logger.AddToStdErr(p.StandardError.ReadToEnd());
p.WaitForExit();
logger.Close(p.ExitCode);
return Packages;
}
public override IReadOnlyList<string> FindCandidateExecutableFiles()
{
return CoreTools.WhichMultiple("pwsh.exe");
}
protected override ManagerStatus LoadManager()
{
var (found, path) = GetExecutableFile();
ManagerStatus status = new()
{
ExecutablePath = path,
Found = found,
ExecutableCallArgs = " -NoProfile -Command",
};
if (!status.Found)
{
return status;
}
Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = status.ExecutablePath,
Arguments = "-NoProfile -Version",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8
}
};
process.Start();
status.Version = process.StandardOutput.ReadToEnd().Trim();
return status;
}
}
}