mirror of
https://github.com/JDM170/SaveWizard
synced 2025-04-20 22:30:42 +07:00
Update module_parsing
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
12
configs/version_new.cfg
Normal file
12
configs/version_new.cfg
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"ats": {
|
||||||
|
"dlc": "c5f4adb336a6c2a7f1987f00c61c8d48",
|
||||||
|
"agencies": "7b6eb8747a5b51d5d03869884e4b6e80",
|
||||||
|
"dealers": "4e3b0d639a6bc85b2e25af2f73656d21"
|
||||||
|
},
|
||||||
|
"ets2": {
|
||||||
|
"dlc": "d3634f683550d9f9d87ad3c1ff579561",
|
||||||
|
"agencies": "cd71f9d0a0b53bbc5c1ae127936455c8",
|
||||||
|
"dealers": "c045068fa3fe4eaf3a2cae7b8ec05066"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,11 +10,20 @@ from util import util
|
|||||||
|
|
||||||
|
|
||||||
def get_response_result(url):
|
def get_response_result(url):
|
||||||
|
"""
|
||||||
|
Getting the result from a given url
|
||||||
|
:param url: url where we get data
|
||||||
|
:return: status code (True or False), response body
|
||||||
|
"""
|
||||||
response = get(url)
|
response = get(url)
|
||||||
return response.status_code == 200, response
|
return response.status_code == 200, response
|
||||||
|
|
||||||
|
|
||||||
def check_path(path):
|
def check_path(path):
|
||||||
|
"""
|
||||||
|
Checks if the path exists (if not, creates it)
|
||||||
|
:param path: path to check
|
||||||
|
"""
|
||||||
current_path = os.getcwd()
|
current_path = os.getcwd()
|
||||||
for item in path.split("/"):
|
for item in path.split("/"):
|
||||||
current_path = os.path.join(current_path, item)
|
current_path = os.path.join(current_path, item)
|
||||||
@@ -26,21 +35,26 @@ def check_path(path):
|
|||||||
|
|
||||||
|
|
||||||
def check_remote_hashes():
|
def check_remote_hashes():
|
||||||
response_status, response = get_response_result(github_link + "configs/version.cfg")
|
# response_status, response = get_response_result(github_link + "configs/version.cfg")
|
||||||
|
response_status, response = get_response_result(github_link + "configs/version_new.cfg")
|
||||||
if response_status:
|
if response_status:
|
||||||
remote_cfg = literal_eval(response.text)
|
remote_cfg = literal_eval(response.text)
|
||||||
need_update = []
|
need_update = []
|
||||||
for key, value in remote_cfg.items():
|
for game, cfg in remote_cfg.items():
|
||||||
path = key.split("_")
|
for f_name, f_hash in cfg.items():
|
||||||
path = "configs/{}/{}.json".format(path[0], path[1])
|
path = "configs/{}/{}.json".format(game, f_name)
|
||||||
if util.generate_md5(path) != value:
|
if util.generate_md5(path) != f_hash:
|
||||||
need_update.append(path)
|
need_update.append(path)
|
||||||
return need_update
|
return need_update
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def update_configs(is_save, cfg_list):
|
def update_configs(cfg_list, ans_upd=0):
|
||||||
if is_save in (0, 1):
|
"""
|
||||||
|
:param cfg_list: config list to update
|
||||||
|
:param ans_upd: ask user to update configs, update or not, remember answer or not
|
||||||
|
"""
|
||||||
|
if ans_upd in (0, 1):
|
||||||
for cfg in cfg_list:
|
for cfg in cfg_list:
|
||||||
check_path(cfg)
|
check_path(cfg)
|
||||||
response_status, response = get_response_result(github_link + cfg)
|
response_status, response = get_response_result(github_link + cfg)
|
||||||
@@ -48,8 +62,6 @@ def update_configs(is_save, cfg_list):
|
|||||||
remote_cfg = literal_eval(response.text)
|
remote_cfg = literal_eval(response.text)
|
||||||
if dataIO.is_valid_json(cfg) or os.path.exists(cfg):
|
if dataIO.is_valid_json(cfg) or os.path.exists(cfg):
|
||||||
dataIO.save_json(cfg, remote_cfg)
|
dataIO.save_json(cfg, remote_cfg)
|
||||||
if is_save in (1, 3):
|
if ans_upd in (1, 3):
|
||||||
text = str({"answer_updates": is_save == 3,
|
|
||||||
"update_on_start": is_save == 1})
|
|
||||||
with open(update_config_name, "w") as f:
|
with open(update_config_name, "w") as f:
|
||||||
f.write(text)
|
f.write(str({"answer_updates": ans_upd == 3, "update_on_start": ans_upd == 1}))
|
||||||
|
|||||||
Reference in New Issue
Block a user