1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 14:25:10 +08:00

Simplify code immensely

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Salman Alshamrani 2025-01-21 02:20:48 -05:00
parent f133042936
commit 3f51626f07
2 changed files with 9 additions and 57 deletions

View File

@ -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.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
@ -17,12 +19,13 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
protected override LocalisableString Header => CommonStrings.General;
private SystemFileImportComponent systemFileImport = null!;
private ISystemFileSelector? selector;
[BackgroundDependencyLoader]
private void load(OsuGameBase game, GameHost host, IPerformFromScreenRunner? performer)
{
Add(systemFileImport = new SystemFileImportComponent(game, host));
if ((selector = host.CreateSystemFileSelector(game.HandledExtensions.ToArray())) != null)
selector.Selected += f => Task.Run(() => game.Import(f.FullName));
AddRange(new Drawable[]
{
@ -31,10 +34,10 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
Text = DebugSettingsStrings.ImportFiles,
Action = () =>
{
if (systemFileImport.PresentIfAvailable())
return;
performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()));
if (selector != null)
selector.Present();
else
performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()));
},
},
new SettingsButton

View File

@ -1,51 +0,0 @@
// 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.Linq;
using System.Threading.Tasks;
using osu.Framework.Graphics;
using osu.Framework.Platform;
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public partial class SystemFileImportComponent : Component
{
private readonly OsuGameBase game;
private readonly GameHost host;
private ISystemFileSelector? selector;
public SystemFileImportComponent(OsuGameBase game, GameHost host)
{
this.game = game;
this.host = host;
}
protected override void LoadComplete()
{
base.LoadComplete();
selector = host.CreateSystemFileSelector(game.HandledExtensions.ToArray());
if (selector != null)
selector.Selected += f => Schedule(() => startImport(f.FullName));
}
public bool PresentIfAvailable()
{
if (selector == null)
return false;
selector.Present();
return true;
}
private void startImport(string path)
{
Task.Factory.StartNew(async () =>
{
await game.Import(path).ConfigureAwait(false);
}, TaskCreationOptions.LongRunning);
}
}
}