// 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 osu.Game.Overlays.Notifications; namespace osu.Game.Database { /// /// Contains information related to an active external edit operation. /// public class ExternalEditOperation where TModel : class, IHasGuidPrimaryKey { /// /// The temporary path at which the model has been exported to for editing. /// public readonly string MountedPath; /// /// Whether the model is still mounted at . /// public bool IsMounted { get; private set; } private readonly IModelImporter importer; private readonly TModel original; public ExternalEditOperation(IModelImporter importer, TModel original, string path) { this.importer = importer; this.original = original; MountedPath = path; IsMounted = true; } /// /// Finish the external edit operation. /// /// /// This will trigger an asynchronous reimport of the model. /// Subsequent calls will be a no-op. /// /// A task which will eventuate in the newly imported model with changes applied. public async Task?> Finish() { if (!Directory.Exists(MountedPath) || !IsMounted) return null; IsMounted = false; Live? imported = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(MountedPath), original) .ConfigureAwait(false); try { Directory.Delete(MountedPath, true); } catch { } return imported; } } }