mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
decide on add/replace via filename instead
This means users will be able to rename the file if they want to force either adding or replacing.
This commit is contained in:
parent
418acb3365
commit
3acea038a2
2 changed files with 4 additions and 28 deletions
|
@ -315,33 +315,10 @@ Unable to import from a read-only file."""))
|
||||||
mw.reset()
|
mw.reset()
|
||||||
|
|
||||||
def setupApkgImport(mw, importer):
|
def setupApkgImport(mw, importer):
|
||||||
meta = None
|
base = os.path.basename(importer.file).lower()
|
||||||
forceFull = False
|
full = (base == "collection.apkg") or re.match("backup-\d+.apkg", base)
|
||||||
try:
|
if not full:
|
||||||
z = zipfile.ZipFile(importer.file)
|
return True
|
||||||
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
|
|
||||||
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
|
|
||||||
if not askUser(_("""\
|
if not askUser(_("""\
|
||||||
This will delete your existing collection and replace it with the data in \
|
This will delete your existing collection and replace it with the data in \
|
||||||
the file you're importing. Are you sure?"""), msgfunc=QMessageBox.warning):
|
the file you're importing. Are you sure?"""), msgfunc=QMessageBox.warning):
|
||||||
|
|
|
@ -296,7 +296,6 @@ how to restore from a backup.""")
|
||||||
z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
|
z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
|
||||||
z.write(path, "collection.anki2")
|
z.write(path, "collection.anki2")
|
||||||
z.writestr("media", "{}")
|
z.writestr("media", "{}")
|
||||||
z.writestr("meta", json.dumps(dict(full="force")))
|
|
||||||
z.close()
|
z.close()
|
||||||
# remove if over
|
# remove if over
|
||||||
if len(backups) + 1 > nbacks:
|
if len(backups) + 1 > nbacks:
|
||||||
|
|
Loading…
Reference in a new issue