WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
WinGetPackageManager.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System;
6using System.Collections.Generic;
7using System.IO;
8using System.Threading;
9using System.Threading.Tasks;
12using WGetNET.Helper;
13using WGetNET.Models;
14
15namespace WGetNET
16{
21 {
22 private readonly Version _downloadMinVersion = new(1, 6, 0);
23 private readonly Version _repairMinVersion = new(1, 7, 0);
24 private readonly Version _pinMinVersion = new(1, 5, 0);
25
30 {
31 // Provide empty constructor for xlm docs
32 }
33
34 //---Search------------------------------------------------------------------------------------
54 public List<WinGetPackage> SearchPackage(string packageId, bool exact = false)
55 {
56 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
57
59
60 if (exact)
61 {
62 cmd.Exact();
63 }
64
65 ProcessResult result = Execute(cmd);
66
67 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.Search);
68 }
69
92 public List<WinGetPackage> SearchPackage(string packageId, string sourceName, bool exact = false)
93 {
94 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
95 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
96
98
99 if (exact)
100 {
101 cmd.Exact();
102 }
103
104 ProcessResult result = Execute(cmd);
105
106 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.SearchBySource, sourceName);
107 }
108
132 public async Task<List<WinGetPackage>> SearchPackageAsync(string packageId, bool exact = false, CancellationToken cancellationToken = default)
133 {
134 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
135
137
138 if (exact)
139 {
140 cmd.Exact();
141 }
142
143 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
144
145 // Return empty list if the task was cancled
146 if (cancellationToken.IsCancellationRequested)
147 {
148 return new List<WinGetPackage>();
149 }
150
151 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.Search);
152 }
153
180 public async Task<List<WinGetPackage>> SearchPackageAsync(string packageId, string sourceName, bool exact = false, CancellationToken cancellationToken = default)
181 {
182 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
183 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
184
186
187 if (exact)
188 {
189 cmd.Exact();
190 }
191
192 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
193
194 // Return empty list if the task was cancled
195 if (cancellationToken.IsCancellationRequested)
196 {
197 return new List<WinGetPackage>();
198 }
199
200 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.SearchBySource, sourceName);
201 }
202 //---------------------------------------------------------------------------------------------
203
204 //---List--------------------------------------------------------------------------------------
214 public List<WinGetPackage> GetInstalledPackages()
215 {
216 ProcessResult result = Execute(WinGetArguments.List().AcceptSourceAgreements());
217
218 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList);
219 }
220
240 public List<WinGetPackage> GetInstalledPackages(string packageId, bool exact = false)
241 {
242 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
243
245
246 if (exact)
247 {
248 cmd.Exact();
249 }
250
251 ProcessResult result = Execute(cmd);
252
253 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList);
254 }
255
278 public List<WinGetPackage> GetInstalledPackages(string packageId, string sourceName, bool exact = false)
279 {
280 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
281 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
282
284
285 if (exact)
286 {
287 cmd.Exact();
288 }
289
290 ProcessResult result = Execute(cmd);
291
292 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledListBySource, sourceName);
293 }
294
308 public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(CancellationToken cancellationToken = default)
309 {
310 ProcessResult result = await ExecuteAsync(WinGetArguments.List().AcceptSourceAgreements(), false, cancellationToken);
311
312 // Return empty list if the task was cancled
313 if (cancellationToken.IsCancellationRequested)
314 {
315 return new List<WinGetPackage>();
316 }
317
318 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList);
319 }
320
344 public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageId, bool exact = false, CancellationToken cancellationToken = default)
345 {
346 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
347
349
350 if (exact)
351 {
352 cmd.Exact();
353 }
354
355 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
356
357 // Return empty list if the task was cancled
358 if (cancellationToken.IsCancellationRequested)
359 {
360 return new List<WinGetPackage>();
361 }
362
363 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList);
364 }
365
392 public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageId, string sourceName, bool exact = false, CancellationToken cancellationToken = default)
393 {
394 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
395 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
396
398
399 if (exact)
400 {
401 cmd.Exact();
402 }
403
404 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
405
406 // Return empty list if the task was cancled
407 if (cancellationToken.IsCancellationRequested)
408 {
409 return new List<WinGetPackage>();
410 }
411
412 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledListBySource, sourceName);
413 }
414
436 public WinGetPackage? GetExactInstalledPackage(string packageId)
437 {
438 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
439
440 ProcessResult result = Execute(WinGetArguments.List().AcceptSourceAgreements());
441
442 return PackageHelper.MatchExact(
443 ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList),
444 packageId.Trim()
445 );
446 }
447
472 public WinGetPackage? GetExactInstalledPackage(string packageId, string sourceName)
473 {
474 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
475 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
476
477 ProcessResult result = Execute(WinGetArguments.List().Query(packageId).Source(sourceName).AcceptSourceAgreements());
478
479 return PackageHelper.MatchExact(
480 ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList),
481 packageId.Trim()
482 );
483 }
484
509 public async Task<WinGetPackage?> GetExactInstalledPackageAsync(string packageId, CancellationToken cancellationToken = default)
510 {
511 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
512
513 ProcessResult result = await ExecuteAsync(WinGetArguments.List().AcceptSourceAgreements(), false, cancellationToken);
514
515 // Return null if the task was cancled
516 if (cancellationToken.IsCancellationRequested)
517 {
518 return null;
519 }
520
521 return PackageHelper.MatchExact(
522 ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList),
523 packageId.Trim()
524 );
525 }
526
554 public async Task<WinGetPackage?> GetExactInstalledPackageAsync(string packageId, string sourceName, CancellationToken cancellationToken = default)
555 {
556 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
557 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName, "sourceName");
558
559 ProcessResult result =
560 await ExecuteAsync(
561 WinGetArguments.List().Query(packageId).Source(sourceName).AcceptSourceAgreements(),
562 false, cancellationToken);
563
564 // Return null if the task was cancled
565 if (cancellationToken.IsCancellationRequested)
566 {
567 return null;
568 }
569
570 return PackageHelper.MatchExact(
571 ProcessOutputReader.ToPackageList(result.Output, PackageAction.InstalledList),
572 packageId.Trim()
573 );
574 }
575 //---------------------------------------------------------------------------------------------
576
577 //---Install-----------------------------------------------------------------------------------
594 public bool InstallPackage(string packageId)
595 {
596 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
597
598 ProcessResult result = Execute(WinGetArguments.Install().Query(packageId).AcceptSourceAgreements().AcceptPackageAgreements());
599
600 return result.Success;
601 }
602
620 public bool InstallPackage(string packageId, bool silent)
621 {
622 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
623
625
626 if (silent)
627 {
628 cmd.Silent();
629 }
630
631 ProcessResult result = Execute(cmd);
632
633 return result.Success;
634 }
635
652 public bool InstallPackage(WinGetPackage package)
653 {
654 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
655
656 if (package.HasShortenedId || package.HasNoId)
657 {
658 return InstallPackage(package.Name);
659 }
660
661 return InstallPackage(package.Id);
662 }
663
681 public bool InstallPackage(WinGetPackage package, bool silent)
682 {
683 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
684
685 if (package.HasShortenedId || package.HasNoId)
686 {
687 return InstallPackage(package.Name, silent);
688 }
689
690 return InstallPackage(package.Id, silent);
691 }
692
713 public async Task<bool> InstallPackageAsync(string packageId, CancellationToken cancellationToken = default)
714 {
715 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
716
717 ProcessResult result =
718 await ExecuteAsync(
720 false, cancellationToken);
721
722 return result.Success;
723 }
724
746 public async Task<bool> InstallPackageAsync(string packageId, bool silent, CancellationToken cancellationToken = default)
747 {
748 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
749
751
752 if (silent)
753 {
754 cmd.Silent();
755 }
756
757 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
758
759 return result.Success;
760 }
761
782 public async Task<bool> InstallPackageAsync(WinGetPackage package, CancellationToken cancellationToken = default)
783 {
784 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
785
786 if (package.HasShortenedId || package.HasNoId)
787 {
788 return await InstallPackageAsync(package.Name, cancellationToken);
789 }
790
791 return await InstallPackageAsync(package.Id, cancellationToken);
792 }
793
815 public async Task<bool> InstallPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken = default)
816 {
817 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
818
819 if (package.HasShortenedId || package.HasNoId)
820 {
821 return await InstallPackageAsync(package.Name, silent, cancellationToken);
822 }
823
824 return await InstallPackageAsync(package.Id, silent, cancellationToken);
825 }
826 //---------------------------------------------------------------------------------------------
827
828 //---Uninstall---------------------------------------------------------------------------------
845 public bool UninstallPackage(string packageId)
846 {
847 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
848
849 ProcessResult result = Execute(WinGetArguments.Uninstall().Query(packageId));
850
851 return result.Success;
852 }
853
871 public bool UninstallPackage(string packageId, bool silent)
872 {
873 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
874
876
877 if (silent)
878 {
879 cmd.Silent();
880 }
881
882 ProcessResult result = Execute(cmd);
883
884 return result.Success;
885 }
886
903 public bool UninstallPackage(WinGetPackage package)
904 {
905 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
906
907 if (package.HasShortenedId || package.HasNoId)
908 {
909 return UninstallPackage(package.Name);
910 }
911
912 return UninstallPackage(package.Id);
913 }
914
932 public bool UninstallPackage(WinGetPackage package, bool silent)
933 {
934 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
935
936 if (package.HasShortenedId || package.HasNoId)
937 {
938 return UninstallPackage(package.Name, silent);
939 }
940
941 return UninstallPackage(package.Id, silent);
942 }
943
964 public async Task<bool> UninstallPackageAsync(string packageId, CancellationToken cancellationToken = default)
965 {
966 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
967
968 ProcessResult result = await ExecuteAsync(WinGetArguments.Uninstall().Query(packageId), false, cancellationToken);
969
970 return result.Success;
971 }
972
994 public async Task<bool> UninstallPackageAsync(string packageId, bool silent, CancellationToken cancellationToken = default)
995 {
996 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
997
999
1000 if (silent)
1001 {
1002 cmd.Silent();
1003 }
1004
1005 ProcessResult result =
1006 await ExecuteAsync(cmd, false, cancellationToken);
1007
1008 return result.Success;
1009 }
1010
1031 public async Task<bool> UninstallPackageAsync(WinGetPackage package, CancellationToken cancellationToken = default)
1032 {
1033 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1034
1035 if (package.HasShortenedId || package.HasNoId)
1036 {
1037 return await UninstallPackageAsync(package.Name, cancellationToken);
1038 }
1039
1040 return await UninstallPackageAsync(package.Id, cancellationToken);
1041 }
1042
1064 public async Task<bool> UninstallPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken = default)
1065 {
1066 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1067
1068 if (package.HasShortenedId || package.HasNoId)
1069 {
1070 return await UninstallPackageAsync(package.Name, silent, cancellationToken);
1071 }
1072
1073 return await UninstallPackageAsync(package.Id, silent, cancellationToken);
1074 }
1075 //---------------------------------------------------------------------------------------------
1076
1077 //---List Upgrades-----------------------------------------------------------------------------
1087 public List<WinGetPackage> GetUpgradeablePackages()
1088 {
1089 WinGetArguments cmd =
1090 IncludeUnknownbyVersion(
1092
1093 ProcessResult result = Execute(cmd);
1094
1095 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.UpgradeList);
1096 }
1097
1111 public async Task<List<WinGetPackage>> GetUpgradeablePackagesAsync(CancellationToken cancellationToken = default)
1112 {
1113 WinGetArguments cmd =
1114 IncludeUnknownbyVersion(
1116
1117 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
1118
1119 // Return empty list if the task was cancled
1120 if (cancellationToken.IsCancellationRequested)
1121 {
1122 return new List<WinGetPackage>();
1123 }
1124
1125 return ProcessOutputReader.ToPackageList(result.Output, PackageAction.UpgradeList);
1126 }
1127 //---------------------------------------------------------------------------------------------
1128
1129 //---Upgrade-----------------------------------------------------------------------------------
1146 public bool UpgradePackage(string packageId)
1147 {
1148 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1149
1150 ProcessResult result = Execute(WinGetArguments.Upgrade().Query(packageId).AcceptSourceAgreements().AcceptPackageAgreements());
1151
1152 return result.Success;
1153 }
1154
1172 public bool UpgradePackage(string packageId, bool silent)
1173 {
1174 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1175
1177
1178 if (silent)
1179 {
1180 cmd.Silent();
1181 }
1182
1183 ProcessResult result = Execute(cmd);
1184
1185 return result.Success;
1186 }
1187
1204 public bool UpgradePackage(WinGetPackage package)
1205 {
1206 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1207
1208 if (package.HasShortenedId || package.HasNoId)
1209 {
1210 return UpgradePackage(package.Name);
1211 }
1212
1213 return UpgradePackage(package.Id);
1214 }
1215
1233 public bool UpgradePackage(WinGetPackage package, bool silent)
1234 {
1235 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1236
1237 if (package.HasShortenedId || package.HasNoId)
1238 {
1239 return UpgradePackage(package.Name, silent);
1240 }
1241
1242 return UpgradePackage(package.Id, silent);
1243 }
1244
1265 public async Task<bool> UpgradePackageAsync(string packageId, CancellationToken cancellationToken = default)
1266 {
1267 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1268
1269 ProcessResult result =
1270 await ExecuteAsync(
1272 false, cancellationToken);
1273
1274 return result.Success;
1275 }
1276
1298 public async Task<bool> UpgradePackageAsync(string packageId, bool silent, CancellationToken cancellationToken = default)
1299 {
1300 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1301
1303
1304 if (silent)
1305 {
1306 cmd.Silent();
1307 }
1308
1309 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
1310
1311 return result.Success;
1312 }
1313
1334 public async Task<bool> UpgradePackageAsync(WinGetPackage package, CancellationToken cancellationToken = default)
1335 {
1336 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1337
1338 if (package.HasShortenedId || package.HasNoId)
1339 {
1340 return await UpgradePackageAsync(package.Name, cancellationToken);
1341 }
1342
1343 return await UpgradePackageAsync(package.Id, cancellationToken);
1344 }
1345
1367 public async Task<bool> UpgradePackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken = default)
1368 {
1369 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1370
1371 if (package.HasShortenedId || package.HasNoId)
1372 {
1373 return await UpgradePackageAsync(package.Name, silent, cancellationToken);
1374 }
1375
1376 return await UpgradePackageAsync(package.Id, silent, cancellationToken);
1377 }
1378
1392 {
1393 ProcessResult result = Execute(WinGetArguments.Upgrade().All().AcceptSourceAgreements().AcceptPackageAgreements());
1394
1395 return result.Success;
1396 }
1397
1411 public bool UpgradeAllPackages(bool silent)
1412 {
1414
1415 if (silent)
1416 {
1417 cmd.Silent();
1418 }
1419
1420 ProcessResult result = Execute(cmd);
1421
1422 return result.Success;
1423 }
1424
1441 public async Task<bool> UpgradeAllPackagesAsync(CancellationToken cancellationToken = default)
1442 {
1443 ProcessResult result =
1444 await ExecuteAsync(
1446 false, cancellationToken);
1447
1448 return result.Success;
1449 }
1450
1468 public async Task<bool> UpgradeAllPackagesAsync(bool silent, CancellationToken cancellationToken = default)
1469 {
1471
1472 if (silent)
1473 {
1474 cmd.Silent();
1475 }
1476
1477 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
1478
1479 return result.Success;
1480 }
1481 //---------------------------------------------------------------------------------------------
1482
1483 //---Repair------------------------------------------------------------------------------------
1504 public bool RepairPackage(string packageId)
1505 {
1506 if (!CheckWinGetVersion(_repairMinVersion))
1507 {
1508 throw new WinGetFeatureNotSupportedException(_repairMinVersion);
1509 }
1510
1511 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1512
1513 ProcessResult result = Execute(WinGetArguments.Repair().Query(packageId).AcceptSourceAgreements().AcceptPackageAgreements());
1514
1515 return result.Success;
1516 }
1517
1539 public bool RepairPackage(string packageId, bool silent)
1540 {
1541 if (!CheckWinGetVersion(_repairMinVersion))
1542 {
1543 throw new WinGetFeatureNotSupportedException(_repairMinVersion);
1544 }
1545
1546 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1547
1549
1550 if (silent)
1551 {
1552 cmd.Silent();
1553 }
1554
1555 ProcessResult result = Execute(cmd);
1556
1557 return result.Success;
1558 }
1559
1580 public bool RepairPackage(WinGetPackage package)
1581 {
1582 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1583
1584 if (package.HasShortenedId || package.HasNoId)
1585 {
1586 return RepairPackage(package.Name);
1587 }
1588
1589 return RepairPackage(package.Id);
1590 }
1591
1613 public bool RepairPackage(WinGetPackage package, bool silent)
1614 {
1615 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1616
1617 if (package.HasShortenedId || package.HasNoId)
1618 {
1619 return RepairPackage(package.Name, silent);
1620 }
1621
1622 return RepairPackage(package.Id, silent);
1623 }
1624
1649 public async Task<bool> RepairPackageAsync(string packageId, CancellationToken cancellationToken = default)
1650 {
1651 if (!CheckWinGetVersion(_repairMinVersion))
1652 {
1653 throw new WinGetFeatureNotSupportedException(_repairMinVersion);
1654 }
1655
1656 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1657
1658 ProcessResult result =
1659 await ExecuteAsync(
1661 .Repair()
1662 .Query(packageId)
1663 .AcceptSourceAgreements()
1664 .AcceptPackageAgreements(),
1665 false, cancellationToken);
1666
1667 return result.Success;
1668 }
1669
1695 public async Task<bool> RepairPackageAsync(string packageId, bool silent, CancellationToken cancellationToken = default)
1696 {
1697 if (!CheckWinGetVersion(_repairMinVersion))
1698 {
1699 throw new WinGetFeatureNotSupportedException(_repairMinVersion);
1700 }
1701
1702 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
1703
1705
1706 if (silent)
1707 {
1708 cmd.Silent();
1709 }
1710
1711 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
1712
1713 return result.Success;
1714 }
1715
1740 public async Task<bool> RepairPackageAsync(WinGetPackage package, CancellationToken cancellationToken = default)
1741 {
1742 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1743
1744 if (package.HasShortenedId || package.HasNoId)
1745 {
1746 return await RepairPackageAsync(package.Name, cancellationToken);
1747 }
1748
1749 return await RepairPackageAsync(package.Id, cancellationToken);
1750 }
1751
1777 public async Task<bool> RepairPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken = default)
1778 {
1779 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
1780
1781 if (package.HasShortenedId || package.HasNoId)
1782 {
1783 return await RepairPackageAsync(package.Name, silent, cancellationToken);
1784 }
1785
1786 return await RepairPackageAsync(package.Id, silent, cancellationToken);
1787 }
1788 //---------------------------------------------------------------------------------------------
1789
1790 //---Export and Import-------------------------------------------------------------------------
1807 public bool ExportPackagesToFile(string file)
1808 {
1809 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
1810
1811 ProcessResult result = Execute(WinGetArguments.Export().File(file).AcceptSourceAgreements());
1812
1813 return result.Success;
1814 }
1815
1836 public async Task<bool> ExportPackagesToFileAsync(string file, CancellationToken cancellationToken = default)
1837 {
1838 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
1839
1840 ProcessResult result =
1841 await ExecuteAsync(WinGetArguments.Export().File(file).AcceptSourceAgreements(), false, cancellationToken);
1842
1843 return result.Success;
1844 }
1845
1866 public bool ImportPackagesFromFile(string file)
1867 {
1868 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
1869
1870 ProcessResult result =
1871 Execute(
1873 .Import()
1874 .File(file)
1875 .IgnoreUnavailable()
1876 .AcceptSourceAgreements()
1877 .AcceptPackageAgreements());
1878
1879 return result.Success;
1880 }
1881
1906 public async Task<bool> ImportPackagesFromFileAsync(string file, CancellationToken cancellationToken = default)
1907 {
1908 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
1909
1910 ProcessResult result =
1911 await ExecuteAsync(
1913 .Import()
1914 .File(file)
1915 .IgnoreUnavailable()
1916 .AcceptSourceAgreements()
1917 .AcceptPackageAgreements(),
1918 false, cancellationToken);
1919
1920 return result.Success;
1921 }
1922 //---------------------------------------------------------------------------------------------
1923
1924 //---Hash--------------------------------------------------------------------------------------
1946 public string Hash(string file)
1947 {
1948 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
1949
1950 if (!File.Exists(file))
1951 {
1952 throw new FileNotFoundException($"Unable to find the specified file. File:'{file}'");
1953 }
1954
1955 ProcessResult result = Execute(WinGetArguments.Hash().File(file));
1956
1957 if (!result.Success)
1958 {
1959 return string.Empty;
1960 }
1961
1962 return ProcessOutputReader.ResultToHash(result);
1963 }
1964
1983 public string Hash(FileInfo file)
1984 {
1985 ArgsHelper.ThrowIfObjectIsNull(file, "file");
1986
1987 if (!file.Exists)
1988 {
1989 throw new FileNotFoundException($"Unable to find the specified file. File:'{file.FullName}'");
1990 }
1991
1992 return Hash(file.FullName);
1993 }
1994
2020 public async Task<string> HashAsync(string file, CancellationToken cancellationToken = default)
2021 {
2022 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file, "file");
2023
2024 if (!File.Exists(file))
2025 {
2026 throw new FileNotFoundException($"Unable to find the specified file. File:'{file}'");
2027 }
2028
2029 ProcessResult result = await ExecuteAsync(WinGetArguments.Hash().File(file), false, cancellationToken);
2030
2031 if (!result.Success || cancellationToken.IsCancellationRequested)
2032 {
2033 return string.Empty;
2034 }
2035
2036 return ProcessOutputReader.ResultToHash(result);
2037 }
2038
2061 public async Task<string> HashAsync(FileInfo file, CancellationToken cancellationToken = default)
2062 {
2063 ArgsHelper.ThrowIfObjectIsNull(file, "file");
2064
2065 if (!file.Exists)
2066 {
2067 throw new FileNotFoundException($"Unable to find the specified file. File:'{file.FullName}'");
2068 }
2069
2070 return await HashAsync(file.FullName, cancellationToken);
2071 }
2072 //---------------------------------------------------------------------------------------------
2073
2074 //---Download----------------------------------------------------------------------------------
2095 public bool Download(string packageId, string directory)
2096 {
2097 if (!CheckWinGetVersion(_downloadMinVersion))
2098 {
2099 throw new WinGetFeatureNotSupportedException(_downloadMinVersion);
2100 }
2101
2102 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2103 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(directory, "directory");
2104
2105 ProcessResult result =
2106 Execute(
2108 .Download()
2109 .Query(packageId)
2110 .Directory(directory)
2111 .AcceptSourceAgreements()
2112 .AcceptPackageAgreements());
2113
2114 return result.Success;
2115 }
2116
2140 public bool Download(string packageId, DirectoryInfo directory)
2141 {
2142 ArgsHelper.ThrowIfObjectIsNull(directory, "directory");
2143
2144 return Download(packageId, directory.FullName);
2145 }
2146
2167 public bool Download(WinGetPackage package, string directory)
2168 {
2169 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2170
2171 if (package.HasShortenedId || package.HasNoId)
2172 {
2173 return Download(package.Name, directory);
2174 }
2175
2176 return Download(package.Id, directory);
2177 }
2178
2202 public bool Download(WinGetPackage package, DirectoryInfo directory)
2203 {
2204 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2205 ArgsHelper.ThrowIfObjectIsNull(directory, "directory");
2206
2207 if (package.HasShortenedId || package.HasNoId)
2208 {
2209 return Download(package.Name, directory.FullName);
2210 }
2211
2212 return Download(package.Id, directory.FullName);
2213 }
2214
2239 public async Task<bool> DownloadAsync(string packageId, string directory, CancellationToken cancellationToken = default)
2240 {
2241 if (!CheckWinGetVersion(_downloadMinVersion))
2242 {
2243 throw new WinGetFeatureNotSupportedException(_downloadMinVersion);
2244 }
2245
2246 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2247 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(directory, "directory");
2248
2249 ProcessResult result =
2250 await ExecuteAsync(
2252 .Download()
2253 .Query(packageId)
2254 .Directory(directory)
2255 .AcceptSourceAgreements()
2256 .AcceptPackageAgreements(),
2257 false, cancellationToken);
2258
2259 return result.Success;
2260 }
2261
2289 public async Task<bool> DownloadAsync(string packageId, DirectoryInfo directory, CancellationToken cancellationToken = default)
2290 {
2291 ArgsHelper.ThrowIfObjectIsNull(directory, "directory");
2292
2293 return await DownloadAsync(packageId, directory.FullName, cancellationToken);
2294 }
2295
2320 public async Task<bool> DownloadAsync(WinGetPackage package, string directory, CancellationToken cancellationToken = default)
2321 {
2322 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2323
2324 if (package.HasShortenedId || package.HasNoId)
2325 {
2326 return await DownloadAsync(package.Name, directory, cancellationToken);
2327 }
2328
2329 return await DownloadAsync(package.Id, directory, cancellationToken);
2330 }
2331
2359 public async Task<bool> DownloadAsync(WinGetPackage package, DirectoryInfo directory, CancellationToken cancellationToken = default)
2360 {
2361 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2362 ArgsHelper.ThrowIfObjectIsNull(directory, "directory");
2363
2364 if (package.HasShortenedId || package.HasNoId)
2365 {
2366 return await DownloadAsync(package.Name, directory.FullName, cancellationToken);
2367 }
2368
2369 return await DownloadAsync(package.Id, directory.FullName, cancellationToken);
2370 }
2371 //---------------------------------------------------------------------------------------------
2372
2373 //---Pin List----------------------------------------------------------------------------------
2386 public List<WinGetPinnedPackage> GetPinnedPackages()
2387 {
2388 if (!CheckWinGetVersion(_pinMinVersion))
2389 {
2390 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2391 }
2392
2393 ProcessResult result = Execute(WinGetArguments.PinList());
2394
2395 return ProcessOutputReader.ToPinnedPackageList(result.Output);
2396 }
2397
2414 public async Task<List<WinGetPinnedPackage>> GetPinnedPackagesAsync(CancellationToken cancellationToken = default)
2415 {
2416 if (!CheckWinGetVersion(_pinMinVersion))
2417 {
2418 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2419 }
2420
2421 ProcessResult result = await ExecuteAsync(WinGetArguments.PinList(), false, cancellationToken);
2422
2423 // Return empty list if the task was cancled
2424 if (cancellationToken.IsCancellationRequested)
2425 {
2426 return new List<WinGetPinnedPackage>();
2427 }
2428
2429 return ProcessOutputReader.ToPinnedPackageList(result.Output);
2430 }
2431 //---------------------------------------------------------------------------------------------
2432
2433 //---Pin Add-----------------------------------------------------------------------------------
2454 public bool PinAdd(string packageId, bool blocking = false)
2455 {
2456 if (!CheckWinGetVersion(_pinMinVersion))
2457 {
2458 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2459 }
2460
2461 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2462
2463 WinGetArguments cmd = WinGetArguments.PinAdd().Query(packageId);
2464
2465 if (blocking)
2466 {
2467 cmd.Blocking();
2468 }
2469
2470 ProcessResult result = Execute(cmd);
2471
2472 return result.Success;
2473 }
2474
2498 public bool PinAdd(string packageId, string version)
2499 {
2500 if (!CheckWinGetVersion(_pinMinVersion))
2501 {
2502 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2503 }
2504
2505 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2506 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
2507
2508 ProcessResult result = Execute(WinGetArguments.PinAdd().Query(packageId).Version(version));
2509
2510 return result.Success;
2511 }
2512
2533 public bool PinAdd(WinGetPackage package, bool blocking = false)
2534 {
2535 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2536
2537 if (package.HasShortenedId || package.HasNoId)
2538 {
2539 return PinAdd(package.Name, blocking);
2540 }
2541
2542 return PinAdd(package.Id, blocking);
2543 }
2544
2568 public bool PinAdd(WinGetPackage package, string version)
2569 {
2570 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2571
2572 if (package.HasShortenedId || package.HasNoId)
2573 {
2574 return PinAdd(package.Name, version);
2575 }
2576
2577 return PinAdd(package.Id, version);
2578 }
2579
2604 public async Task<bool> PinAddAsync(string packageId, bool blocking = false, CancellationToken cancellationToken = default)
2605 {
2606 if (!CheckWinGetVersion(_pinMinVersion))
2607 {
2608 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2609 }
2610
2611 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2612
2613 WinGetArguments cmd = WinGetArguments.PinAdd().Query(packageId);
2614
2615 if (blocking)
2616 {
2617 cmd.Blocking();
2618 }
2619
2620 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
2621
2622 return result.Success;
2623 }
2624
2652 public async Task<bool> PinAddAsync(string packageId, string version, CancellationToken cancellationToken = default)
2653 {
2654 if (!CheckWinGetVersion(_pinMinVersion))
2655 {
2656 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2657 }
2658
2659 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2660 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
2661
2662 ProcessResult result = await ExecuteAsync(WinGetArguments.PinAdd().Query(packageId).Version(version), false, cancellationToken);
2663
2664 return result.Success;
2665 }
2666
2691 public async Task<bool> PinAddAsync(WinGetPackage package, bool blocking = false, CancellationToken cancellationToken = default)
2692 {
2693 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2694
2695 if (package.HasShortenedId || package.HasNoId)
2696 {
2697 return await PinAddAsync(package.Name, blocking, cancellationToken);
2698 }
2699
2700 return await PinAddAsync(package.Id, blocking, cancellationToken);
2701 }
2702
2730 public async Task<bool> PinAddAsync(WinGetPackage package, string version, CancellationToken cancellationToken = default)
2731 {
2732 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2733
2734 if (package.HasShortenedId || package.HasNoId)
2735 {
2736 return await PinAddAsync(package.Name, version, cancellationToken);
2737 }
2738
2739 return await PinAddAsync(package.Id, version, cancellationToken);
2740 }
2741
2762 public bool PinAddInstalled(string packageId, bool blocking = false)
2763 {
2764 if (!CheckWinGetVersion(_pinMinVersion))
2765 {
2766 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2767 }
2768
2769 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2770
2772
2773 if (blocking)
2774 {
2775 cmd.Blocking();
2776 }
2777
2778 ProcessResult result = Execute(cmd);
2779
2780 return result.Success;
2781 }
2782
2806 public bool PinAddInstalled(string packageId, string version)
2807 {
2808 if (!CheckWinGetVersion(_pinMinVersion))
2809 {
2810 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2811 }
2812
2813 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2814 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
2815
2816 ProcessResult result = Execute(WinGetArguments.PinAdd().Query(packageId).Installed().Version(version));
2817
2818 return result.Success;
2819 }
2820
2841 public bool PinAddInstalled(WinGetPackage package, bool blocking = false)
2842 {
2843 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2844
2845 if (package.HasShortenedId || package.HasNoId)
2846 {
2847 return PinAddInstalled(package.Name, blocking);
2848 }
2849
2850 return PinAddInstalled(package.Id, blocking);
2851 }
2852
2876 public bool PinAddInstalled(WinGetPackage package, string version)
2877 {
2878 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
2879
2880 if (package.HasShortenedId || package.HasNoId)
2881 {
2882 return PinAddInstalled(package.Name, version);
2883 }
2884
2885 return PinAddInstalled(package.Id, version);
2886 }
2887
2912 public async Task<bool> PinAddInstalledAsync(string packageId, bool blocking = false, CancellationToken cancellationToken = default)
2913 {
2914 if (!CheckWinGetVersion(_pinMinVersion))
2915 {
2916 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2917 }
2918
2919 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2920
2922
2923 if (blocking)
2924 {
2925 cmd.Blocking();
2926 }
2927
2928 ProcessResult result = await ExecuteAsync(cmd, false, cancellationToken);
2929
2930 return result.Success;
2931 }
2932
2960 public async Task<bool> PinAddInstalledAsync(string packageId, string version, CancellationToken cancellationToken = default)
2961 {
2962 if (!CheckWinGetVersion(_pinMinVersion))
2963 {
2964 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
2965 }
2966
2967 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
2968 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
2969
2970 ProcessResult result =
2971 await ExecuteAsync(
2972 WinGetArguments.PinAdd().Query(packageId).Installed().Version(version),
2973 false, cancellationToken);
2974
2975 return result.Success;
2976 }
2977
3002 public async Task<bool> PinAddInstalledAsync(WinGetPackage package, bool blocking = false, CancellationToken cancellationToken = default)
3003 {
3004 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3005
3006 if (package.HasShortenedId || package.HasNoId)
3007 {
3008 return await PinAddInstalledAsync(package.Name, blocking, cancellationToken);
3009 }
3010
3011 return await PinAddInstalledAsync(package.Id, blocking, cancellationToken);
3012 }
3013
3041 public async Task<bool> PinAddInstalledAsync(WinGetPackage package, string version, CancellationToken cancellationToken = default)
3042 {
3043 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3044
3045 if (package.HasShortenedId || package.HasNoId)
3046 {
3047 return await PinAddInstalledAsync(package.Name, version, cancellationToken);
3048 }
3049
3050 return await PinAddInstalledAsync(package.Id, version, cancellationToken);
3051 }
3052 //---------------------------------------------------------------------------------------------
3053
3054 //---Pin Remove--------------------------------------------------------------------------------
3074 public bool PinRemove(string packageId)
3075 {
3076 if (!CheckWinGetVersion(_pinMinVersion))
3077 {
3078 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3079 }
3080
3081 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
3082
3083 ProcessResult result = Execute(WinGetArguments.PinRemove().Query(packageId));
3084
3085 return result.Success;
3086 }
3087
3107 public bool PinRemove(WinGetPackage package)
3108 {
3109 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3110
3111 if (package.HasShortenedId || package.HasNoId)
3112 {
3113 return PinRemove(package.Name);
3114 }
3115
3116 return PinRemove(package.Id);
3117 }
3118
3142 public async Task<bool> PinRemoveAsync(string packageId, CancellationToken cancellationToken = default)
3143 {
3144 if (!CheckWinGetVersion(_pinMinVersion))
3145 {
3146 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3147 }
3148
3149 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
3150
3151 ProcessResult result = await ExecuteAsync(WinGetArguments.PinRemove().Query(packageId), false, cancellationToken);
3152
3153 return result.Success;
3154 }
3155
3179 public async Task<bool> PinRemoveAsync(WinGetPackage package, CancellationToken cancellationToken = default)
3180 {
3181 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3182
3183 if (package.HasShortenedId || package.HasNoId)
3184 {
3185 return await PinRemoveAsync(package.Name, cancellationToken);
3186 }
3187
3188 return await PinRemoveAsync(package.Id, cancellationToken);
3189 }
3190
3210 public bool PinRemoveInstalled(string packageId)
3211 {
3212 if (!CheckWinGetVersion(_pinMinVersion))
3213 {
3214 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3215 }
3216
3217 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
3218
3219 ProcessResult result = Execute(WinGetArguments.PinRemove().Query(packageId).Installed());
3220
3221 return result.Success;
3222 }
3223
3244 {
3245 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3246
3247 if (package.HasShortenedId || package.HasNoId)
3248 {
3249 return PinRemoveInstalled(package.Name);
3250 }
3251
3252 return PinRemoveInstalled(package.Id);
3253 }
3254
3278 public async Task<bool> PinRemoveInstalledAsync(string packageId, CancellationToken cancellationToken = default)
3279 {
3280 if (!CheckWinGetVersion(_pinMinVersion))
3281 {
3282 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3283 }
3284
3285 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(packageId, "packageId");
3286
3287 ProcessResult result = await ExecuteAsync(WinGetArguments.PinRemove().Query(packageId).Installed(), false, cancellationToken);
3288
3289 return result.Success;
3290 }
3291
3315 public async Task<bool> PinRemoveInstalledAsync(WinGetPackage package, CancellationToken cancellationToken = default)
3316 {
3317 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(package, "package");
3318
3319 if (package.HasShortenedId || package.HasNoId)
3320 {
3321 return await PinRemoveInstalledAsync(package.Name, cancellationToken);
3322 }
3323
3324 return await PinRemoveInstalledAsync(package.Id, cancellationToken);
3325 }
3326 //---------------------------------------------------------------------------------------------
3327
3328 //---Pin Reset---------------------------------------------------------------------------------
3344 public bool ResetPins()
3345 {
3346 if (!CheckWinGetVersion(_pinMinVersion))
3347 {
3348 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3349 }
3350
3351 ProcessResult result = Execute(WinGetArguments.PinReset().Force());
3352
3353 return result.Success;
3354 }
3355
3375 public async Task<bool> ResetPinsAsync(CancellationToken cancellationToken = default)
3376 {
3377 if (!CheckWinGetVersion(_pinMinVersion))
3378 {
3379 throw new WinGetFeatureNotSupportedException(_pinMinVersion);
3380 }
3381
3382 ProcessResult result = await ExecuteAsync(WinGetArguments.PinReset().Force(), false, cancellationToken);
3383
3384 return result.Success;
3385 }
3386 //---------------------------------------------------------------------------------------------
3387
3388 //---Helper Functions--------------------------------------------------------------------------
3399 private WinGetArguments IncludeUnknownbyVersion(WinGetArguments arguments)
3400 {
3401 // Checking version to determine if "--include-unknown" is necessary.
3402 if (CheckWinGetVersion(new Version(1, 4, 0)))
3403 {
3404 // Winget version supports new argument, add "--include-unknown" to arguments
3405 arguments.IncludeUnknown();
3406 }
3407 return arguments;
3408 }
3409 //---------------------------------------------------------------------------------------------
3410 }
3411}
The WGetNET.WinGet class offers informations about the installed winget version.
Definition WinGet.cs:24
Version Version
Gets the version number of the winget installation.
Definition WinGet.cs:107
The WGetNET.WinGetPackageManager class offers methods to manage packages with winget.
async Task< bool > UpgradePackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken=default)
Asynchronously upgrades a package using winget.
async Task< bool > DownloadAsync(WinGetPackage package, DirectoryInfo directory, CancellationToken cancellationToken=default)
Asynchronously downloads the installer of a package using winget.
async Task< bool > PinAddAsync(string packageId, bool blocking=false, CancellationToken cancellationToken=default)
Asynchronously adds a pinned package to winget.
async Task< bool > UpgradePackageAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously upgrades a package using winget.
async Task< bool > RepairPackageAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously repairs a package using winget.
async Task< bool > PinAddInstalledAsync(WinGetPackage package, bool blocking=false, CancellationToken cancellationToken=default)
Asynchronously adds a pinned installed package to winget.
async Task< bool > InstallPackageAsync(string packageId, bool silent, CancellationToken cancellationToken=default)
Asynchronously install a package using winget.
async Task< bool > PinAddInstalledAsync(string packageId, string version, CancellationToken cancellationToken=default)
Asynchronously adds a pinned installed package to winget.
async Task< bool > RepairPackageAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously repair a package using winget.
bool InstallPackage(WinGetPackage package, bool silent)
Install a package using winget.
bool UninstallPackage(string packageId)
Uninsatll a package using winget.
bool UpgradeAllPackages()
Tries to upgrade all packages using winget.
async Task< WinGetPackage?> GetExactInstalledPackageAsync(string packageId, string sourceName, CancellationToken cancellationToken=default)
Asynchronously gets a installed package, that matchs the provided id/name. If there are multiple matc...
bool RepairPackage(WinGetPackage package)
Repairs a package using winget.
async Task< WinGetPackage?> GetExactInstalledPackageAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously gets a installed package, that matchs the provided id/name. If there are multiple matc...
async Task< bool > PinRemoveAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously removes a pinned package from winget.
List< WinGetPinnedPackage > GetPinnedPackages()
Gets a list of all pinned packages.
bool PinRemove(WinGetPackage package)
Removes a pinned package from winget.
bool UninstallPackage(string packageId, bool silent)
Uninsatll a package using winget.
bool RepairPackage(string packageId)
Repairs a package using winget.
async Task< List< WinGetPackage > > GetUpgradeablePackagesAsync(CancellationToken cancellationToken=default)
Asynchronously get all upgradeable packages.
async Task< bool > DownloadAsync(string packageId, string directory, CancellationToken cancellationToken=default)
Asynchronously downloads the installer of a package using winget.
bool PinRemoveInstalled(string packageId)
Removes a pinned package from winget.
bool PinRemove(string packageId)
Removes a pinned package from winget.
async Task< bool > PinAddInstalledAsync(string packageId, bool blocking=false, CancellationToken cancellationToken=default)
Asynchronously adds a pinned installed package to winget.
async Task< bool > InstallPackageAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously install a package using winget.
async Task< bool > RepairPackageAsync(string packageId, bool silent, CancellationToken cancellationToken=default)
Asynchronously repairs a package using winget.
List< WinGetPackage > GetInstalledPackages(string packageId, bool exact=false)
Gets a list of all installed packages. That match the provided name.
bool Download(WinGetPackage package, DirectoryInfo directory)
Downloads the installer of a package using winget.
bool UpgradePackage(string packageId)
Upgrades a package using winget.
bool PinAddInstalled(WinGetPackage package, bool blocking=false)
Adds a pinned installed package to winget.
async Task< bool > InstallPackageAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously install a package using winget.
List< WinGetPackage > GetInstalledPackages(string packageId, string sourceName, bool exact=false)
Gets a list of all installed packages. That match the provided name.
async Task< bool > UpgradePackageAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously upgrades a package using winget.
async Task< bool > UninstallPackageAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously uninstall a package using winget.
async Task< bool > DownloadAsync(WinGetPackage package, string directory, CancellationToken cancellationToken=default)
Asynchronously downloads the installer of a package using winget.
string Hash(FileInfo file)
Executes the WinGet hash function, to calculate the hash for the given file.
async Task< List< WinGetPackage > > SearchPackageAsync(string packageId, string sourceName, bool exact=false, CancellationToken cancellationToken=default)
Uses the winget search function to asynchronously search for a package that maches the given name.
async Task< bool > PinAddAsync(string packageId, string version, CancellationToken cancellationToken=default)
Asynchronously adds a pinned package to winget.
async Task< bool > PinAddInstalledAsync(WinGetPackage package, string version, CancellationToken cancellationToken=default)
Asynchronously adds a pinned installed package to winget.
bool ExportPackagesToFile(string file)
Exports a list of all installed winget packages as json to the given file.
async Task< bool > UpgradePackageAsync(string packageId, bool silent, CancellationToken cancellationToken=default)
Asynchronously upgrades a package using winget.
bool UpgradePackage(WinGetPackage package)
Upgrades a package using winget.
async Task< List< WinGetPackage > > SearchPackageAsync(string packageId, bool exact=false, CancellationToken cancellationToken=default)
Uses the winget search function to asynchronously search for a package that maches the given name.
async Task< bool > ExportPackagesToFileAsync(string file, CancellationToken cancellationToken=default)
Asynchronously exports a list of all installed winget packages as json to the given file.
async Task< bool > ResetPinsAsync(CancellationToken cancellationToken=default)
Asynchronously resets all pinned packages.
bool InstallPackage(string packageId)
Install a package using winget.
async Task< List< WinGetPackage > > GetInstalledPackagesAsync(string packageId, string sourceName, bool exact=false, CancellationToken cancellationToken=default)
Asynchronously gets a list of all installed packages. That match the provided name.
bool Download(string packageId, string directory)
Downloads the installer of a package using winget.
bool ResetPins()
Resets all pinned packages.
async Task< bool > UninstallPackageAsync(string packageId, bool silent, CancellationToken cancellationToken=default)
Asynchronously uninsatll a package using winget.
async Task< bool > PinRemoveInstalledAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously removes a pinned package from winget.
async Task< List< WinGetPackage > > GetInstalledPackagesAsync(CancellationToken cancellationToken=default)
Asynchronously gets a list of all installed packages.
bool UninstallPackage(WinGetPackage package, bool silent)
Uninstall a package using winget.
bool InstallPackage(string packageId, bool silent)
Install a package using winget.
async Task< bool > PinAddAsync(WinGetPackage package, bool blocking=false, CancellationToken cancellationToken=default)
Asynchronously adds a pinned package to winget.
async Task< bool > PinRemoveInstalledAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously removes a pinned package from winget.
async Task< bool > UpgradeAllPackagesAsync(bool silent, CancellationToken cancellationToken=default)
Asynchronously tries to upgrade all packages using winget.
async Task< bool > RepairPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken=default)
Asynchronously repair a package using winget.
bool UninstallPackage(WinGetPackage package)
Uninstall a package using winget.
List< WinGetPackage > SearchPackage(string packageId, string sourceName, bool exact=false)
Uses the winget search function to search for a package that maches the given name.
List< WinGetPackage > GetInstalledPackages()
Gets a list of all installed packages.
bool PinAdd(WinGetPackage package, bool blocking=false)
Adds a pinned package to winget.
bool ImportPackagesFromFile(string file)
Imports packages and trys to installes/upgrade all pakages in the list, if possible.
async Task< bool > PinRemoveAsync(WinGetPackage package, CancellationToken cancellationToken=default)
Asynchronously removes a pinned package from winget.
bool Download(WinGetPackage package, string directory)
Downloads the installer of a package using winget.
bool RepairPackage(WinGetPackage package, bool silent)
Repairs a package using winget.
async Task< bool > UpgradeAllPackagesAsync(CancellationToken cancellationToken=default)
Asynchronously tries to upgrade all packages using winget.
async Task< bool > ImportPackagesFromFileAsync(string file, CancellationToken cancellationToken=default)
Asynchronously imports packages and trys to installes/upgrade all pakages in the list,...
bool UpgradeAllPackages(bool silent)
Tries to upgrade all packages using winget.
async Task< string > HashAsync(FileInfo file, CancellationToken cancellationToken=default)
Asynchronously executes the WinGet hash function, to calculate the hash for the given file.
bool RepairPackage(string packageId, bool silent)
Repairs a package using winget.
bool PinRemoveInstalled(WinGetPackage package)
Removes a pinned package from winget.
async Task< bool > PinAddAsync(WinGetPackage package, string version, CancellationToken cancellationToken=default)
Asynchronously adds a pinned package to winget.
async Task< List< WinGetPackage > > GetInstalledPackagesAsync(string packageId, bool exact=false, CancellationToken cancellationToken=default)
Asynchronously gets a list of all installed packages. That match the provided name.
WinGetPackage? GetExactInstalledPackage(string packageId, string sourceName)
Gets a installed package, that matchs the provided id/name. If there are multiple matches,...
async Task< bool > UninstallPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken=default)
Asynchronously uninstall a package using winget.
bool PinAddInstalled(string packageId, bool blocking=false)
Adds a pinned installed package to winget.
WinGetPackageManager()
Initializes a new instance of the WGetNET.WinGetPackageManager class.
bool UpgradePackage(WinGetPackage package, bool silent)
Upgrades a package using winget.
WinGetPackage? GetExactInstalledPackage(string packageId)
Gets a installed package, that matchs the provided id/name. If there are multiple matches,...
bool PinAddInstalled(string packageId, string version)
Adds a pinned installed package to winget.
bool PinAddInstalled(WinGetPackage package, string version)
Adds a pinned installed package to winget.
async Task< List< WinGetPinnedPackage > > GetPinnedPackagesAsync(CancellationToken cancellationToken=default)
Asynchronously gets a list of all pinned packages.
bool PinAdd(string packageId, string version)
Adds a pinned package to winget.
async Task< bool > DownloadAsync(string packageId, DirectoryInfo directory, CancellationToken cancellationToken=default)
Asynchronously downloads the installer of a package using winget.
bool PinAdd(string packageId, bool blocking=false)
Adds a pinned package to winget.
async Task< bool > InstallPackageAsync(WinGetPackage package, bool silent, CancellationToken cancellationToken=default)
Asynchronously install a package using winget.
List< WinGetPackage > SearchPackage(string packageId, bool exact=false)
Uses the winget search function to search for a package that maches the given name.
List< WinGetPackage > GetUpgradeablePackages()
Get all upgradeable packages.
bool InstallPackage(WinGetPackage package)
Install a package using winget.
string Hash(string file)
Executes the WinGet hash function, to calculate the hash for the given file.
async Task< string > HashAsync(string file, CancellationToken cancellationToken=default)
Asynchronously executes the WinGet hash function, to calculate the hash for the given file.
bool UpgradePackage(string packageId, bool silent)
Upgrades a package using winget.
bool Download(string packageId, DirectoryInfo directory)
Downloads the installer of a package using winget.
async Task< bool > UninstallPackageAsync(string packageId, CancellationToken cancellationToken=default)
Asynchronously uninsatll a package using winget.
bool PinAdd(WinGetPackage package, string version)
Adds a pinned package to winget.
Represents a winget arguments string for different winget actions.
WinGetArguments All()
Adds the '–all' flag to the arguments.
WinGetArguments Blocking()
Adds the '–blocking' flag to the arguments.
WinGetArguments Installed()
Adds the '–installed' flag to the arguments.
static WinGetArguments PinAdd()
Creates a new winget arguments object with "pin add" as the base cmd.
WinGetArguments Force()
Adds the '–force' flag to the arguments.
WinGetArguments Silent()
Adds the '–silent' flag to the arguments.
static WinGetArguments List()
Creates a new winget arguments object with "list" as the base cmd.
WinGetArguments IncludeUnknown()
Adds the '–include-unknown' flag to the arguments.
static WinGetArguments PinList()
Creates a new winget arguments object with "pin list" as the base cmd.
static WinGetArguments Search()
Creates a new winget arguments object with "search" as the base cmd.
WinGetArguments Query(string query)
Adds a query to the arguments.
WinGetArguments AcceptSourceAgreements()
Adds the '–accept-source-agreements' flag to the arguments.
WinGetArguments AcceptPackageAgreements()
Adds the '–accept-package-agreements' flag to the arguments.
WinGetArguments Source(string source)
Adds a source query to the arguments.
WinGetArguments Exact()
Adds the '–exact' flag to the arguments.
static WinGetArguments PinRemove()
Creates a new winget arguments object with "pin remove" as the base cmd.
WinGetArguments File(string file)
Adds a file path to the arguments.
static WinGetArguments Repair()
Creates a new winget arguments object with "repair" as the base cmd.
static WinGetArguments Hash()
Creates a new winget arguments object with "hash" as the base cmd.
static WinGetArguments Uninstall()
Creates a new winget arguments object with "uninstall" as the base cmd.
static WinGetArguments Export()
Creates a new winget arguments object with "export" as the base cmd.
static WinGetArguments Upgrade()
Creates a new winget arguments object with "upgrade" as the base cmd.
static WinGetArguments PinReset()
Creates a new winget arguments object with "pin reset" as the base cmd.
static WinGetArguments Install()
Creates a new winget arguments object with "install" as the base cmd.
WinGetArguments Version(string version)
Adds a version query to the arguments.
Represents a winget package.
string Id
Gets the id of the package.
string Name
Gets the name of the package.
bool HasShortenedId
Gets if id of the package is shortened.
bool HasNoId
Gets if the package does not provide an id.
Exception that gets thrown if a winget feature is not supportet in the installed winget version.