mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge remote-tracking branch 'upstream/master' into use-ShowFileInNativeExplorer
This commit is contained in:
@ -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()
|
||||
{
|
||||
|
@ -8,8 +8,12 @@ namespace osu.Game.Database
|
||||
public interface IHasOnlineID
|
||||
{
|
||||
/// <summary>
|
||||
/// The server-side ID representing this instance, if one exists.
|
||||
/// The server-side ID representing this instance, if one exists. Any value 0 or less denotes a missing ID.
|
||||
/// </summary>
|
||||
int? OnlineID { get; }
|
||||
/// <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; }
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,14 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Statistics;
|
||||
using osu.Game.Models;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
@ -26,7 +28,12 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
public readonly string Filename;
|
||||
|
||||
private const int schema_version = 6;
|
||||
/// <summary>
|
||||
/// Version history:
|
||||
/// 6 First tracked version (~20211018)
|
||||
/// 7 Changed OnlineID fields to non-nullable to add indexing support (20211018)
|
||||
/// </summary>
|
||||
private const int schema_version = 7;
|
||||
|
||||
/// <summary>
|
||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
|
||||
@ -70,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>
|
||||
@ -120,6 +148,36 @@ namespace osu.Game.Database
|
||||
|
||||
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
||||
{
|
||||
if (lastSchemaVersion < 7)
|
||||
{
|
||||
convertOnlineIDs<RealmBeatmap>();
|
||||
convertOnlineIDs<RealmBeatmapSet>();
|
||||
convertOnlineIDs<RealmRuleset>();
|
||||
|
||||
void convertOnlineIDs<T>() where T : RealmObject
|
||||
{
|
||||
var className = typeof(T).Name.Replace(@"Realm", string.Empty);
|
||||
|
||||
// version was not bumped when the beatmap/ruleset models were added
|
||||
// therefore we must manually check for their presence to avoid throwing on the `DynamicApi` calls.
|
||||
if (!migration.OldRealm.Schema.TryFindObjectSchema(className, out _))
|
||||
return;
|
||||
|
||||
var oldItems = migration.OldRealm.DynamicApi.All(className);
|
||||
var newItems = migration.NewRealm.DynamicApi.All(className);
|
||||
|
||||
int itemCount = newItems.Count();
|
||||
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
var oldItem = oldItems.ElementAt(i);
|
||||
var newItem = newItems.ElementAt(i);
|
||||
|
||||
long? nullableOnlineID = oldItem?.OnlineID;
|
||||
newItem.OnlineID = (int)(nullableOnlineID ?? -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user