warn when prefs.db corrupt and catch another case

This commit is contained in:
Damien Elmes 2013-07-18 18:59:14 +09:00
parent 26a3c30365
commit 99c90b929b

View File

@ -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()