Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/UniGetUI.Core.Data/Licenses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static class LicenseData
{"parse_pip_search", "MIT"},
{"PowerShell Gallery", "Unknown"},
{".NET SDK", "MIT"},
{"dotnet-tools-outdated", "MIT"},
{"Cargo", "MIT"},
{"cargo-binstall", "GPL-3.0-only"},
{"cargo-update", "MIT"},
Expand Down Expand Up @@ -59,7 +58,6 @@ public static class LicenseData
{"Pip", new Uri("https://github.com/pypa/pip/blob/main/LICENSE.txt")},
{"parse_pip_search", new Uri("https://github.com/marticliment/parseable_pip_search/blob/master/LICENSE.md")},
{".NET SDK", new Uri("https://github.com/dotnet/sdk/blob/main/LICENSE.TXT")},
{"dotnet-tools-outdated", new Uri("https://github.com/rychlym/dotnet-tools-outdated/blob/master/LICENSE")},
{"PowerShell Gallery", new Uri("https://www.powershellgallery.com/")},
{"Cargo", new Uri("https://github.com/rust-lang/cargo/blob/master/LICENSE-MIT")},
{"cargo-binstall", new Uri("https://spdx.org/licenses/GPL-3.0-only.html")},
Expand Down Expand Up @@ -94,7 +92,6 @@ public static class LicenseData
{"Pip", new Uri("https://github.com/pypa/pip/")},
{"parse_pip_search", new Uri("https://github.com/marticliment/parseable_pip_search/")},
{".NET SDK", new Uri("https://dotnet.microsoft.com/")},
{"dotnet-tools-outdated", new Uri("https://github.com/rychlym/dotnet-tools-outdated/")},
{"PowerShell Gallery", new Uri("https://www.powershellgallery.com/")},
{"Cargo", new Uri("https://github.com/rust-lang/cargo")},
{"cargo-binstall", new Uri("https://github.com/cargo-bins/cargo-binstall")},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
return Packages;
}

