From ef8347fe53775782d4310e91bcd17709dfeb16db Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Jan 2017 13:02:03 +0900 Subject: [PATCH 1/2] Reset the beatmap database when it can't be read, rather than hard failing. --- osu.Game/Database/BeatmapDatabase.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index eda5f1b9a3..de63e7cdca 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; @@ -35,11 +36,22 @@ namespace osu.Game.Database if (connection == null) { - connection = storage.GetDatabase(@"beatmaps"); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); + retry: + try + { + connection = storage.GetDatabase(@"beatmaps"); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); + connection.CreateTable(); + } + catch + { + Debug.WriteLine(@"Beatmap database was unable to be migrated; starting fresh!"); + connection?.Close(); + storage.DeleteDatabase(@"beatmaps"); + goto retry; + } } } From 56fe69852dc0c5402ebf728c30d98439468a0b9b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Jan 2017 18:13:06 +0900 Subject: [PATCH 2/2] Change beatmap database reset logic to only run a maximum of once. --- osu.Game/Database/BeatmapDatabase.cs | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index de63e7cdca..99a8867636 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -36,25 +36,39 @@ namespace osu.Game.Database if (connection == null) { - retry: try { - connection = storage.GetDatabase(@"beatmaps"); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); - connection.CreateTable(); + connection = prepareConnection(); } catch { - Debug.WriteLine(@"Beatmap database was unable to be migrated; starting fresh!"); - connection?.Close(); + Console.WriteLine(@"Failed to initialise the beatmap database! Trying again with a clean database..."); storage.DeleteDatabase(@"beatmaps"); - goto retry; + connection = prepareConnection(); } } } + private SQLiteConnection prepareConnection() + { + var conn = storage.GetDatabase(@"beatmaps"); + + try + { + conn.CreateTable(); + conn.CreateTable(); + conn.CreateTable(); + conn.CreateTable(); + } + catch + { + conn.Close(); + throw; + } + + return conn; + } + public void Reset() { foreach (var setInfo in Query())