From 3acea038a250f30753027f5e005fe4950b41dbeb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 24 Oct 2012 22:59:49 +0900 Subject: [PATCH] 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. --- aqt/importing.py | 31 ++++--------------------------- aqt/main.py | 1 - 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/aqt/importing.py b/aqt/importing.py index eafbdc64b..52bdcb0f4 100644 --- a/aqt/importing.py +++ b/aqt/importing.py @@ -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 - 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 + base = os.path.basename(importer.file).lower() + full = (base == "collection.apkg") or re.match("backup-\d+.apkg", base) + if not full: + return True 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): diff --git a/aqt/main.py b/aqt/main.py index 749d0acaa..fa74b8370 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -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: