@@ -955,7 +955,7 @@ public async Task<bool> UninstallPackageAsync(WinGetPackage package, Cancellatio
955955 }
956956 //---------------------------------------------------------------------------------------------
957957
958- //---Upgrade------ -----------------------------------------------------------------------------
958+ //---List Upgrades -----------------------------------------------------------------------------
959959 /// <summary>
960960 /// Get all upgradeable packages.
961961 /// </summary>
@@ -1001,11 +1001,13 @@ public async Task<List<WinGetPackage>> GetUpgradeablePackagesAsync(CancellationT
10011001
10021002 return ProcessOutputReader . ToPackageList ( result . Output , PackageAction . UpgradeList ) ;
10031003 }
1004+ //---------------------------------------------------------------------------------------------
10041005
1006+ //---Upgrade-----------------------------------------------------------------------------------
10051007 /// <summary>
10061008 /// Upgrades a package using winget.
10071009 /// </summary>
1008- /// <param name="packageId">The id or name of the package for upgrade .</param>
1010+ /// <param name="packageId">The id or name of the package that should be upgraded .</param>
10091011 /// <returns>
10101012 /// <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
10111013 /// </returns>
@@ -1032,7 +1034,40 @@ public bool UpgradePackage(string packageId)
10321034 /// <summary>
10331035 /// Upgrades a package using winget.
10341036 /// </summary>
1035- /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that for the upgrade</param>
1037+ /// <param name="packageId">The id or name of the package that should be upgraded.</param>
1038+ /// <param name="silent">Request silent upgrade of packages.</param>
1039+ /// <returns>
1040+ /// <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
1041+ /// </returns>
1042+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1043+ /// WinGet is not installed or not found on the system.
1044+ /// </exception>
1045+ /// <exception cref="System.ArgumentException">
1046+ /// A provided argument is empty.
1047+ /// </exception>
1048+ /// <exception cref="System.ArgumentNullException">
1049+ /// A provided argument is null.
1050+ /// </exception>
1051+ public bool UpgradePackage ( string packageId , bool silent )
1052+ {
1053+ ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( packageId , "packageId" ) ;
1054+
1055+ string cmd = AcceptSourceAgreements ( string . Format ( _upgradeCmd , packageId ) ) ;
1056+
1057+ if ( silent )
1058+ {
1059+ cmd = Silent ( cmd ) ;
1060+ }
1061+
1062+ ProcessResult result = Execute ( cmd ) ;
1063+
1064+ return result . Success ;
1065+ }
1066+
1067+ /// <summary>
1068+ /// Upgrades a package using winget.
1069+ /// </summary>
1070+ /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that should be upgraded.</param>
10361071 /// <returns>
10371072 /// <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
10381073 /// </returns>
@@ -1057,10 +1092,39 @@ public bool UpgradePackage(WinGetPackage package)
10571092 return UpgradePackage ( package . Id ) ;
10581093 }
10591094
1095+ /// <summary>
1096+ /// Upgrades a package using winget.
1097+ /// </summary>
1098+ /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that should be upgraded.</param>
1099+ /// <param name="silent">Request silent upgrade of packages.</param>
1100+ /// <returns>
1101+ /// <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
1102+ /// </returns>
1103+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1104+ /// WinGet is not installed or not found on the system.
1105+ /// </exception>
1106+ /// <exception cref="System.ArgumentException">
1107+ /// A provided argument is empty.
1108+ /// </exception>
1109+ /// <exception cref="System.ArgumentNullException">
1110+ /// A provided argument is null.
1111+ /// </exception>
1112+ public bool UpgradePackage ( WinGetPackage package , bool silent )
1113+ {
1114+ ArgsHelper . ThrowIfWinGetObjectIsNullOrEmpty ( package , "package" ) ;
1115+
1116+ if ( package . HasShortenedId || package . HasNoId )
1117+ {
1118+ return UpgradePackage ( package . Name , silent ) ;
1119+ }
1120+
1121+ return UpgradePackage ( package . Id , silent ) ;
1122+ }
1123+
10601124 /// <summary>
10611125 /// Asynchronously upgrades a package using winget.
10621126 /// </summary>
1063- /// <param name="packageId">The id or name of the package for upgrade .</param>
1127+ /// <param name="packageId">The id or name of the package that should be upgraded .</param>
10641128 /// <param name="cancellationToken">
10651129 /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
10661130 /// </param>
@@ -1091,7 +1155,44 @@ public async Task<bool> UpgradePackageAsync(string packageId, CancellationToken
10911155 /// <summary>
10921156 /// Asynchronously upgrades a package using winget.
10931157 /// </summary>
1094- /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that for the upgrade</param>
1158+ /// <param name="packageId">The id or name of the package that should be upgraded.</param>
1159+ /// <param name="silent">Request silent upgrade of packages.</param>
1160+ /// <param name="cancellationToken">
1161+ /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
1162+ /// </param>
1163+ /// <returns>
1164+ /// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1165+ /// The result is <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
1166+ /// </returns>
1167+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1168+ /// WinGet is not installed or not found on the system.
1169+ /// </exception>
1170+ /// <exception cref="System.ArgumentException">
1171+ /// A provided argument is empty.
1172+ /// </exception>
1173+ /// <exception cref="System.ArgumentNullException">
1174+ /// A provided argument is null.
1175+ /// </exception>
1176+ public async Task < bool > UpgradePackageAsync ( string packageId , bool silent , CancellationToken cancellationToken = default )
1177+ {
1178+ ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( packageId , "packageId" ) ;
1179+
1180+ string cmd = AcceptSourceAgreements ( string . Format ( _upgradeCmd , packageId ) ) ;
1181+
1182+ if ( silent )
1183+ {
1184+ cmd = Silent ( cmd ) ;
1185+ }
1186+
1187+ ProcessResult result = await ExecuteAsync ( cmd , false , cancellationToken ) ;
1188+
1189+ return result . Success ;
1190+ }
1191+
1192+ /// <summary>
1193+ /// Asynchronously upgrades a package using winget.
1194+ /// </summary>
1195+ /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that should be upgraded.</param>
10951196 /// <param name="cancellationToken">
10961197 /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
10971198 /// </param>
@@ -1120,6 +1221,39 @@ public async Task<bool> UpgradePackageAsync(WinGetPackage package, CancellationT
11201221 return await UpgradePackageAsync ( package . Id , cancellationToken ) ;
11211222 }
11221223
1224+ /// <summary>
1225+ /// Asynchronously upgrades a package using winget.
1226+ /// </summary>
1227+ /// <param name="package">The <see cref="WGetNET.WinGetPackage"/> that should be upgraded.</param>
1228+ /// <param name="silent">Request silent upgrade of packages.</param>
1229+ /// <param name="cancellationToken">
1230+ /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
1231+ /// </param>
1232+ /// <returns>
1233+ /// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1234+ /// The result is <see langword="true"/> if the upgrade was successful or <see langword="false"/> if it failed.
1235+ /// </returns>
1236+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1237+ /// WinGet is not installed or not found on the system.
1238+ /// </exception>
1239+ /// <exception cref="System.ArgumentException">
1240+ /// A provided argument is empty.
1241+ /// </exception>
1242+ /// <exception cref="System.ArgumentNullException">
1243+ /// A provided argument is null.
1244+ /// </exception>
1245+ public async Task < bool > UpgradePackageAsync ( WinGetPackage package , bool silent , CancellationToken cancellationToken = default )
1246+ {
1247+ ArgsHelper . ThrowIfWinGetObjectIsNullOrEmpty ( package , "package" ) ;
1248+
1249+ if ( package . HasShortenedId || package . HasNoId )
1250+ {
1251+ return await UpgradePackageAsync ( package . Name , silent , cancellationToken ) ;
1252+ }
1253+
1254+ return await UpgradePackageAsync ( package . Id , silent , cancellationToken ) ;
1255+ }
1256+
11231257 /// <summary>
11241258 /// Tries to upgrade all packages using winget.
11251259 /// </summary>
@@ -1139,6 +1273,32 @@ public bool UpgradeAllPackages()
11391273 return result . Success ;
11401274 }
11411275
1276+ /// <summary>
1277+ /// Tries to upgrade all packages using winget.
1278+ /// </summary>
1279+ /// <remarks>
1280+ /// The action might run succesfully without upgrading every or even any package.
1281+ /// </remarks>
1282+ /// <param name="silent">Request silent upgrade of packages.</param>
1283+ /// <returns>
1284+ /// <see langword="true"/> if the action run successfully or <see langword="false"/> if it failed.
1285+ /// </returns>
1286+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1287+ /// WinGet is not installed or not found on the system.
1288+ /// </exception>
1289+ public bool UpgradeAllPackages ( bool silent )
1290+ {
1291+ string cmd = AcceptSourceAgreements ( _upgradeAllCmd ) ;
1292+ if ( silent )
1293+ {
1294+ cmd = Silent ( cmd ) ;
1295+ }
1296+
1297+ ProcessResult result = Execute ( cmd ) ;
1298+
1299+ return result . Success ;
1300+ }
1301+
11421302 /// <summary>
11431303 /// Asynchronously tries to upgrade all packages using winget.
11441304 /// </summary>
@@ -1161,6 +1321,36 @@ public async Task<bool> UpgradeAllPackagesAsync(CancellationToken cancellationTo
11611321
11621322 return result . Success ;
11631323 }
1324+
1325+ /// <summary>
1326+ /// Asynchronously tries to upgrade all packages using winget.
1327+ /// </summary>
1328+ /// <param name="silent">Request silent upgrade of packages.</param>
1329+ /// <param name="cancellationToken">
1330+ /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
1331+ /// </param>
1332+ /// <remarks>
1333+ /// The action might run succesfully without upgrading every or even any package.
1334+ /// </remarks>
1335+ /// <returns>
1336+ /// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1337+ /// The result is <see langword="true"/> if the action run successfully or <see langword="false"/> if it failed.
1338+ /// </returns>
1339+ /// <exception cref="WGetNET.Exceptions.WinGetNotInstalledException">
1340+ /// WinGet is not installed or not found on the system.
1341+ /// </exception>
1342+ public async Task < bool > UpgradeAllPackagesAsync ( bool silent , CancellationToken cancellationToken = default )
1343+ {
1344+ string cmd = AcceptSourceAgreements ( _upgradeAllCmd ) ;
1345+ if ( silent )
1346+ {
1347+ cmd = Silent ( cmd ) ;
1348+ }
1349+
1350+ ProcessResult result = await ExecuteAsync ( cmd , false , cancellationToken ) ;
1351+
1352+ return result . Success ;
1353+ }
11641354 //---------------------------------------------------------------------------------------------
11651355
11661356 //---Repair------------------------------------------------------------------------------------
0 commit comments