mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Merge branch 'realm-ruleset-setting-short-name' into realm-ruleset-keybinding-short-name
This commit is contained in:
commit
782191c410
@ -14,7 +14,6 @@ using osu.Framework.Statistics;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Rulesets;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
@ -33,7 +32,7 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
public readonly string Filename;
|
||||
|
||||
private readonly RulesetStore? rulesets;
|
||||
private readonly IDatabaseContextFactory? efContextFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Version history:
|
||||
@ -51,8 +50,8 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
private readonly SemaphoreSlim contextCreationLock = new SemaphoreSlim(1);
|
||||
|
||||
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>("Realm", "Dirty Refreshes");
|
||||
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>("Realm", "Contexts (Created)");
|
||||
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>(@"Realm", @"Dirty Refreshes");
|
||||
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>(@"Realm", @"Contexts (Created)");
|
||||
|
||||
private readonly object contextLock = new object();
|
||||
private Realm? context;
|
||||
@ -62,14 +61,14 @@ namespace osu.Game.Database
|
||||
get
|
||||
{
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException($"Use {nameof(CreateContext)} when performing realm operations from a non-update thread");
|
||||
throw new InvalidOperationException(@$"Use {nameof(CreateContext)} when performing realm operations from a non-update thread");
|
||||
|
||||
lock (contextLock)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
context = CreateContext();
|
||||
Logger.Log($"Opened realm \"{context.Config.DatabasePath}\" at version {context.Config.SchemaVersion}");
|
||||
Logger.Log(@$"Opened realm ""{context.Config.DatabasePath}"" at version {context.Config.SchemaVersion}");
|
||||
}
|
||||
|
||||
// creating a context will ensure our schema is up-to-date and migrated.
|
||||
@ -78,14 +77,20 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
public RealmContextFactory(Storage storage, string filename, RulesetStore? rulesets = null)
|
||||
/// <summary>
|
||||
/// Construct a new instance of a realm context factory.
|
||||
/// </summary>
|
||||
/// <param name="storage">The game storage which will be used to create the realm backing file.</param>
|
||||
/// <param name="filename">The filename to use for the realm backing file. A ".realm" extension will be added automatically if not specified.</param>
|
||||
/// <param name="efContextFactory">An EF factory used only for migration purposes.</param>
|
||||
public RealmContextFactory(Storage storage, string filename, IDatabaseContextFactory? efContextFactory = null)
|
||||
{
|
||||
this.storage = storage;
|
||||
this.rulesets = rulesets;
|
||||
this.efContextFactory = efContextFactory;
|
||||
|
||||
Filename = filename;
|
||||
|
||||
const string realm_extension = ".realm";
|
||||
const string realm_extension = @".realm";
|
||||
|
||||
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
|
||||
Filename += realm_extension;
|
||||
@ -253,7 +258,7 @@ namespace osu.Game.Database
|
||||
var newItem = newSettings.ElementAt(i);
|
||||
|
||||
long rulesetId = oldItem.RulesetID;
|
||||
string? rulesetName = rulesets?.GetRuleset((int)rulesetId)?.ShortName;
|
||||
string? rulesetName = getRulesetShortNameFromLegacyID(rulesetId);
|
||||
|
||||
if (string.IsNullOrEmpty(rulesetName))
|
||||
migration.NewRealm.Remove(newItem);
|
||||
@ -279,8 +284,7 @@ namespace osu.Game.Database
|
||||
continue;
|
||||
|
||||
long rulesetId = oldItem.RulesetID;
|
||||
|
||||
string? rulesetName = rulesets?.GetRuleset((int)rulesetId)?.ShortName;
|
||||
string? rulesetName = getRulesetShortNameFromLegacyID(rulesetId);
|
||||
|
||||
if (string.IsNullOrEmpty(rulesetName))
|
||||
migration.NewRealm.Remove(newItem);
|
||||
@ -292,6 +296,15 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
private string? getRulesetShortNameFromLegacyID(long rulesetId)
|
||||
{
|
||||
if (efContextFactory == null)
|
||||
return null;
|
||||
|
||||
using (var efContext = efContextFactory.Get())
|
||||
return efContext.RulesetInfo.First(r => r.ID == rulesetId)?.ShortName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush any active contexts and block any further writes.
|
||||
/// </summary>
|
||||
@ -306,7 +319,7 @@ namespace osu.Game.Database
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException($"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
|
||||
@ -330,7 +343,7 @@ namespace osu.Game.Database
|
||||
timeout -= sleep_length;
|
||||
|
||||
if (timeout < 0)
|
||||
throw new TimeoutException("Took too long to acquire lock");
|
||||
throw new TimeoutException(@"Took too long to acquire lock");
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -192,7 +192,7 @@ namespace osu.Game
|
||||
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory, Storage));
|
||||
|
||||
dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", RulesetStore));
|
||||
dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", contextFactory));
|
||||
|
||||
dependencies.CacheAs(Storage);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user