From 2e5a40eddf839b6ce4cfbca727db92828e504562 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 1 Dec 2020 20:12:09 +0100 Subject: [PATCH 01/22] Add an IntentFilter to handle osu! files. --- osu.Android/OsuGameActivity.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 7e250dce0e..b6e5742332 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using Android.App; +using Android.Content; using Android.Content.PM; using Android.OS; using Android.Views; @@ -9,7 +10,9 @@ using osu.Framework.Android; namespace osu.Android { + [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] + [IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.CategoryAppFiles }, DataSchemes = new[] { "content" }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity { protected override Framework.Game CreateGame() => new OsuGameAndroid(this); From 005fa3a7eed9230828d7337cc200a405984bab6a Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 1 Dec 2020 20:28:15 +0100 Subject: [PATCH 02/22] Add ability to import files from a stream. --- osu.Game/Database/ArchiveModelManager.cs | 8 ++++++++ osu.Game/Database/ICanAcceptFiles.cs | 9 +++++++++ osu.Game/OsuGameBase.cs | 11 +++++++++++ osu.Game/Screens/Edit/Setup/ResourcesSection.cs | 2 ++ 4 files changed, 30 insertions(+) diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 8bdc804311..9a7aa7b039 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -212,6 +212,14 @@ namespace osu.Game.Database return import; } + /// + /// Import one from a . + /// + /// The stream to import files from. + /// The filename of the archive being imported. + public async Task Import(Stream stream, string filename) + => await Import(new ZipArchiveReader(stream, filename)); // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info + /// /// Fired when the user requests to view the resulting import. /// diff --git a/osu.Game/Database/ICanAcceptFiles.cs b/osu.Game/Database/ICanAcceptFiles.cs index e4d92d957c..111701f0a4 100644 --- a/osu.Game/Database/ICanAcceptFiles.cs +++ b/osu.Game/Database/ICanAcceptFiles.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; namespace osu.Game.Database @@ -17,6 +18,14 @@ namespace osu.Game.Database /// The files which should be imported. Task Import(params string[] paths); + /// + /// Import the specified stream. + /// + /// The stream to import files from. + /// The filename of the archive being imported. + /// + Task Import(Stream stream, string filename); + /// /// An array of accepted file extensions (in the standard format of ".abc"). /// diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index e7b5d3304d..0fc2b8d1d7 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -395,6 +395,17 @@ namespace osu.Game } } + public async Task Import(Stream stream, string filename) + { + var extension = Path.GetExtension(filename)?.ToLowerInvariant(); + + foreach (var importer in fileImporters) + { + if (importer.HandledExtensions.Contains(extension)) + await importer.Import(stream, Path.GetFileNameWithoutExtension(filename)); + } + } + public IEnumerable HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions); protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs index 17ecfdd52e..1527f240cb 100644 --- a/osu.Game/Screens/Edit/Setup/ResourcesSection.cs +++ b/osu.Game/Screens/Edit/Setup/ResourcesSection.cs @@ -99,6 +99,8 @@ namespace osu.Game.Screens.Edit.Setup return Task.CompletedTask; } + Task ICanAcceptFiles.Import(Stream stream, string filename) => Task.CompletedTask; + protected override void LoadComplete() { base.LoadComplete(); From 827e957568d6efc53564193ae9196bbb13cc29bc Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 2 Dec 2020 18:03:49 +0100 Subject: [PATCH 03/22] Allow importing osz files / osk files from Downloads directory. --- osu.Android/OsuGameActivity.cs | 23 +++++++++++++++++++++-- osu.Game/OsuGame.cs | 16 ++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index b6e5742332..c41323b97f 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . 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 Android.App; using Android.Content; using Android.Content.PM; @@ -12,10 +14,12 @@ namespace osu.Android { [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] - [IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable, Intent.CategoryAppFiles }, DataSchemes = new[] { "content" }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] + [IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity { - protected override Framework.Game CreateGame() => new OsuGameAndroid(this); + private OsuGameAndroid game; + + protected override Framework.Game CreateGame() => game = new OsuGameAndroid(this); protected override void OnCreate(Bundle savedInstanceState) { @@ -26,8 +30,23 @@ namespace osu.Android base.OnCreate(savedInstanceState); + OnNewIntent(Intent); + Window.AddFlags(WindowManagerFlags.Fullscreen); Window.AddFlags(WindowManagerFlags.KeepScreenOn); } + + protected override void OnNewIntent(Intent intent) + { + if (intent.Action == Intent.ActionView) + { + var filename = intent.Data.Path.Split('/').Last(); + var stream = ContentResolver.OpenInputStream(intent.Data); + if (stream != null) + // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import + game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename))); + } + base.OnNewIntent(intent); + } } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index bb638bcf3a..5b6b90fba5 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -267,7 +267,7 @@ namespace osu.Game case LinkAction.OpenEditorTimestamp: case LinkAction.JoinMultiplayerMatch: case LinkAction.Spectate: - waitForReady(() => notifications, _ => notifications.Post(new SimpleNotification + WaitForReady(() => notifications, _ => notifications.Post(new SimpleNotification { Text = @"This link type is not yet supported!", Icon = FontAwesome.Solid.LifeRing, @@ -288,7 +288,7 @@ namespace osu.Game } }); - public void OpenUrlExternally(string url) => waitForReady(() => externalLinkOpener, _ => + public void OpenUrlExternally(string url) => WaitForReady(() => externalLinkOpener, _ => { if (url.StartsWith('/')) url = $"{API.Endpoint}{url}"; @@ -300,7 +300,7 @@ namespace osu.Game /// Open a specific channel in chat. /// /// The channel to display. - public void ShowChannel(string channel) => waitForReady(() => channelManager, _ => + public void ShowChannel(string channel) => WaitForReady(() => channelManager, _ => { try { @@ -316,19 +316,19 @@ namespace osu.Game /// Show a beatmap set as an overlay. /// /// The set to display. - public void ShowBeatmapSet(int setId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmapSet(setId)); + public void ShowBeatmapSet(int setId) => WaitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmapSet(setId)); /// /// Show a user's profile as an overlay. /// /// The user to display. - public void ShowUser(int userId) => waitForReady(() => userProfile, _ => userProfile.ShowUser(userId)); + public void ShowUser(int userId) => WaitForReady(() => userProfile, _ => userProfile.ShowUser(userId)); /// /// Show a beatmap's set as an overlay, displaying the given beatmap. /// /// The beatmap to show. - public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId)); + public void ShowBeatmap(int beatmapId) => WaitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId)); /// /// Present a beatmap at song select immediately. @@ -483,13 +483,13 @@ namespace osu.Game /// A function to retrieve a (potentially not-yet-constructed) target instance. /// The action to perform on the instance when load is confirmed. /// The type of the target instance. - private void waitForReady(Func retrieveInstance, Action action) + public void WaitForReady(Func retrieveInstance, Action action) where T : Drawable { var instance = retrieveInstance(); if (ScreenStack == null || ScreenStack.CurrentScreen is StartupScreen || instance?.IsLoaded != true) - Schedule(() => waitForReady(retrieveInstance, action)); + Schedule(() => WaitForReady(retrieveInstance, action)); else action(instance); } From 825120fed3b3111b3dcd836a7ef18e4716160515 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 4 Dec 2020 18:49:01 +0100 Subject: [PATCH 04/22] Display import state in a notification. --- osu.Game/Database/ArchiveModelManager.cs | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 9a7aa7b039..7b59726cd0 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -218,7 +218,42 @@ namespace osu.Game.Database /// The stream to import files from. /// The filename of the archive being imported. public async Task Import(Stream stream, string filename) - => await Import(new ZipArchiveReader(stream, filename)); // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info + { + var notification = new ProgressNotification + { + Progress = 0, + State = ProgressNotificationState.Active, + Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising...", + }; + + PostNotification.Invoke(notification); + + try + { + // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info + var imported = await Import(new ZipArchiveReader(stream, filename), notification.CancellationToken); + + notification.CompletionText = $"Imported {imported}! Click to view."; + notification.CompletionClickAction += () => + { + PresentImport?.Invoke(new[] { imported }); + return true; + }; + notification.State = ProgressNotificationState.Completed; + } + catch (TaskCanceledException) + { + throw; + } + catch (Exception e) + { + notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import failed!"; + notification.State = ProgressNotificationState.Cancelled; + Logger.Error(e, $@"Could not import ({filename})", LoggingTarget.Database); + } + + return; + } /// /// Fired when the user requests to view the resulting import. From dd21de0cd526fb81c4d80beea034e343744a740a Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 4 Dec 2020 22:07:45 +0100 Subject: [PATCH 05/22] Fix code inspections. --- osu.Android/OsuGameActivity.cs | 4 ++-- osu.Game/Database/ArchiveModelManager.cs | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index c41323b97f..2b25c37d58 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -12,7 +12,6 @@ using osu.Framework.Android; namespace osu.Android { - [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] [IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity @@ -44,8 +43,9 @@ namespace osu.Android var stream = ContentResolver.OpenInputStream(intent.Data); if (stream != null) // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import - game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename))); + game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename))); } + base.OnNewIntent(intent); } } diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 7b59726cd0..f4208671d7 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -251,8 +251,6 @@ namespace osu.Game.Database notification.State = ProgressNotificationState.Cancelled; Logger.Error(e, $@"Could not import ({filename})", LoggingTarget.Database); } - - return; } /// From 280abdc473e8bd5e512c1456b906d757e98d6345 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 5 Dec 2020 11:50:08 +0100 Subject: [PATCH 06/22] Use ContentResolver for getting filename. --- osu.Android/OsuGameActivity.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 2b25c37d58..917a39148d 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,12 +1,12 @@ // Copyright (c) ppy Pty Ltd . 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 Android.App; using Android.Content; using Android.Content.PM; using Android.OS; +using Android.Provider; using Android.Views; using osu.Framework.Android; @@ -39,11 +39,14 @@ namespace osu.Android { if (intent.Action == Intent.ActionView) { - var filename = intent.Data.Path.Split('/').Last(); + var cursor = ContentResolver.Query(intent.Data, null, null, null); + var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); + cursor.MoveToFirst(); + var stream = ContentResolver.OpenInputStream(intent.Data); if (stream != null) // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import - game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename))); + game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column)))); } base.OnNewIntent(intent); From 0266410368a9ed8c62265ac67a21f8ef7e7d6593 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 5 Dec 2020 18:30:40 +0100 Subject: [PATCH 07/22] Allow importing files through the android share sheet. --- osu.Android/OsuGameActivity.cs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 917a39148d..b331f3d734 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; +using Android.Net; using Android.OS; using Android.Provider; using Android.Views; @@ -13,7 +14,7 @@ using osu.Framework.Android; namespace osu.Android { [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] - [IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] + [IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity { private OsuGameAndroid game; @@ -37,19 +38,29 @@ namespace osu.Android protected override void OnNewIntent(Intent intent) { - if (intent.Action == Intent.ActionView) + if (intent.Action == Intent.ActionDefault) { - var cursor = ContentResolver.Query(intent.Data, null, null, null); - var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); - cursor.MoveToFirst(); - - var stream = ContentResolver.OpenInputStream(intent.Data); - if (stream != null) - // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import - game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column)))); + if (intent.Scheme == ContentResolver.SchemeContent) + handleImportFromUri(intent.Data); } - base.OnNewIntent(intent); + if (intent.Action == Intent.ActionSend) + { + var content = intent.ClipData.GetItemAt(0); + handleImportFromUri(content.Uri); + } + } + + private void handleImportFromUri(Uri uri) + { + var cursor = ContentResolver.Query(uri, null, null, null); + var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); + cursor.MoveToFirst(); + + var stream = ContentResolver.OpenInputStream(uri); + if (stream != null) + // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import + game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column)))); } } } From 2ea8b105d51a42491b7663c2f5b6c01d6a467843 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 5 Dec 2020 20:42:07 +0100 Subject: [PATCH 08/22] Apply review suggestions --- osu.Android/OsuGameActivity.cs | 11 ++++------- osu.Android/OsuGameAndroid.cs | 9 +++++++++ osu.Game/OsuGame.cs | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index b331f3d734..a56206c969 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; @@ -38,10 +37,9 @@ namespace osu.Android protected override void OnNewIntent(Intent intent) { - if (intent.Action == Intent.ActionDefault) + if (intent.Action == Intent.ActionDefault && intent.Scheme == ContentResolver.SchemeContent) { - if (intent.Scheme == ContentResolver.SchemeContent) - handleImportFromUri(intent.Data); + handleImportFromUri(intent.Data); } if (intent.Action == Intent.ActionSend) @@ -53,14 +51,13 @@ namespace osu.Android private void handleImportFromUri(Uri uri) { - var cursor = ContentResolver.Query(uri, null, null, null); + var cursor = ContentResolver.Query(uri, new[] { OpenableColumns.DisplayName }, null, null); var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); cursor.MoveToFirst(); var stream = ContentResolver.OpenInputStream(uri); if (stream != null) - // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import - game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column)))); + game.ScheduleImport(stream, cursor.GetString(filename_column)); } } } diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index 21d6336b2c..81945ee083 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.IO; +using System.Threading.Tasks; using Android.App; using Android.OS; using osu.Framework.Allocation; @@ -65,6 +67,13 @@ namespace osu.Android } } + /// + /// Schedules a file to be imported once the game is loaded. + /// + /// A stream to the file to import. + /// The filename of the file to import. + public void ScheduleImport(Stream stream, string filename) => WaitForReady(() => this, _ => Task.Run(() => Import(stream, filename))); + protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 5b6b90fba5..2c1db67d24 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -483,7 +483,7 @@ namespace osu.Game /// A function to retrieve a (potentially not-yet-constructed) target instance. /// The action to perform on the instance when load is confirmed. /// The type of the target instance. - public void WaitForReady(Func retrieveInstance, Action action) + protected void WaitForReady(Func retrieveInstance, Action action) where T : Drawable { var instance = retrieveInstance(); From c778646f101d9f73709c5b76ae339b4ffeaef7c2 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 7 Dec 2020 18:01:57 +0100 Subject: [PATCH 09/22] Add support for importing replay files. --- osu.Android/OsuGameActivity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index a56206c969..541455277d 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -13,7 +13,7 @@ using osu.Framework.Android; namespace osu.Android { [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] - [IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] + [IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk", ".*\\.osr" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity { private OsuGameAndroid game; From d8838ddbfbda709e1b92e10e6914d8f492a23623 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 8 Dec 2020 18:48:50 +0100 Subject: [PATCH 10/22] Remove duplicated overload. --- osu.Game/Database/ArchiveModelManager.cs | 43 +----------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 3ec3b96579..6766ca2b77 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -218,48 +218,7 @@ namespace osu.Game.Database } return import; - } - - /// - /// Import one from a . - /// - /// The stream to import files from. - /// The filename of the archive being imported. - public async Task Import(Stream stream, string filename) - { - var notification = new ProgressNotification - { - Progress = 0, - State = ProgressNotificationState.Active, - Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising...", - }; - - PostNotification.Invoke(notification); - - try - { - // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info - var imported = await Import(new ZipArchiveReader(stream, filename), notification.CancellationToken); - - notification.CompletionText = $"Imported {imported}! Click to view."; - notification.CompletionClickAction += () => - { - PresentImport?.Invoke(new[] { imported }); - return true; - }; - notification.State = ProgressNotificationState.Completed; - } - catch (TaskCanceledException) - { - throw; - } - catch (Exception e) - { - notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import failed!"; - notification.State = ProgressNotificationState.Cancelled; - Logger.Error(e, $@"Could not import ({filename})", LoggingTarget.Database); - } - } + } /// /// Fired when the user requests to view the resulting import. From aa7d22460d2b7e77bae25f7edd030fbef3cb71ba Mon Sep 17 00:00:00 2001 From: Lucas A Date: Tue, 8 Dec 2020 19:46:55 +0100 Subject: [PATCH 11/22] Override Import() instead. --- osu.Android/OsuGameActivity.cs | 3 ++- osu.Android/OsuGameAndroid.cs | 11 +++++------ osu.Game/Database/ArchiveModelManager.cs | 2 +- osu.Game/OsuGameBase.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 541455277d..eb9df24bf7 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; @@ -57,7 +58,7 @@ namespace osu.Android var stream = ContentResolver.OpenInputStream(uri); if (stream != null) - game.ScheduleImport(stream, cursor.GetString(filename_column)); + Task.Factory.StartNew(() => game.Import(stream, cursor.GetString(filename_column)), TaskCreationOptions.LongRunning); } } } diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index 81945ee083..c9b27a16d6 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -67,12 +67,11 @@ namespace osu.Android } } - /// - /// Schedules a file to be imported once the game is loaded. - /// - /// A stream to the file to import. - /// The filename of the file to import. - public void ScheduleImport(Stream stream, string filename) => WaitForReady(() => this, _ => Task.Run(() => Import(stream, filename))); + public override Task Import(Stream stream, string filename) + { + WaitForReady(() => this, _ => Task.Run(() => base.Import(stream, filename))); + return Task.CompletedTask; + } protected override void LoadComplete() { diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 6766ca2b77..36cc4cce39 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -218,7 +218,7 @@ namespace osu.Game.Database } return import; - } + } /// /// Fired when the user requests to view the resulting import. diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 0fc2b8d1d7..150569f1dd 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -395,7 +395,7 @@ namespace osu.Game } } - public async Task Import(Stream stream, string filename) + public virtual async Task Import(Stream stream, string filename) { var extension = Path.GetExtension(filename)?.ToLowerInvariant(); From 6da854e37c3eb3b8f426904895f6ece374bea498 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 9 Dec 2020 13:32:59 +0100 Subject: [PATCH 12/22] Move scheduled import logic to OsuGame. --- osu.Android/OsuGameAndroid.cs | 6 ------ osu.Game/OsuGame.cs | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index c9b27a16d6..57512012f9 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -67,12 +67,6 @@ namespace osu.Android } } - public override Task Import(Stream stream, string filename) - { - WaitForReady(() => this, _ => Task.Run(() => base.Import(stream, filename))); - return Task.CompletedTask; - } - protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 2c1db67d24..0ad58b2438 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -52,6 +52,7 @@ using osu.Game.Updater; using osu.Game.Utils; using LogLevel = osu.Framework.Logging.LogLevel; using osu.Game.Users; +using System.IO; namespace osu.Game { @@ -426,6 +427,12 @@ namespace osu.Game }, validScreens: new[] { typeof(PlaySongSelect) }); } + public override Task Import(Stream stream, string filename) + { + WaitForReady(() => this, _ => Task.Run(() => base.Import(stream, filename))); + return Task.CompletedTask; + } + protected virtual Loader CreateLoader() => new Loader(); protected virtual UpdateManager CreateUpdateManager() => new UpdateManager(); From 08b79bb92126925a538eb8ff62a7c7d058f6c574 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 12 Dec 2020 17:12:15 +0100 Subject: [PATCH 13/22] Store and return unstarted task for consumers to await on. --- osu.Game/OsuGame.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0ad58b2438..6c32e2e94c 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -429,8 +429,9 @@ namespace osu.Game public override Task Import(Stream stream, string filename) { - WaitForReady(() => this, _ => Task.Run(() => base.Import(stream, filename))); - return Task.CompletedTask; + var importTask = new Task(async () => await base.Import(stream, filename)); + WaitForReady(() => this, _ => importTask.Start()); + return importTask; } protected virtual Loader CreateLoader() => new Loader(); From f3e6c586f7765c2ade6bf446e0605f792ef49bf9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Dec 2020 17:59:04 +0900 Subject: [PATCH 14/22] Change waitForReady back to private implementation --- osu.Game/OsuGame.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 6c32e2e94c..888fd8c803 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -268,7 +268,7 @@ namespace osu.Game case LinkAction.OpenEditorTimestamp: case LinkAction.JoinMultiplayerMatch: case LinkAction.Spectate: - WaitForReady(() => notifications, _ => notifications.Post(new SimpleNotification + waitForReady(() => notifications, _ => notifications.Post(new SimpleNotification { Text = @"This link type is not yet supported!", Icon = FontAwesome.Solid.LifeRing, @@ -289,7 +289,7 @@ namespace osu.Game } }); - public void OpenUrlExternally(string url) => WaitForReady(() => externalLinkOpener, _ => + public void OpenUrlExternally(string url) => waitForReady(() => externalLinkOpener, _ => { if (url.StartsWith('/')) url = $"{API.Endpoint}{url}"; @@ -301,7 +301,7 @@ namespace osu.Game /// Open a specific channel in chat. /// /// The channel to display. - public void ShowChannel(string channel) => WaitForReady(() => channelManager, _ => + public void ShowChannel(string channel) => waitForReady(() => channelManager, _ => { try { @@ -317,19 +317,19 @@ namespace osu.Game /// Show a beatmap set as an overlay. /// /// The set to display. - public void ShowBeatmapSet(int setId) => WaitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmapSet(setId)); + public void ShowBeatmapSet(int setId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmapSet(setId)); /// /// Show a user's profile as an overlay. /// /// The user to display. - public void ShowUser(int userId) => WaitForReady(() => userProfile, _ => userProfile.ShowUser(userId)); + public void ShowUser(int userId) => waitForReady(() => userProfile, _ => userProfile.ShowUser(userId)); /// /// Show a beatmap's set as an overlay, displaying the given beatmap. /// /// The beatmap to show. - public void ShowBeatmap(int beatmapId) => WaitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId)); + public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId)); /// /// Present a beatmap at song select immediately. @@ -430,7 +430,7 @@ namespace osu.Game public override Task Import(Stream stream, string filename) { var importTask = new Task(async () => await base.Import(stream, filename)); - WaitForReady(() => this, _ => importTask.Start()); + waitForReady(() => this, _ => importTask.Start()); return importTask; } @@ -491,13 +491,13 @@ namespace osu.Game /// A function to retrieve a (potentially not-yet-constructed) target instance. /// The action to perform on the instance when load is confirmed. /// The type of the target instance. - protected void WaitForReady(Func retrieveInstance, Action action) + private void waitForReady(Func retrieveInstance, Action action) where T : Drawable { var instance = retrieveInstance(); if (ScreenStack == null || ScreenStack.CurrentScreen is StartupScreen || instance?.IsLoaded != true) - Schedule(() => WaitForReady(retrieveInstance, action)); + Schedule(() => waitForReady(retrieveInstance, action)); else action(instance); } From c5112edd08b5fea1688bbc4e339536b725f8cd7e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Dec 2020 18:03:01 +0900 Subject: [PATCH 15/22] Add comment regarding the reasoning for encapsulating the task in another --- osu.Game/OsuGame.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 888fd8c803..d67d790ce2 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -429,8 +429,11 @@ namespace osu.Game public override Task Import(Stream stream, string filename) { + // encapsulate task as we don't want to begin the import process until in a ready state. var importTask = new Task(async () => await base.Import(stream, filename)); + waitForReady(() => this, _ => importTask.Start()); + return importTask; } From 7bf04808485e78ea96c85176dcfdf8e3360cc89b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Dec 2020 18:12:23 +0900 Subject: [PATCH 16/22] Tidy up android-side code quality --- osu.Android/OsuGameActivity.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index eb9df24bf7..9798d669d6 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -38,27 +38,38 @@ namespace osu.Android protected override void OnNewIntent(Intent intent) { - if (intent.Action == Intent.ActionDefault && intent.Scheme == ContentResolver.SchemeContent) + switch (intent.Action) { - handleImportFromUri(intent.Data); - } + case Intent.ActionDefault: + if (intent.Scheme == ContentResolver.SchemeContent) + handleImportFromUri(intent.Data); + break; - if (intent.Action == Intent.ActionSend) - { - var content = intent.ClipData.GetItemAt(0); - handleImportFromUri(content.Uri); + case Intent.ActionSend: + { + var content = intent.ClipData?.GetItemAt(0); + if (content != null) + handleImportFromUri(content.Uri); + break; + } } } private void handleImportFromUri(Uri uri) { - var cursor = ContentResolver.Query(uri, new[] { OpenableColumns.DisplayName }, null, null); - var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); + var cursor = ContentResolver?.Query(uri, new[] { OpenableColumns.DisplayName }, null, null); + + if (cursor == null) + return; + cursor.MoveToFirst(); + var filenameColumn = cursor.GetColumnIndex(OpenableColumns.DisplayName); + var stream = ContentResolver.OpenInputStream(uri); + if (stream != null) - Task.Factory.StartNew(() => game.Import(stream, cursor.GetString(filename_column)), TaskCreationOptions.LongRunning); + Task.Factory.StartNew(() => game.Import(stream, cursor.GetString(filenameColumn)), TaskCreationOptions.LongRunning); } } } From 38e0b4e64dd3fbf26b3e39364ef0d968f66c193f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Dec 2020 18:13:32 +0900 Subject: [PATCH 17/22] Remove unused using statements --- osu.Android/OsuGameAndroid.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index 57512012f9..21d6336b2c 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -2,8 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.IO; -using System.Threading.Tasks; using Android.App; using Android.OS; using osu.Framework.Allocation; From a323c5ce580bee6ed909ee3bb84adc5baf5a9efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 14 Dec 2020 20:01:28 +0100 Subject: [PATCH 18/22] Use most backwards-compatible overload for query --- osu.Android/OsuGameActivity.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 9798d669d6..fe9b292389 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -57,7 +57,9 @@ namespace osu.Android private void handleImportFromUri(Uri uri) { - var cursor = ContentResolver?.Query(uri, new[] { OpenableColumns.DisplayName }, null, null); + // there are more performant overloads of this method, but this one is the most backwards-compatible + // (dates back to API 1). + var cursor = ContentResolver?.Query(uri, null, null, null, null); if (cursor == null) return; From 1f6e5f4d329934d06b5423481806e1fc8c78ddb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 14 Dec 2020 20:11:53 +0100 Subject: [PATCH 19/22] Copy archive contents to memory stream --- osu.Android/OsuGameActivity.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index fe9b292389..f531b79d92 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.IO; using System.Threading.Tasks; using Android.App; using Android.Content; @@ -69,9 +70,21 @@ namespace osu.Android var filenameColumn = cursor.GetColumnIndex(OpenableColumns.DisplayName); var stream = ContentResolver.OpenInputStream(uri); + string filename = cursor.GetString(filenameColumn); if (stream != null) - Task.Factory.StartNew(() => game.Import(stream, cursor.GetString(filenameColumn)), TaskCreationOptions.LongRunning); + Task.Factory.StartNew(() => runImport(stream, filename), TaskCreationOptions.LongRunning); + } + + private Task runImport(Stream stream, string filename) + { + // SharpCompress requires archive streams to be seekable, which the stream opened by + // OpenInputStream() seems to not necessarily be. + // copy to an arbitrary-access memory stream to be able to proceed with the import. + var copy = new MemoryStream(); + stream.CopyTo(copy); + + return game.Import(copy, filename); } } } From 3e3be56e468d5bdf8d6a3042d7d21159d7b7e538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 14 Dec 2020 20:23:49 +0100 Subject: [PATCH 20/22] Touch up and clarify intent handling --- osu.Android/OsuGameActivity.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index f531b79d92..28c9433095 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using System.IO; using System.Threading.Tasks; using Android.App; @@ -31,13 +32,18 @@ namespace osu.Android base.OnCreate(savedInstanceState); - OnNewIntent(Intent); + // OnNewIntent() only fires for an activity if it's *re-launched* while it's on top of the activity stack. + // on first launch we still have to fire manually. + // reference: https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent) + handleIntent(Intent); Window.AddFlags(WindowManagerFlags.Fullscreen); Window.AddFlags(WindowManagerFlags.KeepScreenOn); } - protected override void OnNewIntent(Intent intent) + protected override void OnNewIntent(Intent intent) => handleIntent(intent); + + private void handleIntent(Intent intent) { switch (intent.Action) { From f9d7945a6f96b9b7bf19c301a251372e6c3bb681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 14 Dec 2020 21:03:49 +0100 Subject: [PATCH 21/22] Remove non-functional replay import for now --- osu.Android/OsuGameActivity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index 28c9433095..cf0179e2ac 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -16,7 +16,7 @@ using osu.Framework.Android; namespace osu.Android { [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)] - [IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk", ".*\\.osr" }, DataMimeType = "application/*")] + [IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")] public class OsuGameActivity : AndroidGameActivity { private OsuGameAndroid game; From d0668192aad1d44fea6516ce0d108146177a7737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 15 Dec 2020 21:25:53 +0100 Subject: [PATCH 22/22] Ensure stream disposal & move entire operation inside task --- osu.Android/OsuGameActivity.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index cf0179e2ac..e801c2ca6e 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using System.IO; using System.Threading.Tasks; using Android.App; @@ -62,7 +61,7 @@ namespace osu.Android } } - private void handleImportFromUri(Uri uri) + private void handleImportFromUri(Uri uri) => Task.Factory.StartNew(async () => { // there are more performant overloads of this method, but this one is the most backwards-compatible // (dates back to API 1). @@ -74,23 +73,16 @@ namespace osu.Android cursor.MoveToFirst(); var filenameColumn = cursor.GetColumnIndex(OpenableColumns.DisplayName); - - var stream = ContentResolver.OpenInputStream(uri); string filename = cursor.GetString(filenameColumn); - if (stream != null) - Task.Factory.StartNew(() => runImport(stream, filename), TaskCreationOptions.LongRunning); - } - - private Task runImport(Stream stream, string filename) - { // SharpCompress requires archive streams to be seekable, which the stream opened by // OpenInputStream() seems to not necessarily be. // copy to an arbitrary-access memory stream to be able to proceed with the import. var copy = new MemoryStream(); - stream.CopyTo(copy); + using (var stream = ContentResolver.OpenInputStream(uri)) + await stream.CopyToAsync(copy); - return game.Import(copy, filename); - } + await game.Import(copy, filename); + }, TaskCreationOptions.LongRunning); } }