protected override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
{
Process p = new()
{
Expand Down
100 changes: 1 addition & 99 deletions src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ public class DotNet : BaseNuGet

public DotNet()
{
Dependencies = [
new ManagerDependency(
".NET Tools Outdated",
Path.Join(Environment.SystemDirectory, "windowspowershell\\v1.0\\powershell.exe"),
"-ExecutionPolicy Bypass -NoLogo -NoProfile -Command \"& {dotnet tool install --global dotnet-tools-outdated --add-source https://api.nuget.org/v3/index.json; if ($error.count -ne 0){pause}}\"",
"dotnet tool install --global dotnet-tools-outdated --add-source https://api.nuget.org/v3/index.json",
async () => (await CoreTools.WhichAsync("dotnet-tools-outdated.exe")).Item1)
];

Capabilities = new ManagerCapabilities
{
CanRunAsAdmin = true,
Expand Down Expand Up @@ -66,96 +57,7 @@ public DotNet()
OperationHelper = new DotNetPkgOperationHelper(this);
}

protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
{
var (found, path) = CoreTools.Which("dotnet-tools-outdated.exe");
if (!found)
{
Process proc = new()
{
StartInfo = new ProcessStartInfo
{
FileName = Status.ExecutablePath,
Arguments = Properties.ExecutableCallArgs + " install --global dotnet-tools-outdated",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};

IProcessTaskLogger aux_logger = TaskLogger.CreateNew(LoggableTaskType.InstallManagerDependency, proc);
proc.Start();

aux_logger.AddToStdOut(proc.StandardOutput.ReadToEnd());
aux_logger.AddToStdErr(proc.StandardError.ReadToEnd());
proc.WaitForExit();
aux_logger.Close(proc.ExitCode);

path = "dotnet-tools-outdated.exe";
}

Process p = new()
{
StartInfo = new ProcessStartInfo
{
FileName = path,
Arguments = "--format json --utf8",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
StandardOutputEncoding = System.Text.Encoding.UTF8
}
};

p.StartInfo = CoreTools.UpdateEnvironmentVariables(p.StartInfo);
IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.ListUpdates, p);
p.Start();

List<Package> Packages = [];
string output = p.StandardOutput.ReadToEnd();
logger.AddToStdOut(output);
logger.AddToStdErr(p.StandardError.ReadToEnd());

while (output[0] != '{') output = output[1..];
JsonArray? data = (JsonNode.Parse(output) as JsonObject)?["dotnet-tools-outdated"] as JsonArray;
if (data is not null)
{
foreach (JsonNode? node in data)
{
if (node is not JsonObject element) continue;

bool unlisted = element["becomeUnlisted"]?.GetValue<bool>() ?? false;
string id = element["packageName"]?.ToString() ?? "";
string version = element["currentVer"]?.ToString() ?? "";
string newVersion = element["availableVer"]?.ToString() ?? "";

if (unlisted)
{
Logger.Warn($".NET package {id} is unlisted, not showing it...");
continue;
};

Packages.Add(new(
CoreTools.FormatAsName(id), id, version, newVersion, DefaultSource, this,
new(PackageScope.Global)
));

}
}
else
{
logger.AddToStdErr("\"JsonArray? data\" was null!");
}

p.WaitForExit();
logger.Close(p.ExitCode);

return Packages;
}

protected override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
{
List<Package> Packages = [];
foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) })
Expand Down
77 changes: 77 additions & 0 deletions src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using UniGetUI.Core.Classes;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;
Expand Down Expand Up @@ -104,6 +108,79 @@ protected sealed override IReadOnlyList<Package> FindPackages_UnSafe(string quer
return Packages;
}


protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
{
int errors = 0;
var logger = TaskLogger.CreateNew(LoggableTaskType.ListUpdates);

var installedPackages = TaskRecycler<IReadOnlyList<IPackage>>.RunOrAttach(GetInstalledPackages);
var Packages = new List<Package>();

Dictionary<IManagerSource, List<IPackage>> sourceMapping = new();

foreach (var package in installedPackages)
{
var uri = package.Source;
if (!sourceMapping.ContainsKey(uri)) sourceMapping[uri] = new();
sourceMapping[uri].Add(package);
}

foreach (var pair in sourceMapping)
{
var packageIds = new StringBuilder();
var packageVers = new StringBuilder();
var packageIdVersion = new Dictionary<string, string>();
foreach (var package in pair.Value)
{
packageIds.Append(package.Id + "|");
packageVers.Append(package.VersionString + "|");
packageIdVersion[package.Id.ToLower()] = package.VersionString;
}

var SearchUrl = $"{pair.Key.Url.ToString().Trim('/')}/GetUpdates()" +
$"?packageIds=%27{HttpUtility.UrlEncode(packageIds.ToString().Trim('|'))}%27" +
$"&versions=%27{HttpUtility.UrlEncode(packageVers.ToString().Trim('|'))}%27" +
$"&includePrerelease=0&includeAllVersions=0";

using HttpClient client = new(CoreData.GenericHttpClientParameters);
client.DefaultRequestHeaders.UserAgent.ParseAdd(CoreData.UserAgentString);
HttpResponseMessage response = client.GetAsync(SearchUrl).GetAwaiter().GetResult();

if (!response.IsSuccessStatusCode)
{
logger.Error($"Failed to fetch api at Url={SearchUrl} with status code {response.StatusCode}");
errors++;
}
else
{
string SearchResults = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
MatchCollection matches = Regex.Matches(SearchResults, "<entry>([\\s\\S]*?)<\\/entry>");

foreach (Match match in matches)
{
if (!match.Success) continue;

string id = Regex.Match(match.Value, "<d:Id>([^<]+)</d:Id>").Groups[1].Value;
string new_version = Regex.Match(match.Value, "<d:Version>([^<]+)</d:Version>").Groups[1].Value;
// Match title = Regex.Match(match.Value, "<title[ \\\"\\=A-Za-z0-9]+>([^<>]+)<\\/title>");

logger.Log($"Found package {id} version {new_version} on source {pair.Key.Name}");
Packages.Add(new Package(CoreTools.FormatAsName(id), id, packageIdVersion[id.ToLower()], new_version, pair.Key, this));
}
}
}

logger.Close(errors);
return Packages;
}

protected sealed override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
=> TaskRecycler<IReadOnlyList<Package>>.RunOrAttach(_getInstalledPackages_UnSafe);

protected abstract IReadOnlyList<Package> _getInstalledPackages_UnSafe();


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected override OperationVeredict _getOperationResult(
{
string output_string = string.Join("\n", processOutput);

if (!package.OverridenOptions.RunAsAdministrator != true && output_string.Contains("AdminPrivilegesAreRequired"))
if (package.OverridenOptions.RunAsAdministrator is not true &&
(output_string.Contains("AdminPrivilegesAreRequired") || output_string.Contains("AdminPrivilegeRequired")))
{
package.OverridenOptions.RunAsAdministrator = true;
return OperationVeredict.AutoRetry;
Expand Down
88 changes: 1 addition & 87 deletions src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,94 +55,8 @@ public PowerShell()
SourcesHelper = new PowerShellSourceHelper(this);
OperationHelper = new PowerShellPkgOperationHelper(this);
}
protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
{
Process p = new()
{
StartInfo = new ProcessStartInfo
{
FileName = Status.ExecutablePath,
Arguments = "-NoProfile",
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true,
StandardOutputEncoding = System.Text.Encoding.UTF8,
StandardInputEncoding = new UTF8Encoding(false),
}
};

IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.ListUpdates, p);

p.Start();

string command = """
function Test-GalleryModuleUpdate {
param (
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] [string] $Name,
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] [version] $Version,
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] [string] $Repository,
[switch] $NeedUpdateOnly
)
process {
$URLs = @{}
@(Get-PSRepository).ForEach({$URLs[$_.Name] = If ($_.Uri) {$_.Uri.AbsoluteUri} Else {$_.SourceLocation}})
$page = Invoke-WebRequest -Uri ($URLs[$Repository] + "/package/$Name") -UseBasicParsing -Maximum 0 -ea Ignore
[version]$latest = Split-Path -Path ($page.Headers.Location -replace "$Name." -replace ".nupkg") -Leaf
$needsupdate = $Latest -gt $Version
if ($needsupdate) {
Write-Output($Name + "|" + $Version.ToString() + "|" + $Latest.ToString() + "|" + $Repository)
}
}
}
Get-InstalledModule | Test-GalleryModuleUpdate


exit
""";
p.StandardInput.WriteLine(command);
logger.AddToStdIn(command);
p.StandardInput.Close();

string? line;
List<Package> Packages = [];
while ((line = p.StandardOutput.ReadLine()) is not null)
{
logger.AddToStdOut(line);
if (line.StartsWith(">>"))
{
continue;
}

string[] elements = line.Split('|');
if (elements.Length < 4)
{
continue;
}

for (int i = 0; i < elements.Length; i++)
{
elements[i] = elements[i].Trim();
}

if (elements[1] + ".0" == elements[2] || elements[1] + ".0.0" == elements[2])
{
continue;
}

Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1],
elements[2], SourcesHelper.Factory.GetSourceOrDefault(elements[3]), this));
}

logger.AddToStdErr(p.StandardError.ReadToEnd());
p.WaitForExit();
logger.Close(p.ExitCode);

return Packages;
}

protected override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
{
Process p = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected override OperationVeredict _getOperationResult(
{
string output_string = string.Join("\n", processOutput);

if (!package.OverridenOptions.RunAsAdministrator != true && output_string.Contains("AdminPrivilegesAreRequired"))
if (package.OverridenOptions.RunAsAdministrator is not true &&
(output_string.Contains("AdminPrivilegesAreRequired") || output_string.Contains("AdminPrivilegeRequired")))
{
package.OverridenOptions.RunAsAdministrator = true;
return OperationVeredict.AutoRetry;
Expand Down
Loading
Loading