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

Cherrypick compatibility wildcard support #15606

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ Dynamo.Controls.TreeViewVLineMarginConverter
Dynamo.Controls.TreeViewVLineMarginConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.TreeViewVLineMarginConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.TreeViewVLineMarginConverter.TreeViewVLineMarginConverter() -> void
Dynamo.Controls.VersionStringAsteriskToXConverter
Dynamo.Controls.VersionStringAsteriskToXConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.VersionStringAsteriskToXConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.VersionStringAsteriskToXConverter.VersionStringAsteriskToXConverter() -> void
Dynamo.Controls.ViewButtonClipRectConverter
Dynamo.Controls.ViewButtonClipRectConverter.Convert(object[] values, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.ViewButtonClipRectConverter.ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) -> object[]
Expand Down
25 changes: 25 additions & 0 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4029,4 +4029,29 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

/// <summary>
/// Returns "2019.10.x" from "2019.10.*" input
/// </summary>
public class VersionStringAsteriskToXConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string version && !string.IsNullOrEmpty(version))
{
return version.Replace("*", "x");
}

return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string version && !string.IsNullOrEmpty(version))
{
return version.Replace("x", "*");
}

return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@
<Color x:Key="PMBorderColor">#5F5F5F</Color>
<Color x:Key="PMHeaderBackgroundColor">#3f3f3f</Color>
<Color x:Key="PMDataGridBackgroundColor">#474747</Color>
<Color x:Key="PMDataAltBackgroundColor">#535353</Color>
<Color x:Key="PMVersionCompatibleColor">#87B340</Color>
<Color x:Key="PMVersionUncompatibleColor">#EB5555</Color>
<Color x:Key="PMVersionUnknownColor">#73C5FF</Color>
<Color x:Key="PMInnerVerticleLineColor">#646464</Color>

<SolidColorBrush x:Key="PMForegroundColorBrush" Color="{StaticResource PMForegroundColor}" />
<SolidColorBrush x:Key="PMBorderColorBrush" Color="{StaticResource PMBorderColor}" />
<SolidColorBrush x:Key="PMHeaderBackgroundColorBrush" Color="{StaticResource PMHeaderBackgroundColor}" />
<SolidColorBrush x:Key="PMDataGridBackgroundColorBrush" Color="{StaticResource PMDataGridBackgroundColor}" />
<SolidColorBrush x:Key="PMDataAltBackgroundColorBrush" Color="{StaticResource PMDataAltBackgroundColor}" />
<SolidColorBrush x:Key="PMVersionCompatibleColorBrush" Color="{StaticResource PMVersionCompatibleColor}" />
<SolidColorBrush x:Key="PMVersionUncompatibleColorBrush" Color="{StaticResource PMVersionUncompatibleColor}" />
<SolidColorBrush x:Key="PMVersionUnknownColorBrush" Color="{StaticResource PMVersionUnknownColor}" />
<SolidColorBrush x:Key="PMInnerVerticleLineColorBrush" Color="{StaticResource PMInnerVerticleLineColor}" />
</ResourceDictionary>
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6480,7 +6480,7 @@
<Setter Property="BorderBrush" Value="{StaticResource DarkMidGreyBrush}" />
<Setter Property="ColumnWidth" Value="Auto" />
<Setter Property="GridLinesVisibility" Value="Vertical" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource DarkMidGreyBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource PMInnerVerticleLineColorBrush}" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,24 @@ internal void filter_PropertyChanged(object sender, PropertyChangedEventArgs e)
negateFilter.OnChecked = false;
break;

// Mutually exclusive case for Compatible and Incompatible
case var name when name.Equals(Resources.PackageCompatible):
if (!filter.OnChecked)
break;
var incompatibleFilter = CompatibilityFilter.First(x => x.FilterName.Equals(Resources.PackageIncompatible));
if (!incompatibleFilter.OnChecked)
break;
incompatibleFilter.OnChecked = false;
break;

