1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 11:53:00 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/DebugSettings/MemorySettings.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
3.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Threading;
using System.Threading.Tasks;
2017-02-26 17:28:01 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Localisation;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Settings.Sections.DebugSettings
2017-02-26 17:28:01 +08:00
{
public partial class MemorySettings : SettingsSubsection
2017-02-26 17:28:01 +08:00
{
protected override LocalisableString Header => DebugSettingsStrings.MemoryHeader;
2018-04-13 17:19:50 +08:00
2017-02-26 17:28:01 +08:00
[BackgroundDependencyLoader]
private void load(GameHost host, RealmAccess realm)
2017-02-26 17:28:01 +08:00
{
SettingsButton blockAction;
SettingsButton unblockAction;
2017-02-26 17:28:01 +08:00
Children = new Drawable[]
{
2017-10-21 10:46:06 +08:00
new SettingsButton
2017-02-26 17:28:01 +08:00
{
Text = DebugSettingsStrings.ClearAllCaches,
Action = host.Collect
2017-02-26 17:28:01 +08:00
},
new SettingsButton
{
2022-09-16 20:08:25 +08:00
Text = "Compact realm",
Action = () =>
{
// Blocking operations implicitly causes a Compact().
using (realm.BlockAllOperations("compact"))
{
}
}
},
blockAction = new SettingsButton
{
2022-09-16 20:08:25 +08:00
Text = "Block realm",
},
unblockAction = new SettingsButton
{
2022-09-16 20:08:25 +08:00
Text = "Unblock realm",
},
};
blockAction.Action = () =>
{
try
{
var token = realm.BlockAllOperations("maintenance");
blockAction.Enabled.Value = false;
// As a safety measure, unblock after 10 seconds.
// This is to handle the case where a dev may block, but then something on the update thread
// accesses realm and blocks for eternity.
Task.Factory.StartNew(() =>
{
Thread.Sleep(10000);
unblock();
});
unblockAction.Action = unblock;
void unblock()
{
if (token == null)
return;
token?.Dispose();
token = null;
Scheduler.Add(() =>
{
blockAction.Enabled.Value = true;
unblockAction.Action = null;
});
}
}
catch (Exception e)
{
Logger.Error(e, "Blocking realm failed");
}
2017-02-26 17:28:01 +08:00
};
}
}
}