Skip to content

Commit 9affa94

Browse files
committed
Added a function to allow users to re-query for a winget installation
1 parent 5245505 commit 9affa94

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

‎src/WGet.NET/Components/WinGet.cs‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class WinGet
2121
private const string _versionCmd = "--version";
2222
private const string _exportSettingsCmd = "settings export";
2323

24-
private protected readonly ProcessManager _processManager;
25-
private protected readonly bool _isInstalled;
24+
private protected ProcessManager _processManager;
25+
private protected bool _isInstalled;
2626

27-
private readonly string _wingetExePath;
28-
private readonly string _versionString;
29-
private readonly Version _version;
27+
private string _wingetExePath;
28+
private string _versionString;
29+
private Version _version;
3030

3131
/// <summary>
3232
/// Gets if winget is installed on the system.
@@ -92,6 +92,37 @@ public WinGet()
9292
_version = VersionParser.Parse(_versionString);
9393
}
9494

95+
/// <summary>
96+
/// Checks the system for a winget installation.
97+
/// </summary>
98+
/// <remarks>
99+
/// <para>Can be used to check if winget got installed will the installation is running without needing to restart it.</para>
100+
/// <para>This needs to be called manually, because a re-query for the installation will not be done automatically by the library.</para>
101+
/// </remarks>
102+
/// <returns>
103+
/// <see langword="true"/> if the installation was found and <see langword="false"/> if not.
104+
/// </returns>
105+
public bool ReQueryInstallation()
106+
{
107+
_wingetExePath = CheckInstallation();
108+
109+
if (string.IsNullOrWhiteSpace(_wingetExePath))
110+
{
111+
_isInstalled = false;
112+
_processManager = new ProcessManager("winget");
113+
}
114+
else
115+
{
116+
_isInstalled = true;
117+
_processManager = new ProcessManager(_wingetExePath);
118+
}
119+
120+
_versionString = CheckWinGetVersion();
121+
_version = VersionParser.Parse(_versionString);
122+
123+
return _isInstalled;
124+
}
125+
95126
/// <summary>
96127
/// Exports the WinGet settings to a json string.
97128
/// </summary>

0 commit comments

Comments
 (0)