115 lines
2.4 KiB
Python
115 lines
2.4 KiB
Python
# -*- coding: UTF-8 -*-
|
|
# collecting settings to here
|
|
import json
|
|
import os
|
|
import modules.scripts as scripts
|
|
from . import util
|
|
|
|
|
|
name = "setting.json"
|
|
path = os.path.join(scripts.basedir(), name)
|
|
|
|
data = {
|
|
"model":{
|
|
"max_size_preview": True,
|
|
"skip_nsfw_preview": False,
|
|
"check_new_ver_exist_in_all_folder": False
|
|
},
|
|
"general":{
|
|
"open_url_with_js": True,
|
|
"proxy": "",
|
|
"civitai_domain": "civitai.com"
|
|
},
|
|
"tool":{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# save setting
|
|
# return output msg for log
|
|
def save():
|
|
print("Saving setting to: " + path)
|
|
|
|
json_data = json.dumps(data, indent=4)
|
|
|
|
output = ""
|
|
|
|
#write to file
|
|
try:
|
|
with open(path, 'w') as f:
|
|
f.write(json_data)
|
|
except Exception as e:
|
|
util.printD("Error when writing file:"+path)
|
|
output = str(e)
|
|
util.printD(str(e))
|
|
return output
|
|
|
|
output = "Setting saved to: " + path
|
|
util.printD(output)
|
|
|
|
return output
|
|
|
|
|
|
# load setting to global data
|
|
def load():
|
|
# load data into globel data
|
|
global data
|
|
|
|
util.printD("Load setting from: " + path)
|
|
|
|
if not os.path.isfile(path):
|
|
util.printD("No setting file, use default")
|
|
return
|
|
|
|
json_data = None
|
|
with open(path, 'r') as f:
|
|
json_data = json.load(f)
|
|
|
|
# check error
|
|
if not json_data:
|
|
util.printD("load setting file failed")
|
|
return
|
|
|
|
data = json_data
|
|
|
|
# check for new key
|
|
if "proxy" not in data["general"].keys():
|
|
data["general"]["proxy"] = ""
|
|
|
|
if "check_new_ver_exist_in_all_folder" not in data["model"].keys():
|
|
data["general"]["check_new_ver_exist_in_all_folder"] = False
|
|
|
|
if "civitai_domain" not in data["general"].keys():
|
|
data["general"]["civitai_domain"] = "civitai.com"
|
|
|
|
|
|
|
|
return
|
|
|
|
# save setting from parameter
|
|
def save_from_input(max_size_preview, skip_nsfw_preview, open_url_with_js, proxy, check_new_ver_exist_in_all_folder, civitai_domain):
|
|
global data
|
|
data = {
|
|
"model":{
|
|
"max_size_preview": max_size_preview,
|
|
"skip_nsfw_preview": skip_nsfw_preview,
|
|
"check_new_ver_exist_in_all_folder": check_new_ver_exist_in_all_folder
|
|
},
|
|
"general":{
|
|
"open_url_with_js": open_url_with_js,
|
|
"proxy": proxy,
|
|
"civitai_domain": civitai_domain,
|
|
},
|
|
"tool":{
|
|
}
|
|
}
|
|
|
|
output = save()
|
|
|
|
if not output:
|
|
output = ""
|
|
|
|
return output
|
|
|