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 12 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 (OperatingSystem.IsWindows())
LoadComponentAsync(new CompatibilityModeChecker(), Add);

osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this);
archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this);
}
Expand Down
28 changes: 19 additions & 9 deletions osu.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ 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"
+ "Please upgrade your operating system or consider using an older version of osu!.\n\n"
+ "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero);
bool isInCompatibilityMode = CompatibilityModeChecker.CheckCompatibilityMode();

if (isInCompatibilityMode)
{
SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
"osu! is running in compatibility mode",
"osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode.", IntPtr.Zero);

CompatibilityModeChecker.LogCompatibilityFlags();
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
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"
+ "Please upgrade your operating system or consider using an older version of osu!.\n\n"
+ "If you are running a newer version of windows, please check you don't have \"Compatibility mode\" turned on for osu!", IntPtr.Zero);
}

return;
}

Expand Down
76 changes: 76 additions & 0 deletions osu.Desktop/Windows/CompatibilityModeChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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 System.Runtime.Versioning;
using Microsoft.Win32;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Logging;
using osu.Game.Graphics;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;

namespace osu.Desktop.Windows
{
/// <summary>
/// Checks if the game is running with windows compatibility optimizations which could cause issues. Displays a warning notification if so.
/// </summary>
[SupportedOSPlatform("windows")]
public partial class CompatibilityModeChecker : Component
{
[Resolved]
private INotificationOverlay notifications { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
{
if (!CheckCompatibilityMode()) return;

notifications.Post(new CompatibilityModeNotification());
LogCompatibilityFlags();
}

/// <summary>
/// Check if the game is running with windows compatibility optimizations
/// </summary>
/// <returns></returns>
public static bool CheckCompatibilityMode()
{
using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");

return layers != null && layers.GetValueNames().Any(name => name.Equals(Environment.ProcessPath, StringComparison.OrdinalIgnoreCase));
}

/// <summary>
/// Log the compatibility flags for the current process if they exist
/// </summary>
public static void LogCompatibilityFlags()
{
using var layers = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");

if (layers?.GetValue(Environment.ProcessPath) is string flags)
Logger.Log($"Compatibility flags for {Environment.ProcessPath}: {flags}", LoggingTarget.Information);
smallketchup82 marked this conversation as resolved.
Show resolved Hide resolved
}

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

public CompatibilityModeNotification()
{
Text = WindowsCompatibilityModeCheckerStrings.NotificationText;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Icon = FontAwesome.Solid.ShieldAlt;
IconContent.Colour = colours.YellowDark;
}
}
}
}
19 changes: 19 additions & 0 deletions osu.Game/Localisation/WindowsCompatibilityModeCheckerStrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 osu.Framework.Localisation;

namespace osu.Game.Localisation
{
public static class WindowsCompatibilityModeCheckerStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.WindowsCompatibilityModeChecker";

/// <summary>
/// "osu! is running in compatibility mode. This may cause issues with the game. Please ensure osu! is not set to run in compatibility mode."
/// </summary>
public static LocalisableString NotificationText => new TranslatableString(getKey(@"notification_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.");

private static string getKey(string key) => $@"{prefix}:{key}";
}
}