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

Skip minor updates #3101

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IInstallationOptions
public bool InteractiveInstallation { get; set; }
public bool RunAsAdministrator { get; set; }
public string Version { get; set; }
public bool SkipMinorUpdates { get; set; }
public Architecture? Architecture { get; set; }
public PackageScope? InstallationScope { get; set; }
public List<string> CustomParameters { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public interface IPackage : INotifyPropertyChanged, IEquatable<IPackage>
/// </summary>
public bool NewerVersionIsInstalled();

/// <summary>
/// Checks whether a new update of this package is a minor update or not (0.0.x)
/// </summary>
/// <returns>False if the update is a major update or the update doesn't exist, true if it's a minor update</returns>
public bool IsUpdateMinor();

public SerializablePackage_v1 AsSerializable();

public SerializableIncompatiblePackage_v1 AsSerializable_Incompatible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected override async Task<bool> IsPackageValid(IPackage package)
IgnoredPackages[package.Id] = package;
return false;
}
if (package.AsSerializable().InstallationOptions.SkipMinorUpdates && package.IsUpdateMinor()) return false;
if (package.NewerVersionIsInstalled()) return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class InstallationOptions : IInstallationOptions
public bool InteractiveInstallation { get; set; }
public bool RunAsAdministrator { get; set; }
public string Version { get; set; } = "";
public bool SkipMinorUpdates { get; set; }
public Architecture? Architecture { get; set; }
public PackageScope? InstallationScope { get; set; }
public List<string> CustomParameters { get; set; } = [];
Expand Down Expand Up @@ -113,6 +114,7 @@ public void FromSerializable(SerializableInstallationOptions_v1 options)
RunAsAdministrator = options.RunAsAdministrator;
CustomInstallLocation = options.CustomInstallLocation;
Version = options.Version;
SkipMinorUpdates = options.SkipMinorUpdates;
PreRelease = options.PreRelease;

if (options.Architecture != "" && CommonTranslations.InvertedArchNames.TryGetValue(options.Architecture, out var name))
Expand Down Expand Up @@ -148,7 +150,8 @@ public SerializableInstallationOptions_v1 AsSerializable()
RunAsAdministrator = RunAsAdministrator,
CustomInstallLocation = CustomInstallLocation,
PreRelease = PreRelease,
Version = Version
Version = Version,
SkipMinorUpdates = SkipMinorUpdates
};
if (Architecture is not null)
{
Expand All @@ -166,7 +169,7 @@ public SerializableInstallationOptions_v1 AsSerializable()

private FileInfo GetPackageOptionsFile()
{
string optionsFileName = Package.Manager.Name + "." + Package.Id + ".json";
string optionsFileName = Package.Manager.Name + "." + Package.Id.Split(":")[0] + ".json";
return new FileInfo(Path.Join(CoreData.UniGetUIInstallationOptionsDirectory, optionsFileName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public bool NewerVersionIsInstalled()
return false;
}

public bool IsUpdateMinor()
{
return false;
}

public async Task RemoveFromIgnoredUpdatesAsync()
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ public virtual bool NewerVersionIsInstalled()
return PackageCacher.NewerVersionIsInstalled(this);
}

public virtual bool IsUpdateMinor()
{
if (!IsUpgradable) return false;
string[] VersionSplit = Version.Split(".");
string[] NewVersionSplit = NewVersion.Split(".");

// When in doubt, return false
if (VersionSplit.Length < 3 || NewVersionSplit.Length < 3) return false;

if (
VersionSplit[0] != NewVersionSplit[0] ||
VersionSplit[1] != NewVersionSplit[1]
) return false; // Major update

return VersionSplit[2].CompareTo(NewVersionSplit[2]) < 0;
}

public virtual SerializablePackage_v1 AsSerializable()
{
return new SerializablePackage_v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class SerializableInstallationOptions_v1
public bool PreRelease { get; set; }
public string CustomInstallLocation { get; set; } = "";
public string Version { get; set; } = "";
public bool SkipMinorUpdates { get; set; }

public SerializableInstallationOptions_v1 Copy()
{
Expand All @@ -25,6 +26,7 @@ public SerializableInstallationOptions_v1 Copy()
PreRelease = PreRelease,
RunAsAdministrator = RunAsAdministrator,
Version = Version,
SkipMinorUpdates = SkipMinorUpdates,
};
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/UniGetUI/Pages/DialogPages/InstallOptions.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@

<ProgressBar IsIndeterminate="True" Name="VersionProgress" Visibility="Visible" Grid.Column="2" VerticalAlignment="Top" CornerRadius="4,4,0,0" Margin="1,0,1,0"/>
</Grid>
<CheckBox Name="IgnoreUpdatesCheckbox" Grid.Column="4">
<widgets:TranslatedTextBlock Text="Ignore future updates for this package"/>
</CheckBox>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<CheckBox Name="IgnoreUpdatesCheckbox" Grid.Column="0">
<widgets:TranslatedTextBlock Text="Ignore future updates for this package"/>
</CheckBox>
<CheckBox Name="SkipMinorUpdatesCheckbox" Grid.Column="2">
<widgets:TranslatedTextBlock Text="Skip minor updates for this package"/>
</CheckBox>
</Grid>
</StackPanel>
</Border>

Expand Down
3 changes: 3 additions & 0 deletions src/UniGetUI/Pages/DialogPages/InstallOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public InstallOptionsPage(IPackage package, OperationType operation, Serializabl
}
}

SkipMinorUpdatesCheckbox.IsChecked = Options.SkipMinorUpdates;

if (Package.Manager.Capabilities.SupportsCustomVersions)
{
_ = LoadVersions();
Expand Down Expand Up @@ -186,6 +188,7 @@ public async Task<SerializableInstallationOptions_v1> GetUpdatedOptions()
{
Options.Version = "";
}
Options.SkipMinorUpdates = SkipMinorUpdatesCheckbox?.IsChecked ?? false;

if (IgnoreUpdatesCheckbox?.IsChecked ?? false)
{
Expand Down
Loading