Merge pull request #13552 from peppy/fix-ruleset-dll-rename

Fix loading a ruleset with an updated internal name causing a potential startup crash
This commit is contained in:
Dean Herbert 2021-06-18 20:18:54 +09:00 committed by GitHub
commit 5897475708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,13 +96,25 @@ namespace osu.Game.Rulesets
context.SaveChanges();
// add any other modes
var existingRulesets = context.RulesetInfo.ToList();
// add any other rulesets which have assemblies present but are not yet in the database.
foreach (var r in instances.Where(r => !(r is ILegacyRuleset)))
{
if (existingRulesets.FirstOrDefault(ri => ri.InstantiationInfo.Equals(r.RulesetInfo.InstantiationInfo, StringComparison.Ordinal)) == null)
context.RulesetInfo.Add(r.RulesetInfo);
{
var existingSameShortName = existingRulesets.FirstOrDefault(ri => ri.ShortName == r.RulesetInfo.ShortName);
if (existingSameShortName != null)
{
// even if a matching InstantiationInfo was not found, there may be an existing ruleset with the same ShortName.
// this generally means the user or ruleset provider has renamed their dll but the underlying ruleset is *likely* the same one.
// in such cases, update the instantiation info of the existing entry to point to the new one.
existingSameShortName.InstantiationInfo = r.RulesetInfo.InstantiationInfo;
}
else
context.RulesetInfo.Add(r.RulesetInfo);
}
}
context.SaveChanges();