2019-07-29 21:49:12 +09:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 17:43:03 +09:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2017-08-01 15:12:12 +09:00
|
|
|
using System;
|
2017-03-04 19:02:36 +09:00
|
|
|
using System.IO;
|
2018-03-26 18:55:55 +09:00
|
|
|
using System.Reflection;
|
2020-11-20 12:06:08 +03:00
|
|
|
using System.Runtime.Versioning;
|
2024-09-02 16:43:46 +09:00
|
|
|
using System.Threading.Tasks;
|
2020-05-08 10:38:31 +09:00
|
|
|
using Microsoft.Win32;
|
2024-02-27 19:36:03 +09:00
|
|
|
using osu.Desktop.Performance;
|
2021-04-26 22:37:08 -04:00
|
|
|
using osu.Desktop.Security;
|
2017-09-18 22:32:49 +09:00
|
|
|
using osu.Framework.Platform;
|
2017-10-14 02:10:21 +09:00
|
|
|
using osu.Game;
|
2018-07-06 16:39:27 +09:00
|
|
|
using osu.Desktop.Updater;
|
2018-08-01 02:58:39 +09:00
|
|
|
using osu.Framework;
|
2019-03-30 23:56:38 +09:00
|
|
|
using osu.Framework.Logging;
|
2019-09-24 18:03:01 +09:00
|
|
|
using osu.Game.Updater;
|
2020-07-01 17:15:41 +02:00
|
|
|
using osu.Desktop.Windows;
|
2024-02-27 19:36:03 +09:00
|
|
|
using osu.Framework.Allocation;
|
2021-01-24 19:18:16 +01:00
|
|
|
using osu.Game.IO;
|
2022-06-20 21:21:16 +02:00
|
|
|
using osu.Game.IPC;
|
2024-09-02 16:43:46 +09:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2024-02-27 19:36:03 +09:00
|
|
|
using osu.Game.Performance;
|
2022-07-30 14:26:19 +02:00
|
|
|
using osu.Game.Utils;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2017-10-14 02:10:21 +09:00
|
|
|
namespace osu.Desktop
|
2017-02-04 22:03:39 +01:00
|
|
|
{
|
2017-03-07 10:59:19 +09:00
|
|
|
internal partial class OsuGameDesktop : OsuGame
|
2017-02-04 22:03:39 +01:00
|
|
|
{
|
2022-06-20 21:21:16 +02:00
|
|
|
private OsuSchemeLinkIPCChannel? osuSchemeLinkIPCChannel;
|
2023-02-03 18:57:50 +01:00
|
|
|
private ArchiveImportIPCChannel? archiveImportIPCChannel;
|
2022-06-20 21:21:16 +02:00
|
|
|
|
2024-02-27 19:36:03 +09:00
|
|
|
[Cached(typeof(IHighPerformanceSessionManager))]
|
|
|
|
private readonly HighPerformanceSessionManager highPerformanceSessionManager = new HighPerformanceSessionManager();
|
|
|
|
|
2022-06-20 21:21:16 +02:00
|
|
|
public OsuGameDesktop(string[]? args = null)
|
2017-02-04 22:03:39 +01:00
|
|
|
: base(args)
|
|
|
|
{
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2022-06-20 21:21:16 +02:00
|
|
|
public override StableStorage? GetStorageForStableInstall()
|
2017-08-01 15:12:12 +09:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-03-30 23:56:38 +09:00
|
|
|
if (Host is DesktopGameHost desktopHost)
|
2020-05-08 10:38:31 +09:00
|
|
|
{
|
2022-06-20 21:21:16 +02:00
|
|
|
string? stablePath = getStableInstallPath();
|
2020-05-08 10:38:31 +09:00
|
|
|
if (!string.IsNullOrEmpty(stablePath))
|
2021-01-24 19:18:16 +01:00
|
|
|
return new StableStorage(stablePath, desktopHost);
|
2020-05-08 10:38:31 +09:00
|
|
|
}
|
2017-08-01 15:12:12 +09:00
|
|
|
}
|
2019-07-30 12:44:08 +09:00
|
|
|
catch (Exception)
|
2017-08-01 15:12:12 +09:00
|
|
|
{
|
2019-07-30 12:44:08 +09:00
|
|
|
Logger.Log("Could not find a stable install", LoggingTarget.Runtime, LogLevel.Important);
|
2017-08-01 15:12:12 +09:00
|
|
|
}
|
2019-03-30 23:56:38 +09:00
|
|
|
|
|
|
|
return null;
|
2017-08-01 15:12:12 +09:00
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2022-06-20 21:21:16 +02:00
|
|
|
private string? getStableInstallPath()
|
2020-05-08 10:38:31 +09:00
|
|
|
{
|
2021-06-02 15:13:21 +09:00
|
|
|
static bool checkExists(string p) => Directory.Exists(Path.Combine(p, "Songs")) || File.Exists(Path.Combine(p, "osu!.cfg"));
|
2020-05-08 10:38:31 +09:00
|
|
|
|
2022-06-20 21:21:16 +02:00
|
|
|
string? stableInstallPath;
|
2020-05-08 10:38:31 +09:00
|
|
|
|
2020-11-20 12:06:08 +03:00
|
|
|
if (OperatingSystem.IsWindows())
|
2020-05-08 10:38:31 +09:00
|
|
|
{
|
2021-01-15 15:17:38 +09:00
|
|
|
try
|
|
|
|
{
|
|
|
|
stableInstallPath = getStableInstallPathFromRegistry();
|
2020-05-08 10:38:31 +09:00
|
|
|
|
2021-01-15 15:17:38 +09:00
|
|
|
if (!string.IsNullOrEmpty(stableInstallPath) && checkExists(stableInstallPath))
|
|
|
|
return stableInstallPath;
|
|
|
|
}
|
2021-12-13 06:48:40 +03:00
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
2020-05-08 10:38:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
|
|
|
|
if (checkExists(stableInstallPath))
|
|
|
|
return stableInstallPath;
|
|
|
|
|
|
|
|
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
|
|
|
|
if (checkExists(stableInstallPath))
|
|
|
|
return stableInstallPath;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:06:08 +03:00
|
|
|
[SupportedOSPlatform("windows")]
|
2022-06-20 21:21:16 +02:00
|
|
|
private string? getStableInstallPathFromRegistry()
|
2020-11-20 12:06:08 +03:00
|
|
|
{
|
2024-02-08 00:54:48 +01:00
|
|
|
using (RegistryKey? key = Registry.ClassesRoot.OpenSubKey("osu!"))
|
|
|
|
return key?.OpenSubKey(WindowsAssociationManager.SHELL_OPEN_COMMAND)?.GetValue(string.Empty)?.ToString()?.Split('"')[1].Replace("osu!.exe", "");
|
2020-11-20 12:06:08 +03:00
|
|
|
}
|
|
|
|
|
2020-03-05 13:34:04 +09:00
|
|
|
protected override UpdateManager CreateUpdateManager()
|
|
|
|
{
|
2022-06-20 21:21:16 +02:00
|
|
|
string? packageManaged = Environment.GetEnvironmentVariable("OSU_EXTERNAL_UPDATE_PROVIDER");
|
2021-11-16 12:11:11 +09:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(packageManaged))
|
|
|
|
return new NoActionUpdateManager();
|
|
|
|
|
2024-08-31 23:03:10 +09:00
|
|
|
return new VelopackUpdateManager();
|
2020-03-05 13:34:04 +09:00
|
|
|
}
|
|
|
|
|
2024-07-04 17:30:42 -04:00
|
|
|
public override bool RestartAppWhenExited()
|
2023-06-21 18:29:34 +09:00
|
|
|
{
|
2024-09-02 16:43:46 +09:00
|
|
|
Task.Run(() => Velopack.UpdateExe.Start()).FireAndForget();
|
|
|
|
return true;
|
2023-06-21 18:29:34 +09:00
|
|
|
}
|
|
|
|
|
2017-02-12 14:54:56 +09:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2019-12-18 14:07:32 +09:00
|
|
|
LoadComponentAsync(new DiscordRichPresence(), Add);
|
2020-07-01 17:15:41 +02:00
|
|
|
|
|
|
|
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
2020-07-24 16:38:48 +09:00
|
|
|
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
|
2021-04-26 17:41:04 -04:00
|
|
|
|
2021-04-26 21:05:18 -04:00
|
|
|
LoadComponentAsync(new ElevatedPrivilegesChecker(), Add);
|
2022-06-20 21:21:16 +02:00
|
|
|
|
|
|
|
osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this);
|
2023-02-03 18:57:50 +01:00
|
|
|
archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this);
|
2017-02-12 14:54:56 +09:00
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2017-02-23 15:38:17 +09:00
|
|
|
public override void SetHost(GameHost host)
|
2017-02-04 22:03:39 +01:00
|
|
|
{
|
|
|
|
base.SetHost(host);
|
2019-04-01 12:16:05 +09:00
|
|
|
|
2022-10-05 14:15:54 +09:00
|
|
|
var iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "lazer.ico");
|
|
|
|
if (iconStream != null)
|
2023-07-01 19:02:09 +02:00
|
|
|
host.Window.SetIconFromStream(iconStream);
|
2022-10-05 14:15:54 +09:00
|
|
|
|
2023-07-01 19:02:09 +02:00
|
|
|
host.Window.CursorState |= CursorState.Hidden;
|
|
|
|
host.Window.Title = Name;
|
2017-02-04 22:03:39 +01:00
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
2024-05-23 12:53:33 +02:00
|
|
|
protected override BatteryInfo CreateBatteryInfo() => FrameworkEnvironment.UseSDL3 ? new SDL3BatteryInfo() : new SDL2BatteryInfo();
|
2022-07-30 14:26:19 +02:00
|
|
|
|
2022-06-20 21:21:16 +02:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
osuSchemeLinkIPCChannel?.Dispose();
|
2023-02-03 18:57:50 +01:00
|
|
|
archiveImportIPCChannel?.Dispose();
|
2022-06-20 21:21:16 +02:00
|
|
|
}
|
2017-02-04 22:03:39 +01:00
|
|
|
}
|
|
|
|
}
|