66using System . Collections . Generic ;
77using System . IO ;
88using System . Security ;
9- using System . Security . Principal ;
109using System . Threading ;
1110using System . Threading . Tasks ;
1211using WGetNET . Builder ;
@@ -131,7 +130,7 @@ public Version Version
131130 public WinGet ( )
132131 {
133132 // Check if the current process has administrator privileges
134- _administratorPrivileges = CheckAdministratorPrivileges ( ) ;
133+ _administratorPrivileges = SystemHelper . CheckAdministratorPrivileges ( ) ;
135134
136135 // Set inital values
137136 _processManager = new ProcessManager ( "winget" ) ;
@@ -860,35 +859,6 @@ private string CheckWinGetVersion()
860859 return string . Empty ;
861860 }
862861
863- /// <summary>
864- /// Checks if winget is installed on the system and returns the path to the executable.
865- /// </summary>
866- /// <returns>
867- /// <see cref="System.String"/> containing the executable path if it was found or <see cref="System.String.Empty"/> if not.
868- /// </returns>
869- private string CheckInstallation ( )
870- {
871- string ? pathEnvVar = Environment . GetEnvironmentVariable ( "Path" , EnvironmentVariableTarget . User ) ;
872- if ( string . IsNullOrWhiteSpace ( pathEnvVar ) )
873- {
874- return string . Empty ;
875- }
876-
877- string [ ] paths = pathEnvVar . Split ( ';' ) ;
878-
879- string exePath ;
880- for ( int i = 0 ; i < paths . Length ; i ++ )
881- {
882- exePath = Path . Combine ( paths [ i ] , "winget.exe" ) ;
883- if ( File . Exists ( exePath ) )
884- {
885- return exePath ;
886- }
887- }
888-
889- return string . Empty ;
890- }
891-
892862 /// <summary>
893863 /// Gets the last modification date (UTC) of the currently set winget executable.
894864 /// </summary>
@@ -915,7 +885,7 @@ private bool QueryInstallation()
915885 {
916886 bool isInstalled ;
917887
918- _wingetExePath = CheckInstallation ( ) ;
888+ _wingetExePath = SystemHelper . CheckWingetInstallation ( ) ;
919889
920890 if ( string . IsNullOrWhiteSpace ( _wingetExePath ) )
921891 {
@@ -945,32 +915,6 @@ private bool QueryInstallation()
945915
946916 return isInstalled ;
947917 }
948-
949- /// <summary>
950- /// Check if the current user has administrator privileges.
951- /// </summary>
952- /// <returns>
953- /// <see langword="true"/> if the current user has administrator privileges and
954- /// <see langword="false"/> if not.
955- /// </returns>
956- private bool CheckAdministratorPrivileges ( )
957- {
958- if ( Environment . OSVersion . Platform == PlatformID . Unix )
959- {
960- // Making sure windows related functions dont get called on none windows systems.
961- return true ;
962- }
963-
964- using WindowsIdentity ? identity = WindowsIdentity . GetCurrent ( false ) ;
965-
966- if ( identity != null )
967- {
968- return new WindowsPrincipal ( identity )
969- . IsInRole ( WindowsBuiltInRole . Administrator ) ;
970- }
971-
972- return false ;
973- }
974918 //---------------------------------------------------------------------------------------------
975919 }
976920}
0 commit comments