Merge pull request #15120 from peppy/realm-importer

Implement realm beatmap importer
This commit is contained in:
Dan Balasescu
2021-10-20 16:44:16 +09:00
committed by GitHub
12 changed files with 1740 additions and 24 deletions

View File

@ -30,7 +30,7 @@ namespace osu.Game.Database
/// </summary>
/// <typeparam name="TModel">The model type.</typeparam>
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>, IModelFileManager<TModel, TFileModel>
public abstract class ArchiveModelManager<TModel, TFileModel> : IModelManager<TModel>, IModelFileManager<TModel, TFileModel>
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
where TFileModel : class, INamedFileInfo, new()
{

View File

@ -8,8 +8,12 @@ namespace osu.Game.Database
public interface IHasOnlineID
{
/// <summary>
/// The server-side ID representing this instance, if one exists. -1 denotes a missing ID.
/// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID.
/// </summary>
/// <remarks>
/// Generally we use -1 when specifying "missing" in code, but values of 0 are also considered missing as the online source
/// is generally a MySQL autoincrement value, which can never be 0.
/// </remarks>
int OnlineID { get; }
}
}

View File

@ -13,21 +13,9 @@ namespace osu.Game.Database
/// A class which handles importing of associated models to the game store.
/// </summary>
/// <typeparam name="TModel">The model type.</typeparam>
public interface IModelImporter<TModel> : IPostNotifications, IPostImports<TModel>
public interface IModelImporter<TModel> : IPostNotifications, IPostImports<TModel>, ICanAcceptFiles
where TModel : class
{
/// <summary>
/// Import one or more <typeparamref name="TModel"/> items from filesystem <paramref name="paths"/>.
/// </summary>
/// <remarks>
/// This will be treated as a low priority import if more than one path is specified; use <see cref="ArchiveModelManager{TModel,TFileModel}.Import(osu.Game.Database.ImportTask[])"/> to always import at standard priority.
/// This will post notifications tracking progress.
/// </remarks>
/// <param name="paths">One or more archive locations on disk.</param>
Task Import(params string[] paths);
Task Import(params ImportTask[] tasks);
Task<IEnumerable<ILive<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks);
/// <summary>

View File

@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
#nullable enable
namespace osu.Game.Database
{
public interface IPostImports<out TModel>
@ -12,6 +14,6 @@ namespace osu.Game.Database
/// <summary>
/// Fired when the user requests to view the resulting import.
/// </summary>
public Action<IEnumerable<ILive<TModel>>> PostImport { set; }
public Action<IEnumerable<ILive<TModel>>>? PostImport { set; }
}
}

View File

@ -77,6 +77,27 @@ namespace osu.Game.Database
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
Filename += realm_extension;
cleanupPendingDeletions();
}
private void cleanupPendingDeletions()
{
using (var realm = CreateContext())
using (var transaction = realm.BeginWrite())
{
var pendingDeleteSets = realm.All<RealmBeatmapSet>().Where(s => s.DeletePending);
foreach (var s in pendingDeleteSets)
{
foreach (var b in s.Beatmaps)
realm.Remove(b);
realm.Remove(s);
}
transaction.Commit();
}
}
/// <summary>