Modified fixLongName to work bytewise

This fixes #6
This commit is contained in:
RemixDev 2020-07-29 11:32:25 +02:00
parent b450929553
commit 73358d1c22
1 changed files with 14 additions and 2 deletions

View File

@ -19,17 +19,29 @@ def fixName(txt, char='_'):
txt = re.sub(r'[\0\/\\:*?"<>|]', char, txt)
return txt
def fixEndOfData(bString):
try:
bString.decode()
return True
except:
return False
def fixLongName(name):
if pathSep in name:
name2 = name.split(pathSep)
name = ""
for txt in name2:
txt = txt[:200]
txt = txt.encode('utf-8')[:200]
while not fixEndOfData(txt):
txt = txt[:-1]
txt = txt.decode()
name += txt + pathSep
name = name[:-1]
else:
name = name[:200]
name = name.encode('utf-8')[:200]
while not fixEndOfData(name):
name = name[:-1]
name = name.decode()
return name