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
1 changed files with 23 additions and 9 deletions

View File

@ -36,25 +36,39 @@ public BeatmapDatabase(BasicStorage storage, BasicGameHost importHost = null)
if (connection == null)
{
retry:
try
{
connection = storage.GetDatabase(@"beatmaps");
connection.CreateTable<BeatmapMetadata>();
connection.CreateTable<BaseDifficulty>();
connection.CreateTable<BeatmapSetInfo>();
connection.CreateTable<BeatmapInfo>();
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<BeatmapMetadata>();
conn.CreateTable<BaseDifficulty>();
conn.CreateTable<BeatmapSetInfo>();
conn.CreateTable<BeatmapInfo>();
}
catch
{
conn.Close();
throw;
}
return conn;
}
public void Reset()
{
foreach (var setInfo in Query<BeatmapSetInfo>())