mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -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()
|
||||
|
||||
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
|
||||
base = os.path.basename(importer.file).lower()
|
||||
full = (base == "collection.apkg") or re.match("backup-\d+.apkg", base)
|
||||
if not full:
|
||||
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(_("""\
|
||||
This will delete your existing collection and replace it with the data in \
|
||||
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.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