mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:42:56 +08:00
Merge branch 'master' into realm/remove-ef-migrations
This commit is contained in:
commit
3407b34b11
@ -12,7 +12,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
|
||||
<PackageReference Include="nunit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -35,12 +35,12 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
HitObjects = new List<HitObject> { new Fruit() },
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = @"Unknown",
|
||||
Title = @"You're breathtaking",
|
||||
AuthorString = @"Everyone",
|
||||
Author = { Username = @"Everyone" },
|
||||
},
|
||||
Ruleset = new CatchRuleset().RulesetInfo
|
||||
},
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
BeatmapInfo =
|
||||
{
|
||||
Ruleset = ruleset,
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 3.6f }
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 3.6f }
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 5, SliderMultiplier = 2 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 5, SliderMultiplier = 2 },
|
||||
Ruleset = ruleset
|
||||
},
|
||||
HitObjects = new List<HitObject>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Project">
|
||||
|
@ -264,7 +264,7 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
},
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
SliderTickRate = 4,
|
||||
OverallDifficulty = 10,
|
||||
@ -306,7 +306,7 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
},
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = tick_rate },
|
||||
Difficulty = new BeatmapDifficulty { SliderTickRate = tick_rate },
|
||||
Ruleset = new ManiaRuleset().RulesetInfo
|
||||
},
|
||||
};
|
||||
@ -383,7 +383,7 @@ namespace osu.Game.Rulesets.Mania.Tests
|
||||
},
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 4 },
|
||||
Difficulty = new BeatmapDifficulty { SliderTickRate = 4 },
|
||||
Ruleset = new ManiaRuleset().RulesetInfo
|
||||
},
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Project">
|
||||
|
@ -73,7 +73,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
|
||||
|
||||
public static int GetColumnCountForNonConvert(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
double roundedCircleSize = Math.Round(beatmapInfo.BaseDifficulty.CircleSize);
|
||||
double roundedCircleSize = Math.Round(beatmapInfo.Difficulty.CircleSize);
|
||||
return (int)Math.Max(1, roundedCircleSize);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
|
||||
var beatmap = new Beatmap<HitObject>
|
||||
{
|
||||
HitObjects = hitObjects,
|
||||
BeatmapInfo = new BeatmapInfo { BaseDifficulty = new BeatmapDifficulty(beatmapDifficulty) }
|
||||
BeatmapInfo = new BeatmapInfo { Difficulty = new BeatmapDifficulty(beatmapDifficulty) }
|
||||
};
|
||||
|
||||
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
CircleSize = 8
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 6 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { OverallDifficulty = 10 },
|
||||
Difficulty = new BeatmapDifficulty { OverallDifficulty = 10 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -358,7 +358,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
},
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },
|
||||
Difficulty = new BeatmapDifficulty { SliderTickRate = 3 },
|
||||
Ruleset = new OsuRuleset().RulesetInfo
|
||||
},
|
||||
});
|
||||
|
@ -364,7 +364,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
HitObjects = hitObjects,
|
||||
BeatmapInfo =
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },
|
||||
Difficulty = new BeatmapDifficulty { SliderTickRate = 3 },
|
||||
Ruleset = new OsuRuleset().RulesetInfo
|
||||
},
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Project">
|
||||
|
@ -32,12 +32,12 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
||||
HitObjects = new List<HitObject> { new Hit { Type = HitType.Centre } },
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = @"Unknown",
|
||||
Title = @"Sample Beatmap",
|
||||
AuthorString = @"peppy",
|
||||
Author = { Username = @"peppy" },
|
||||
},
|
||||
Ruleset = new TaikoRuleset().RulesetInfo
|
||||
},
|
||||
|
@ -158,12 +158,12 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
||||
HitObjects = new List<HitObject> { new Hit { Type = HitType.Centre } },
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "Unknown",
|
||||
Title = "Sample Beatmap",
|
||||
AuthorString = "Craftplacer",
|
||||
Author = { Username = "Craftplacer" },
|
||||
},
|
||||
Ruleset = new TaikoRuleset().RulesetInfo
|
||||
},
|
||||
|
@ -4,7 +4,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Project">
|
||||
|
@ -128,7 +128,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
{
|
||||
MD5Hash = md5Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
BaseDifficulty = new BeatmapDifficulty()
|
||||
Difficulty = new BeatmapDifficulty()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -57,8 +57,9 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
detachedBeatmapSet = live.Detach();
|
||||
|
||||
Assert.AreEqual(live.Files.Count, detachedBeatmapSet.Files.Count);
|
||||
Assert.AreEqual(live.Files.Select(f => f.File).Count(), detachedBeatmapSet.Files.Select(f => f.File).Count());
|
||||
// files are omitted
|
||||
Assert.AreEqual(0, detachedBeatmapSet.Files.Count);
|
||||
|
||||
Assert.AreEqual(live.Beatmaps.Count, detachedBeatmapSet.Beatmaps.Count);
|
||||
Assert.AreEqual(live.Beatmaps.Select(f => f.Difficulty).Count(), detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
|
||||
Assert.AreEqual(live.Metadata, detachedBeatmapSet.Metadata);
|
||||
@ -67,11 +68,9 @@ namespace osu.Game.Tests.Database
|
||||
Debug.Assert(detachedBeatmapSet != null);
|
||||
|
||||
// Check detached instances can all be accessed without throwing.
|
||||
Assert.NotNull(detachedBeatmapSet.Files.Count);
|
||||
Assert.NotZero(detachedBeatmapSet.Files.Select(f => f.File).Count());
|
||||
Assert.AreEqual(0, detachedBeatmapSet.Files.Count);
|
||||
Assert.NotNull(detachedBeatmapSet.Beatmaps.Count);
|
||||
Assert.NotZero(detachedBeatmapSet.Beatmaps.Select(f => f.Difficulty).Count());
|
||||
Assert.NotNull(detachedBeatmapSet.Beatmaps.First().Path);
|
||||
Assert.NotNull(detachedBeatmapSet.Metadata);
|
||||
|
||||
// Check cyclic reference to beatmap set
|
||||
@ -96,9 +95,12 @@ namespace osu.Game.Tests.Database
|
||||
Assert.NotNull(beatmapSet);
|
||||
Debug.Assert(beatmapSet != null);
|
||||
|
||||
BeatmapSetInfo? detachedBeatmapSet = null;
|
||||
// Detach at the BeatmapInfo point, similar to what GetWorkingBeatmap does.
|
||||
BeatmapInfo? detachedBeatmap = null;
|
||||
|
||||
beatmapSet.PerformRead(s => detachedBeatmapSet = s.Detach());
|
||||
beatmapSet.PerformRead(s => detachedBeatmap = s.Beatmaps.First().Detach());
|
||||
|
||||
BeatmapSetInfo? detachedBeatmapSet = detachedBeatmap?.BeatmapSet;
|
||||
|
||||
Debug.Assert(detachedBeatmapSet != null);
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
|
||||
{
|
||||
Ruleset = new RulesetInfo { OnlineID = 0 },
|
||||
StarRating = 4.0d,
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
ApproachRate = 5.0f,
|
||||
DrainRate = 3.0f,
|
||||
@ -30,7 +30,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
|
||||
ArtistUnicode = "check unicode too",
|
||||
Title = "Title goes here",
|
||||
TitleUnicode = "Title goes here",
|
||||
AuthorString = "The Author",
|
||||
Author = { Username = "The Author" },
|
||||
Source = "unit tests",
|
||||
Tags = "look for tags too",
|
||||
},
|
||||
|
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Resources
|
||||
// Create random metadata, then we can check if sorting works based on these
|
||||
Artist = "Some Artist " + RNG.Next(0, 9),
|
||||
Title = $"Some Song (set id {setId}) {Guid.NewGuid()}",
|
||||
AuthorString = "Some Guy " + RNG.Next(0, 9),
|
||||
Author = { Username = "Some Guy " + RNG.Next(0, 9) },
|
||||
};
|
||||
|
||||
var beatmapSet = new BeatmapSetInfo
|
||||
@ -133,7 +133,7 @@ namespace osu.Game.Tests.Resources
|
||||
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
|
||||
Ruleset = rulesetInfo,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
OverallDifficulty = diff,
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 },
|
||||
Difficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 },
|
||||
Ruleset = ruleset
|
||||
}
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
Artist = "Some Artist",
|
||||
Title = "Some Beatmap",
|
||||
AuthorString = "Some Author"
|
||||
Author = { Username = "Some Author" },
|
||||
};
|
||||
|
||||
var beatmapSetInfo = new BeatmapSetInfo
|
||||
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Length = length,
|
||||
BPM = bpm,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = new BeatmapDifficulty()
|
||||
Difficulty = new BeatmapDifficulty()
|
||||
};
|
||||
|
||||
beatmaps.Add(beatmap);
|
||||
|
@ -100,7 +100,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "SomeArtist",
|
||||
AuthorString = "SomeAuthor",
|
||||
Author = { Username = "SomeAuthor" },
|
||||
Title = $"import {i}"
|
||||
};
|
||||
|
||||
@ -114,14 +114,14 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
OnlineID = i * 1024,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
OnlineID = i * 2048,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||
},
|
||||
}
|
||||
|
@ -41,10 +41,10 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "SomeArtist",
|
||||
AuthorString = "SomeAuthor",
|
||||
Author = { Username = "SomeAuthor" },
|
||||
Title = "import"
|
||||
},
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Ruleset = new OsuRuleset().RulesetInfo
|
||||
},
|
||||
new BeatmapInfo
|
||||
@ -53,10 +53,10 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "SomeArtist",
|
||||
AuthorString = "SomeAuthor",
|
||||
Author = { Username = "SomeAuthor" },
|
||||
Title = "import"
|
||||
},
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Ruleset = new OsuRuleset().RulesetInfo
|
||||
},
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
@ -12,9 +10,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
||||
[Cached]
|
||||
private MusicController musicController { get; set; } = new MusicController();
|
||||
|
||||
public TestScenePlaylistsScreen()
|
||||
{
|
||||
var multi = new Screens.OnlinePlay.Playlists.Playlists();
|
||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
private BeatmapInfo exampleBeatmapInfo => new BeatmapInfo
|
||||
{
|
||||
Ruleset = rulesets.AvailableRulesets.First(),
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
CircleSize = 7.2f,
|
||||
DrainRate = 3,
|
||||
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
AddStep("set beatmap", () => advancedStats.BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Ruleset = rulesets.GetRuleset(3) ?? throw new InvalidOperationException(),
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
CircleSize = 5,
|
||||
DrainRate = 4.3f,
|
||||
|
@ -409,7 +409,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string);
|
||||
|
||||
if (i == 16)
|
||||
set.Beatmaps.ForEach(b => b.Metadata.AuthorString = zzz_string);
|
||||
set.Beatmaps.ForEach(b => b.Metadata.Author.Username = zzz_string);
|
||||
|
||||
sets.Add(set);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
AuthorString = $"{ruleset.ShortName}Author",
|
||||
Author = { Username = $"{ruleset.ShortName}Author" },
|
||||
Artist = $"{ruleset.ShortName}Artist",
|
||||
Source = $"{ruleset.ShortName}Source",
|
||||
Title = $"{ruleset.ShortName}Title"
|
||||
@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
Ruleset = ruleset,
|
||||
StarRating = 6,
|
||||
DifficultyName = $"{ruleset.ShortName}Version",
|
||||
BaseDifficulty = new BeatmapDifficulty()
|
||||
Difficulty = new BeatmapDifficulty()
|
||||
},
|
||||
HitObjects = objects
|
||||
};
|
||||
@ -230,7 +230,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
AuthorString = "WWWWWWWWWWWWWWW",
|
||||
Author = { Username = "WWWWWWWWWWWWWWW" },
|
||||
Artist = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Artist",
|
||||
Source = "Verrrrry long Source",
|
||||
Title = "Verrrrry long Title"
|
||||
|
@ -267,7 +267,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
OverallDifficulty = value,
|
||||
CircleSize = value,
|
||||
|
@ -6,7 +6,7 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
</ItemGroup>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Project">
|
||||
<OutputType>WinExe</OutputType>
|
||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Beatmaps
|
||||
difficulty = value;
|
||||
|
||||
if (beatmapInfo != null)
|
||||
beatmapInfo.BaseDifficulty = difficulty.Clone();
|
||||
beatmapInfo.Difficulty = difficulty.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
beatmapInfo = value;
|
||||
|
||||
if (beatmapInfo?.BaseDifficulty != null)
|
||||
Difficulty = beatmapInfo.BaseDifficulty.Clone();
|
||||
if (beatmapInfo?.Difficulty != null)
|
||||
Difficulty = beatmapInfo.Difficulty.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,10 +54,10 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
Artist = @"Unknown",
|
||||
Title = @"Unknown",
|
||||
AuthorString = @"Unknown Creator",
|
||||
Author = { Username = @"Unknown Creator" },
|
||||
},
|
||||
DifficultyName = @"Normal",
|
||||
BaseDifficulty = Difficulty,
|
||||
Difficulty = Difficulty,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ namespace osu.Game.Beatmaps
|
||||
[Ignored]
|
||||
public RealmNamedFileUsage? File => BeatmapSet?.Files.FirstOrDefault(f => f.File.Hash == Hash);
|
||||
|
||||
[Ignored]
|
||||
public BeatmapOnlineStatus Status
|
||||
{
|
||||
get => (BeatmapOnlineStatus)StatusInt;
|
||||
@ -166,6 +167,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
[Ignored]
|
||||
[Obsolete("Use BeatmapInfo.Difficulty instead.")] // can be removed 20220719
|
||||
public BeatmapDifficulty BaseDifficulty
|
||||
{
|
||||
get => Difficulty;
|
||||
|
@ -93,7 +93,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
Ruleset = ruleset,
|
||||
Metadata = metadata,
|
||||
WidescreenStoryboard = true,
|
||||
@ -299,7 +299,23 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
#region Implementation of IWorkingBeatmapCache
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? importedBeatmap) => workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
|
||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo? importedBeatmap)
|
||||
{
|
||||
// Detached sets don't come with files.
|
||||
// If we seem to be missing files, now is a good time to re-fetch.
|
||||
if (importedBeatmap?.BeatmapSet?.Files.Count == 0)
|
||||
{
|
||||
using (var realm = contextFactory.CreateContext())
|
||||
{
|
||||
var refetch = realm.Find<BeatmapInfo>(importedBeatmap.ID)?.Detach();
|
||||
|
||||
if (refetch != null)
|
||||
importedBeatmap = refetch;
|
||||
}
|
||||
}
|
||||
|
||||
return workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
|
||||
}
|
||||
|
||||
public WorkingBeatmap GetWorkingBeatmap(ILive<BeatmapInfo>? importedBeatmap)
|
||||
{
|
||||
|
@ -45,16 +45,6 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
IUser IBeatmapMetadataInfo.Author => Author;
|
||||
|
||||
#region Compatibility properties
|
||||
|
||||
public string AuthorString
|
||||
{
|
||||
get => Author.Username;
|
||||
set => Author.Username = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString() => this.GetDisplayTitle();
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Beatmaps
|
||||
// Warning: The directionality here is important. Changes have to be copied *from* beatmapContent (which comes from editor and is being saved)
|
||||
// *to* the beatmapInfo (which is a database model and needs to receive values without the taiko slider velocity multiplier for correct operation).
|
||||
// CopyTo() will undo such adjustments, while CopyFrom() will not.
|
||||
beatmapContent.Difficulty.CopyTo(beatmapInfo.BaseDifficulty);
|
||||
beatmapContent.Difficulty.CopyTo(beatmapInfo.Difficulty);
|
||||
|
||||
// All changes to metadata are made in the provided beatmapInfo, so this should be copied to the `IBeatmap` before encoding.
|
||||
beatmapContent.BeatmapInfo = beatmapInfo;
|
||||
|
@ -32,6 +32,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public IList<RealmNamedFileUsage> Files { get; } = null!;
|
||||
|
||||
[Ignored]
|
||||
public BeatmapOnlineStatus Status
|
||||
{
|
||||
get => (BeatmapOnlineStatus)StatusInt;
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Beatmaps
|
||||
Title = "no beatmaps available!"
|
||||
},
|
||||
BeatmapSet = new BeatmapSetInfo(),
|
||||
BaseDifficulty = new BeatmapDifficulty
|
||||
Difficulty = new BeatmapDifficulty
|
||||
{
|
||||
DrainRate = 0,
|
||||
CircleSize = 0,
|
||||
|
@ -251,7 +251,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
break;
|
||||
|
||||
case @"Creator":
|
||||
metadata.AuthorString = pair.Value;
|
||||
metadata.Author.Username = pair.Value;
|
||||
break;
|
||||
|
||||
case @"Version":
|
||||
|
@ -1,9 +1,12 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Statistics;
|
||||
|
||||
@ -144,6 +147,18 @@ namespace osu.Game.Database
|
||||
Database = { AutoTransactionsEnabled = false }
|
||||
};
|
||||
|
||||
public void CreateBackup(string backupFilename)
|
||||
{
|
||||
Logger.Log($"Creating full EF database backup at {backupFilename}", LoggingTarget.Database);
|
||||
|
||||
if (DebugUtils.IsDebugBuild)
|
||||
Logger.Log("Your development database has been fully migrated to realm. If you switch back to a pre-realm branch and need your previous database, rename the backup file back to \"client.db\".\n\nNote that doing this can potentially leave your file store in a bad state.", level: LogLevel.Important);
|
||||
|
||||
using (var source = storage.GetStream(DATABASE_NAME))
|
||||
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
|
||||
public void ResetDatabase()
|
||||
{
|
||||
lock (writeLock)
|
||||
|
@ -1,8 +1,11 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Models;
|
||||
@ -21,6 +24,8 @@ namespace osu.Game.Database
|
||||
private readonly RealmContextFactory realmContextFactory;
|
||||
private readonly OsuConfigManager config;
|
||||
|
||||
private bool hasTakenBackup;
|
||||
|
||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config)
|
||||
{
|
||||
this.efContextFactory = efContextFactory;
|
||||
@ -30,97 +35,125 @@ namespace osu.Game.Database
|
||||
|
||||
public void Run()
|
||||
{
|
||||
using (var db = efContextFactory.GetForWrite())
|
||||
using (var ef = efContextFactory.GetForWrite())
|
||||
{
|
||||
migrateSettings(db);
|
||||
migrateSkins(db);
|
||||
|
||||
migrateBeatmaps(db);
|
||||
migrateScores(db);
|
||||
migrateSettings(ef);
|
||||
migrateSkins(ef);
|
||||
migrateBeatmaps(ef);
|
||||
migrateScores(ef);
|
||||
}
|
||||
|
||||
// Delete the database permanently.
|
||||
// Will cause future startups to not attempt migration.
|
||||
Logger.Log("Migration successful, deleting EF database", LoggingTarget.Database);
|
||||
efContextFactory.ResetDatabase();
|
||||
}
|
||||
|
||||
private void migrateBeatmaps(DatabaseWriteUsage db)
|
||||
private void migrateBeatmaps(DatabaseWriteUsage ef)
|
||||
{
|
||||
// can be removed 20220730.
|
||||
var existingBeatmapSets = db.Context.EFBeatmapSetInfo
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||
.Include(s => s.Metadata)
|
||||
.ToList();
|
||||
List<EFBeatmapSetInfo> existingBeatmapSets = ef.Context.EFBeatmapSetInfo
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||
.Include(s => s.Metadata)
|
||||
.ToList();
|
||||
|
||||
Logger.Log("Beginning beatmaps migration to realm", LoggingTarget.Database);
|
||||
|
||||
// previous entries in EF are removed post migration.
|
||||
if (!existingBeatmapSets.Any())
|
||||
{
|
||||
Logger.Log("No beatmaps found to migrate", LoggingTarget.Database);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var realm = realmContextFactory.CreateContext())
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
// only migrate data if the realm database is empty.
|
||||
// note that this cannot be written as: `realm.All<BeatmapInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||
if (!realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||
Logger.Log($"Found {existingBeatmapSets.Count} beatmaps in EF", LoggingTarget.Database);
|
||||
|
||||
if (!hasTakenBackup)
|
||||
{
|
||||
foreach (var beatmapSet in existingBeatmapSets)
|
||||
string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
|
||||
hasTakenBackup = true;
|
||||
}
|
||||
|
||||
// only migrate data if the realm database is empty.
|
||||
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||
{
|
||||
Logger.Log("Skipping migration as realm already has beatmaps loaded", LoggingTarget.Database);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
var realmBeatmapSet = new BeatmapSetInfo
|
||||
foreach (var beatmapSet in existingBeatmapSets)
|
||||
{
|
||||
OnlineID = beatmapSet.OnlineID ?? -1,
|
||||
DateAdded = beatmapSet.DateAdded,
|
||||
Status = beatmapSet.Status,
|
||||
DeletePending = beatmapSet.DeletePending,
|
||||
Hash = beatmapSet.Hash,
|
||||
Protected = beatmapSet.Protected,
|
||||
};
|
||||
|
||||
migrateFiles(beatmapSet, realm, realmBeatmapSet);
|
||||
|
||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||
{
|
||||
var realmBeatmap = new BeatmapInfo
|
||||
var realmBeatmapSet = new BeatmapSetInfo
|
||||
{
|
||||
DifficultyName = beatmap.DifficultyName,
|
||||
Status = beatmap.Status,
|
||||
OnlineID = beatmap.OnlineID ?? -1,
|
||||
Length = beatmap.Length,
|
||||
BPM = beatmap.BPM,
|
||||
Hash = beatmap.Hash,
|
||||
StarRating = beatmap.StarRating,
|
||||
MD5Hash = beatmap.MD5Hash,
|
||||
Hidden = beatmap.Hidden,
|
||||
AudioLeadIn = beatmap.AudioLeadIn,
|
||||
StackLeniency = beatmap.StackLeniency,
|
||||
SpecialStyle = beatmap.SpecialStyle,
|
||||
LetterboxInBreaks = beatmap.LetterboxInBreaks,
|
||||
WidescreenStoryboard = beatmap.WidescreenStoryboard,
|
||||
EpilepsyWarning = beatmap.EpilepsyWarning,
|
||||
SamplesMatchPlaybackRate = beatmap.SamplesMatchPlaybackRate,
|
||||
DistanceSpacing = beatmap.DistanceSpacing,
|
||||
BeatDivisor = beatmap.BeatDivisor,
|
||||
GridSize = beatmap.GridSize,
|
||||
TimelineZoom = beatmap.TimelineZoom,
|
||||
Countdown = beatmap.Countdown,
|
||||
CountdownOffset = beatmap.CountdownOffset,
|
||||
MaxCombo = beatmap.MaxCombo,
|
||||
Bookmarks = beatmap.Bookmarks,
|
||||
Ruleset = realm.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName),
|
||||
Difficulty = new BeatmapDifficulty(beatmap.BaseDifficulty),
|
||||
Metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata),
|
||||
BeatmapSet = realmBeatmapSet,
|
||||
OnlineID = beatmapSet.OnlineID ?? -1,
|
||||
DateAdded = beatmapSet.DateAdded,
|
||||
Status = beatmapSet.Status,
|
||||
DeletePending = beatmapSet.DeletePending,
|
||||
Hash = beatmapSet.Hash,
|
||||
Protected = beatmapSet.Protected,
|
||||
};
|
||||
|
||||
realmBeatmapSet.Beatmaps.Add(realmBeatmap);
|
||||
migrateFiles(beatmapSet, realm, realmBeatmapSet);
|
||||
|
||||
foreach (var beatmap in beatmapSet.Beatmaps)
|
||||
{
|
||||
var realmBeatmap = new BeatmapInfo
|
||||
{
|
||||
DifficultyName = beatmap.DifficultyName,
|
||||
Status = beatmap.Status,
|
||||
OnlineID = beatmap.OnlineID ?? -1,
|
||||
Length = beatmap.Length,
|
||||
BPM = beatmap.BPM,
|
||||
Hash = beatmap.Hash,
|
||||
StarRating = beatmap.StarRating,
|
||||
MD5Hash = beatmap.MD5Hash,
|
||||
Hidden = beatmap.Hidden,
|
||||
AudioLeadIn = beatmap.AudioLeadIn,
|
||||
StackLeniency = beatmap.StackLeniency,
|
||||
SpecialStyle = beatmap.SpecialStyle,
|
||||
LetterboxInBreaks = beatmap.LetterboxInBreaks,
|
||||
WidescreenStoryboard = beatmap.WidescreenStoryboard,
|
||||
EpilepsyWarning = beatmap.EpilepsyWarning,
|
||||
SamplesMatchPlaybackRate = beatmap.SamplesMatchPlaybackRate,
|
||||
DistanceSpacing = beatmap.DistanceSpacing,
|
||||
BeatDivisor = beatmap.BeatDivisor,
|
||||
GridSize = beatmap.GridSize,
|
||||
TimelineZoom = beatmap.TimelineZoom,
|
||||
Countdown = beatmap.Countdown,
|
||||
CountdownOffset = beatmap.CountdownOffset,
|
||||
MaxCombo = beatmap.MaxCombo,
|
||||
Bookmarks = beatmap.Bookmarks,
|
||||
Ruleset = realm.Find<RulesetInfo>(beatmap.RulesetInfo.ShortName),
|
||||
Difficulty = new BeatmapDifficulty(beatmap.BaseDifficulty),
|
||||
Metadata = getBestMetadata(beatmap.Metadata, beatmapSet.Metadata),
|
||||
BeatmapSet = realmBeatmapSet,
|
||||
};
|
||||
|
||||
realmBeatmapSet.Beatmaps.Add(realmBeatmap);
|
||||
}
|
||||
|
||||
realm.Add(realmBeatmapSet);
|
||||
}
|
||||
|
||||
realm.Add(realmBeatmapSet);
|
||||
transaction.Commit();
|
||||
Logger.Log($"Successfully migrated {existingBeatmapSets.Count} beatmaps to realm", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
|
||||
db.Context.RemoveRange(existingBeatmapSets);
|
||||
ef.Context.RemoveRange(existingBeatmapSets);
|
||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,69 +177,91 @@ namespace osu.Game.Database
|
||||
PreviewTime = metadata.PreviewTime,
|
||||
AudioFile = metadata.AudioFile,
|
||||
BackgroundFile = metadata.BackgroundFile,
|
||||
AuthorString = metadata.AuthorString,
|
||||
};
|
||||
}
|
||||
|
||||
private void migrateScores(DatabaseWriteUsage db)
|
||||
{
|
||||
// can be removed 20220730.
|
||||
var existingScores = db.Context.ScoreInfo
|
||||
.Include(s => s.Ruleset)
|
||||
.Include(s => s.BeatmapInfo)
|
||||
.Include(s => s.Files)
|
||||
.ThenInclude(f => f.FileInfo)
|
||||
.ToList();
|
||||
List<EFScoreInfo> existingScores = db.Context.ScoreInfo
|
||||
.Include(s => s.Ruleset)
|
||||
.Include(s => s.BeatmapInfo)
|
||||
.Include(s => s.Files)
|
||||
.ThenInclude(f => f.FileInfo)
|
||||
.ToList();
|
||||
|
||||
Logger.Log("Beginning scores migration to realm", LoggingTarget.Database);
|
||||
|
||||
// previous entries in EF are removed post migration.
|
||||
if (!existingScores.Any())
|
||||
{
|
||||
Logger.Log("No scores found to migrate", LoggingTarget.Database);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var realm = realmContextFactory.CreateContext())
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
// only migrate data if the realm database is empty.
|
||||
// note that this cannot be written as: `realm.All<ScoreInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||
if (!realm.All<ScoreInfo>().Any())
|
||||
Logger.Log($"Found {existingScores.Count} scores in EF", LoggingTarget.Database);
|
||||
|
||||
if (!hasTakenBackup)
|
||||
{
|
||||
foreach (var score in existingScores)
|
||||
string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
|
||||
hasTakenBackup = true;
|
||||
}
|
||||
|
||||
// only migrate data if the realm database is empty.
|
||||
if (realm.All<ScoreInfo>().Any())
|
||||
{
|
||||
Logger.Log("Skipping migration as realm already has scores loaded", LoggingTarget.Database);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
var realmScore = new ScoreInfo
|
||||
foreach (var score in existingScores)
|
||||
{
|
||||
Hash = score.Hash,
|
||||
DeletePending = score.DeletePending,
|
||||
OnlineID = score.OnlineID ?? -1,
|
||||
ModsJson = score.ModsJson,
|
||||
StatisticsJson = score.StatisticsJson,
|
||||
User = score.User,
|
||||
TotalScore = score.TotalScore,
|
||||
MaxCombo = score.MaxCombo,
|
||||
Accuracy = score.Accuracy,
|
||||
HasReplay = ((IScoreInfo)score).HasReplay,
|
||||
Date = score.Date,
|
||||
PP = score.PP,
|
||||
BeatmapInfo = realm.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash),
|
||||
Ruleset = realm.Find<RulesetInfo>(score.Ruleset.ShortName),
|
||||
Rank = score.Rank,
|
||||
HitEvents = score.HitEvents,
|
||||
Passed = score.Passed,
|
||||
Combo = score.Combo,
|
||||
Position = score.Position,
|
||||
Statistics = score.Statistics,
|
||||
Mods = score.Mods,
|
||||
APIMods = score.APIMods,
|
||||
};
|
||||
var realmScore = new ScoreInfo
|
||||
{
|
||||
Hash = score.Hash,
|
||||
DeletePending = score.DeletePending,
|
||||
OnlineID = score.OnlineID ?? -1,
|
||||
ModsJson = score.ModsJson,
|
||||
StatisticsJson = score.StatisticsJson,
|
||||
User = score.User,
|
||||
TotalScore = score.TotalScore,
|
||||
MaxCombo = score.MaxCombo,
|
||||
Accuracy = score.Accuracy,
|
||||
HasReplay = ((IScoreInfo)score).HasReplay,
|
||||
Date = score.Date,
|
||||
PP = score.PP,
|
||||
BeatmapInfo = realm.All<BeatmapInfo>().First(b => b.Hash == score.BeatmapInfo.Hash),
|
||||
Ruleset = realm.Find<RulesetInfo>(score.Ruleset.ShortName),
|
||||
Rank = score.Rank,
|
||||
HitEvents = score.HitEvents,
|
||||
Passed = score.Passed,
|
||||
Combo = score.Combo,
|
||||
Position = score.Position,
|
||||
Statistics = score.Statistics,
|
||||
Mods = score.Mods,
|
||||
APIMods = score.APIMods,
|
||||
};
|
||||
|
||||
migrateFiles(score, realm, realmScore);
|
||||
migrateFiles(score, realm, realmScore);
|
||||
|
||||
realm.Add(realmScore);
|
||||
realm.Add(realmScore);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
Logger.Log($"Successfully migrated {existingScores.Count} scores to realm", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
|
||||
db.Context.RemoveRange(existingScores);
|
||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,6 +298,8 @@ namespace osu.Game.Database
|
||||
// note that this cannot be written as: `realm.All<SkinInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||
if (!realm.All<SkinInfo>().Any(s => !s.Protected))
|
||||
{
|
||||
Logger.Log($"Migrating {existingSkins.Count} skins", LoggingTarget.Database);
|
||||
|
||||
foreach (var skin in existingSkins)
|
||||
{
|
||||
var realmSkin = new SkinInfo
|
||||
@ -286,18 +343,22 @@ namespace osu.Game.Database
|
||||
private void migrateSettings(DatabaseWriteUsage db)
|
||||
{
|
||||
// migrate ruleset settings. can be removed 20220315.
|
||||
var existingSettings = db.Context.DatabasedSetting;
|
||||
var existingSettings = db.Context.DatabasedSetting.ToList();
|
||||
|
||||
// previous entries in EF are removed post migration.
|
||||
if (!existingSettings.Any())
|
||||
return;
|
||||
|
||||
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
||||
|
||||
using (var realm = realmContextFactory.CreateContext())
|
||||
using (var transaction = realm.BeginWrite())
|
||||
{
|
||||
// only migrate data if the realm database is empty.
|
||||
if (!realm.All<RealmRulesetSetting>().Any())
|
||||
{
|
||||
Logger.Log($"Migrating {existingSettings.Count} settings", LoggingTarget.Database);
|
||||
|
||||
foreach (var dkb in existingSettings)
|
||||
{
|
||||
if (dkb.RulesetID == null)
|
||||
|
@ -21,6 +21,7 @@ using osu.Game.Stores;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Scoring;
|
||||
using Realms;
|
||||
using Realms.Exceptions;
|
||||
|
||||
#nullable enable
|
||||
|
||||
@ -105,8 +106,20 @@ namespace osu.Game.Database
|
||||
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
|
||||
Filename += realm_extension;
|
||||
|
||||
// This method triggers the first `CreateContext` call, which will implicitly run realm migrations and bring the schema up-to-date.
|
||||
cleanupPendingDeletions();
|
||||
try
|
||||
{
|
||||
// This method triggers the first `CreateContext` call, which will implicitly run realm migrations and bring the schema up-to-date.
|
||||
cleanupPendingDeletions();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "Realm startup failed with unrecoverable error; starting with a fresh database. A backup of your database has been made.");
|
||||
|
||||
CreateBackup($"{Filename.Replace(realm_extension, string.Empty)}_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_corrupt{realm_extension}");
|
||||
storage.Delete(Filename);
|
||||
|
||||
cleanupPendingDeletions();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupPendingDeletions()
|
||||
@ -361,6 +374,17 @@ namespace osu.Game.Database
|
||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||
|
||||
public void CreateBackup(string backupFilename)
|
||||
{
|
||||
using (BlockAllOperations())
|
||||
{
|
||||
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
||||
using (var source = storage.GetStream(Filename))
|
||||
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush any active contexts and block any further writes.
|
||||
/// </summary>
|
||||
@ -374,17 +398,17 @@ namespace osu.Game.Database
|
||||
if (isDisposed)
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
|
||||
try
|
||||
{
|
||||
contextCreationLock.Wait();
|
||||
|
||||
lock (contextLock)
|
||||
{
|
||||
if (!ThreadSafety.IsUpdateThread && context != null)
|
||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
|
||||
context?.Dispose();
|
||||
context = null;
|
||||
}
|
||||
@ -392,14 +416,23 @@ namespace osu.Game.Database
|
||||
const int sleep_length = 200;
|
||||
int timeout = 5000;
|
||||
|
||||
// see https://github.com/realm/realm-dotnet/discussions/2657
|
||||
while (!Compact())
|
||||
try
|
||||
{
|
||||
Thread.Sleep(sleep_length);
|
||||
timeout -= sleep_length;
|
||||
// see https://github.com/realm/realm-dotnet/discussions/2657
|
||||
while (!Compact())
|
||||
{
|
||||
Thread.Sleep(sleep_length);
|
||||
timeout -= sleep_length;
|
||||
|
||||
if (timeout < 0)
|
||||
throw new TimeoutException(@"Took too long to acquire lock");
|
||||
if (timeout < 0)
|
||||
throw new TimeoutException(@"Took too long to acquire lock");
|
||||
}
|
||||
}
|
||||
catch (RealmException e)
|
||||
{
|
||||
// Compact may fail if the realm is in a bad state.
|
||||
// We still want to continue with the blocking operation, though.
|
||||
Logger.Log($"Realm compact failed with error {e}", LoggingTarget.Database);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -74,21 +74,18 @@ namespace osu.Game.Database
|
||||
|
||||
private static readonly IMapper mapper = new MapperConfiguration(c =>
|
||||
{
|
||||
c.ShouldMapField = fi => false;
|
||||
applyCommonConfiguration(c);
|
||||
|
||||
// This is specifically to avoid mapping explicit interface implementations.
|
||||
// If we want to limit this further, we can avoid mapping properties with no setter that are not IList<>.
|
||||
// Takes a bit of effort to determine whether this is the case though, see https://stackoverflow.com/questions/951536/how-do-i-tell-whether-a-type-implements-ilist
|
||||
c.ShouldMapProperty = pi => pi.GetMethod?.IsPublic == true;
|
||||
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
|
||||
.MaxDepth(2)
|
||||
.AfterMap((s, d) =>
|
||||
{
|
||||
foreach (var beatmap in d.Beatmaps)
|
||||
beatmap.BeatmapSet = d;
|
||||
});
|
||||
|
||||
c.CreateMap<RealmKeyBinding, RealmKeyBinding>();
|
||||
c.CreateMap<BeatmapMetadata, BeatmapMetadata>();
|
||||
c.CreateMap<BeatmapDifficulty, BeatmapDifficulty>();
|
||||
c.CreateMap<RulesetInfo, RulesetInfo>();
|
||||
c.CreateMap<ScoreInfo, ScoreInfo>();
|
||||
c.CreateMap<RealmUser, RealmUser>();
|
||||
c.CreateMap<RealmFile, RealmFile>();
|
||||
c.CreateMap<RealmNamedFileUsage, RealmNamedFileUsage>();
|
||||
// This can be further optimised to reduce cyclic retrievals, similar to the optimised set mapper below.
|
||||
// Only hasn't been done yet as we detach at the point of BeatmapInfo less often.
|
||||
c.CreateMap<BeatmapInfo, BeatmapInfo>()
|
||||
.MaxDepth(2)
|
||||
.AfterMap((s, d) =>
|
||||
@ -102,14 +99,39 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
});
|
||||
}).CreateMapper();
|
||||
|
||||
/// <summary>
|
||||
/// A slightly optimised mapper that avoids double-fetches in cyclic reference.
|
||||
/// </summary>
|
||||
private static readonly IMapper beatmap_set_mapper = new MapperConfiguration(c =>
|
||||
{
|
||||
applyCommonConfiguration(c);
|
||||
|
||||
c.CreateMap<BeatmapSetInfo, BeatmapSetInfo>()
|
||||
.MaxDepth(2)
|
||||
.ForMember(b => b.Files, cc => cc.Ignore())
|
||||
.AfterMap((s, d) =>
|
||||
{
|
||||
foreach (var beatmap in d.Beatmaps)
|
||||
beatmap.BeatmapSet = d;
|
||||
});
|
||||
|
||||
c.CreateMap<BeatmapInfo, BeatmapInfo>()
|
||||
.MaxDepth(1)
|
||||
// This is not required as it will be populated in the `AfterMap` call from the `BeatmapInfo`'s parent.
|
||||
.ForMember(b => b.BeatmapSet, cc => cc.Ignore());
|
||||
}).CreateMapper();
|
||||
|
||||
private static void applyCommonConfiguration(IMapperConfigurationExpression c)
|
||||
{
|
||||
c.ShouldMapField = fi => false;
|
||||
|
||||
// This is specifically to avoid mapping explicit interface implementations.
|
||||
// If we want to limit this further, we can avoid mapping properties with no setter that are not IList<>.
|
||||
// Takes a bit of effort to determine whether this is the case though, see https://stackoverflow.com/questions/951536/how-do-i-tell-whether-a-type-implements-ilist
|
||||
c.ShouldMapProperty = pi => pi.GetMethod?.IsPublic == true;
|
||||
|
||||
c.Internal().ForAllMaps((typeMap, expression) =>
|
||||
{
|
||||
expression.ForAllMembers(m =>
|
||||
@ -118,7 +140,16 @@ namespace osu.Game.Database
|
||||
m.Ignore();
|
||||
});
|
||||
});
|
||||
}).CreateMapper();
|
||||
|
||||
c.CreateMap<RealmKeyBinding, RealmKeyBinding>();
|
||||
c.CreateMap<BeatmapMetadata, BeatmapMetadata>();
|
||||
c.CreateMap<BeatmapDifficulty, BeatmapDifficulty>();
|
||||
c.CreateMap<RulesetInfo, RulesetInfo>();
|
||||
c.CreateMap<ScoreInfo, ScoreInfo>();
|
||||
c.CreateMap<RealmUser, RealmUser>();
|
||||
c.CreateMap<RealmFile, RealmFile>();
|
||||
c.CreateMap<RealmNamedFileUsage, RealmNamedFileUsage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a detached copy of the each item in the collection.
|
||||
@ -153,6 +184,9 @@ namespace osu.Game.Database
|
||||
if (!item.IsManaged)
|
||||
return item;
|
||||
|
||||
if (item is BeatmapSetInfo)
|
||||
return beatmap_set_mapper.Map<T>(item);
|
||||
|
||||
return mapper.Map<T>(item);
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,14 @@ namespace osu.Game.Input.Bindings
|
||||
|
||||
public int? Variant { get; set; }
|
||||
|
||||
[Ignored]
|
||||
public KeyCombination KeyCombination
|
||||
{
|
||||
get => KeyCombinationString;
|
||||
set => KeyCombinationString = value.ToString();
|
||||
}
|
||||
|
||||
[Ignored]
|
||||
public object Action
|
||||
{
|
||||
get => ActionInt;
|
||||
|
@ -193,6 +193,7 @@ namespace osu.Game
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage));
|
||||
dependencies.CacheAs<IRulesetStore>(RulesetStore);
|
||||
|
||||
// A non-null context factory means there's still content to migrate.
|
||||
if (efContextFactory != null)
|
||||
new EFToRealmMigrator(efContextFactory, realmFactory, LocalConfig).Run();
|
||||
|
||||
|
@ -74,7 +74,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
return;
|
||||
}
|
||||
|
||||
var difficulty = beatmap.Value.BeatmapInfo.BaseDifficulty;
|
||||
var difficulty = beatmap.Value.BeatmapInfo.Difficulty;
|
||||
|
||||
// generally should always be implemented, else the slider will have a zero default.
|
||||
if (difficultyBindable.ReadCurrentFromDifficulty == null)
|
||||
|
@ -104,6 +104,7 @@ namespace osu.Game.Scoring
|
||||
}
|
||||
}
|
||||
|
||||
[Ignored]
|
||||
public ScoreRank Rank
|
||||
{
|
||||
get => (ScoreRank)RankInt;
|
||||
|
@ -110,7 +110,7 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
Beatmap.Metadata.TitleUnicode = TitleTextBox.Current.Value;
|
||||
Beatmap.Metadata.Title = RomanisedTitleTextBox.Current.Value;
|
||||
|
||||
Beatmap.Metadata.AuthorString = creatorTextBox.Current.Value;
|
||||
Beatmap.Metadata.Author.Username = creatorTextBox.Current.Value;
|
||||
Beatmap.BeatmapInfo.DifficultyName = difficultyTextBox.Current.Value;
|
||||
Beatmap.Metadata.Source = sourceTextBox.Current.Value;
|
||||
Beatmap.Metadata.Tags = tagsTextBox.Current.Value;
|
||||
|
@ -39,10 +39,10 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
}
|
||||
|
||||
match &= !criteria.StarDifficulty.HasFilter || criteria.StarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
||||
match &= !criteria.ApproachRate.HasFilter || criteria.ApproachRate.IsInRange(BeatmapInfo.BaseDifficulty.ApproachRate);
|
||||
match &= !criteria.DrainRate.HasFilter || criteria.DrainRate.IsInRange(BeatmapInfo.BaseDifficulty.DrainRate);
|
||||
match &= !criteria.CircleSize.HasFilter || criteria.CircleSize.IsInRange(BeatmapInfo.BaseDifficulty.CircleSize);
|
||||
match &= !criteria.OverallDifficulty.HasFilter || criteria.OverallDifficulty.IsInRange(BeatmapInfo.BaseDifficulty.OverallDifficulty);
|
||||
match &= !criteria.ApproachRate.HasFilter || criteria.ApproachRate.IsInRange(BeatmapInfo.Difficulty.ApproachRate);
|
||||
match &= !criteria.DrainRate.HasFilter || criteria.DrainRate.IsInRange(BeatmapInfo.Difficulty.DrainRate);
|
||||
match &= !criteria.CircleSize.HasFilter || criteria.CircleSize.IsInRange(BeatmapInfo.Difficulty.CircleSize);
|
||||
match &= !criteria.OverallDifficulty.HasFilter || criteria.OverallDifficulty.IsInRange(BeatmapInfo.Difficulty.OverallDifficulty);
|
||||
match &= !criteria.Length.HasFilter || criteria.Length.IsInRange(BeatmapInfo.Length);
|
||||
match &= !criteria.BPM.HasFilter || criteria.BPM.IsInRange(BeatmapInfo.BPM);
|
||||
|
||||
|
@ -218,7 +218,7 @@ namespace osu.Game.Stores
|
||||
}
|
||||
|
||||
var decodedInfo = decoded.BeatmapInfo;
|
||||
var decodedDifficulty = decodedInfo.BaseDifficulty;
|
||||
var decodedDifficulty = decodedInfo.Difficulty;
|
||||
|
||||
var ruleset = realm.All<RulesetInfo>().FirstOrDefault(r => r.OnlineID == decodedInfo.RulesetID);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user