Skip to content

Commit

Permalink
Update PackageManagerSearchViewModel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Jul 3, 2024
1 parent 5a1bcc1 commit 9553a9f
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,8 @@ private void PopulateMyPackages()
var pkgs = PackageManagerClientViewModel.CachedPackageList.Where(x => x.Maintainers != null && x.Maintainers.Contains(name)).ToList();
foreach(var pkg in pkgs)
{
var p = new PackageManagerSearchElementViewModel(pkg,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(pkg.Name));
var p = GetSearchElementViewModel(pkg, true);

p.RequestDownload += this.PackageOnExecuted;
p.RequestShowFileDialog += this.OnRequestShowFileDialog;
p.IsOnwer = true;
Expand Down Expand Up @@ -1503,12 +1502,18 @@ private PackageManagerSearchElementViewModel GetViewModelForPackageSearchElement
return null;
}

return GetSearchElementViewModel(result.ElementAt(0));
return GetSearchElementViewModel(result.FirstOrDefault());
}

private PackageManagerSearchElementViewModel GetSearchElementViewModel(PackageManagerSearchElement package)
/// <summary>
/// Returns a new PackageManagerSearchElementViewModel for the given package, with updated properties.
/// </summary>
/// <param name="package">Package to cast</param>
/// <param name="bypassCustomPackageLocations">When true, will bypass the check for loading package from custom locations.</param>
/// <returns></returns>
private PackageManagerSearchElementViewModel GetSearchElementViewModel(PackageManagerSearchElement package, bool bypassCustomPackageLocations = false)
{
var isEnabledForInstall = !(Preferences as IDisablePackageLoadingPreferences).DisableCustomPackageLocations;
var isEnabledForInstall = bypassCustomPackageLocations || !(Preferences as IDisablePackageLoadingPreferences).DisableCustomPackageLocations;
return new PackageManagerSearchElementViewModel(package,
PackageManagerClientViewModel.AuthenticationManager.HasAuthProvider,
CanInstallPackage(package.Name),
Expand Down

0 comments on commit 9553a9f

Please sign in to comment.