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
9 changes: 9 additions & 0 deletions src/UniGetUI.PAckageEngine.Interfaces/IPackageDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,14 @@ public interface IPackageDetails
/// </summary>
/// <returns>An asynchronous task that can be awaited</returns>
public Task Load();

public List<Dependency> Dependencies { get; }

public struct Dependency
{
public string Name;
public string Version;
public bool Mandatory;
}
}
}
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Enums/ManagerCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct ManagerCapabilities
public bool CanRemoveDataOnUninstall = false;
public bool CanDownloadInstaller = false;
public bool CanUninstallPreviousVersionsAfterUpdate = false;
public bool CanListDependencies = false;
public bool SupportsCustomVersions = false;
public bool SupportsCustomArchitectures = false;
public string[] SupportedCustomArchitectures = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Chocolatey()
CanSkipIntegrityChecks = true,
CanRunInteractively = true,
SupportsCustomVersions = true,
CanListDependencies = true,
SupportsCustomArchitectures = true,
SupportedCustomArchitectures = [Architecture.x86],
SupportsPreRelease = true,
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public DotNet()
SupportsCustomArchitectures = true,
SupportedCustomArchitectures = [Architecture.x86, Architecture.x64, Architecture.arm64, Architecture.arm32],
SupportsPreRelease = true,
CanListDependencies = true,
SupportsCustomLocations = true,
SupportsCustomPackageIcons = true,
SupportsCustomVersions = true,
Expand Down
15 changes: 7 additions & 8 deletions src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ public abstract class BaseNuGet : PackageManager

public sealed override void Initialize()
{
if (DetailsHelper is not BaseNuGetDetailsHelper)
static void ThrowIC(string name)
{
throw new InvalidOperationException("NuGet-based package managers must not reassign the PackageDetailsProvider property");
throw new InvalidOperationException($"NuGet-based package managers must have Capabilities.{name} set to true");
}

if (!Capabilities.SupportsCustomVersions)
if (DetailsHelper is not BaseNuGetDetailsHelper)
{
throw new InvalidOperationException("NuGet-based package managers must support custom versions");
throw new InvalidOperationException("NuGet-based package managers must not reassign the PackageDetailsProvider property");
}

if (!Capabilities.SupportsCustomPackageIcons)
{
throw new InvalidOperationException("NuGet-based package managers must support custom versions");
}
if (!Capabilities.SupportsCustomVersions) ThrowIC(nameof(Capabilities.SupportsCustomVersions));
if (!Capabilities.SupportsCustomPackageIcons) ThrowIC(nameof(Capabilities.SupportsCustomPackageIcons));
if (!Capabilities.CanListDependencies) ThrowIC(nameof(Capabilities.CanListDependencies));

base.Initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
break;
}

details.Dependencies.Clear();
foreach (Match match in Regex.Matches(PackageManifestContents,
@"<d\:Dependencies>([^<]+)</d\:Dependencies>"))
{
foreach (var dep in match.Groups[1].ToString().Split('|'))
{
if(string.IsNullOrEmpty(dep))
continue;
else if (dep.StartsWith("::"))
details.Dependencies.Add(new() { Name = dep.TrimStart(':'), Version = "", Mandatory = true });
else
details.Dependencies.Add(new()
{
Name = dep.Split(':')[0], Version = dep.Split(':')[1].TrimEnd(':'), Mandatory = true
});
}
}


logger.Close(0);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,47 @@ protected override void GetDetails_UnSafe(IPackageDetails details)

details.InstallerHash = contents?["dist"]?["integrity"]?.ToString();

details.Dependencies.Clear();
HashSet<string> addedDeps = new();
foreach (var rawDep in (contents?["dependencies"]?.AsObject() ?? []))
{
if(addedDeps.Contains(rawDep.Key)) continue;
addedDeps.Add(rawDep.Key);

details.Dependencies.Add(new()
{
Name = rawDep.Key,
Version = rawDep.Value?.GetValue<string>() ?? "",
Mandatory = true,
});
}

foreach (var rawDep in (contents?["devDependencies"]?.AsObject() ?? []))
{
if(addedDeps.Contains(rawDep.Key)) continue;
addedDeps.Add(rawDep.Key);

details.Dependencies.Add(new()
{
Name = rawDep.Key,
Version = rawDep.Value?.GetValue<string>() ?? "",
Mandatory = false,
});
}

foreach (var rawDep in (contents?["peerDependencies"]?.AsObject() ?? []))
{
if(addedDeps.Contains(rawDep.Key)) continue;
addedDeps.Add(rawDep.Key);

details.Dependencies.Add(new()
{
Name = rawDep.Key,
Version = rawDep.Value?.GetValue<string>() ?? "",
Mandatory = false,
});
}

logger.AddToStdErr(p.StandardError.ReadToEnd());
p.WaitForExit();
logger.Close(p.ExitCode);
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public Npm()
SupportsCustomVersions = true,
CanDownloadInstaller = true,
SupportsCustomScopes = true,
CanListDependencies = true,
SupportsPreRelease = true,
SupportsProxy = ProxySupport.No,
SupportsProxyAuth = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
}
details.Tags = Tags.ToArray();
}

details.Dependencies.Clear();
foreach (var rawDep in (info?["requires_dist"]?.AsArray() ?? []))
{
string line = rawDep?.GetValue<string>().Split(';')[0] ?? "";
string name = line.Split(['>', '<', '=', '!'])[0];
details.Dependencies.Add(new()
{
Name = name,
Version = line[name.Length..],
Mandatory = true,
});
}
}

