From ae78c13684b74d6433492e792edd38600e48bfa8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 5 Mar 2024 20:44:32 +0800 Subject: [PATCH] Use Environment.IsPrivilegedProcess --- .../Security/ElevatedPrivilegesChecker.cs | 37 +------------------ osu.Desktop/osu.Desktop.csproj | 1 - 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs index 666573365606..0bed9830dfd8 100644 --- a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs +++ b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Security.Principal; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -21,48 +20,14 @@ public partial class ElevatedPrivilegesChecker : Component [Resolved] private INotificationOverlay notifications { get; set; } = null!; - private bool elevated; - - [BackgroundDependencyLoader] - private void load() - { - elevated = checkElevated(); - } - protected override void LoadComplete() { base.LoadComplete(); - if (elevated) + if (Environment.IsPrivilegedProcess) notifications.Post(new ElevatedPrivilegesNotification()); } - private bool checkElevated() - { - try - { - switch (RuntimeInfo.OS) - { - case RuntimeInfo.Platform.Windows: - if (!OperatingSystem.IsWindows()) return false; - - var windowsIdentity = WindowsIdentity.GetCurrent(); - var windowsPrincipal = new WindowsPrincipal(windowsIdentity); - - return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); - - case RuntimeInfo.Platform.macOS: - case RuntimeInfo.Platform.Linux: - return Mono.Unix.Native.Syscall.geteuid() == 0; - } - } - catch - { - } - - return false; - } - private partial class ElevatedPrivilegesNotification : SimpleNotification { public override bool IsImportant => true; diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index e7a63bd921a9..acb53835a31f 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -24,7 +24,6 @@ -