From 99c90b929b5fcb3f4ac49b59a55990ce70edd9a0 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 18 Jul 2013 18:59:14 +0900 Subject: [PATCH] warn when prefs.db corrupt and catch another case --- aqt/profiles.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/aqt/profiles.py b/aqt/profiles.py index 2ec5b71eb..834560c7b 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -187,9 +187,20 @@ documentation for information on using a flash drive.""") path = os.path.join(self.base, "prefs.db") new = not os.path.exists(path) self.db = DB(path, text=str) - self.db.execute(""" + def recover(): + # if we can't load profile, start with a new one + os.rename(path, path+".broken") + QMessageBox.warning( + None, "Preferences Corrupt", """\ +Anki's prefs.db file was corrupt and has been recreated. If you were using multiple \ +profiles, please add them back using the same names to recover your cards.""") + try: + self.db.execute(""" create table if not exists profiles (name text primary key, data text not null);""") + except: + recover() + return self._loadMeta() if not new: # load previously created try: @@ -198,8 +209,7 @@ create table if not exists profiles "select data from profiles where name = '_global'")) return except: - # if we can't load profile, start with a new one - os.rename(path, path+".broken") + recover() return self._loadMeta() # create a default global profile self.meta = metaConf.copy()