feat: 配置文件类型检查

This commit is contained in:
helloplhm-qwq 2023-11-26 11:37:30 +08:00
parent 1f380b6dd1
commit 6de45a86e5
No known key found for this signature in database
GPG Key ID: 6BE1B64B905567C7
2 changed files with 6 additions and 2 deletions

View File

@ -16,7 +16,6 @@ import traceback
import zlib
import ujson as json
import re
import binascii
import time
import pickle
from . import log

View File

@ -14,7 +14,6 @@ import os
import traceback
import sys
import sqlite3
from .utils import readfile
from . import variable
from .log import log
import threading
@ -473,6 +472,12 @@ def initConfig():
with open("./config.json", "r", encoding="utf-8") as f:
try:
variable.config = json.loads(f.read())
if (not isinstance(variable.config, dict)):
logger.warning('配置文件并不是一个有效的字典,使用默认值')
variable.config = default
with open("./config.json", "w", encoding="utf-8") as f:
f.write(json.dumps(variable.config, indent=2, ensure_ascii=False))
f.close()
except:
if os.path.getsize("./config.json") != 0:
logger.error("配置文件加载失败请检查是否遵循JSON语法规范")