Skip to content
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

Modernize package manager dialog #1969

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb20225
Rewrite package view to show version and warnings
glopesdev Aug 12, 2024
a8eee3f
Add deprecation warning message to package details
glopesdev Aug 12, 2024
ec196f6
Refactor resize code to improve component reuse
glopesdev Aug 12, 2024
6ecd74c
Avoid blanking package view on resize
glopesdev Aug 13, 2024
5033d18
Refactor package view event args for reuse
glopesdev Aug 14, 2024
69aa3a9
Restyle package details to show title and button
glopesdev Aug 14, 2024
65aae55
Ensure label resizes when package is set to null
glopesdev Aug 20, 2024
a619e98
Add multi-version selector and package status icon
glopesdev Aug 23, 2024
1fa4d73
Add alternate package link to deprecation notice
glopesdev Aug 23, 2024
4b91235
Refactor image resize as internal extension method
glopesdev Aug 24, 2024
0d95591
Add package prefix reservation icon and tooltip
glopesdev Aug 24, 2024
495678f
Add inline package authors and download count
glopesdev Aug 24, 2024
3a59c4a
Ensure update search includes version info
glopesdev Aug 25, 2024
cf4dc31
Embed default package icon to avoid remote lookup
glopesdev Aug 27, 2024
77afe42
Draw prerelease label and larger package title
glopesdev Aug 27, 2024
61aa039
Add support for viewing embedded license files
glopesdev Aug 28, 2024
ee99810
Add filtering for gallery and library packages
glopesdev Aug 28, 2024
33c88e6
Add debugging profile to starter pack
glopesdev Aug 29, 2024
f76ff32
Add library package type to base build properties
glopesdev Aug 29, 2024
c2071ca
Refactor package operations into common extensions
glopesdev Aug 31, 2024
e79d2a0
Sanitize tab order and increase dialog size
glopesdev Sep 3, 2024
3fe873b
Remove redundant font allocation
glopesdev Sep 3, 2024
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
30 changes: 20 additions & 10 deletions Bonsai.Configuration/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Bonsai.Configuration
Expand All @@ -29,9 +30,9 @@ public LicenseAwarePackageManager PackageManager
get { return packageManager; }
}

protected virtual async Task RunPackageOperationAsync(Func<Task> operationFactory)
protected virtual async Task RunPackageOperationAsync(Func<CancellationToken, Task> operationFactory, CancellationToken cancellationToken)
{
await operationFactory();
await operationFactory(cancellationToken);
}

