// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using osu.Framework.Bindables; using osu.Game.IO; using osu.Game.IO.Archives; using osu.Game.Overlays.Notifications; namespace osu.Game.Database { /// /// Represents a model manager that publishes events when s are added or removed. /// /// The model type. public interface IModelManager where TModel : class { /// /// A bindable which contains a weak reference to the last item that was updated. /// This is not thread-safe and should be scheduled locally if consumed from a drawable component. /// IBindable> ItemUpdated { get; } /// /// A bindable which contains a weak reference to the last item that was removed. /// This is not thread-safe and should be scheduled locally if consumed from a drawable component. /// IBindable> ItemRemoved { get; } /// /// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future. /// Task ImportFromStableAsync(StableStorage stableStorage); /// /// Exports an item to a legacy (.zip based) package. /// /// The item to export. void Export(TModel item); /// /// Exports an item to the given output stream. /// /// The item to export. /// The output stream to export to. void ExportModelTo(TModel model, Stream outputStream); /// /// Perform an update of the specified item. /// TODO: Support file additions/removals. /// /// The item to update. void Update(TModel item); /// /// Delete an item from the manager. /// Is a no-op for already deleted items. /// /// The item to delete. /// false if no operation was performed bool Delete(TModel item); /// /// Delete multiple items. /// This will post notifications tracking progress. /// void Delete(List items, bool silent = false); /// /// Restore multiple items that were previously deleted. /// This will post notifications tracking progress. /// void Undelete(List items, bool silent = false); /// /// Restore an item that was previously deleted. Is a no-op if the item is not in a deleted state, or has its protected flag set. /// /// The item to restore void Undelete(TModel item); /// /// Import one or more items from filesystem . /// /// /// This will be treated as a low priority import if more than one path is specified; use to always import at standard priority. /// This will post notifications tracking progress. /// /// One or more archive locations on disk. Task Import(params string[] paths); Task Import(params ImportTask[] tasks); Task> Import(ProgressNotification notification, params ImportTask[] tasks); /// /// Import one from the filesystem and delete the file on success. /// Note that this bypasses the UI flow and should only be used for special cases or testing. /// /// The containing data about the to import. /// Whether this is a low priority import. /// An optional cancellation token. /// The imported model, if successful. Task Import(ImportTask task, bool lowPriority = false, CancellationToken cancellationToken = default); /// /// Silently import an item from an . /// /// The archive to be imported. /// Whether this is a low priority import. /// An optional cancellation token. Task Import(ArchiveReader archive, bool lowPriority = false, CancellationToken cancellationToken = default); /// /// Silently import an item from a . /// /// The model to be imported. /// An optional archive to use for model population. /// Whether this is a low priority import. /// An optional cancellation token. Task Import(TModel item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default); } }