Skip to content

Commit 29ab5d4

Browse files
committed
Added winget version check for repair function
1 parent 9a4982f commit 29ab5d4

2 files changed

Lines changed: 82 additions & 33 deletions

File tree

src/WGet.NET/Components/WinGetPackageManager.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class WinGetPackageManager : WinGet
4848
private const string _acceptSourceAgreements = "--accept-source-agreements";
4949

5050
private readonly Version _downloadMinVersion = new(1, 6, 0);
51+
private readonly Version _repairMinVersion = new(1, 7, 0);
5152
private readonly Version _pinMinVersion = new(1, 5, 0);
5253

5354
/// <summary>
@@ -899,6 +900,9 @@ public async Task<bool> UpgradeAllPackagesAsync(CancellationToken cancellationTo
899900
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
900901
/// WinGet is not installed or not found on the system.
901902
/// </exception>
903+
/// <exception cref="WGetNET.Exceptions.WinGetFeatureNotSupportedException">
904+
/// This feature is not supported in the installed WinGet version.
905+
/// </exception>
902906
/// <exception cref="System.ArgumentException">
903907
/// A provided argument is empty.
904908
/// </exception>
@@ -907,6 +911,11 @@ public async Task<bool> UpgradeAllPackagesAsync(CancellationToken cancellationTo
907911
/// </exception>
908912
public bool RepairPackage(string packageId)
909913
{
914+
if (!CheckWinGetVersion(_repairMinVersion))
915+
{
916+
throw new WinGetFeatureNotSupportedException(_repairMinVersion);
917+
}
918+
910919
ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
911920

912921
string cmd = string.Format(_repairCmd, packageId);
@@ -927,6 +936,9 @@ public bool RepairPackage(string packageId)
927936
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
928937
/// WinGet is not installed or not found on the system.
929938
/// </exception>
939+
/// <exception cref="WGetNET.Exceptions.WinGetFeatureNotSupportedException">
940+
/// This feature is not supported in the installed WinGet version.
941+
/// </exception>
930942
/// <exception cref="System.ArgumentException">
931943
/// A provided argument is empty.
932944
/// </exception>
@@ -960,6 +972,9 @@ public bool RepairPackage(WinGetPackage package)
960972
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
961973
/// WinGet is not installed or not found on the system.
962974
/// </exception>
975+
/// <exception cref="WGetNET.Exceptions.WinGetFeatureNotSupportedException">
976+
/// This feature is not supported in the installed WinGet version.
977+
/// </exception>
963978
/// <exception cref="System.ArgumentException">
964979
/// A provided argument is empty.
965980
/// </exception>
@@ -968,6 +983,11 @@ public bool RepairPackage(WinGetPackage package)
968983
/// </exception>
969984
public async Task<bool> RepairPackageAsync(string packageId, CancellationToken cancellationToken = default)
970985
{
986+
if (!CheckWinGetVersion(_repairMinVersion))
987+
{
988+
throw new WinGetFeatureNotSupportedException(_repairMinVersion);
989+
}
990+
971991
ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
972992

973993
string cmd = string.Format(_repairCmd, packageId);
@@ -992,6 +1012,9 @@ public async Task<bool> RepairPackageAsync(string packageId, CancellationToken c
9921012
/// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
9931013
/// WinGet is not installed or not found on the system.
9941014
/// </exception>
1015+
/// <exception cref="WGetNET.Exceptions.WinGetFeatureNotSupportedException">
1016+
/// This feature is not supported in the installed WinGet version.
1017+
/// </exception>
9951018
/// <exception cref="System.ArgumentException">
9961019
/// A provided argument is empty.
9971020
/// </exception>

src/WGet.NET/XmlDocumentation/WGet.NET.xml

Lines changed: 59 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)