From 8aea6068ba4d2a3f0f923070b983ee7ebf0c9941 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 19 Oct 2017 21:37:09 +0900 Subject: [PATCH] Add fallback logic for the case where previous database can't be migrated --- osu.Game/Database/OsuDbContext.cs | 12 +++++++++--- osu.Game/OsuGameBase.cs | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index 0ebea94683..93d23cc1bc 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -221,19 +221,25 @@ namespace osu.Game.Database Database.ExecuteSqlCommand( "INSERT INTO BeatmapInfo SELECT ID, AudioLeadIn, BaseDifficultyID, BeatDivisor, BeatmapSetInfoID, Countdown, DistanceSpacing, GridSize, Hash, Hidden, LetterboxInBreaks, MD5Hash, NULLIF(BeatmapMetadataID, 0), OnlineBeatmapID, Path, RulesetID, SpecialStyle, StackLeniency, StarDifficulty, StoredBookmarks, TimelineZoom, Version, WidescreenStoryboard FROM BeatmapInfo_Old"); Database.ExecuteSqlCommand("DROP TABLE BeatmapInfo_Old"); - - throw new Exception(); } catch { // if anything went wrong during migration just nuke the database. - Database.EnsureDeleted(); + throw new MigrationFailedException(); } } + catch (MigrationFailedException e) + { + throw; + } catch { } } } } + + public class MigrationFailedException : Exception + { + } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index be12f3ddbc..e7ad77d099 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -90,8 +90,18 @@ namespace osu.Game dependencies.Cache(this); dependencies.Cache(LocalConfig); - using (var context = contextFactory.GetContext()) - context.Migrate(); + try + { + using (var context = contextFactory.GetContext()) + context.Migrate(); + } + catch (MigrationFailedException) + { + using (var context = contextFactory.GetContext()) + context.Database.EnsureDeleted(); + using (var context = contextFactory.GetContext()) + context.Migrate(); + } dependencies.Cache(API = new APIAccess { @@ -203,10 +213,7 @@ namespace osu.Game // TODO: This is temporary until we reimplement the local FPS display. // It's just to allow end-users to access the framework FPS display without knowing the shortcut key. fpsDisplayVisible = LocalConfig.GetBindable(OsuSetting.ShowFpsDisplay); - fpsDisplayVisible.ValueChanged += val => - { - FrameStatisticsMode = val ? FrameStatisticsMode.Minimal : FrameStatisticsMode.None; - }; + fpsDisplayVisible.ValueChanged += val => { FrameStatisticsMode = val ? FrameStatisticsMode.Minimal : FrameStatisticsMode.None; }; fpsDisplayVisible.TriggerChange(); }