mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 07:12:54 +08:00
Remove DatabaseBackedStore Prepare functions
This commit is contained in:
parent
89cc7b7945
commit
63fe569afa
@ -25,21 +25,6 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Prepare(bool reset = false)
|
|
||||||
{
|
|
||||||
if (reset)
|
|
||||||
{
|
|
||||||
var context = GetContext();
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/10450893
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapMetadata");
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapDifficulty");
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetInfo");
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetFileInfo");
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapInfo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a <see cref="BeatmapSetInfo"/> to the database.
|
/// Add a <see cref="BeatmapSetInfo"/> to the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -151,6 +136,18 @@ namespace osu.Game.Beatmaps
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
var context = GetContext();
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/10450893
|
||||||
|
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapMetadata");
|
||||||
|
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapDifficulty");
|
||||||
|
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetInfo");
|
||||||
|
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetFileInfo");
|
||||||
|
context.Database.ExecuteSqlCommand("DELETE FROM BeatmapInfo");
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<BeatmapSetInfo> BeatmapSets => GetContext().BeatmapSetInfo
|
public IEnumerable<BeatmapSetInfo> BeatmapSets => GetContext().BeatmapSetInfo
|
||||||
.Include(s => s.Metadata)
|
.Include(s => s.Metadata)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
@ -32,16 +31,6 @@ namespace osu.Game.Database
|
|||||||
queryContext = new ThreadLocal<OsuDbContext>(CreateContext);
|
queryContext = new ThreadLocal<OsuDbContext>(CreateContext);
|
||||||
|
|
||||||
Storage = storage;
|
Storage = storage;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Prepare();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.Error(e, $@"Failed to initialise the {GetType()}! Trying again with a clean database...");
|
|
||||||
Prepare(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -51,14 +40,9 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepare this database for use. Tables should be created here.
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void Prepare(bool reset = false);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reset this database to a default state. Undo all changes to database and storage backings.
|
/// Reset this database to a default state. Undo all changes to database and storage backings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Reset() => Prepare(true);
|
public abstract void Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,6 @@ namespace osu.Game.IO
|
|||||||
Store = new StorageBackedResourceStore(Storage);
|
Store = new StorageBackedResourceStore(Storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Prepare(bool reset = false)
|
|
||||||
{
|
|
||||||
if (reset)
|
|
||||||
{
|
|
||||||
if (Storage.ExistsDirectory(string.Empty))
|
|
||||||
Storage.DeleteDirectory(string.Empty);
|
|
||||||
|
|
||||||
GetContext().Database.ExecuteSqlCommand("DELETE FROM FileInfo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileInfo Add(Stream data, bool reference = true)
|
public FileInfo Add(Stream data, bool reference = true)
|
||||||
{
|
{
|
||||||
var context = GetContext();
|
var context = GetContext();
|
||||||
@ -114,5 +103,13 @@ namespace osu.Game.IO
|
|||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
if (Storage.ExistsDirectory(string.Empty))
|
||||||
|
Storage.DeleteDirectory(string.Empty);
|
||||||
|
|
||||||
|
GetContext().Database.ExecuteSqlCommand("DELETE FROM FileInfo");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,6 @@ namespace osu.Game.Input
|
|||||||
|
|
||||||
public void Register(KeyBindingInputManager manager) => insertDefaults(manager.DefaultKeyBindings);
|
public void Register(KeyBindingInputManager manager) => insertDefaults(manager.DefaultKeyBindings);
|
||||||
|
|
||||||
protected override void Prepare(bool reset = false)
|
|
||||||
{
|
|
||||||
if (reset)
|
|
||||||
GetContext().Database.ExecuteSqlCommand("DELETE FROM KeyBinding");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||||
{
|
{
|
||||||
var context = GetContext();
|
var context = GetContext();
|
||||||
@ -83,5 +77,10 @@ namespace osu.Game.Input
|
|||||||
|
|
||||||
KeyBindingChanged?.Invoke();
|
KeyBindingChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
GetContext().Database.ExecuteSqlCommand("DELETE FROM KeyBinding");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ namespace osu.Game.Rulesets
|
|||||||
public RulesetStore(Func<OsuDbContext> factory)
|
public RulesetStore(Func<OsuDbContext> factory)
|
||||||
: base(factory)
|
: base(factory)
|
||||||
{
|
{
|
||||||
|
AddMissingRulesets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -47,15 +48,10 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
private const string ruleset_library_prefix = "osu.Game.Rulesets";
|
private const string ruleset_library_prefix = "osu.Game.Rulesets";
|
||||||
|
|
||||||
protected override void Prepare(bool reset = false)
|
protected void AddMissingRulesets()
|
||||||
{
|
{
|
||||||
var context = GetContext();
|
var context = GetContext();
|
||||||
|
|
||||||
if (reset)
|
|
||||||
{
|
|
||||||
context.Database.ExecuteSqlCommand("DELETE FROM RulesetInfo");
|
|
||||||
}
|
|
||||||
|
|
||||||
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, new RulesetInfo())).ToList();
|
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, new RulesetInfo())).ToList();
|
||||||
|
|
||||||
//add all legacy modes in correct order
|
//add all legacy modes in correct order
|
||||||
@ -123,5 +119,10 @@ namespace osu.Game.Rulesets
|
|||||||
InstantiationInfo = ruleset.GetType().AssemblyQualifiedName,
|
InstantiationInfo = ruleset.GetType().AssemblyQualifiedName,
|
||||||
ID = ruleset.LegacyID
|
ID = ruleset.LegacyID
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
GetContext().Database.ExecuteSqlCommand("DELETE FROM RulesetInfo");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,8 +144,9 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
return new Replay { Frames = frames };
|
return new Replay { Frames = frames };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Prepare(bool reset = false)
|
public override void Reset()
|
||||||
{
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user