mirror of
https://github.com/ppy/osu
synced 2025-04-01 22:48:33 +00:00
Merge pull request #8972 from peppy/fix-ruleset-upgrade
Fix loading a ruleset with a new version specification causing a crash
This commit is contained in:
commit
2d49210250
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets
|
namespace osu.Game.Rulesets
|
||||||
@ -15,7 +16,20 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
public string ShortName { get; set; }
|
public string ShortName { get; set; }
|
||||||
|
|
||||||
public string InstantiationInfo { get; set; }
|
private string instantiationInfo;
|
||||||
|
|
||||||
|
public string InstantiationInfo
|
||||||
|
{
|
||||||
|
get => instantiationInfo;
|
||||||
|
set => instantiationInfo = abbreviateInstantiationInfo(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string abbreviateInstantiationInfo(string value)
|
||||||
|
{
|
||||||
|
// exclude version onwards, matching only on namespace and type.
|
||||||
|
// this is mainly to allow for new versions of already loaded rulesets to "upgrade" from old.
|
||||||
|
return string.Join(',', value.Split(',').Take(2));
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool Available { get; set; }
|
public bool Available { get; set; }
|
||||||
|
@ -93,7 +93,9 @@ namespace osu.Game.Rulesets
|
|||||||
// add any other modes
|
// add any other modes
|
||||||
foreach (var r in instances.Where(r => !(r is ILegacyRuleset)))
|
foreach (var r in instances.Where(r => !(r is ILegacyRuleset)))
|
||||||
{
|
{
|
||||||
if (context.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == r.RulesetInfo.InstantiationInfo) == null)
|
// todo: StartsWith can be changed to Equals on 2020-11-08
|
||||||
|
// This is to give users enough time to have their database use new abbreviated info).
|
||||||
|
if (context.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo.StartsWith(r.RulesetInfo.InstantiationInfo)) == null)
|
||||||
context.RulesetInfo.Add(r.RulesetInfo);
|
context.RulesetInfo.Add(r.RulesetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +106,7 @@ namespace osu.Game.Rulesets
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var instanceInfo = ((Ruleset)Activator.CreateInstance(Type.GetType(r.InstantiationInfo, asm =>
|
var instanceInfo = ((Ruleset)Activator.CreateInstance(Type.GetType(r.InstantiationInfo))).RulesetInfo;
|
||||||
{
|
|
||||||
// for the time being, let's ignore the version being loaded.
|
|
||||||
// this allows for debug builds to successfully load rulesets (even though debug rulesets have a 0.0.0 version).
|
|
||||||
asm.Version = null;
|
|
||||||
return Assembly.Load(asm);
|
|
||||||
}, null))).RulesetInfo;
|
|
||||||
|
|
||||||
r.Name = instanceInfo.Name;
|
r.Name = instanceInfo.Name;
|
||||||
r.ShortName = instanceInfo.ShortName;
|
r.ShortName = instanceInfo.ShortName;
|
||||||
|
Loading…
Reference in New Issue
Block a user