mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
recover from a corrupt prefs.db that fails to load at all
This commit is contained in:
parent
9c678c32ad
commit
9f548ad85a
1 changed files with 8 additions and 2 deletions
|
@ -6,8 +6,13 @@
|
||||||
# - Saves in pickles rather than json to easily store Qt window state.
|
# - Saves in pickles rather than json to easily store Qt window state.
|
||||||
# - Saves in sqlite rather than a flat file so the config can't be corrupted
|
# - Saves in sqlite rather than a flat file so the config can't be corrupted
|
||||||
|
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import cPickle
|
||||||
|
import locale
|
||||||
|
import re
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import os, random, cPickle, shutil, locale, re
|
|
||||||
from anki.db import DB
|
from anki.db import DB
|
||||||
from anki.utils import isMac, isWin, intTime, checksum
|
from anki.utils import isMac, isWin, intTime, checksum
|
||||||
from anki.lang import langs
|
from anki.lang import langs
|
||||||
|
@ -16,6 +21,7 @@ from aqt import appHelpSite
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
from send2trash import send2trash
|
from send2trash import send2trash
|
||||||
|
|
||||||
|
|
||||||
metaConf = dict(
|
metaConf = dict(
|
||||||
ver=0,
|
ver=0,
|
||||||
updates=True,
|
updates=True,
|
||||||
|
@ -186,7 +192,6 @@ documentation for information on using a flash drive.""")
|
||||||
def _loadMeta(self):
|
def _loadMeta(self):
|
||||||
path = os.path.join(self.base, "prefs.db")
|
path = os.path.join(self.base, "prefs.db")
|
||||||
new = not os.path.exists(path)
|
new = not os.path.exists(path)
|
||||||
self.db = DB(path, text=str)
|
|
||||||
def recover():
|
def recover():
|
||||||
# if we can't load profile, start with a new one
|
# if we can't load profile, start with a new one
|
||||||
os.rename(path, path+".broken")
|
os.rename(path, path+".broken")
|
||||||
|
@ -195,6 +200,7 @@ documentation for information on using a flash drive.""")
|
||||||
Anki's prefs.db file was corrupt and has been recreated. If you were using multiple \
|
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.""")
|
profiles, please add them back using the same names to recover your cards.""")
|
||||||
try:
|
try:
|
||||||
|
self.db = DB(path, text=str)
|
||||||
self.db.execute("""
|
self.db.execute("""
|
||||||
create table if not exists profiles
|
create table if not exists profiles
|
||||||
(name text primary key, data text not null);""")
|
(name text primary key, data text not null);""")
|
||||||
|
|
Loading…
Reference in a new issue