mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:18:22 +08:00
Move AdminChecker to osu.Desktop.Admin
This commit is contained in:
parent
9ad30da729
commit
260dd06f47
@ -1,6 +1,8 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// 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.Containers;
|
||||
@ -9,7 +11,7 @@ using osu.Game.Graphics;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
|
||||
namespace osu.Game.Admin
|
||||
namespace osu.Desktop.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the game is running with elevated privileges (as admin in Windows, root in Unix) and displays a warning notification if so.
|
||||
@ -22,11 +24,11 @@ namespace osu.Game.Admin
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
if (IsAdmin())
|
||||
if (isAdmin())
|
||||
Notifications.Post(new AdminNotification());
|
||||
}
|
||||
|
||||
protected virtual bool IsAdmin() => false;
|
||||
private bool isAdmin() => OperatingSystem.IsWindows() ? new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) : Mono.Unix.Native.Syscall.geteuid() == 0;
|
||||
|
||||
private class AdminNotification : SimpleNotification
|
||||
{
|
||||
@ -34,8 +36,7 @@ namespace osu.Game.Admin
|
||||
|
||||
public AdminNotification()
|
||||
{
|
||||
bool isUnix = RuntimeInfo.IsUnix;
|
||||
Text = $"Running osu! as {(isUnix ? "root" : "administrator")} does not improve performance and poses a security risk. Please run the game normally.";
|
||||
Text = $"Running osu! as {(RuntimeInfo.IsUnix ? "root" : "administrator")} does not improve performance and poses a security risk. Please run the game normally.";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -52,6 +53,4 @@ namespace osu.Game.Admin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,9 +7,9 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
using osu.Desktop.Admin;
|
||||
using osu.Desktop.Overlays;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
@ -21,7 +21,6 @@ using osu.Game.Screens.Menu;
|
||||
using osu.Game.Updater;
|
||||
using osu.Desktop.Windows;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Admin;
|
||||
using osu.Game.IO;
|
||||
|
||||
namespace osu.Desktop
|
||||
@ -104,8 +103,6 @@ namespace osu.Desktop
|
||||
}
|
||||
}
|
||||
|
||||
protected override AdminChecker CreateAdminChecker() => new DesktopAdminChecker();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
@ -117,6 +114,8 @@ namespace osu.Desktop
|
||||
|
||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
|
||||
|
||||
LoadComponentAsync(new AdminChecker(), Add);
|
||||
}
|
||||
|
||||
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
||||
@ -184,10 +183,5 @@ namespace osu.Desktop
|
||||
Task.Factory.StartNew(() => Import(paths), TaskCreationOptions.LongRunning);
|
||||
}
|
||||
}
|
||||
|
||||
private class DesktopAdminChecker : AdminChecker
|
||||
{
|
||||
protected override bool IsAdmin() => OperatingSystem.IsWindows() ? new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) : Mono.Unix.Native.Syscall.geteuid() == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Admin;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Graphics;
|
||||
@ -451,8 +450,6 @@ namespace osu.Game
|
||||
|
||||
protected virtual UpdateManager CreateUpdateManager() => new UpdateManager();
|
||||
|
||||
protected virtual AdminChecker CreateAdminChecker() => new AdminChecker();
|
||||
|
||||
protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything);
|
||||
|
||||
#region Beatmap progression
|
||||
@ -676,8 +673,6 @@ namespace osu.Game
|
||||
// dependency on notification overlay, dependent by settings overlay
|
||||
loadComponentSingleFile(CreateUpdateManager(), Add, true);
|
||||
|
||||
loadComponentSingleFile(CreateAdminChecker(), Add, false);
|
||||
|
||||
// overlay elements
|
||||
loadComponentSingleFile(new ManageCollectionsDialog(), overlayContent.Add, true);
|
||||
loadComponentSingleFile(beatmapListing = new BeatmapListingOverlay(), overlayContent.Add, true);
|
||||
|
Loading…
Reference in New Issue
Block a user