case var name when name.Equals(Resources.PackageIncompatible):
if (!filter.OnChecked)
break;
var compatibleFilter = CompatibilityFilter.First(x => x.FilterName.Equals(Resources.PackageCompatible));
if (!compatibleFilter.OnChecked)
break;
compatibleFilter.OnChecked = false;
break;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/DynamoPackages/PackageManagerSearchElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,14 @@ internal static bool IsVersionCompatible(Greg.Responses.Compatibility compatibil
bool isWithinMinMax = true;
if (!string.IsNullOrEmpty(compatibility.min) || !string.IsNullOrEmpty(compatibility.max))
{
Version minVersion = compatibility.min != null ? VersionUtilities.Parse(compatibility.min) : null;
Version maxVersion = compatibility.max != null ? VersionUtilities.Parse(compatibility.max) : null;
Version minVersion = VersionUtilities.Parse(compatibility.min);
Version maxVersion = VersionUtilities.Parse(compatibility.max);

// if max is null, try to parse based on wildcard symantics
if(maxVersion == null)
{
maxVersion = VersionUtilities.WildCardParse(compatibility.max);
}

// If max is specified without min, return false as max-only ranges are unsupported
if (minVersion == null && maxVersion != null)
Expand Down
1 change: 1 addition & 0 deletions src/DynamoUtilities/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ static Dynamo.Utilities.TypeExtensions.GetInstance<TArg>(this System.Type type,
static Dynamo.Utilities.TypeExtensions.ImplementsGeneric(System.Type generic, System.Type toCheck) -> bool
static Dynamo.Utilities.VersionUtilities.Parse(string version) -> System.Version
static Dynamo.Utilities.VersionUtilities.PartialParse(string versionString, int numberOfFields = 3) -> System.Version
static Dynamo.Utilities.VersionUtilities.WildCardParse(string version) -> System.Version
static DynamoUtilities.CertificateVerification.CheckAssemblyForValidCertificate(string assemblyPath) -> bool
static DynamoUtilities.PathHelper.CreateFolderIfNotExist(string folderPath) -> System.Exception
static DynamoUtilities.PathHelper.ExtractAndSaveEmbeddedFont(string resourcePath, string outputPath, string outputFileName, System.Reflection.Assembly assembly) -> void
Expand Down
70 changes: 68 additions & 2 deletions src/DynamoUtilities/VersionUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,74 @@ public static Version Parse(string version)
versionParts = version.Split('.');
}

// Now it should be safe to parse
return Version.Parse(version);
// Now it should be safe to parse - this catches any other incompatible Versions
// Including '1.2.3.4.5'
return Version.TryParse(version, out parsedVersion) ? parsedVersion : null;
}

/// <summary>
/// The maximum version we check against when substituting a wildcard
/// </summary>
private const string WILDCARD_MAX_VERSION = "2147483647";

/// <summary>
/// Parse the first n fields of a version string. Delegates to
/// Version.Parse.
/// </summary>
public static Version WildCardParse(string version)
{
// If the version string is null or empty, return null
if (string.IsNullOrEmpty(version))
{
return null;
}

// Check if the version string ends with a wildcard
if (!version.EndsWith(".*"))
{
return null;
}

var splitVersion = version.Split('.');

// Check that there are no more than 3 version items specified
if (splitVersion.Length > 3)
{
return null;
}

// Ensure the first part is a valid number
if (!int.TryParse(splitVersion[0], out _))
{
return null;
}

string newVersion;
if (splitVersion.Length == 2)
{
// Major and wildcard
newVersion = AppendWildcardVersion(splitVersion[0], WILDCARD_MAX_VERSION, "0");
}
else if (splitVersion.Length == 3)
{
// Major, minor, and wildcard
if (!int.TryParse(splitVersion[1], out _))
{
return null;
}
newVersion = AppendWildcardVersion(splitVersion[0], splitVersion[1], WILDCARD_MAX_VERSION);
}
else
{
return null;
}

return Version.TryParse(newVersion, out Version parsedVersion) ? parsedVersion : null;
}

private static string AppendWildcardVersion(string major, string minor = WILDCARD_MAX_VERSION, string patch = "0")
{
return $"{major}.{minor}.{patch}";
}
}
}
6 changes: 4 additions & 2 deletions src/PackageDetailsViewExtension/PackageDetailsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<controls:InverseEmptyListToVisibilityConverter x:Key="InverseEmptyListToVisibilityConverter" />
<controls:CopyrightInfoTooltipConverter x:Key="CopyrightInfoTooltipConverter" />
<controls:PackageDetailsLinkCollapseOnEmpty x:Key="PackageDetailsLinkCollapseOnEmpty" />
<controls:VersionStringAsteriskToXConverter x:Key="VersionStringAsteriskToXConverter" />
<SolidColorBrush x:Key="ForegroundGrayBrush" Color="#D8D8D8" />
<SolidColorBrush x:Key="HoverBorderGrayBrush" Color="#6d6d6d" />
<SolidColorBrush x:Key="PressedBorderGrayBrush" Color="#7e7e7e" />
Expand Down Expand Up @@ -693,7 +694,7 @@
<TextBlock Margin="0,5" Text="{x:Static p:Resources.PackageDetailsCompatibilityWithSetup}" />
<DataGrid x:Name="VersionCompatibilityDataGrid"
Margin="0,0,20,20"
AlternatingRowBackground="{StaticResource PMDataGridBackgroundColorBrush}"
AlternatingRowBackground="{StaticResource PMDataAltBackgroundColorBrush}"
AlternationCount="2"
AutoGenerateColumns="False"
Background="{StaticResource ExtensionBackgroundColor}"
Expand All @@ -709,6 +710,7 @@
IsReadOnly="True"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding VersionInformation}"
RowBackground="{StaticResource PMDataGridBackgroundColorBrush}"
RowDetailsVisibilityMode="Collapsed"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Expand All @@ -721,7 +723,7 @@
Binding="{Binding CompatibilityName}"
Header="" />
<DataGridTextColumn Width="3*"
Binding="{Binding Versions}"
Binding="{Binding Versions, Converter={StaticResource VersionStringAsteriskToXConverter}}"
Header="{x:Static p:Resources.PublishPackageViewPackageVersion}" />
</DataGrid.Columns>
</DataGrid>
Expand Down
Loading
Loading