2023-11-20 12:31:57 +01:00
|
|
|
import gzip
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
from encryption import decrypt_file
|
|
|
|
|
|
|
|
|
|
|
|
def isChn():
|
2023-11-21 11:12:49 +01:00
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Trying to load file for 08.18
|
|
|
|
json.load(gzip.open("./Data/x64/datatable/musicinfo.bin", "rb"))["items"]
|
|
|
|
return False
|
|
|
|
except Exception as error:
|
|
|
|
# Trying to load file for 32.09 CHN
|
|
|
|
json.loads(decrypt_file(input_file="./Data/x64/datatable/musicinfo.bin"))[
|
|
|
|
"items"
|
|
|
|
]
|
|
|
|
return True
|
|
|
|
except Exception as error:
|
|
|
|
print(error)
|
|
|
|
print("Couldn't find musicinfo.bin, assuming 08.18")
|
2023-11-20 12:31:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
def loadFile(path: str):
|
|
|
|
if doesPathExist(path):
|
|
|
|
try:
|
|
|
|
if not isChn():
|
|
|
|
# Loading files for 08.18
|
|
|
|
return json.load(gzip.open(path, "rb"))["items"]
|
|
|
|
else:
|
|
|
|
# Loading files for 32.09 CHN
|
|
|
|
return json.loads(decrypt_file(input_file=path))["items"]
|
|
|
|
except Exception as error:
|
|
|
|
print(error)
|
|
|
|
print("Couldn't load", path)
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
print(path, "doesn't exist")
|
|
|
|
|
|
|
|
|
|
|
|
def findKeyInList(list: list, key: str, keyValue, value=None):
|
|
|
|
for object in list:
|
|
|
|
try:
|
|
|
|
if object[key] == keyValue:
|
|
|
|
if value is not None:
|
|
|
|
return object[value]
|
|
|
|
else:
|
|
|
|
return object
|
|
|
|
except:
|
|
|
|
if value is not None:
|
|
|
|
print(
|
|
|
|
value
|
|
|
|
+ " doesn't exist in "
|
|
|
|
+ str(object)
|
|
|
|
+ ", are you using the right language ?"
|
|
|
|
)
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
if value is not None:
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def findAllObjects(list: list, key: str, keyValue):
|
|
|
|
templist = []
|
|
|
|
templist.append(list)
|
|
|
|
objects = []
|
|
|
|
|
|
|
|
for element in templist[0]:
|
|
|
|
if element[key] == keyValue:
|
|
|
|
objects.append(element)
|
|
|
|
|
|
|
|
return objects
|
|
|
|
|
|
|
|
|
|
|
|
def findDoubloninList(list: list, key: str, keyValue):
|
|
|
|
if len(findAllObjects(list=list, key=key, keyValue=keyValue)) > 1:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def doesPathExist(path: str):
|
|
|
|
if os.path.exists(path):
|
|
|
|
return True
|
|
|
|
return False
|