This commit is contained in:
恍兮惚兮 2024-07-27 17:38:13 +08:00
parent ad05ca5cf2
commit 5e2119091c

View File

@ -1,23 +1,20 @@
import json import json
import os, time, uuid import os, time, uuid, shutil
from traceback import print_exc from traceback import print_exc
from qtsymbols import * from qtsymbols import *
def tryreadconfig(path, default=None): def tryreadconfig(path, default=None):
path = os.path.join("userconfig", path) 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: try:
with open(path, "r", encoding="utf-8") as ff: with open(path, "r", encoding="utf-8") as ff:
x = json.load(ff) return json.load(ff)
return x
except: 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): def tryreadconfig2(path):
@ -473,7 +470,9 @@ def safesave(fname, js, beatiful=True):
ff.write(json.dumps(js, sort_keys=False)) ff.write(json.dumps(js, sort_keys=False))
if os.path.exists(fname): if os.path.exists(fname):
os.remove(fname) os.remove(fname)
os.rename(fname + ".tmp", fname) shutil.copy(fname + ".tmp", fname)
os.remove(fname + ".tmp")
# wine上MoveFile会权限问题失败不知道为什么WinError 32
def saveallconfig(): def saveallconfig():