Skip to content

Commit 2f7a240

Browse files
committed
Fixed possible loop in the winget installed check, that can occure when winget is not installed
1 parent 4f8b2ba commit 2f7a240

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

src/WGet.NET/Components/WinGet.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class WinGet
3131

3232
private ProcessManager _processManager;
3333
private string _wingetExePath;
34-
private DateTime _wingetExeModificationData;
34+
private DateTime _wingetExeModificationDate;
3535
private string _versionString;
3636
private Version _version;
3737

@@ -72,7 +72,7 @@ public string VersionString
7272
get
7373
{
7474
// Check if winget got modefied or removed while the application is running.
75-
if (_wingetExeModificationData != GetLastModificationData())
75+
if (_wingetExeModificationDate != GetLastModificationData())
7676
{
7777
// Re-query installation if a change was detected.
7878
QueryInstallation();
@@ -93,7 +93,7 @@ public Version Version
9393
get
9494
{
9595
// Check if winget got modefied or removed while the application is running.
96-
if (_wingetExeModificationData != GetLastModificationData())
96+
if (_wingetExeModificationDate != GetLastModificationData())
9797
{
9898
// Re-query installation if a change was detected.
9999
QueryInstallation();
@@ -114,7 +114,7 @@ public WinGet()
114114
// Set inital values
115115
_processManager = new ProcessManager("winget");
116116
_wingetExePath = string.Empty;
117-
_wingetExeModificationData = DateTime.MinValue;
117+
_wingetExeModificationDate = DateTime.MinValue;
118118
_versionString = string.Empty;
119119
_version = new Version(0, 0);
120120

@@ -846,7 +846,7 @@ private string CheckWinGetVersion()
846846
/// </returns>
847847
private string CheckInstallation()
848848
{
849-
string? pathEnvVar = Environment.GetEnvironmentVariable("Path");
849+
string? pathEnvVar = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User);
850850
if (string.IsNullOrWhiteSpace(pathEnvVar))
851851
{
852852
return string.Empty;
@@ -906,9 +906,17 @@ private bool QueryInstallation()
906906
_processManager = new ProcessManager(_wingetExePath);
907907
}
908908

909-
_wingetExeModificationData = GetLastModificationData();
909+
_wingetExeModificationDate = GetLastModificationData();
910+
911+
if (isInstalled)
912+
{
913+
_versionString = CheckWinGetVersion();
914+
}
915+
else
916+
{
917+
_versionString = string.Empty;
918+
}
910919

911-
_versionString = CheckWinGetVersion();
912920
_version = VersionParser.Parse(_versionString);
913921

914922
return isInstalled;

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

Lines changed: 21 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)