@@ -30,6 +30,7 @@ private protected ProcessManager ProcessManager
3030
3131 private ProcessManager _processManager ;
3232 private string _wingetExePath ;
33+ private DateTime _wingetExeModificationData ;
3334 private string _versionString ;
3435 private Version _version ;
3536
@@ -67,6 +68,13 @@ public string VersionString
6768 {
6869 get
6970 {
71+ // Check if winget got modefied or removed while the application is running.
72+ if ( _wingetExeModificationData != GetLastModificationData ( ) )
73+ {
74+ // Re-query installation if a change was detected.
75+ QueryInstallation ( ) ;
76+ }
77+
7078 return _versionString ;
7179 }
7280 }
@@ -81,6 +89,13 @@ public Version Version
8189 {
8290 get
8391 {
92+ // Check if winget got modefied or removed while the application is running.
93+ if ( _wingetExeModificationData != GetLastModificationData ( ) )
94+ {
95+ // Re-query installation if a change was detected.
96+ QueryInstallation ( ) ;
97+ }
98+
8499 return _version ;
85100 }
86101 }
@@ -90,19 +105,14 @@ public Version Version
90105 /// </summary>
91106 public WinGet ( )
92107 {
93- _wingetExePath = CheckInstallation ( ) ;
94-
95- if ( string . IsNullOrWhiteSpace ( _wingetExePath ) )
96- {
97- _processManager = new ProcessManager ( "winget" ) ;
98- }
99- else
100- {
101- _processManager = new ProcessManager ( _wingetExePath ) ;
102- }
103-
104- _versionString = CheckWinGetVersion ( ) ;
105- _version = VersionParser . Parse ( _versionString ) ;
108+ // Set inital values
109+ _processManager = new ProcessManager ( "winget" ) ;
110+ _wingetExePath = string . Empty ;
111+ _wingetExeModificationData = DateTime . MinValue ;
112+ _versionString = string . Empty ;
113+ _version = new Version ( 0 , 0 ) ;
114+
115+ QueryInstallation ( ) ;
106116 }
107117
108118 /// <summary>
@@ -484,6 +494,22 @@ private string CheckInstallation()
484494 return string . Empty ;
485495 }
486496
497+ /// <summary>
498+ /// Gets the last modification date (UTC) of the currently set winget executable.
499+ /// </summary>
500+ /// <returns>
501+ /// <see cref="System.DateTime"/> object of the last modification date (UTC).
502+ /// </returns>
503+ private DateTime GetLastModificationData ( )
504+ {
505+ if ( string . IsNullOrWhiteSpace ( _wingetExePath ) || ! File . Exists ( _wingetExePath ) )
506+ {
507+ return DateTime . MinValue ;
508+ }
509+
510+ return File . GetLastWriteTimeUtc ( _wingetExePath ) ;
511+ }
512+
487513 /// <summary>
488514 /// Checks the system for a winget installation.
489515 /// </summary>
@@ -507,6 +533,8 @@ private bool QueryInstallation()
507533 _processManager = new ProcessManager ( _wingetExePath ) ;
508534 }
509535
536+ _wingetExeModificationData = GetLastModificationData ( ) ;
537+
510538 _versionString = CheckWinGetVersion ( ) ;
511539 _version = VersionParser . Parse ( _versionString ) ;
512540
0 commit comments