@@ -37,6 +37,7 @@ public class WinGetPackageManager : WinGetInfo
3737 private const string _pinAddInstalledCmd = "pin add \" {0}\" --installed" ;
3838 private const string _pinAddInstalledByVersionCmd = "pin add \" {0}\" --installed --version \" {1}\" " ;
3939 private const string _pinRemoveInstalledCmd = "pin remove \" {0}\" --installed" ;
40+ private const string _pinResetCmd = "pin reset --force" ;
4041
4142 /// <summary>
4243 /// Initializes a new instance of the <see cref="WGetNET.WinGetPackageManager"/> class.
@@ -2510,5 +2511,93 @@ public async Task<bool> PinRemoveInstalledAsync(WinGetPackage package)
25102511 return await PinRemoveInstalledAsync ( package . Id ) ;
25112512 }
25122513 //---------------------------------------------------------------------------------------------
2514+
2515+ //---Pin Reset---------------------------------------------------------------------------------
2516+ /// <summary>
2517+ /// Resets all pinned packages.
2518+ /// </summary>
2519+ /// <remarks>
2520+ /// This will remove all pins and it is not possible to restore them.
2521+ /// </remarks>
2522+ /// <returns>
2523+ /// <see langword="true"/> if the reset was successful or <see langword="false"/> if it failed.
2524+ /// </returns>
2525+ /// <exception cref="WGetNET.WinGetNotInstalledException">
2526+ /// WinGet is not installed or not found on the system.
2527+ /// </exception>
2528+ /// <exception cref="WGetNET.WinGetActionFailedException">
2529+ /// The current action failed for an unexpected reason.
2530+ /// Please see inner exception.
2531+ /// </exception>
2532+ /// <exception cref="WGetNET.WinGetFeatureNotSupportedException">
2533+ /// This feature is not supported in the installed WinGet version.
2534+ /// </exception>
2535+ public bool ResetPins ( )
2536+ {
2537+ if ( ! WinGetVersionIsMatchOrAbove ( 1 , 5 ) )
2538+ {
2539+ throw new WinGetFeatureNotSupportedException ( "1.5" ) ;
2540+ }
2541+
2542+ try
2543+ {
2544+ ProcessResult result =
2545+ _processManager . ExecuteWingetProcess ( _pinResetCmd ) ;
2546+
2547+ return result . Success ;
2548+ }
2549+ catch ( Win32Exception )
2550+ {
2551+ throw new WinGetNotInstalledException ( ) ;
2552+ }
2553+ catch ( Exception e )
2554+ {
2555+ throw new WinGetActionFailedException ( "Reseting of pins failed." , e ) ;
2556+ }
2557+ }
2558+
2559+ /// <summary>
2560+ /// Asynchronously resets all pinned packages.
2561+ /// </summary>
2562+ /// <remarks>
2563+ /// This will remove all pins and it is not possible to restore them.
2564+ /// </remarks>
2565+ /// <returns>
2566+ /// <see langword="true"/> if the reset was successful or <see langword="false"/> if it failed.
2567+ /// </returns>
2568+ /// <exception cref="WGetNET.WinGetNotInstalledException">
2569+ /// WinGet is not installed or not found on the system.
2570+ /// </exception>
2571+ /// <exception cref="WGetNET.WinGetActionFailedException">
2572+ /// The current action failed for an unexpected reason.
2573+ /// Please see inner exception.
2574+ /// </exception>
2575+ /// <exception cref="WGetNET.WinGetFeatureNotSupportedException">
2576+ /// This feature is not supported in the installed WinGet version.
2577+ /// </exception>
2578+ public async Task < bool > ResetPinsAsync ( )
2579+ {
2580+ if ( ! WinGetVersionIsMatchOrAbove ( 1 , 5 ) )
2581+ {
2582+ throw new WinGetFeatureNotSupportedException ( "1.5" ) ;
2583+ }
2584+
2585+ try
2586+ {
2587+ ProcessResult result =
2588+ await _processManager . ExecuteWingetProcessAsync ( _pinResetCmd ) ;
2589+
2590+ return result . Success ;
2591+ }
2592+ catch ( Win32Exception )
2593+ {
2594+ throw new WinGetNotInstalledException ( ) ;
2595+ }
2596+ catch ( Exception e )
2597+ {
2598+ throw new WinGetActionFailedException ( "Reseting of pins failed." , e ) ;
2599+ }
2600+ }
2601+ //---------------------------------------------------------------------------------------------
25132602 }
25142603}
0 commit comments