Skip to content

Commit

Permalink
Fix NuGet-based package managers failing to get installer url and size
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Jul 2, 2024
1 parent 9336417 commit 07ca060
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,36 @@ protected override async Task GetPackageDetails_Unsafe(PackageDetails details)
return;
}

details.InstallerUrl = PackageManifestLoader.GetPackageNuGetPackageUrl(details.Package);
// details.InstallerUrl = PackageManifestLoader.GetPackageNuGetPackageUrl(details.Package);
details.InstallerType = CoreTools.Translate("NuPkg (zipped manifest)");
details.InstallerSize = await CoreTools.GetFileSizeAsync(details.InstallerUrl);
//details.InstallerSize = await CoreTools.GetFileSizeAsync(details.InstallerUrl);

foreach (Match match in Regex.Matches(PackageManifestContents, @"<content type=[""']\w+\/\w+[""'] src=""([^""]+)"" ?\/>"))
{
try
{
details.InstallerUrl = new Uri(match.Groups[1].Value);
break;
}
catch (Exception ex)
{
Logger.Warn($"Failed to parse NuGet Installer URL on package Id={details.Package.Id} for value={match.Groups[1].Value}: " + ex.Message);
}
}

foreach (Match match in Regex.Matches(PackageManifestContents, @"<(d\:)?PackageSize (m\:type=""[^""]+"")?>([0-9]+)<\/"))
{
try
{
details.InstallerSize = long.Parse(match.Groups[3].Value)/1000000.0;
break;
}
catch (Exception ex)
{
Logger.Warn($"Failed to parse NuGet Installer Size on package Id={details.Package.Id} for value={match.Groups[1].Value}: " + ex.Message);
}
}

foreach (Match match in Regex.Matches(PackageManifestContents, @"<name>[^<>]+<\/name>"))
{
details.Author = match.Value.Replace("<name>", "").Replace("</name>", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static Uri GetPackageManifestUrl(Package package)
/// <returns>A Uri object</returns>
public static Uri GetPackageNuGetPackageUrl(Package package)
{
return new Uri($"{package.Source.Url}/Packages/{package.Id}.{package.Version}.nupkg");
return new Uri($"{package.Source.Url}/package/{package.Id}/{package.Version}");
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Windows.Storage.Pickers;
using Windows.UI;
using Windows.UI.Text;
using UniGetUI.PackageEngine.Managers.PowerShellManager;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -337,14 +338,17 @@ public async void DownloadInstallerButton_Click(object sender, RoutedEventArgs e
IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
WinRT.Interop.InitializeWithWindow.Initialize(savePicker, hWnd);
savePicker.SuggestedStartLocation = PickerLocationId.Downloads;
savePicker.SuggestedFileName = Package.Id + " installer." + Package.Details.InstallerUrl.ToString().Split('.')[^1];
string extension = Package.Manager is BaseNuGet
? "nupkg"
: Package.Details.InstallerUrl.ToString().Split('.')[^1];
savePicker.SuggestedFileName = Package.Id + " installer." + extension;

if (Package.Details.InstallerUrl.ToString().Split('.')[^1] == "nupkg")
{
savePicker.FileTypeChoices.Add("Compressed Manifest File", [".zip"]);
}

savePicker.FileTypeChoices.Add("Default", ["." + Package.Details.InstallerUrl.ToString().Split('.')[^1]]);
savePicker.FileTypeChoices.Add("Default", [$".{extension}"]);

StorageFile file = await savePicker.PickSaveFileAsync();
if (file != null)
Expand Down

0 comments on commit 07ca060

Please sign in to comment.