Skip to content

Commit

Permalink
Merge pull request #975 from TheCakeIsNaOH/nuget-uplift
Browse files Browse the repository at this point in the history
(#974) Preliminary update chocolatey.lib
  • Loading branch information
gep13 authored Jan 25, 2023
2 parents b5f59ee + 5f36d77 commit 9aebe38
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 108 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 1.0.0
next-version: 2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="chocolatey, Version=1.0.0.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb, processorArchitecture=MSIL">
<HintPath>..\packages\chocolatey.lib.1.0.0\lib\chocolatey.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
<Reference Include="chocolatey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb, processorArchitecture=MSIL">
<HintPath>..\packages\chocolatey.lib.2.0.0-alpha-20230124\lib\net48\chocolatey.dll</HintPath>
</Reference>
<Reference Include="ControlzEx, Version=4.0.0.0, Culture=neutral, PublicKeyToken=69f1c32f803d307e, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.4.4.0\lib\net462\ControlzEx.dll</HintPath>
Expand Down
49 changes: 29 additions & 20 deletions Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using AutoMapper;
using chocolatey;
using chocolatey.infrastructure.app;
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.domain;
using chocolatey.infrastructure.app.nuget;
Expand All @@ -22,14 +23,17 @@
using ChocolateyGui.Common.Services;
using ChocolateyGui.Common.Utilities;
using Microsoft.VisualStudio.Threading;
using NuGet;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
using ChocolateySource = ChocolateyGui.Common.Models.ChocolateySource;
using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem;

namespace ChocolateyGui.Common.Windows.Services
{
using ChocolateySource = ChocolateySource;
using ILogger = Serilog.ILogger;
using LogLevel = Models.LogLevel;
using LogMessage = Models.LogMessage;

public class ChocolateyService : IChocolateyService
{
Expand Down Expand Up @@ -141,7 +145,7 @@ public async Task<IReadOnlyList<OutdatedPackage>> GetOutdatedPackages(bool inclu
var results = packages
.Where(p => !p.Value.Inconclusive)
.Select(p => new OutdatedPackage
{ Id = p.Value.Package.Id, VersionString = p.Value.Package.Version.ToNormalizedString() })
{ Id = p.Value.Name, VersionString = p.Value.Version })
.ToArray();

try
Expand Down Expand Up @@ -213,7 +217,9 @@ public async Task<PackageOperationResult> InstallPackage(
config.ApplyInstallArgumentsToDependencies = advancedInstallOptions.ApplyInstallArgumentsToDependencies;
config.ApplyPackageParametersToDependencies = advancedInstallOptions.ApplyPackageParametersToDependencies;
config.AllowDowngrade = advancedInstallOptions.AllowDowngrade;
#pragma warning disable CS0618 // Type or member is obsolete
config.AllowMultipleVersions = advancedInstallOptions.AllowMultipleVersions;
#pragma warning restore CS0618 // Type or member is obsolete
config.IgnoreDependencies = advancedInstallOptions.IgnoreDependencies;
config.ForceDependencies = advancedInstallOptions.ForceDependencies;
config.SkipPackageInstallProvider = advancedInstallOptions.SkipPowerShell;
Expand Down Expand Up @@ -312,9 +318,11 @@ public async Task<Package> GetByVersionAndIdAsync(string id, string version, boo
});
var chocoConfig = _choco.GetConfiguration();

var nugetLogger = _choco.Container().GetInstance<NuGet.ILogger>();
var semvar = new SemanticVersion(version);
var nugetPackage = await Task.Run(() => (NugetList.GetPackages(chocoConfig, nugetLogger) as IQueryable<IPackage>).FirstOrDefault(p => p.Version == semvar));
var nugetLogger = _choco.Container().GetInstance<NuGet.Common.ILogger>();
var origVer = chocoConfig.Version;
chocoConfig.Version = version;
var nugetPackage = await Task.Run(() => (NugetList.GetPackages(chocoConfig, nugetLogger, _fileSystem) as IQueryable<IPackageSearchMetadata>).FirstOrDefault());
chocoConfig.Version = origVer;
if (nugetPackage == null)
{
throw new Exception("No Package Found");
Expand All @@ -323,7 +331,7 @@ public async Task<Package> GetByVersionAndIdAsync(string id, string version, boo
return GetMappedPackage(_choco, new PackageResult(nugetPackage, null, chocoConfig.Sources), _mapper);
}

public async Task<List<SemanticVersion>> GetAvailableVersionsForPackageIdAsync(string id, int page, int pageSize, bool includePreRelease)
public async Task<List<NuGetVersion>> GetAvailableVersionsForPackageIdAsync(string id, int page, int pageSize, bool includePreRelease)
{
_choco.Set(
config =>
Expand All @@ -343,7 +351,7 @@ public async Task<List<SemanticVersion>> GetAvailableVersionsForPackageIdAsync(s
});
var chocoConfig = _choco.GetConfiguration();
var packages = await _choco.ListAsync<PackageResult>();
return packages.Select(p => new SemanticVersion(p.Version)).OrderByDescending(p => p.Version).ToList();
return packages.Select(p => NuGetVersion.Parse(p.Version)).OrderByDescending(p => p.Version).ToList();
}

public async Task<PackageOperationResult> UninstallPackage(string id, string version, bool force = false)
Expand Down Expand Up @@ -398,6 +406,7 @@ public async Task<PackageOperationResult> PinPackage(string id, string version)
config.PinCommand.Command = PinCommandType.add;
config.PinCommand.Name = id;
config.Version = version;
config.Sources = ApplicationParameters.PackagesLocation;
});

try
Expand All @@ -424,6 +433,7 @@ public async Task<PackageOperationResult> UnpinPackage(string id, string version
config.PinCommand.Command = PinCommandType.remove;
config.PinCommand.Name = id;
config.Version = version;
config.Sources = ApplicationParameters.PackagesLocation;
});
try
{
Expand Down Expand Up @@ -619,26 +629,25 @@ public async Task ExportPackages(string exportFilePath, bool includeVersionNumbe

private static Package GetMappedPackage(GetChocolatey choco, PackageResult package, IMapper mapper, bool forceInstalled = false)
{
var mappedPackage = package == null ? null : mapper.Map<Package>(package.Package);
var mappedPackage = package == null ? null : mapper.Map<Package>(package.SearchMetadata);
if (mappedPackage != null)
{
if (package.PackageMetadata != null)
{
mappedPackage.ReleaseNotes = package.PackageMetadata.ReleaseNotes;
mappedPackage.Language = package.PackageMetadata.Language;
mappedPackage.Copyright = package.PackageMetadata.Copyright;
}

var packageInfoService = choco.Container().GetInstance<IChocolateyPackageInformationService>();
var packageInfo = packageInfoService.get_package_information(package.Package);
var packageInfo = packageInfoService.get_package_information(package.PackageMetadata);
mappedPackage.IsPinned = packageInfo.IsPinned;
mappedPackage.IsInstalled = !string.IsNullOrWhiteSpace(package.InstallLocation) || forceInstalled;
#pragma warning disable CS0618 // Type or member is obsolete
mappedPackage.IsSideBySide = packageInfo.IsSideBySide;
#pragma warning restore CS0618 // Type or member is obsolete

mappedPackage.IsPrerelease = !string.IsNullOrWhiteSpace(mappedPackage.Version.SpecialVersion);

// Add a sanity check here for pre-release packages
// By default, pre-release packages are marked as IsLatestVersion = false, however, IsLatestVersion is
// what is used to show/hide the Out of Date message in the UI. In these cases, if it is a pre-release
// mark IsLatestVersion as true, and then the outcome of the call to choco outdated will correct whether
// it is actually Out of Date or not
if (mappedPackage.IsPrerelease && mappedPackage.IsAbsoluteLatestVersion && !mappedPackage.IsLatestVersion)
{
mappedPackage.IsLatestVersion = true;
}
mappedPackage.IsPrerelease = mappedPackage.Version.IsPrerelease;
}

return mappedPackage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using ChocolateyGui.Common.Windows.ViewModels;
using ChocolateyGui.Common.Windows.Views;
using LiteDB;
using NuGet;
using NuGet.Protocol.Core.Types;
using ChocolateySource = chocolatey.infrastructure.app.configuration.ChocolateySource;
using Environment = System.Environment;
using PackageViewModel = ChocolateyGui.Common.Windows.ViewModels.Items.PackageViewModel;
Expand Down Expand Up @@ -94,10 +94,11 @@ protected override void Load(ContainerBuilder builder)
config.CreateMap<IPackageViewModel, IPackageViewModel>()
.ForMember(vm => vm.IsInstalled, options => options.Ignore());

config.CreateMap<DataServicePackage, Package>()
config.CreateMap<IPackageSearchMetadata, Package>()
.ForMember(dest => dest.Version, opt => opt.MapFrom(src => src.Identity.Version))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Identity.Id))
.ForMember(dest => dest.Authors, opt => opt.MapFrom(src => src.Authors.Split(',')))
.ForMember(dest => dest.Owners, opt => opt.MapFrom(src => src.Owners.Split(',')));
config.CreateMap<IPackage, Package>();

config.CreateMap<ConfigFileFeatureSetting, ChocolateyFeature>();
config.CreateMap<ConfigFileConfigSetting, ChocolateySetting>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using ChocolateyGui.Common.Windows.Commands;
using ChocolateyGui.Common.Windows.Controls.Dialogs;
using ChocolateyGui.Common.Windows.Utilities;
using NuGet;
using NuGet.Versioning;

namespace ChocolateyGui.Common.Windows.ViewModels
{
Expand Down Expand Up @@ -60,7 +60,7 @@ public class AdvancedInstallViewModel : ObservableBase, IClosableChildWindow<Adv
public AdvancedInstallViewModel(
IChocolateyService chocolateyService,
IPersistenceService persistenceService,
SemanticVersion packageVersion)
NuGetVersion packageVersion)
{
_chocolateyService = chocolateyService;
_persistenceService = persistenceService;
Expand All @@ -75,7 +75,7 @@ public AdvancedInstallViewModel(
AvailableChecksumTypes = new List<string> { "md5", "sha1", "sha256", "sha512" };
InstallCommand = new RelayCommand(
o => { Close?.Invoke(this); },
o => string.IsNullOrEmpty(SelectedVersion) || SelectedVersion == Resources.AdvancedChocolateyDialog_LatestVersion || SemanticVersion.TryParse(SelectedVersion, out _));
o => string.IsNullOrEmpty(SelectedVersion) || SelectedVersion == Resources.AdvancedChocolateyDialog_LatestVersion || NuGetVersion.TryParse(SelectedVersion, out _));
CancelCommand = new RelayCommand(
o =>
{
Expand Down Expand Up @@ -437,11 +437,11 @@ private void SetDefaults()

private void OnSelectedVersionChanged(string stringVersion)
{
SemanticVersion version;
NuGetVersion version;

if (SemanticVersion.TryParse(stringVersion, out version))
if (NuGetVersion.TryParse(stringVersion, out version))
{
PreRelease = !string.IsNullOrEmpty(version.SpecialVersion);
PreRelease = version.IsPrerelease;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using ChocolateyGui.Common.Windows.Services;
using ChocolateyGui.Common.Windows.Views;
using MahApps.Metro.Controls.Dialogs;
using NuGet;
using NuGet.Versioning;
using Action = System.Action;
using MemoryCache = System.Runtime.Caching.MemoryCache;

Expand Down Expand Up @@ -68,23 +68,21 @@ public class PackageViewModel :

private string _id;

private bool _isAbsoluteLatestVersion;
private bool _isOutdated;

private bool _isInstalled;

private bool _isPinned;

private bool _isSideBySide;

private bool _isLatestVersion;

private bool _isPrerelease;

private string _language;

private DateTime _lastUpdated;

private SemanticVersion _latestVersion;
private NuGetVersion _latestVersion;

private string _licenseUrl = string.Empty;

Expand Down Expand Up @@ -114,7 +112,7 @@ public class PackageViewModel :

private string _title;

private SemanticVersion _version;
private NuGetVersion _version;

private int _versionDownloadCount;

Expand Down Expand Up @@ -173,7 +171,7 @@ public string[] Authors

public bool IsUninstallAllowed => _allowedCommandsService.IsUninstallCommandAllowed;

public bool CanUpdate => IsInstalled && !IsPinned && !IsSideBySide && !IsLatestVersion;
public bool CanUpdate => IsInstalled && !IsPinned && !IsSideBySide && IsOutdated;

public bool IsUpgradeAllowed => _allowedCommandsService.IsUpgradeCommandAllowed;

Expand Down Expand Up @@ -232,12 +230,6 @@ public string LowerCaseId
get { return Id.ToLowerInvariant(); }
}

public bool IsAbsoluteLatestVersion
{
get { return _isAbsoluteLatestVersion; }
set { SetPropertyValue(ref _isAbsoluteLatestVersion, value); }
}

public bool IsInstalled
{
get
Expand Down Expand Up @@ -286,16 +278,16 @@ public bool IsSideBySide
}
}

public bool IsLatestVersion
public bool IsOutdated
{
get
{
return _isLatestVersion;
return _isOutdated;
}

set
{
if (SetPropertyValue(ref _isLatestVersion, value))
if (SetPropertyValue(ref _isOutdated, value))
{
NotifyPropertyChanged(nameof(CanUpdate));
}
Expand All @@ -314,7 +306,7 @@ public string Language
set { SetPropertyValue(ref _language, value); }
}

public SemanticVersion LatestVersion
public NuGetVersion LatestVersion
{
get { return _latestVersion; }
set { SetPropertyValue(ref _latestVersion, value); }
Expand Down Expand Up @@ -404,7 +396,7 @@ public string Title
set { SetPropertyValue(ref _title, value); }
}

public SemanticVersion Version
public NuGetVersion Version
{
get { return _version; }
set { SetPropertyValue(ref _version, value); }
Expand Down Expand Up @@ -713,7 +705,7 @@ public void Handle(PackageHasUpdateMessage message)
}

LatestVersion = message.Version;
IsLatestVersion = false;
IsOutdated = true;
}

private async Task InstallPackage(string version, AdvancedInstall advancedOptions = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using ChocolateyGui.Common.Windows.Utilities;
using ChocolateyGui.Common.Windows.Utilities.Extensions;
using NuGet;
using NuGet.Packaging;
using Serilog;
using ILogger = Serilog.ILogger;

Expand Down Expand Up @@ -322,10 +323,6 @@ public async Task LoadPackages(bool forceCheckForOutdatedPackages)
{
p.IsInstalled = true;
}
if (outdated.Any(package => string.Equals(package.Id, p.Id, StringComparison.OrdinalIgnoreCase)))
{
p.IsLatestVersion = false;
}

Packages.Add(Mapper.Map<IPackageViewModel>(p));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsInstalled, Mode=OneWay}" Value="True" />
<Condition Binding="{Binding IsLatestVersion, Mode=OneWay}" Value="False" />
<Condition Binding="{Binding IsOutdated, Mode=OneWay}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter TargetName="OutOfDateOverlay" Property="Visibility" Value="Visible" />
</MultiDataTrigger>
Expand Down Expand Up @@ -317,7 +317,7 @@
<DataTemplate DataType="{x:Type items:IPackageViewModel}">
<Grid Background="{DynamicResource {x:Static theming:ChocolateyBrushes.OutOfDateKey}}"
TextElement.Foreground="{DynamicResource {x:Static theming:ChocolateyBrushes.OutOfDateForegroundKey}}"
Visibility="{Binding IsLatestVersion, Converter={StaticResource BooleanToVisibilityInverted}}"
Visibility="{Binding IsOutdated, Converter={StaticResource BooleanToVisibility}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
Expand Down
4 changes: 2 additions & 2 deletions Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource MultiBooleanAndToVisibility}">
<Binding Path="IsInstalled" />
<Binding Path="IsLatestVersion" Converter="{StaticResource BooleanInverter}" />
<Binding Path="IsOutdated" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
Expand All @@ -277,7 +277,7 @@
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource MultiBooleanAndToVisibility}">
<Binding Path="IsInstalled" />
<Binding Path="IsLatestVersion" />
<Binding Path="IsOutdated" Converter="{StaticResource BooleanInverter}" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
Expand Down
Loading

0 comments on commit 9aebe38

Please sign in to comment.