JsonObject? url = contents?["url"] as JsonObject;
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Pip()
SupportsCustomScopes = true,
CanDownloadInstaller = true,
SupportsPreRelease = true,
CanListDependencies = true,
SupportsProxy = ProxySupport.Yes,
SupportsProxyAuth = true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public PowerShell()
SupportsCustomVersions = true,
CanDownloadInstaller = true,
SupportsCustomScopes = true,
CanListDependencies = true,
SupportsCustomSources = true,
SupportsPreRelease = true,
SupportsCustomPackageIcons = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public PowerShell7()
SupportsCustomSources = true,
SupportsPreRelease = true,
CanDownloadInstaller = true,
CanListDependencies = true,
SupportsCustomPackageIcons = true,
CanUninstallPreviousVersionsAfterUpdate = true,
Sources = new SourceCapabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,64 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
out var releaseNotesUrl))
details.ReleaseNotesUrl = releaseNotesUrl;

details.Dependencies.Clear();
_getDepends(details, contents);
_getSuggests(details, contents);

logger.Close(0);
}

private static void _getSuggests(IPackageDetails details, JsonObject? contents)
{
foreach (var rawDep in (contents?["suggest"]?.AsObject() ?? []))
{
List<string> innerDeps = [];

if(rawDep.Value is JsonValue value) innerDeps.Add(value.GetValue<string>());
else
{
foreach (var iDep in rawDep.Value?.AsArray() ?? [])
{
string? val = iDep?.GetValue<string>();
if(val is not null) innerDeps.Add(val);
}
}

foreach(var val in innerDeps)
details.Dependencies.Add(new()
{
Name = val,
Version = "",
Mandatory = false,
});
}
}

private static void _getDepends(IPackageDetails details, JsonObject? contents)
{
var node = contents?["depends"];
List<string> innerDeps = [];


if(node is JsonValue value) innerDeps.Add(value.GetValue<string>());
else
{
foreach (var iDep in node?.AsArray() ?? [])
{
string? val = iDep?.GetValue<string>();
if(val is not null) innerDeps.Add(val);
}
}

foreach(var val in innerDeps)
details.Dependencies.Add(new()
{
Name = val,
Version = "",
Mandatory = true,
});
}

protected override CacheableIcon? GetIcon_UnSafe(IPackage package)
{
throw new NotImplementedException();
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Scoop()
CanRunAsAdmin = true,
CanSkipIntegrityChecks = true,
CanDownloadInstaller = true,
CanListDependencies = true,
CanRemoveDataOnUninstall = true,
SupportsCustomArchitectures = true,
SupportedCustomArchitectures = [Architecture.x86, Architecture.x64, Architecture.arm64],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ protected override void GetDetails_UnSafe(IPackageDetails details)

details.Tags = Tags.ToArray();

details.Dependencies.Clear();
foreach (var iDep in contents?["dependencies"]?.AsArray() ?? [])
{
string? val = iDep?.GetValue<string>();
if (val is not null)
{
details.Dependencies.Add(new() { Name = val, Version = "", Mandatory = true, });
}
}

logger.Close(0);
}

Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Vcpkg()
{
CanRunAsAdmin = true,
SupportsCustomSources = true,
CanListDependencies = true,
SupportsProxy = ProxySupport.No,
SupportsProxyAuth = false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)
bool IsLoadingDescription = false;
bool IsLoadingReleaseNotes = false;
bool IsLoadingTags = false;
bool IsCapturingDependencies = false;
details.Dependencies.Clear();
foreach (string __line in output)
{
try
Expand All @@ -484,6 +486,16 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)
{
details.Tags = details.Tags.Append(line.Trim()).ToArray();
}
else if (line.StartsWith(" ") && IsCapturingDependencies)
{
line = line.Trim();
details.Dependencies.Add(new()
{
Name = line.Split(' ')[0],
Version = line.Contains('[') ? line.Split('[')[1].TrimEnd(']'): "",
Mandatory = true
});
}

// Stop loading multiline fields
else if (IsLoadingDescription)
Expand All @@ -498,6 +510,10 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)
{
IsLoadingTags = false;
}
else if (IsCapturingDependencies)
{
IsCapturingDependencies = false;
}

// Check for single-line fields
if (line.Contains("Publisher:"))
Expand Down Expand Up @@ -556,6 +572,10 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)
details.Tags = [];
IsLoadingTags = true;
}
else if (line.Contains("- Package Dependencies"))
{
IsCapturingDependencies = true;
}
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)

logger.Error(process.StandardError.ReadToEnd());

bool capturingDependencies = false;
details.Dependencies.Clear();
// Parse the output
foreach (string __line in output)
{
Expand All @@ -419,6 +421,20 @@ public void GetPackageDetails_UnSafe(IPackageDetails details)
{
details.InstallerType = line.Split(":")[1].Trim();
}
else if (line.Contains("- Package Dependencies"))
{
capturingDependencies = true;
}
else if (__line.Contains(" ") && capturingDependencies)
{
details.Dependencies.Add(new()
{
Name = line.Split(' ')[0],
Version = line.Contains('[') ? line.Split('[')[1].TrimEnd(']'): "",
Mandatory = true
});
}
else if (!__line.Contains(" ")) capturingDependencies = false;
}
catch (Exception e)
{
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public WinGet()
CanRunInteractively = true,
SupportsCustomVersions = true,
CanDownloadInstaller = true,
CanListDependencies = true,
SupportsCustomArchitectures = true,
SupportedCustomArchitectures = [Architecture.x86, Architecture.x64, Architecture.arm64],
SupportsCustomScopes = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public class PackageDetails : IPackageDetails
/// </summary>
public string[] Tags { get; set; } = [];

public List<IPackageDetails.Dependency> Dependencies { get; set; } = [];

public PackageDetails(IPackage package)
{
Package = package;
Expand Down
Loading
Loading