From 5e2119091c6667188364284fc73cb24bdc065a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 27 Jul 2024 17:38:13 +0800 Subject: [PATCH] fix wine --- .../LunaTranslator/myutils/config.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 0515c91f..d00ac69e 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -1,23 +1,20 @@ import json -import os, time, uuid +import os, time, uuid, shutil from traceback import print_exc from qtsymbols import * def tryreadconfig(path, default=None): path = os.path.join("userconfig", path) - if not os.path.exists(path): - path += ".tmp" - dfret = default if default else {} - if not os.path.exists(path): - return dfret try: with open(path, "r", encoding="utf-8") as ff: - x = json.load(ff) - - return x + return json.load(ff) except: - return dfret + try: + with open(path + ".tmp", "r", encoding="utf-8") as ff: + return json.load(ff) + except: + return default if default else {} def tryreadconfig2(path): @@ -473,7 +470,9 @@ def safesave(fname, js, beatiful=True): ff.write(json.dumps(js, sort_keys=False)) if os.path.exists(fname): os.remove(fname) - os.rename(fname + ".tmp", fname) + shutil.copy(fname + ".tmp", fname) + os.remove(fname + ".tmp") + # wine上MoveFile会权限问题失败,不知道为什么,WinError 32 def saveallconfig():