Skip to content

Only Enumerate Existing Triplet Directories #3088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 19, 2024
Merged
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
33 changes: 32 additions & 1 deletion src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
Expand Down Expand Up @@ -403,6 +404,18 @@ public static Tuple<bool, string> GetVcpkgRoot()
{
vcpkgRoot = Environment.GetEnvironmentVariable("VCPKG_ROOT");
}
if (vcpkgRoot == null)
{
// Unfortuanately, we can't use `GetVcpkgPath` for this
// as it would become a bunch of functions calling each other
var (found, path) = CoreTools.Which("vcpkg");
path = Path.GetDirectoryName(path);
// Make sure the root is a valid root not just a random directory
if (found && Path.Exists($"{path}\\triplets"))
{
vcpkgRoot = path;
}
}

return Tuple.Create(vcpkgRoot != null, vcpkgRoot ?? "");
}
Expand Down Expand Up @@ -439,7 +452,25 @@ public static List<string> GetSystemTriplets()
string tripletLocation = Path.Join(vcpkgRoot, "triplets");
string communityTripletLocation = Path.Join(vcpkgRoot, "triplets", "community");

foreach (string tripletFile in Directory.EnumerateFiles(tripletLocation).Concat(Directory.EnumerateFiles(communityTripletLocation)))
IEnumerable<string> tripletFiles = [];
if (Path.Exists(tripletLocation))
{
tripletFiles = tripletFiles.Concat(Directory.EnumerateFiles(tripletLocation));
}
else
{
Logger.Warn($"The built-in triplet directory {tripletLocation} does not exist; triplets will not be loaded.");
}
if (Path.Exists(communityTripletLocation))
{
tripletFiles = tripletFiles.Concat(Directory.EnumerateFiles(communityTripletLocation));
}
else
{
Logger.Warn($"The community triplet directory {communityTripletLocation} does not exist; community triplets will not be loaded.");
}

foreach (string tripletFile in tripletFiles)
{
string triplet = Path.GetFileNameWithoutExtension(tripletFile);
Triplets.Add(triplet);
Expand Down
Loading