static NuGetVersion ParseVersion(string version)
Expand All @@ -52,7 +53,8 @@ public async Task RunAsync(
NuGetFramework projectFramework,
PackageConfiguration packageConfiguration,
string bootstrapperPath,
PackageIdentity bootstrapperPackage)
PackageIdentity bootstrapperPackage,
CancellationToken cancellationToken = default)
{
const string OldExtension = ".old";
var backupExePath = bootstrapperPath + OldExtension;
Expand All @@ -65,7 +67,7 @@ public async Task RunAsync(
var missingPackages = GetMissingPackages(packageConfiguration, packageManager.LocalRepository).ToList();
if (missingPackages.Count > 0)
{
async Task RestoreMissingPackages()
async Task RestoreMissingPackages(CancellationToken cancellationToken)
{
using var monitor = new PackageConfigurationUpdater(
projectFramework,
Expand All @@ -75,31 +77,39 @@ async Task RestoreMissingPackages()
bootstrapperPackage);
foreach (var package in missingPackages)
{
await packageManager.StartRestorePackage(package.Id, ParseVersion(package.Version), projectFramework);
await packageManager.RestorePackageAsync(
package.Id,
ParseVersion(package.Version),
projectFramework,
cancellationToken);
}
};

packageManager.RestorePackages = true;
try { await RunPackageOperationAsync(RestoreMissingPackages); }
try { await RunPackageOperationAsync(RestoreMissingPackages, cancellationToken); }
finally { packageManager.RestorePackages = false; }
}

var editorPackage = packageManager.LocalRepository.FindLocalPackage(bootstrapperPackage.Id);
if (editorPackage == null || editorPackage.Identity.Version < bootstrapperPackage.Version)
{
async Task RestoreEditorPackage()
async Task RestoreEditorPackage(CancellationToken cancellationToken)
{
using var monitor = new PackageConfigurationUpdater(
projectFramework,
packageConfiguration,
packageManager,
bootstrapperPath,
bootstrapperPackage);
var package = await packageManager.StartInstallPackage(bootstrapperPackage.Id, bootstrapperPackage.Version, projectFramework);
var package = await packageManager.InstallPackageAsync(
bootstrapperPackage.Id,
bootstrapperPackage.Version,
projectFramework,
cancellationToken);
editorPackage = packageManager.LocalRepository.GetLocalPackage(package.GetIdentity());
};

await RunPackageOperationAsync(RestoreEditorPackage);
await RunPackageOperationAsync(RestoreEditorPackage, cancellationToken);
}
}

Expand All @@ -112,7 +122,7 @@ public RestorePackageManager(PackageSourceProvider packageSourceProvider, string

public bool RestorePackages { get; set; }

protected override bool AcceptLicenseAgreement(IEnumerable<IPackageSearchMetadata> licensePackages)
protected override bool AcceptLicenseAgreement(IEnumerable<RequiringLicenseAcceptancePackageInfo> licensePackages)
{
if (RestorePackages) return true;
else return base.AcceptLicenseAgreement(licensePackages);
Expand Down
29 changes: 8 additions & 21 deletions Bonsai.Configuration/PackageConfigurationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ namespace Bonsai.Configuration
{
public class PackageConfigurationUpdater : IDisposable
{
const string PackageTagFilter = "Bonsai";
const string GalleryDirectory = "Gallery";
const string ExtensionsDirectory = "Extensions";
const string BinDirectory = "bin";
const string DebugDirectory = "debug";
const string BonsaiExtension = ".bonsai";
const string AssemblyExtension = ".dll";
const string OldExtension = ".old";

Expand Down Expand Up @@ -55,7 +51,7 @@ public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfi
configurationPlugin = new PackageConfigurationPlugin(this);
packageManager.PackageManagerPlugins.Add(configurationPlugin);

var galleryPath = Path.Combine(bootstrapperDirectory, GalleryDirectory);
var galleryPath = Path.Combine(bootstrapperDirectory, Constants.GalleryDirectory);
var galleryPackageSource = new PackageSource(galleryPath);
galleryRepository = new SourceRepository(galleryPackageSource, Repository.Provider.GetCoreV3());
NormalizePathSeparators(packageConfiguration);
Expand Down Expand Up @@ -92,12 +88,6 @@ static void NormalizePathSeparators(PackageConfiguration configuration)
}
}

static bool IsTaggedPackage(PackageReaderBase package)
{
var tags = package.NuspecReader.GetTags();
return tags != null && tags.Contains(PackageTagFilter);
}

static ProcessorArchitecture ResolveArchitectureAlias(string name)
{
switch (name)
Expand Down Expand Up @@ -410,10 +400,7 @@ public PackageConfigurationPlugin(PackageConfigurationUpdater owner)

public override async Task<bool> OnPackageInstallingAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath)
{
var entryPoint = package.Id + BonsaiExtension;
var nearestFrameworkGroup = packageReader.GetContentItems().GetNearest(projectFramework);
var executablePackage = nearestFrameworkGroup?.Items.Any(file => PathUtility.GetRelativePath(ContentFolder, file) == entryPoint);
if (executablePackage.GetValueOrDefault())
if (packageReader.IsExecutablePackage(package, projectFramework))
{
var packageFolder = Path.GetDirectoryName(packageReader.GetNuspecFile());
var resolver = new VersionFolderPathResolver(packageFolder, isLowercase: false);
Expand Down Expand Up @@ -461,15 +448,15 @@ public override async Task<bool> OnPackageInstallingAsync(PackageIdentity packag
public override Task OnPackageInstalledAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath)
{
var packageConfiguration = Owner.packageConfiguration;
var taggedPackage = IsTaggedPackage(packageReader);
var addReferences = packageReader.IsLibraryPackage();
var relativePath = Owner.GetRelativePath(installPath);
if (!packageConfiguration.Packages.Contains(package.Id))
{
packageConfiguration.Packages.Add(package.Id, package.Version.ToString());
}
else packageConfiguration.Packages[package.Id].Version = package.Version.ToString();

Owner.AddContentFolders(installPath, ExtensionsDirectory);
Owner.AddContentFolders(installPath, Constants.ExtensionsDirectory);
Owner.RegisterLibraryFolders(packageReader, relativePath);
Owner.RegisterAssemblyLocations(packageReader, installPath, relativePath, false);
if (IsRunningOnMono) Owner.AddAssemblyConfigFiles(packageReader, installPath);
Expand All @@ -494,7 +481,7 @@ public override Task OnPackageInstalledAsync(PackageIdentity package, NuGetFrame
// resolution is OS-specific and architecture-specific and should not be versioned together
// with the package dependency graph.
var assemblyLocations = GetCompatibleAssemblyReferences(projectFramework, packageReader);
Owner.RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, taggedPackage);
Owner.RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, addReferences);
packageConfiguration.Save();

if (package.Id == Owner.bootstrapperPackageId && package.Version > Owner.bootstrapperVersion)
Expand All @@ -516,11 +503,11 @@ public override Task OnPackageInstalledAsync(PackageIdentity package, NuGetFrame

public override async Task OnPackageUninstalledAsync(PackageIdentity package, NuGetFramework projectFramework, PackageReaderBase packageReader, string installPath)
{
var taggedPackage = IsTaggedPackage(packageReader);
var removeReferences = packageReader.IsLibraryPackage();
var relativePath = Owner.GetRelativePath(installPath);
Owner.packageConfiguration.Packages.Remove(package.Id);

Owner.RemoveContentFolders(packageReader, installPath, ExtensionsDirectory);
Owner.RemoveContentFolders(packageReader, installPath, Constants.ExtensionsDirectory);
Owner.RemoveLibraryFolders(packageReader, relativePath);
Owner.RemoveAssemblyLocations(packageReader, relativePath, false);
if (IsRunningOnMono) Owner.RemoveAssemblyConfigFiles(packageReader, installPath);
Expand All @@ -541,7 +528,7 @@ public override async Task OnPackageUninstalledAsync(PackageIdentity package, Nu
}

var assemblyLocations = GetCompatibleAssemblyReferences(projectFramework, packageReader);
Owner.RemoveAssemblyLocations(assemblyLocations, relativePath, taggedPackage);
Owner.RemoveAssemblyLocations(assemblyLocations, relativePath, removeReferences);
Owner.packageConfiguration.Save();

if (pivots.Length > 0)
Expand Down
5 changes: 4 additions & 1 deletion Bonsai.Editor/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public AboutBox()
this.labelVersion.Text = $"Version {AssemblyVersion}";
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription + Environment.NewLine + Resources.AttributionNotices;
this.textBoxDescription.Text = string.Format(
Resources.AttributionNotices,
AssemblyProduct,
AssemblyDescription);
}

internal static string BuildKindTitleSuffix
Expand Down
5 changes: 3 additions & 2 deletions Bonsai.Editor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Bonsai.Editor/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@
</value>
</data>
<data name="AttributionNotices" xml:space="preserve">
<value>
The Bonsai framework includes software from the Reactive Extensions for .NET and the NuGet projects developed at the .NET Foundation (https://dotnetfoundation.org/).
<value>{1}

{0} includes software and media content from the Reactive Extensions for .NET and the NuGet projects developed at the .NET Foundation (https://dotnetfoundation.org/).

Copyright (c) .NET Foundation and Contributors</value>
</data>
Expand Down
28 changes: 28 additions & 0 deletions Bonsai.NuGet.Design/DrawingHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Bonsai.NuGet.Design
{
static class DrawingHelper
{
public static SizeF GetImageSize(this Graphics graphics, Image image)
{
return new(
width: image.Width * graphics.DpiX / image.HorizontalResolution,
height: image.Height * graphics.DpiY / image.VerticalResolution);
}

public static Bitmap Resize(this Image image, Size newSize)
{
var result = new Bitmap(newSize.Width, newSize.Height);
using (var graphics = Graphics.FromImage(result))
{
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.DrawImage(image, 0, 0, newSize.Width, newSize.Height);
}
return result;
}
}
}
18 changes: 18 additions & 0 deletions Bonsai.NuGet.Design/FormatHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Globalization;

namespace Bonsai.NuGet.Design
{
internal static class FormatHelper
{
public static string ToLargeSuffix(long count)
{
return count switch
{
> 999999999 => count.ToString("0,,,.#B", CultureInfo.InvariantCulture),
> 999999 => count.ToString("0,,.#M", CultureInfo.InvariantCulture),
> 999 => count.ToString("0,.#K", CultureInfo.InvariantCulture),
_ => count.ToString(CultureInfo.InvariantCulture)
};
}
}
}
Loading