Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if Windows compatibility mode flags are detected on startup #27654

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions osu.Desktop/OsuGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ protected override void LoadComplete()

LoadComponentAsync(new ElevatedPrivilegesChecker(), Add);

if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
LoadComponentAsync(new CompatibilityModeChecker(), Add);

osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this);
archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this);
}
Expand Down
4 changes: 0 additions & 4 deletions osu.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ public static void Main(string[] args)
// See https://www.mongodb.com/docs/realm/sdk/dotnet/compatibility/
if (windowsVersion.Major < 6 || (windowsVersion.Major == 6 && windowsVersion.Minor <= 2))
{
// If users running in compatibility mode becomes more of a common thing, we may want to provide better guidance or even consider
// disabling it ourselves.
// We could also better detect compatibility mode if required:
// https://stackoverflow.com/questions/10744651/how-i-can-detect-if-my-application-is-running-under-compatibility-mode#comment58183249_10744730
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved
SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
"Your operating system is too old to run osu!",
"This version of osu! requires at least Windows 8.1 to run.\n"
Expand Down
58 changes: 58 additions & 0 deletions osu.Desktop/Security/CompatibilityModeChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using Microsoft.Win32;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;

namespace osu.Desktop.Security
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so.
/// </summary>
public partial class CompatibilityModeChecker : Component
{
[Resolved]
private INotificationOverlay notifications { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
{
if (checkCompatibilityMode())
notifications.Post(new CompatibilityModeNotification());
}

private bool checkCompatibilityMode()
{
if (!OperatingSystem.IsWindows())
return false;
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved

using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");

return layers != null && layers.GetValueNames().Any(name => name.EndsWith("osu!.exe", StringComparison.OrdinalIgnoreCase));
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved
}

private partial class CompatibilityModeNotification : SimpleNotification
{
public override bool IsImportant => true;

public CompatibilityModeNotification()
{
Text = "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.";
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Icon = FontAwesome.Solid.ShieldAlt;
IconContent.Colour = colours.YellowDark;
}
}
}
}