Merge pull request #292 from peppy/general-fixes

Reset the beatmap database when it can't be read, rather than hard failing.
This commit is contained in:
Dean Herbert 2017-01-23 21:43:52 +09:00 committed by GitHub
commit 23938a810b

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -35,14 +36,39 @@ namespace osu.Game.Database
if (connection == null) if (connection == null)
{ {
connection = storage.GetDatabase(@"beatmaps"); try
connection.CreateTable<BeatmapMetadata>(); {
connection.CreateTable<BaseDifficulty>(); connection = prepareConnection();
connection.CreateTable<BeatmapSetInfo>(); }
connection.CreateTable<BeatmapInfo>(); catch
{
Console.WriteLine(@"Failed to initialise the beatmap database! Trying again with a clean database...");
storage.DeleteDatabase(@"beatmaps");
connection = prepareConnection();
}
} }
} }
private SQLiteConnection prepareConnection()
{
var conn = storage.GetDatabase(@"beatmaps");
try
{
conn.CreateTable<BeatmapMetadata>();
conn.CreateTable<BaseDifficulty>();
conn.CreateTable<BeatmapSetInfo>();
conn.CreateTable<BeatmapInfo>();
}
catch
{
conn.Close();
throw;
}
return conn;
}
public void Reset() public void Reset()
{ {
foreach (var setInfo in Query<BeatmapSetInfo>()) foreach (var setInfo in Query<BeatmapSetInfo>())