@@ -18,6 +18,7 @@ public class WinGetPackageManager : WinGetInfo
1818 {
1919 private const string _listCmd = "list" ;
2020 private const string _searchInstalledCmd = "list {0}" ;
21+ private const string _searchInstalledBySourceCmd = "list {0} --source {1}" ;
2122 private const string _searchCmd = "search {0} --accept-source-agreements" ;
2223 private const string _searchBySourceCmd = "search {0} --source {1} --accept-source-agreements" ;
2324 private const string _installCmd = "install {0}" ;
@@ -260,6 +261,44 @@ public List<WinGetPackage> GetInstalledPackages(string packageName)
260261 }
261262 }
262263
264+ /// <summary>
265+ /// Gets a list of all installed packages. That match the provided name.
266+ /// </summary>
267+ /// <param name="packageName">
268+ /// The name of the package for the search.
269+ /// </param>
270+ /// <param name="sourceName">
271+ /// The name of the source for the search.
272+ /// </param>
273+ /// <returns>
274+ /// A <see cref="System.Collections.Generic.List{T}"/> of <see cref="WGetNET.WinGetPackage"/> instances.
275+ /// </returns>
276+ /// <exception cref="WGetNET.WinGetNotInstalledException">
277+ /// WinGet is not installed or not found on the system.
278+ /// </exception>
279+ /// <exception cref="WGetNET.WinGetActionFailedException">
280+ /// The current action failed for an unexpected reason.
281+ /// Please see inner exception.
282+ /// </exception>
283+ public List < WinGetPackage > GetInstalledPackages ( string packageName , string sourceName )
284+ {
285+ try
286+ {
287+ ProcessResult result =
288+ _processManager . ExecuteWingetProcess ( string . Format ( _searchInstalledBySourceCmd , packageName , sourceName ) ) ;
289+
290+ return ProcessOutputReader . ToPackageList ( result . Output , PackageAction . InstalledListBySource , sourceName ) ;
291+ }
292+ catch ( Win32Exception )
293+ {
294+ throw new WinGetNotInstalledException ( ) ;
295+ }
296+ catch ( Exception e )
297+ {
298+ throw new WinGetActionFailedException ( "The search of installed packages failed." , e ) ;
299+ }
300+ }
301+
263302 /// <summary>
264303 /// Asynchronously gets a list of all installed packages.
265304 /// </summary>
@@ -329,6 +368,45 @@ public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageN
329368 }
330369 }
331370
371+ /// <summary>
372+ /// Asynchronously gets a list of all installed packages. That match the provided name.
373+ /// </summary>
374+ /// <param name="packageName">
375+ /// The name of the package for the search.
376+ /// </param>
377+ /// <param name="sourceName">
378+ /// The name of the source for the search.
379+ /// </param>
380+ /// <returns>
381+ /// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
382+ /// The result is a <see cref="System.Collections.Generic.List{T}"/> of <see cref="WGetNET.WinGetPackage"/> instances.
383+ /// </returns>
384+ /// <exception cref="WGetNET.WinGetNotInstalledException">
385+ /// WinGet is not installed or not found on the system.
386+ /// </exception>
387+ /// <exception cref="WGetNET.WinGetActionFailedException">
388+ /// The current action failed for an unexpected reason.
389+ /// Please see inner exception.
390+ /// </exception>
391+ public async Task < List < WinGetPackage > > GetInstalledPackagesAsync ( string packageName , string sourceName )
392+ {
393+ try
394+ {
395+ ProcessResult result =
396+ await _processManager . ExecuteWingetProcessAsync ( string . Format ( _searchInstalledBySourceCmd , packageName , sourceName ) ) ;
397+
398+ return ProcessOutputReader . ToPackageList ( result . Output , PackageAction . InstalledListBySource , sourceName ) ;
399+ }
400+ catch ( Win32Exception )
401+ {
402+ throw new WinGetNotInstalledException ( ) ;
403+ }
404+ catch ( Exception e )
405+ {
406+ throw new WinGetActionFailedException ( "The search of installed packages failed." , e ) ;
407+ }
408+ }
409+
332410 /// <summary>
333411 /// Install a package using winget.
334412 /// </summary>
0 commit comments