mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
force backups to be treated as a replace
This commit is contained in:
parent
c64f5130e2
commit
418acb3365
2 changed files with 17 additions and 12 deletions
|
@ -316,28 +316,32 @@ Unable to import from a read-only file."""))
|
|||
|
||||
def setupApkgImport(mw, importer):
|
||||
meta = None
|
||||
forceFull = False
|
||||
try:
|
||||
z = zipfile.ZipFile(importer.file)
|
||||
meta = json.load(z.open("meta"))
|
||||
if not meta['full']:
|
||||
# add
|
||||
return True
|
||||
elif meta['full'] == "force":
|
||||
forceFull = True
|
||||
except:
|
||||
# no meta attribute on broken file
|
||||
pass
|
||||
# if old file or full collection, we have to prompt user
|
||||
diag = askUserDialog(_("""\
|
||||
if not forceFull:
|
||||
diag = askUserDialog(_("""\
|
||||
Would you like to add to your collection, or replace it?"""),
|
||||
[_("Add"),
|
||||
_("Replace"),
|
||||
_("Cancel")])
|
||||
diag.setIcon(QMessageBox.Question)
|
||||
diag.setDefault(0)
|
||||
ret = diag.run()
|
||||
if ret == _("Add"):
|
||||
return True
|
||||
elif ret == _("Cancel"):
|
||||
return False
|
||||
[_("Add"),
|
||||
_("Replace"),
|
||||
_("Cancel")])
|
||||
diag.setIcon(QMessageBox.Question)
|
||||
diag.setDefault(0)
|
||||
ret = diag.run()
|
||||
if ret == _("Add"):
|
||||
return True
|
||||
elif ret == _("Cancel"):
|
||||
return False
|
||||
if not askUser(_("""\
|
||||
This will delete your existing collection and replace it with the data in \
|
||||
the file you're importing. Are you sure?"""), msgfunc=QMessageBox.warning):
|
||||
|
|
|
@ -10,7 +10,7 @@ from aqt.qt import *
|
|||
QtConfig = pyqtconfig.Configuration()
|
||||
|
||||
from anki import Collection
|
||||
from anki.utils import stripHTML, checksum, isWin, isMac, intTime
|
||||
from anki.utils import stripHTML, checksum, isWin, isMac, intTime, json
|
||||
from anki.hooks import runHook, addHook, remHook
|
||||
import anki.consts
|
||||
|
||||
|
@ -296,6 +296,7 @@ how to restore from a backup.""")
|
|||
z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
|
||||
z.write(path, "collection.anki2")
|
||||
z.writestr("media", "{}")
|
||||
z.writestr("meta", json.dumps(dict(full="force")))
|
||||
z.close()
|
||||
# remove if over
|
||||
if len(backups) + 1 > nbacks:
|
||||
|
|
Loading…
Reference in a new issue