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
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Diagnostics;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using UniGetUI.Core.Data;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.IconEngine;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.PackageEngine.Classes.Manager.BaseProviders;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;

namespace UniGetUI.PackageEngine.Managers.VcpkgManager
{
internal sealed class VcpkgPackageDetailsProvider : BasePackageDetailsProvider<PackageManager>
{
public VcpkgPackageDetailsProvider(Vcpkg manager) : base(manager) { }

protected override void GetDetails_UnSafe(IPackageDetails details)
{
INativeTaskLogger logger = Manager.TaskLogger.CreateNew(LoggableTaskType.LoadPackageDetails);

const string VCPKG_REPO = "microsoft/vcpkg";
const string VCPKG_PORT_PATH = "master/ports";
const string VCPKG_PORT_FILE = "vcpkg.json";
string PackagePrefix = details.Package.Id.Split(":")[0];
string PackageName = PackagePrefix.Split("[")[0];

string JsonString;
HttpClient client = new(CoreData.GenericHttpClientParameters);
client.DefaultRequestHeaders.UserAgent.ParseAdd(CoreData.UserAgentString);
JsonString = client.GetStringAsync($"https://raw.githubusercontent.com/{VCPKG_REPO}/refs/heads/{VCPKG_PORT_PATH}/{PackageName}/{VCPKG_PORT_FILE}").GetAwaiter().GetResult();

JsonObject? contents = JsonNode.Parse(JsonString) as JsonObject;

details.Description = contents?["description"]?.ToString();
details.Publisher = contents?["maintainers"]?.ToString();
// vcpkg doesn't store the author, for some reason???
if (Uri.TryCreate(contents?["homepage"]?.ToString(), UriKind.RelativeOrAbsolute, out var homepageUrl))
details.HomepageUrl = homepageUrl;
details.License = contents?["license"]?.ToString();
details.ManifestUrl = new Uri($"https://github.com/{VCPKG_REPO}/blob/{VCPKG_PORT_PATH}/{PackageName}/{VCPKG_PORT_FILE}");
// TODO: since each change results in a new commit to the file, you could determine the `UpdateDate` via figuring out the date of the last commit that changed the file was.
// Unfortunately, the GitHub API doesn't seem to allow getting the commit that changed a file, but you can get the date of a commit with
// https://api.github.com/repos/{VCPKG_REPO}/commits/{CommitHash}

List<string> Tags = [];
// TODO: the "features" and "dependencies" keys could also be good candgidates for tags, however their type specifications are all over -
// strings, dictionaries, arrays - so one would first have to figure out how to handle that.
// See https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json
if (PackagePrefix.Contains('['))
{
Tags.Add($"{CoreTools.Translate("library")}: " + PackageName);
Tags.Add($"{CoreTools.Translate("feature")}: " + PackagePrefix.Split('[')[^1][..^1]);
}

details.Tags = Tags.ToArray();

logger.Close(0);
}

protected override CacheableIcon? GetIcon_UnSafe(IPackage package)
{
throw new NotImplementedException();
}

protected override IEnumerable<Uri> GetScreenshots_UnSafe(IPackage package)
{
throw new NotImplementedException();
}

protected override string? GetInstallLocation_UnSafe(IPackage package)
{
var (rootFound, rootPath) = Vcpkg.GetVcpkgRoot();
if (!rootFound)
{
return null;
}

string PackageId = Regex.Replace(package.Id.Replace(":", "_"), @"\[.*\]", String.Empty);
var PackagePath = Path.Join(rootPath, "packages", PackageId);
var VcpkgInstalledPath = Path.Join(rootPath, "installed", package.Id.Split(":")[1]);
return Directory.Exists(PackagePath) ? PackagePath : (Directory.Exists(VcpkgInstalledPath) ? VcpkgInstalledPath : Path.GetDirectoryName(PackageId));
}

protected override IEnumerable<string> GetInstallableVersions_UnSafe(IPackage package)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@ protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerS
protected override IEnumerable<IManagerSource> GetSources_UnSafe()
{
List<ManagerSource> Sources = [];
// Retrieve all triplets on the system (in %VCPKG_ROOT%\triplets{\community})
var (vcpkgRootFound, vcpkgRoot) = Vcpkg.GetVcpkgRoot();
if (vcpkgRootFound)
{
string tripletLocation = Path.Join(vcpkgRoot, "triplets");
string communityTripletLocation = Path.Join(vcpkgRoot, "triplets", "community");

foreach (string tripletFile in Directory.EnumerateFiles(tripletLocation).Concat(Directory.EnumerateFiles(communityTripletLocation)))
{
string triplet = Path.GetFileNameWithoutExtension(tripletFile);
Sources.Add(new ManagerSource(Manager, triplet, Vcpkg.URI_VCPKG_IO));
}
}

foreach (string Triplet in Vcpkg.GetSystemTriplets()) {
Sources.Add(new ManagerSource(Manager, Triplet, Vcpkg.URI_VCPKG_IO));
}

return Sources;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public Vcpkg()
};

SourceProvider = new VcpkgSourceProvider(this);
PackageDetailsProvider = new VcpkgPackageDetailsProvider(this);
OperationProvider = new VcpkgOperationProvider(this);
}

Expand Down Expand Up @@ -343,7 +344,6 @@ public override void RefreshPackageIndexes()
var (vcpkgRootFound, vcpkgRoot) = GetVcpkgRoot();
var (gitFound, gitPath) = CoreTools.Which("git");

// TODO: Check if Settings.Get("DisableUpdateVcpkgGitPorts") is still needed
if (!found || !gitFound || !vcpkgRootFound || Settings.Get("DisableUpdateVcpkgGitPorts"))
{
INativeTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.RefreshIndexes);
Expand Down