WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
SystemHelper.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System;
6using System.IO;
7using System.Security.Principal;
8
9namespace WGetNET.Helper
10{
14 internal static class SystemHelper
15 {
23 public static bool CheckAdministratorPrivileges()
24 {
25 if (Environment.OSVersion.Platform == PlatformID.Unix)
26 {
27 // Making sure windows related functions dont get called on none windows systems.
28 return false;
29 }
30
31 using WindowsIdentity? identity = WindowsIdentity.GetCurrent(false);
32
33 if (identity != null)
34 {
35 return new WindowsPrincipal(identity)
36 .IsInRole(WindowsBuiltInRole.Administrator);
37 }
38
39 return false;
40 }
41
48 public static string CheckWingetInstallation()
49 {
50 string? pathEnvVar = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User);
51 if (string.IsNullOrWhiteSpace(pathEnvVar))
52 {
53 return string.Empty;
54 }
55
56 string[] paths = pathEnvVar.Split(';');
57
58 string exePath;
59 for (int i = 0; i < paths.Length; i++)
60 {
61 exePath = Path.Combine(paths[i], "winget.exe");
62 if (File.Exists(exePath))
63 {
64 return exePath;
65 }
66 }
67
68 return string.Empty;
69 }
70 }
71}