Skip to content

Commit

Permalink
Use Environment.IsPrivilegedProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jul 8, 2024
1 parent 9c2a057 commit ae78c13
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
37 changes: 1 addition & 36 deletions osu.Desktop/Security/ElevatedPrivilegesChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion osu.Desktop/osu.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Clowd.Squirrel" Version="2.11.1" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
</ItemGroup>
Expand Down

0 comments on commit ae78c13

Please sign in to comment.