1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 13:42:55 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Maintenance/SystemFileImportComponent.cs

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

52 lines
1.4 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.
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
{
2025-01-21 14:14:18 +08:00
private readonly OsuGameBase game;
private readonly GameHost host;
private ISystemFileSelector? selector;
2025-01-21 14:14:18 +08:00
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);
}
}
}