From 2a6ea99e6a0da51b7e610125e4bbb2d6175675b3 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 19 Feb 2023 02:09:59 +0900 Subject: [PATCH] store exportingModels for all exporter No one wants to export multiple copies of the same model at the same time, right? --- osu.Game/Database/LegacyModelExporter.cs | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/osu.Game/Database/LegacyModelExporter.cs b/osu.Game/Database/LegacyModelExporter.cs index e17805f417..f9605140e3 100644 --- a/osu.Game/Database/LegacyModelExporter.cs +++ b/osu.Game/Database/LegacyModelExporter.cs @@ -35,6 +35,9 @@ namespace osu.Game.Database public Action? PostNotification { get; set; } + // Store the model being exported. + private readonly List exportingModels = new List(); + /// /// Construct exporter. /// Create a new exporter for each export, otherwise it will cause confusing notifications. @@ -59,13 +62,26 @@ namespace osu.Game.Database /// public async Task ExportAsync(TModel model, CancellationToken? cancellationToken = null) { + if (!exportingModels.Contains(model)) + { + exportingModels.Add(model); + } + else + { + PostNotification?.Invoke(new SimpleErrorNotification() + { + Text = "File is being exported" + }); + return; + } + string itemFilename = GetFilename(model).GetValidFilename(); IEnumerable existingExports = exportStorage .GetFiles(string.Empty, $"{itemFilename}*{FileExtension}") .Concat(exportStorage.GetDirectories(string.Empty)); string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}"); - bool success; + bool success = false; ProgressNotification notification = new ProgressNotification { @@ -87,10 +103,14 @@ namespace osu.Game.Database { success = false; } - - if (!success) + finally { - exportStorage.Delete(filename); + if (!success) + { + exportStorage.Delete(filename); + } + + exportingModels.Remove(model); } }