// 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 { public class ExternalEditOperation where TModel : class, IHasGuidPrimaryKey { public readonly string MountedPath; private readonly IModelImporter importer; private readonly TModel original; private bool isMounted; public ExternalEditOperation(IModelImporter importer, TModel original, string path) { this.importer = importer; this.original = original; MountedPath = path; isMounted = true; } public async Task?> Finish() { if (!Directory.Exists(MountedPath) || !isMounted) return null; Live? imported = await importer.ImportAsUpdate(new ProgressNotification(), new ImportTask(MountedPath), original) .ConfigureAwait(false); try { Directory.Delete(MountedPath, true); } catch { } isMounted = false; return imported; } } }