From 59f3c0bb92597600ef3bd52eaa7152b6b0b4b695 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Wed, 14 Jun 2017 20:46:14 -1000 Subject: [PATCH] Fix #320: argv is `str` but our filenames must be `unicode` TODO: figure out why argparse sometimes gets the exe as a filename --- src/mcedit2/editorapp.py | 6 ++++++ src/mcedit2/main.py | 1 + 2 files changed, 7 insertions(+) diff --git a/src/mcedit2/editorapp.py b/src/mcedit2/editorapp.py index 53cf2a9..a06c80a 100644 --- a/src/mcedit2/editorapp.py +++ b/src/mcedit2/editorapp.py @@ -487,12 +487,18 @@ class MCEditApp(QtGui.QApplication): for filename in self.args.filename: try: + # we use `unicode` filenames, but argv is `str` + # should only get `str` on linux/osx - need to get wargv on windows + if isinstance(filename, str): + filename = filename.decode(sys.getfilesystemencoding()) if os.path.exists(filename): self.commandLineWorlds.append(filename) else: log.info("File not found: %s", filename) except EnvironmentError as e: log.info("%r", e) + except UnicodeDecodeError as e: + log.info("%r", e) # --- Language Menu --- diff --git a/src/mcedit2/main.py b/src/mcedit2/main.py index b86e31b..782d8f0 100644 --- a/src/mcedit2/main.py +++ b/src/mcedit2/main.py @@ -187,6 +187,7 @@ def startup(): from mcedit2 import support_modules + # TODO: get wchar_t argv from windows editorApp = MCEditApp(sys.argv) editorApp.startup()