mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 02:43:02 +08:00
store exportingModels for all exporter
No one wants to export multiple copies of the same model at the same time, right?
This commit is contained in:
parent
30985f192e
commit
2a6ea99e6a
@ -35,6 +35,9 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
public Action<Notification>? PostNotification { get; set; }
|
public Action<Notification>? PostNotification { get; set; }
|
||||||
|
|
||||||
|
// Store the model being exported.
|
||||||
|
private readonly List<TModel> exportingModels = new List<TModel>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct exporter.
|
/// Construct exporter.
|
||||||
/// Create a new exporter for each export, otherwise it will cause confusing notifications.
|
/// Create a new exporter for each export, otherwise it will cause confusing notifications.
|
||||||
@ -59,13 +62,26 @@ namespace osu.Game.Database
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task ExportAsync(TModel model, CancellationToken? cancellationToken = null)
|
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();
|
string itemFilename = GetFilename(model).GetValidFilename();
|
||||||
IEnumerable<string> existingExports =
|
IEnumerable<string> existingExports =
|
||||||
exportStorage
|
exportStorage
|
||||||
.GetFiles(string.Empty, $"{itemFilename}*{FileExtension}")
|
.GetFiles(string.Empty, $"{itemFilename}*{FileExtension}")
|
||||||
.Concat(exportStorage.GetDirectories(string.Empty));
|
.Concat(exportStorage.GetDirectories(string.Empty));
|
||||||
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}");
|
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}");
|
||||||
bool success;
|
bool success = false;
|
||||||
|
|
||||||
ProgressNotification notification = new ProgressNotification
|
ProgressNotification notification = new ProgressNotification
|
||||||
{
|
{
|
||||||
@ -87,11 +103,15 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
exportStorage.Delete(filename);
|
exportStorage.Delete(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportingModels.Remove(model);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user