Change beatmap database reset logic to only run a maximum of once.

This commit is contained in:
Dean Herbert
2017-01-23 18:13:06 +09:00
parent ef8347fe53
commit 56fe69852d

View File

@ -36,25 +36,39 @@ namespace osu.Game.Database
if (connection == null) if (connection == null)
{ {
retry:
try try
{ {
connection = storage.GetDatabase(@"beatmaps"); connection = prepareConnection();
connection.CreateTable<BeatmapMetadata>();
connection.CreateTable<BaseDifficulty>();
connection.CreateTable<BeatmapSetInfo>();
connection.CreateTable<BeatmapInfo>();
} }
catch catch
{ {
Debug.WriteLine(@"Beatmap database was unable to be migrated; starting fresh!"); Console.WriteLine(@"Failed to initialise the beatmap database! Trying again with a clean database...");
connection?.Close();
storage.DeleteDatabase(@"beatmaps"); storage.DeleteDatabase(@"beatmaps");
goto retry; 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>())