mirror of https://github.com/ppy/osu
Use Environment.IsPrivilegedProcess
This commit is contained in:
parent
9c2a0576fb
commit
ae78c13684
|
@ -2,7 +2,6 @@
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Principal;
|
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
@ -21,48 +20,14 @@ public partial class ElevatedPrivilegesChecker : Component
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private INotificationOverlay notifications { get; set; } = null!;
|
private INotificationOverlay notifications { get; set; } = null!;
|
||||||
|
|
||||||
private bool elevated;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
elevated = checkElevated();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
if (elevated)
|
if (Environment.IsPrivilegedProcess)
|
||||||
notifications.Post(new ElevatedPrivilegesNotification());
|
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
|
private partial class ElevatedPrivilegesNotification : SimpleNotification
|
||||||
{
|
{
|
||||||
public override bool IsImportant => true;
|
public override bool IsImportant => true;
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
<PackageReference Include="Clowd.Squirrel" Version="2.11.1" />
|
<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="System.IO.Packaging" Version="8.0.0" />
|
||||||
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
|
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue