don't allow invalid chars in file export (#694)
This commit is contained in:
parent
7e74248901
commit
fa07268763
@ -320,9 +320,13 @@ def call(argv, wait=True, **kwargs):
|
||||
isMac = sys.platform.startswith("darwin")
|
||||
isWin = sys.platform.startswith("win32")
|
||||
|
||||
invalidFilenameChars = "\\/:*?\"<>|"
|
||||
invalidFilenameChars = ":*?\"<>|"
|
||||
|
||||
def invalidFilename(str):
|
||||
def invalidFilename(str, dirsep=True):
|
||||
for c in invalidFilenameChars:
|
||||
if c in str:
|
||||
return True
|
||||
return c
|
||||
if (dirsep or isWin) and "/" in str:
|
||||
return "/"
|
||||
elif (dirsep or not isWin) and "\\" in str:
|
||||
return "\\"
|
||||
|
@ -4,7 +4,8 @@
|
||||
import os
|
||||
from aqt.qt import *
|
||||
import aqt
|
||||
from aqt.utils import getSaveFile, tooltip, showWarning, askUser
|
||||
from aqt.utils import getSaveFile, tooltip, showWarning, askUser, \
|
||||
checkInvalidFilename
|
||||
from anki.exporting import exporters
|
||||
|
||||
class ExportDialog(QDialog):
|
||||
@ -65,11 +66,15 @@ class ExportDialog(QDialog):
|
||||
return
|
||||
else:
|
||||
verbatim = False
|
||||
file = getSaveFile(
|
||||
self, _("Export"), "export",
|
||||
self.exporter.key, self.exporter.ext)
|
||||
if not file:
|
||||
return
|
||||
while 1:
|
||||
file = getSaveFile(
|
||||
self, _("Export"), "export",
|
||||
self.exporter.key, self.exporter.ext)
|
||||
if not file:
|
||||
return
|
||||
if checkInvalidFilename(file, dirsep=False):
|
||||
continue
|
||||
break
|
||||
self.hide()
|
||||
if file:
|
||||
self.mw.progress.start(immediate=True)
|
||||
|
10
aqt/main.py
10
aqt/main.py
@ -14,7 +14,8 @@ from anki.hooks import runHook, addHook
|
||||
|
||||
import aqt, aqt.progress, aqt.webview, aqt.toolbar, aqt.stats
|
||||
from aqt.utils import restoreGeom, showInfo, showWarning,\
|
||||
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, openHelp, openLink
|
||||
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
|
||||
openHelp, openLink, checkInvalidFilename
|
||||
|
||||
class AnkiQt(QMainWindow):
|
||||
def __init__(self, app, profileManager, args):
|
||||
@ -151,12 +152,7 @@ class AnkiQt(QMainWindow):
|
||||
|
||||
def profileNameOk(self, str):
|
||||
from anki.utils import invalidFilename, invalidFilenameChars
|
||||
if invalidFilename(str):
|
||||
showWarning(
|
||||
_("A profile name cannot contain these characters: %s") %
|
||||
" ".join(invalidFilenameChars))
|
||||
return
|
||||
return True
|
||||
return not checkInvalidFilename(str)
|
||||
|
||||
def onAddProfile(self):
|
||||
name = getOnlyText(_("Name:"))
|
||||
|
13
aqt/utils.py
13
aqt/utils.py
@ -4,8 +4,8 @@
|
||||
from aqt.qt import *
|
||||
import re, os, sys, urllib, subprocess
|
||||
import aqt
|
||||
from anki.sound import stripSounds
|
||||
from anki.utils import isWin, isMac
|
||||
from anki.sound import stripSounds
|
||||
from anki.utils import isWin, isMac, invalidFilename
|
||||
|
||||
def openHelp(section):
|
||||
link = aqt.appHelpSite
|
||||
@ -411,3 +411,12 @@ def closeTooltip():
|
||||
if _tooltipTimer:
|
||||
_tooltipTimer.stop()
|
||||
_tooltipTimer = None
|
||||
|
||||
# true if invalid; print warning
|
||||
def checkInvalidFilename(str, dirsep=True):
|
||||
bad = invalidFilename(str, dirsep)
|
||||
if bad:
|
||||
showWarning(_("The following character can not be used: %s") %
|
||||
bad)
|
||||
return True
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user