Skip to content

Commit 13f9494

Browse files
authored
Merge pull request #3 from AcedTimo/main
Continue on non package data instead of causing an exception; Support for "--include-unknown" argument from the version "1.4.2161-preview"
2 parents 3d844c0 + 1652156 commit 13f9494

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/WGet.NET/Components/WinGetPackageManager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class WinGetPackageManager : WinGetInfo
1919
private const string _installCmd = "install {0}";
2020
private const string _upgradeCmd = "upgrade {0}";
2121
private const string _getUpgradeableCmd = "upgrade";
22+
private const string _includeUnknown = "--include-unknown";
2223
private const string _uninstallCmd = "uninstall {0}";
2324
private const string _exportCmd = "export -o {0}";
2425
private const string _importCmd = "import -i {0} --ignore-unavailable";
@@ -207,7 +208,7 @@ public bool UninstallPackage(string packageId)
207208
}
208209

209210
/// <summary>
210-
/// Uninsatll a package using winget.
211+
/// Uninstall a package using winget.
211212
/// </summary>
212213
/// <param name="package">The <see cref="WGetNET.WinGetPackage"/> for the uninstallation.</param>
213214
/// <returns>
@@ -259,8 +260,20 @@ public List<WinGetPackage> GetUpgradeablePackages()
259260
{
260261
try
261262
{
263+
string argument = _getUpgradeableCmd;
264+
265+
// Checking version to determine if "--include-unknown" is necessary
266+
int wingetVersion = 0;
267+
bool castSuccessful = int.TryParse(WinGetVersion.Split("-")[0].Replace("v", "").Replace(".", ""), out wingetVersion);
268+
269+
if (castSuccessful && wingetVersion >= 142161)
270+
{
271+
// Winget version supports new argument, add "--include-unknown" to arguments
272+
argument += " " + _includeUnknown;
273+
}
274+
262275
ProcessResult result =
263-
_processManager.ExecuteWingetProcess(_getUpgradeableCmd);
276+
_processManager.ExecuteWingetProcess(argument);
264277

265278
return ProcessOutputReader.ToPackageList(result.Output);
266279
}

src/WGet.NET/HelperClasses/ProcessOutputReader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5+
using System;
56
using System.Collections.Generic;
67

78
namespace WGetNET.HelperClasses
@@ -70,13 +71,17 @@ private static List<WinGetPackage> CreatePackageListFromOutput(
7071
{
7172
// [var1..var2] : selects the index range from var1 to var2
7273
// (eg. if var1 is 2 and var2 is 5, the selectet index range will be [2, 3, 4])
73-
resultList.Add(
74+
try
75+
{
76+
resultList.Add(
7477
new WinGetPackage()
7578
{
7679
PackageName = output[i][0..idStartIndex].Trim(),
7780
PackageId = output[i][idStartIndex..versionStartIndex].Trim(),
7881
PackageVersion = output[i][versionStartIndex..extraInfoStartIndex].Trim()
7982
});
83+
}
84+
catch { continue; }
8085
}
8186

8287
return resultList;

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)