Skip to content

Commit ae78c13

Browse files
committed
Use Environment.IsPrivilegedProcess
1 parent 9c2a057 commit ae78c13

File tree

2 files changed

+1
-37
lines changed

2 files changed

+1
-37
lines changed

osu.Desktop/Security/ElevatedPrivilegesChecker.cs

+1-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5-
using System.Security.Principal;
65
using osu.Framework;
76
using osu.Framework.Allocation;
87
using osu.Framework.Graphics;
@@ -21,48 +20,14 @@ public partial class ElevatedPrivilegesChecker : Component
2120
[Resolved]
2221
private INotificationOverlay notifications { get; set; } = null!;
2322

24-
private bool elevated;
25-
26-
[BackgroundDependencyLoader]
27-
private void load()
28-
{
29-
elevated = checkElevated();
30-
}
31-
3223
protected override void LoadComplete()
3324
{
3425
base.LoadComplete();
3526

36-
if (elevated)
27+
if (Environment.IsPrivilegedProcess)
3728
notifications.Post(new ElevatedPrivilegesNotification());
3829
}
3930

40-
private bool checkElevated()
41-
{
42-
try
43-
{
44-
switch (RuntimeInfo.OS)
45-
{
46-
case RuntimeInfo.Platform.Windows:
47-
if (!OperatingSystem.IsWindows()) return false;
48-
49-
var windowsIdentity = WindowsIdentity.GetCurrent();
50-
var windowsPrincipal = new WindowsPrincipal(windowsIdentity);
51-
52-
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
53-
54-
case RuntimeInfo.Platform.macOS:
55-
case RuntimeInfo.Platform.Linux:
56-
return Mono.Unix.Native.Syscall.geteuid() == 0;
57-
}
58-
}
59-
catch
60-
{
61-
}
62-
63-
return false;
64-
}
65-
6631
private partial class ElevatedPrivilegesNotification : SimpleNotification
6732
{
6833
public override bool IsImportant => true;

osu.Desktop/osu.Desktop.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
</ItemGroup>
2525
<ItemGroup Label="Package References">
2626
<PackageReference Include="Clowd.Squirrel" Version="2.11.1" />
27-
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
2827
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
2928
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
3029
</ItemGroup>

0 commit comments

Comments
 (0)