2022-08-02 03:10:24 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import hashlib
|
|
|
|
import json
|
|
|
|
from pprint import pprint
|
|
|
|
from configparser import ConfigParser
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_md5(file_path):
|
|
|
|
hash_md5 = hashlib.md5()
|
|
|
|
with open(file_path, "rb") as f:
|
|
|
|
for chunk in iter(lambda: f.read(4096), b""):
|
|
|
|
hash_md5.update(chunk)
|
|
|
|
return hash_md5.hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
def read_config(config_path):
|
|
|
|
config = ConfigParser()
|
|
|
|
config.read(config_path)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def temp_forge_json():
|
|
|
|
with open('temp_forge.json') as json_file:
|
|
|
|
data = json.load(json_file)
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
def temp_forge_libs():
|
|
|
|
with open('temp_forge_libs.json') as json_file:
|
|
|
|
data = json.load(json_file)
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
def generate_forge_list(download_url, forge_version):
|
|
|
|
# forge_jar = scan_forge_folder(forge_path)
|
|
|
|
forge_submodules_list = generate_lib_list('none', download_url)
|
2022-08-04 00:39:24 +00:00
|
|
|
forge_module = [{
|
2022-08-10 01:48:48 +00:00
|
|
|
# 'id': 'net.minecraftForge:forge:' + forge_version,
|
|
|
|
'id': "net.minecraftforge:forge:1.12.2-14.23.5.2847",
|
2022-08-04 00:39:24 +00:00
|
|
|
'name': 'Minecraft Forge',
|
|
|
|
'type': 'ForgeHosted',
|
2022-08-10 01:48:48 +00:00
|
|
|
'artifact': {
|
|
|
|
"size": 4884700,
|
|
|
|
"MD5": "90734a5a713e24902d24c45c15caa42c",
|
|
|
|
# 'url': download_url + 'forge/' + 'net.minecraftForge:forge:' + forge_version + '.jar',
|
|
|
|
'url': "http://mc.westeroscraft.com/WesterosCraftLauncher/files/1.12.2/forge-1.12.2-14.23.5.2847-universal.jar",
|
|
|
|
},
|
|
|
|
'subModules': temp_forge_libs()
|
2022-08-04 00:39:24 +00:00
|
|
|
}]
|
2022-08-10 01:48:48 +00:00
|
|
|
return forge_module
|
2022-08-04 00:39:24 +00:00
|
|
|
|
|
|
|
|
2022-08-10 23:53:23 +00:00
|
|
|
def scan_mods_folder(minecraft_version):
|
|
|
|
mods_files_dict = {}
|
|
|
|
|
|
|
|
path = os.path.join(config.get('Basic', 'modules_' + minecraft_version), 'mods')
|
|
|
|
|
|
|
|
mods_files = list_files_in_folder(path)
|
|
|
|
for mod_file in mods_files:
|
|
|
|
mod_file_path = os.path.join(path, mod_file)
|
|
|
|
new_mod = {
|
|
|
|
'MD5': calculate_md5(mod_file_path),
|
|
|
|
'size': os.stat(mod_file_path).st_size
|
|
|
|
}
|
|
|
|
mods_files_dict[mod_file] = new_mod
|
|
|
|
print(mods_files_dict)
|
|
|
|
|
|
|
|
return mods_files_dict
|
|
|
|
|
|
|
|
|
|
|
|
def temp_files_json():
|
|
|
|
with open('temp_files.json') as json_file:
|
|
|
|
data = json.load(json_file)
|
|
|
|
return [data]
|
|
|
|
|
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
def parse_servers_config(config: ConfigParser):
|
|
|
|
servers = []
|
2022-08-04 00:39:24 +00:00
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
submodules_dict = generate_submodules_dict()
|
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
for section in config.sections():
|
|
|
|
if section.split(' ')[0] == 'Server' or section.split(' ')[0] == 'server':
|
2022-08-04 00:39:24 +00:00
|
|
|
download_url = config.get(section, 'download_url')
|
2022-08-10 01:48:48 +00:00
|
|
|
# server_mods_path = os.path.join(config.get(section, 'path'), 'mods')
|
|
|
|
# server_optional_mods_path = config.get(section, 'optional_mods_path')
|
|
|
|
# forge_path = config.get(section, 'forge_reference_folder')
|
|
|
|
|
|
|
|
forge_version = config.get(section, 'forge_version')
|
|
|
|
forge_module = generate_forge_list(download_url, forge_version)
|
|
|
|
|
2022-08-10 23:53:23 +00:00
|
|
|
mods_files_dict = scan_mods_folder(config.get(section, 'minecraftVersion'))
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
config_share_mods = config.get(section, 'share_mods').split(' ')
|
2022-08-10 23:53:23 +00:00
|
|
|
forge_share_modules = generate_mod_list(config_share_mods, download_url, submodules_dict, True, True, mods_files_dict)
|
2022-08-04 00:39:24 +00:00
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
config_client_mods = config.get(section, 'client_mods').split(' ')
|
2022-08-10 23:53:23 +00:00
|
|
|
forge_client_modules = generate_mod_list(config_client_mods, download_url, submodules_dict, True, True, mods_files_dict)
|
|
|
|
|
|
|
|
config_client_optional_enabled_mods = config.get(section, 'client_optional_enabled_mods').split(' ')
|
|
|
|
forge_client_optional_enabled_modules = generate_mod_list(config_client_optional_enabled_mods, download_url,
|
|
|
|
submodules_dict, False, True, mods_files_dict)
|
|
|
|
config_client_optional_disabled_mods = config.get(section, 'client_optional_disabled_mods').split(' ')
|
|
|
|
forge_client_optional_disabled_modules = generate_mod_list(config_client_optional_disabled_mods, download_url,
|
|
|
|
submodules_dict, False, False, mods_files_dict)
|
2022-08-07 15:48:40 +00:00
|
|
|
|
2022-08-10 23:53:23 +00:00
|
|
|
forge_client_optional_modules = forge_client_optional_enabled_modules + forge_client_optional_disabled_modules
|
2022-08-10 01:48:48 +00:00
|
|
|
|
2022-08-10 23:53:23 +00:00
|
|
|
temp_files = temp_files_json()
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
new_server_modules = forge_module \
|
|
|
|
+ forge_share_modules \
|
2022-08-10 23:53:23 +00:00
|
|
|
+ forge_client_modules \
|
|
|
|
+ forge_client_optional_modules \
|
|
|
|
+ temp_files
|
2022-08-04 00:39:24 +00:00
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
new_server = {'id': (config.get(section, 'id')),
|
|
|
|
'name': (config.get(section, 'name')),
|
|
|
|
'description': (config.get(section, 'description')),
|
|
|
|
'icon': (config.get(section, 'icon')),
|
|
|
|
'version': (config.get(section, 'version')),
|
|
|
|
'address': (config.get(section, 'address')),
|
|
|
|
'minecraftVersion': (config.get(section, 'minecraftVersion')),
|
|
|
|
'discord_shortId': (config.get(section, 'discord_shortId')),
|
|
|
|
'discord_largeImageText': (config.get(section, 'discord_largeImageText')),
|
|
|
|
'discord_largeImageKey': (config.get(section, 'discord_largeImageKey')),
|
|
|
|
'mainServer': (config.get(section, 'mainServer')),
|
|
|
|
'autoconnect': (config.get(section, 'autoconnect')),
|
2022-08-04 00:39:24 +00:00
|
|
|
'modules': new_server_modules
|
|
|
|
}
|
2022-08-02 03:10:24 +00:00
|
|
|
servers.append(new_server)
|
|
|
|
return servers
|
|
|
|
|
|
|
|
|
2022-08-04 00:39:24 +00:00
|
|
|
def scan_forge_folder(forge_path):
|
|
|
|
forge_jar = list_files_in_folder(forge_path)[0]
|
|
|
|
return forge_jar
|
|
|
|
|
|
|
|
|
|
|
|
def list_files_in_folder(path):
|
2022-08-02 03:10:24 +00:00
|
|
|
f = []
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
|
|
|
f.extend(filenames)
|
|
|
|
break
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
def get_name_in_dict(mod):
|
|
|
|
try:
|
|
|
|
human_mod_name = config.get('Mods Names', mod)
|
|
|
|
except:
|
|
|
|
print('Not find human name for: ' + mod)
|
|
|
|
return mod
|
|
|
|
return human_mod_name
|
|
|
|
|
|
|
|
|
|
|
|
def check_for_submodule(param):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def generate_submodules_dict():
|
|
|
|
mods_with_submodules = config.items('Mods Submodules')
|
|
|
|
submodules_dict = {}
|
|
|
|
for mod in mods_with_submodules:
|
|
|
|
for submodule in mod[1].split(' '):
|
|
|
|
submodules_dict[submodule] = mod[0]
|
|
|
|
return submodules_dict
|
|
|
|
|
|
|
|
|
2022-08-10 23:53:23 +00:00
|
|
|
def generate_mod_list(mods_config_list, download_url, submodules_dict, is_required, is_enabled, mods_files_dict):
|
2022-08-10 01:48:48 +00:00
|
|
|
# mods_file_list = list_files_in_folder(os.path.join(mods_path))
|
2022-08-07 15:48:40 +00:00
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
mod_list = []
|
2022-08-10 01:48:48 +00:00
|
|
|
for mod in mods_config_list:
|
|
|
|
# path_to_mod = os.path.join(mods_path, mod)
|
|
|
|
parsed_mod = mod.split(':')
|
2022-08-02 03:10:24 +00:00
|
|
|
new_mod = {
|
2022-08-10 01:48:48 +00:00
|
|
|
'id': mod,
|
|
|
|
'name': get_name_in_dict(parsed_mod[1]),
|
2022-08-02 03:10:24 +00:00
|
|
|
'type': 'ForgeMod',
|
2022-08-10 23:53:23 +00:00
|
|
|
'artifact': {'size': mods_files_dict[mod + '.jar'].get('size'),
|
|
|
|
'MD5': mods_files_dict[mod + '.jar'].get('MD5'),
|
2022-08-10 01:48:48 +00:00
|
|
|
'url': download_url + 'mods/' + mod + '.jar'
|
2022-08-02 03:10:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-10 01:48:48 +00:00
|
|
|
if is_required is not True:
|
2022-08-10 23:53:23 +00:00
|
|
|
new_mod['required'] = {
|
|
|
|
'value': is_required,
|
|
|
|
'def': is_enabled
|
|
|
|
}
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
mod_list.append(new_mod)
|
2022-08-10 01:48:48 +00:00
|
|
|
# try:
|
|
|
|
# master_mod = submodules_dict.get(parsed_mod[1])
|
|
|
|
# kek = list(filter(lambda master_mod_dict: master_mod_dict['name'] == master_mod, mod_list))
|
|
|
|
# pprint(kek)
|
|
|
|
# except:
|
|
|
|
# pass
|
2022-08-02 03:10:24 +00:00
|
|
|
return mod_list
|
|
|
|
|
|
|
|
|
2022-08-04 00:39:24 +00:00
|
|
|
def generate_lib_list(libs_path, download_url):
|
|
|
|
lib_list = []
|
|
|
|
return lib_list
|
|
|
|
|
|
|
|
|
2022-08-02 03:10:24 +00:00
|
|
|
def generate_json(config: ConfigParser):
|
|
|
|
new_distribution = {
|
|
|
|
'version': (config.get('Basic', 'version')),
|
|
|
|
'discord': {
|
|
|
|
'clientId': (config.get('Basic', 'version')),
|
|
|
|
'smallImageText': (config.get('Basic', 'discord_smallImageText')),
|
|
|
|
'smallImageKey': (config.get('Basic', 'dicord_smallImageKey'))
|
|
|
|
},
|
|
|
|
'java': {
|
|
|
|
'oracle': (config.get('Basic', 'java'))
|
|
|
|
},
|
|
|
|
'rss': (config.get('Basic', 'rss')),
|
|
|
|
'servers': parse_servers_config(config)
|
|
|
|
}
|
|
|
|
return new_distribution
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
temp_forge_json()
|
|
|
|
config = read_config(sys.argv[1])
|
|
|
|
distribution = generate_json(config)
|
|
|
|
|
2022-08-10 01:48:48 +00:00
|
|
|
# pprint(distribution)
|
2022-08-02 03:10:24 +00:00
|
|
|
|
|
|
|
with open('distribution.json', 'w', encoding='utf-8') as f:
|
|
|
|
json.dump(distribution, f, ensure_ascii=False, indent=4)
|