update __main__.py.
新增了完整的启动功能
This commit is contained in:
parent
83d1269a9c
commit
c109baadc1
497
__main__.py
497
__main__.py
@ -1,4 +1,4 @@
|
||||
import os,requests,json,time,sys,argparse,psutil
|
||||
import os,requests,json,time,sys,argparse,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
@ -6,6 +6,8 @@ import os,requests,json,time,sys,argparse,psutil
|
||||
|
||||
#Set Global Var.
|
||||
Log='[Logs Output]'
|
||||
number=0
|
||||
source=json.loads('["https://bmclapi2.bangbang93.com","https://download.mcbbs.net","https://gemcapi.ghink.net/?path=","https://download.minebbs.com/?path="]')
|
||||
#Read Config File.
|
||||
config_open=open("config.json", mode='r')
|
||||
config_json=config_open.read()
|
||||
@ -35,35 +37,42 @@ else:
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--launcher_name", help="The name of the launcher.")
|
||||
parser.add_argument("--launcher_version", help="The version of the launcher.")
|
||||
parser.add_argument("--type", help="The type of task,{\"get_game_version_list\",\"get_java_path\",\"get_system_memory\",\"get_online_source_list\",\"install_online_source\",\"download_file\"}")
|
||||
parser.add_argument("--type", help="The type of task,{\"launcher_game\",\"search_file\",\"get_game_version_list\",\"get_java_path\",\"get_system_memory\",\"get_online_source_list\",\"install_online_source\",\"get_uuid\",\"download_file\",\"clean_logs\",\"clean_temp\",\"clean\",\"clean_logs_without_output\",\"clean_without_output\"}")
|
||||
parser.add_argument("--copyright", help="The copyright of the game,true of false.")
|
||||
#Launcher Game Parameter Area.
|
||||
#Search File Area.
|
||||
parser.add_argument("--file_name", help="The name of file which you want to search.")
|
||||
parser.add_argument("--file_dir", help="The dir of file which you want to search.")
|
||||
#True Copyright.
|
||||
parser.add_argument("--email", help="The email of game account.(If your game is genuine,you have to input this parameter.)")
|
||||
parser.add_argument("--password", help="The password of game account.(If your game is genuine,you have to input this parameter.")
|
||||
#False Copyright.
|
||||
parser.add_argument("--id", help="The id of game.(If your game is not genuine,you have to input this parameter.)")
|
||||
#Get Game Version List Area.
|
||||
parser.add_argument("--game_dir", help="The dir of your game.If you not input this parameter,the GMCL Core will use the Mojang's Launcher's game dir.")
|
||||
#Get System Memory Area.
|
||||
parser.add_argument("--memory_data_type", help="The data type of memory that will return.{\"free\",\"used\",\"total\"}")
|
||||
parser.add_argument("--memory_data_type", help="The data type of memory that will return.{\"free\",\"used\",\"total\",\"auto\"}")
|
||||
parser.add_argument("--memory_data_unit", help="The data unit of memory that will return,the default unit is B.{\"MB\",\"KB\",\"GB\",\"B\",\"TB\"}")
|
||||
#Get Online Source List Area.
|
||||
parser.add_argument("--online_source_list_from", help="The from of online source list.{\"BMCLAPI\",\"GEMCAPI\",\"MOJANG\",\"MIX\"}")
|
||||
parser.add_argument("--online_source_list_type", help="The online source type of list.")
|
||||
parser.add_argument("--online_source_list_return_type", help="The return data type of return data of online source,the default is json.{\"json\"}")
|
||||
#Get Online Resources List Area.
|
||||
parser.add_argument("--online_resources_list_type", help="The online resources type of list,you have to input a json there.{\"tree_number\":int,")
|
||||
parser.add_argument("--online_resources_list_return_type", help="The return data type of return data of online resources,the default is json.{\"json\"}")
|
||||
#Install online Source Area.
|
||||
parser.add_argument("--install_online_source_from", help="The from of online source which you want to install.{\"BMCLAPI\",\"GEMCAPI\",\"MOJANG\",\"MIX\"}")
|
||||
parser.add_argument("--install_online_source_type", help="The online source type of which source you want to install,If you want to install one type with other source,you have to input a json there.")
|
||||
parser.add_argument("--install_online_source_id", help="The online source id of which source you want to install.")
|
||||
parser.add_argument("--install_online_source_dir", help="The game dir which you want to install to.")
|
||||
#Download Source Area.
|
||||
parser.add_argument("--download_url", help="The file url of source which you want download.If you want to download multi files,you have to input json like:{\"number\":10,\"url\":[\"example1.com\",\"example2.com\"]} and {\"number\":10,\"path\":[\"\\usr\\root\\home\\Desktop\\1\",\"\\usr\\root\\home\\Desktop\\2\"]}")
|
||||
parser.add_argument("--download_path", help="The save path of source which you want download.")
|
||||
parser.add_argument("--install_online_resources_type", help="The online resources type of which resources you want to install,you have to input a json there.")
|
||||
parser.add_argument("--install_online_resources_id", help="The online resources id of which resources you want to install.")
|
||||
parser.add_argument("--install_online_resources_dir", help="The game dir which you want to install to.")
|
||||
#Download Resources Area.
|
||||
parser.add_argument("--download_url", help="The file url of resources which you want download.If you want to download multi files,you have to input json like:{\"number\":10,\"url\":[\"example1.com\",\"example2.com\"]} and {\"number\":10,\"path\":[\"\\usr\\root\\home\\Desktop\\1\",\"\\usr\\root\\home\\Desktop\\2\"]}")
|
||||
parser.add_argument("--download_path", help="The save path of resources which you want download.")
|
||||
#Get System Java Path Area.
|
||||
parser.add_argument("--number_of_java", help="How many java path(s) you want to return.Do not set the number too big,it will cost a lot of time and system performance.")
|
||||
#Global Parameter Area.
|
||||
parser.add_argument("--memory", help="The memory that could be used by game.You should input with unit.")
|
||||
parser.add_argument("--source", help="The source of online resources.If you want to use mix mode,you have to input a json like:{\"mode\":\"mix\",\"source\":{\"number\":number,\"source\":[\"source_1\",\"source_2\"]}}or not input anything.{\"bmclapi\",\"gemcapi\",\"minebbs\",\"mojang\",\"mix\"}")
|
||||
parser.add_argument("--memory", help="The memory that could be used by game.You should input with unit,if you send a null parameter,the core will get java path automatically.")
|
||||
parser.add_argument("--java", help="The java path of the system,if you send a null parameter,the core will get java path automatically.")
|
||||
parser.add_argument("--parameter", help="The excess parameter that launcher game need.")
|
||||
parser.add_argument("--dir", help="The game dir.")
|
||||
parser.add_argument("--dir", help="The game dir,if you send a null parameter,the core will use Mojang's Launcher's game dir.")
|
||||
parser.add_argument("--version", help="The game version.")
|
||||
parser.add_argument("--uuid", help="Your UUID,you can input your UUID by your self,this parameter isn't must,the core will generate one automatically.There's two mode you can use to generate UUID.The default mode is gmclc.If you want to use other mode,for example:hmcl mode,just input \"hmcl\" there.{\"hmcl\",\"gmclc\"}")
|
||||
parser=parser.parse_args()
|
||||
#Set Parameter into Var.
|
||||
if(parser.launcher_name==None):
|
||||
@ -74,6 +83,18 @@ if(parser.launcher_version==None):
|
||||
launcher_version=config['version']
|
||||
else:
|
||||
launcher_version=parser.launcher_version
|
||||
if(parser.number_of_java==None):
|
||||
number_of_java=1
|
||||
else:
|
||||
try:
|
||||
number_of_java=int(parser.number_of_java)
|
||||
except:
|
||||
number_of_java=""
|
||||
if(parser.game_dir==None):
|
||||
game_dir='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft'
|
||||
else:
|
||||
game_dir=parser.game_dir
|
||||
|
||||
#Set Config Into Var.
|
||||
UA={'User-Agent':launcher_name + '/' + launcher_version + config['useragent']}
|
||||
name=config['name']
|
||||
@ -93,25 +114,39 @@ def log(log_type,logvar):
|
||||
elif(log_type=="error"):
|
||||
log_type="ERROR"
|
||||
Log=Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar
|
||||
def return_data(return_d):
|
||||
if(config['return_mode']=='directly'):
|
||||
print(return_d)
|
||||
elif(config['return_mode']=='json'):
|
||||
if(check_json(return_d)):
|
||||
print('{"return":' + return_d + ',"logs":"' + Log.replace('\n','\\n') + '"}')
|
||||
else:
|
||||
print('{"return":"' + return_d + '","logs":"' + Log.replace('\n','\\n') + '"}')
|
||||
def launcher_true(email,password,memory,java,parameter,dir,version):
|
||||
null=""
|
||||
pass
|
||||
def launcher_false(id,memory,java,parameter,dir,version):
|
||||
null=""
|
||||
def download_source(type,assembly,version):
|
||||
null=""
|
||||
pass
|
||||
def download_resources(type,assembly,version):
|
||||
pass
|
||||
def check_json(input_str):
|
||||
try:
|
||||
json.loads(input_str)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
def download(url, dirpath):
|
||||
global Log
|
||||
global UA
|
||||
global name
|
||||
log("info",'The ' + name + ' is downloading the file ' + filepath + '.')
|
||||
log("info",'The ' + name + ' is downloading the file ' + dirpath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UA)
|
||||
with open(filepath,"wb") as code:
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
log("error",'There has a error in task while downloading the file ' + filepath + '.')
|
||||
log("error",'There has a error in task while downloading the file ' + dirpath + ' from ' + url + '.')
|
||||
else:
|
||||
log("info",'The file ' + filepath + ' has been downloaded successfully.')
|
||||
log("info",'The file ' + dirpath + ' has been downloaded successfully.')
|
||||
def make_dir_exist(dirpath):
|
||||
global Log
|
||||
global name
|
||||
@ -127,6 +162,8 @@ def memory(return_type):
|
||||
return psutil.virtual_memory().used
|
||||
elif(return_type=="total"):
|
||||
return psutil.virtual_memory().total
|
||||
elif(return_type=="auto"):
|
||||
return 0.8 * psutil.virtual_memory().free
|
||||
def error_output_log(logpath):
|
||||
global Log
|
||||
global logs_head
|
||||
@ -135,9 +172,116 @@ def error_output_log(logpath):
|
||||
logs_output.close()
|
||||
def deadly_error():
|
||||
log("warn","There is a deadly error,the program will stop soon.")
|
||||
make_dir_exist(config['logs_path'])
|
||||
error_output_log(config['logs_path'])
|
||||
make_dir_exist('logs')
|
||||
error_output_log('logs')
|
||||
sys.exit(0)
|
||||
def search_java_windows_temp(path,tagfile):
|
||||
global number
|
||||
for ipath in os.listdir(path):
|
||||
fulldir = os.path.join(path,ipath)
|
||||
if(os.path.isfile(fulldir)):
|
||||
if(tagfile in os.path.split(fulldir)[1]):
|
||||
print(fulldir)
|
||||
number=number+1
|
||||
if(os.path.isdir(fulldir)):
|
||||
try:
|
||||
search_java_windows_temp(fulldir,tagfile)
|
||||
except:
|
||||
pass
|
||||
if(parser.number_of_java=="all"):
|
||||
pass
|
||||
elif(number==number_of_java):
|
||||
break
|
||||
def search_files(path,tagfile):
|
||||
global number
|
||||
for ipath in os.listdir(path):
|
||||
fulldir = os.path.join(path,ipath)
|
||||
if(os.path.isfile(fulldir)):
|
||||
if(tagfile in os.path.split(fulldir)[1]):
|
||||
print(fulldir)
|
||||
number=number+1
|
||||
if(os.path.isdir(fulldir)):
|
||||
try:
|
||||
search_files(fulldir,tagfile)
|
||||
except:
|
||||
pass
|
||||
def get_uuid(id,g_type):
|
||||
if(g_type=='hmcl'):
|
||||
return_i='OfflinePlayer:' + id
|
||||
md5=hashlib.md5()
|
||||
md5.update(return_i.encode(encoding='utf-8'))
|
||||
return md5.hexdigest()
|
||||
elif(g_type=='gmclc'):
|
||||
result=id
|
||||
for i in range(0,len(id)):
|
||||
md5=hashlib.md5()
|
||||
md5.update(result.encode(encoding='utf-8'))
|
||||
result=md5.hexdigest()
|
||||
return result
|
||||
def make_file_exist(file,url):
|
||||
if(parser.source==None):
|
||||
num=random.randint(0,3)
|
||||
domain=source[num]
|
||||
if(num==0):
|
||||
source_type=0
|
||||
elif(num==1):
|
||||
source_type=0
|
||||
elif(num==2):
|
||||
source_type=1
|
||||
elif(num==3):
|
||||
source_type=1
|
||||
elif(parser.source=='mix'):
|
||||
num=random.randint(0,3)
|
||||
domain=source[num]
|
||||
if(num==0):
|
||||
source_type=0
|
||||
elif(num==1):
|
||||
source_type=0
|
||||
elif(num==2):
|
||||
source_type=1
|
||||
elif(num==3):
|
||||
source_type=1
|
||||
elif(parser.source=='bmclapi'):
|
||||
domain=source[0]
|
||||
source_type=0
|
||||
elif(parser.source=='mcbbs'):
|
||||
domain=source[1]
|
||||
source_type=0
|
||||
elif(parser.source=='gemcapi'):
|
||||
domain=source[2]
|
||||
source_type=1
|
||||
elif(parser.source=='minebbs'):
|
||||
domain=source[3]
|
||||
source_type=1
|
||||
elif(parser.source=='mojang'):
|
||||
source_type=2
|
||||
try:
|
||||
f=open(file)
|
||||
f.close()
|
||||
except:
|
||||
if(source_type==2):
|
||||
os.system("python __main__.py --type download_file --download_url " + url + " --download_path " + file)
|
||||
return_data('Downloading ' + url + ' to ' + file + '.')
|
||||
elif(source_type==0):
|
||||
url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries')
|
||||
os.system("python __main__.py --type download_file --download_url " + url + " --download_path " + file)
|
||||
return_data('Downloading ' + url + ' to ' + file + '.')
|
||||
elif(source_type==1):
|
||||
url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries')
|
||||
os.system("python __main__.py --type download_file --download_url " + url + " --download_path " + file)
|
||||
return_data('Downloading ' + url + ' to ' + file + '.')
|
||||
def unzip(src,dir):
|
||||
uz=zipfile.ZipFile(src,'r')
|
||||
for file in uz.namelist():
|
||||
try:
|
||||
uz.extract(file,dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
#Make Dir Area.
|
||||
make_dir_exist("temp")
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
@ -154,16 +298,16 @@ if(parser.type=="download_file"):
|
||||
try:
|
||||
download(urljson['url'][count],pathjson['path'][count])
|
||||
except:
|
||||
log("error""Some errors happened while downloading files,please check and try again.")
|
||||
log("error","Some errors happened while downloading files,please check and try again.")
|
||||
count=count+1
|
||||
else:
|
||||
log("error","The file(s) number is not same!We can't download the file(s).")
|
||||
deadly_error()
|
||||
except:
|
||||
try:
|
||||
download(urljson['url'][count],pathjson['path'][count])
|
||||
download(parser.download_url,parser.download_path)
|
||||
except:
|
||||
log("error""Some errors happened while downloading files,please check and try again.")
|
||||
log("error","Some errors happened while downloading files,please check and try again.")
|
||||
deadly_error()
|
||||
except:
|
||||
log("error","Some errors happened.We can't download the file(s),please check if the parameter you input is correct.")
|
||||
@ -177,40 +321,317 @@ elif(parser.type=="get_system_memory"):
|
||||
memory_data=memory("used")
|
||||
elif(parser.memory_data_type=="total"):
|
||||
memory_data=memory("total")
|
||||
elif(parser.memory_data_type=="auto"):
|
||||
memory_data=memory("auto")
|
||||
else:
|
||||
log("error","We can't get the memory data,please check if the parameter you input is coreect.")
|
||||
deadly_error()
|
||||
if(parser.memory_data_unit==None):
|
||||
print(memory_data)
|
||||
log("info","Return:" + str(memory_data) + '.')
|
||||
return_data(str(memory_data))
|
||||
elif(parser.memory_data_unit=="B"):
|
||||
print(memory_data)
|
||||
log("info","Return:" + str(memory_data) + '.')
|
||||
return_data(str(memory_data))
|
||||
elif(parser.memory_data_unit=="KB"):
|
||||
print(memory_data / 1024)
|
||||
log("info","Return:" + str(memory_data / 1024) + '.')
|
||||
return_data(str(memory_data / 1024))
|
||||
elif(parser.memory_data_unit=="MB"):
|
||||
print(memory_data / 1024 / 1024)
|
||||
log("info","Return:" + str(memory_data / 1024 / 1024) + '.')
|
||||
return_data(str(memory_data / 1024 / 1024))
|
||||
elif(parser.memory_data_unit=="GB"):
|
||||
print(memory_data / 1024 / 1024 / 1024)
|
||||
log("info","Return:" + str(memory_data / 1024 / 1024 / 1024) + '.')
|
||||
return_data(str(memory_data / 1024 / 1024 / 1024))
|
||||
elif(parser.memory_data_unit=="TB"):
|
||||
print(memory_data / 1024 / 1024 / 1024 / 1024)
|
||||
log("info","Return:" + str(memory_data / 1024 / 1024 / 1024 / 1024) + '.')
|
||||
return_data(str(memory_data / 1024 / 1024 / 1024 / 1024))
|
||||
except:
|
||||
log("error","Some errors happened.We can't get the memory data,please check if the parameter you input is correct.")
|
||||
deadly_error()
|
||||
elif(parser.type=="search_file"):
|
||||
log("info","Search file mode.")
|
||||
if(parser.file_name==None):
|
||||
log("error","There has a error while search file,you can't let the parameter \"file_name\" be \"None\",please check is the parameter input correct.")
|
||||
else:
|
||||
search_files(parser.file_dir,parser.file_name)
|
||||
elif(parser.type=="get_uuid"):
|
||||
log("info","Get UUID mode.")
|
||||
if(parser.id==None):
|
||||
return_data('There has a error in parameters you input,please check if the parameter "id" is correct.')
|
||||
log('error','There has a error in parameters you input,please check if the parameter "id" is correct.')
|
||||
deadly_error()
|
||||
else:
|
||||
if(parser.uuid==None):
|
||||
uuid=get_uuid(parser.id,'gmclc')
|
||||
elif(parser.uuid=='gmclc'):
|
||||
uuid=get_uuid(parser.id,'gmclc')
|
||||
elif(parser.uuid=='hmcl'):
|
||||
uuid=get_uuid(parser.id,'hmcl')
|
||||
else:
|
||||
return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
||||
log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
||||
deadly_error()
|
||||
print(uuid)
|
||||
elif(parser.type=="get_java_path"):
|
||||
log("info","Get system java environment path mode.")
|
||||
if(platform.system()=='Windows'):
|
||||
return_info=os.popen('python __main__.py --type temp_1 --number_of_java ' + str(number_of_java))
|
||||
return_i=return_info.read()
|
||||
return_info.close()
|
||||
with open('temp/temp-3.gmclc', 'w') as file_object:
|
||||
file_object.write(return_i)
|
||||
number=0
|
||||
count = len(open('temp/temp-3.gmclc', 'r').readlines())
|
||||
for line in open("temp/temp-3.gmclc"):
|
||||
number=number+1
|
||||
with open('temp/temp-4.gmclc', 'a') as file_object:
|
||||
if(number==count):
|
||||
if(count==1):
|
||||
file_object.write(line.replace("\n",""))
|
||||
else:
|
||||
file_object.write(line.replace("\n","") + '"]')
|
||||
elif(number==1):
|
||||
file_object.write('["' + line.replace("\n","") + '","')
|
||||
else:
|
||||
file_object.write(line.replace("\n","") + '","')
|
||||
return_data(open("temp/temp-4.gmclc",'r').read())
|
||||
os.remove('temp/temp-3.gmclc')
|
||||
os.remove('temp/temp-4.gmclc')
|
||||
else:
|
||||
return_data('java')
|
||||
elif(parser.type=="get_game_version_list"):
|
||||
log("info","Get game versions list mode.")
|
||||
if(platform.system()=='Windows'):
|
||||
return_info=os.popen('python __main__.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"')
|
||||
return_i=return_info.read()
|
||||
return_info.close()
|
||||
with open('temp/temp-1.gmclc', 'w') as file_object:
|
||||
file_object.write(return_i)
|
||||
number=0
|
||||
count = len(open('temp/temp-1.gmclc', 'r').readlines())
|
||||
for line in open("temp/temp-1.gmclc"):
|
||||
number=number+1
|
||||
with open('temp/temp-2.gmclc', 'a') as file_object:
|
||||
if(number==count):
|
||||
if(count==1):
|
||||
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n',''))
|
||||
else:
|
||||
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]')
|
||||
elif(number==1):
|
||||
file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
||||
else:
|
||||
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
||||
return_data(open("temp/temp-2.gmclc",'r').read())
|
||||
os.remove('temp/temp-1.gmclc')
|
||||
os.remove('temp/temp-2.gmclc')
|
||||
else:
|
||||
if(parser.game_dir==None):
|
||||
log('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
||||
else:
|
||||
return_info=os.popen('python __main__.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"')
|
||||
return_i=return_info.read()
|
||||
return_info.close()
|
||||
with open('temp/temp-1.gmclc', 'w') as file_object:
|
||||
file_object.write(return_i)
|
||||
number=0
|
||||
count = len(open('temp/temp-1.gmclc', 'r').readlines())
|
||||
for line in open("temp/temp-1.gmclc"):
|
||||
number=number+1
|
||||
with open('temp/temp-2.gmclc', 'a+') as file_object:
|
||||
if(number==count):
|
||||
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]')
|
||||
elif(number==1):
|
||||
file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
||||
else:
|
||||
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
||||
return_data(open("temp/temp-2.gmclc",'r').read())
|
||||
os.remove('temp/temp-1.gmclc')
|
||||
os.remove('temp/temp-2.gmclc')
|
||||
elif(parser.type=="clean_logs"):
|
||||
log("info","Clean logs mode.")
|
||||
log("info","Cleaning logs......")
|
||||
try:
|
||||
shutil.rmtree("logs")
|
||||
except:
|
||||
log("error","Cleaning logs error.")
|
||||
elif(parser.type=="clean_temp"):
|
||||
log("info","Clean temp mode.")
|
||||
log("info","Cleaning temp......")
|
||||
try:
|
||||
shutil.rmtree("temp")
|
||||
except:
|
||||
log("error","Cleaning temp error.")
|
||||
elif(parser.type=="clean"):
|
||||
log("info","Clean file mode.")
|
||||
log("info","Cleaning file......")
|
||||
try:
|
||||
shutil.rmtree("logs")
|
||||
except:
|
||||
log("error","Cleaning logs error.")
|
||||
try:
|
||||
shutil.rmtree("temp")
|
||||
except:
|
||||
log("error","Cleaning temp error.")
|
||||
elif(parser.type=="clean_without_output"):
|
||||
log("info","Clean file mode.")
|
||||
log("info","Cleaning file......")
|
||||
try:
|
||||
shutil.rmtree("logs")
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
shutil.rmtree("temp")
|
||||
except:
|
||||
pass
|
||||
sys.exit(0)
|
||||
elif(parser.type=="clean_logs_without_output"):
|
||||
log("info","Clean logs mode.")
|
||||
log("info","Cleaning logs......")
|
||||
try:
|
||||
shutil.rmtree("logs")
|
||||
except:
|
||||
pass
|
||||
sys.exit(0)
|
||||
elif(parser.type=="launcher_game"):
|
||||
log("info","Launcher game mode.")
|
||||
return_data('Checking game dir.')
|
||||
log('info','Checking game dir.')
|
||||
if(parser.dir==None):
|
||||
if(platform.system()=='Windows'):
|
||||
dir_i='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft'
|
||||
else:
|
||||
return_data('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
||||
log('error','Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
||||
deadly_error()
|
||||
else:
|
||||
dir_i=parser.dir
|
||||
return_data('Checking player id.')
|
||||
log('info','Checking player id.')
|
||||
if(parser.id==None):
|
||||
return_data('There has a error in parameters you input,please check if the parameter "id" is correct.')
|
||||
log('error','There has a error in parameters you input,please check if the parameter "id" is correct.')
|
||||
deadly_error()
|
||||
else:
|
||||
return_data('Checking player uuid.')
|
||||
log('info','Checking player uuid.')
|
||||
if(parser.uuid==None):
|
||||
uuid=get_uuid(parser.id,'gmclc')
|
||||
elif(parser.uuid=='gmclc'):
|
||||
uuid=get_uuid(parser.id,'gmclc')
|
||||
elif(parser.uuid=='hmcl'):
|
||||
uuid=get_uuid(parser.id,'hmcl')
|
||||
elif(len(parser.uuid)==32):
|
||||
uuid=parser.uuid
|
||||
else:
|
||||
return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
||||
log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
||||
deadly_error()
|
||||
return_data('Checking game version(s).')
|
||||
log('info','Checking game version(s).')
|
||||
if(parser.version==None):
|
||||
return_data('There has a error in parameters you input,please check if the parameter "version" is correct.')
|
||||
log('error','There has a error in parameters you input,please check if the parameter "version" is correct.')
|
||||
deadly_error()
|
||||
else:
|
||||
return_info=os.popen('python __main__.py --type get_game_version_list --game_dir "' + dir_i)
|
||||
return_i=return_info.read()
|
||||
if(return_i.count('"' + parser.version + '"')!=0):
|
||||
game_config_open=open(dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.json')
|
||||
game_config_json=game_config_open.read()
|
||||
game_config_open.close()
|
||||
game_config=json.loads(game_config_json)
|
||||
return_data('Checking game files.')
|
||||
log('info','Checking game files.')
|
||||
number=0
|
||||
for i in range(0,game_config_json.count('"path"')):
|
||||
try:
|
||||
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['artifact']['url'])
|
||||
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['javadoc']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['javadoc']['url'])
|
||||
if(platform.system()=='Windows'):
|
||||
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['url'])
|
||||
elif(platform.system()=='Linux'):
|
||||
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['url'])
|
||||
else:
|
||||
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['url'])
|
||||
except:
|
||||
pass
|
||||
number=number+1
|
||||
if(os.path.isdir(dir_i + '\\versions\\' + parser.version + '\\natives')):
|
||||
pass
|
||||
else:
|
||||
make_dir_exist(dir_i + '\\versions\\' + parser.version + '\\natives')
|
||||
number=0
|
||||
for i in range(0,game_config_json.count('"path"')):
|
||||
if(platform.system()=='Windows'):
|
||||
try:
|
||||
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
||||
except:
|
||||
pass
|
||||
elif(platform.system()=='Linux'):
|
||||
try:
|
||||
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
||||
except:
|
||||
pass
|
||||
number=number+1
|
||||
cp=""
|
||||
number=0
|
||||
for i in range(0,game_config_json.count('"path"')):
|
||||
try:
|
||||
cp=cp + dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';'
|
||||
except:
|
||||
pass
|
||||
number=number+1
|
||||
cp=cp + dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.jar'
|
||||
return_data('Checking java environment.')
|
||||
log('info','Checking java environment.')
|
||||
if(parser.java==None):
|
||||
return_info=os.popen('python __main__.py --type get_java_path')
|
||||
java=return_info.read()
|
||||
return_info.close()
|
||||
elif(os.path.exists(parser.java)):
|
||||
java=parser.java
|
||||
else:
|
||||
return_data('The java program you input is not exist!Please check if the parameter you input is correct!')
|
||||
log('error','The java program you input is not exist!Please check if the parameter you input is correct!')
|
||||
deadly_error()
|
||||
return_data('Checking memory parameter.')
|
||||
log('info','Checking memory parameter.')
|
||||
if(parser.memory==None):
|
||||
return_info=os.popen('python __main__.py --type get_system_memory --memory_data_type auto --memory_data_unit MB')
|
||||
memory=str(math.ceil(float(return_info.read().replace("\n","")))) + "m"
|
||||
return_info.close()
|
||||
else:
|
||||
memory=parser.memory
|
||||
asset_index=game_config['assetIndex']['id']
|
||||
#
|
||||
command='\"' + java.replace('\n','') + '\" -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn128m -Xmx' + memory + ' -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Djava.library.path=' + dir_i + '\\versions\\' + parser.version + '\\natives -Dminecraft.launcher.brand=' + config['default_launcher_name'] + ' -Dminecraft.launcher.version=' + config['version'] + ' -cp ' + cp + ' net.minecraft.client.main.Main --username ' + parser.id + ' --version "' + config['default_launcher_name'] + ' ' + config['version'] + '" --gameDir ' + dir_i + ' --assetsDir ' + dir_i + '\\assets --assetIndex ' + asset_index + ' --uuid ' + uuid + ' --accessToken ' + uuid + ' --userProperties {} --userType mojang'
|
||||
subprocess.Popen(command, shell=True)
|
||||
else:
|
||||
return_data('The ersion you input is not exist!Please check if the parameter you input is correct!')
|
||||
log('error','The vversion you input is not exist!Please check if the parameter you input is correct!')
|
||||
deadly_error()
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
#Make Dir Area.
|
||||
make_dir_exist("logs")
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
#Temp Mode Area.
|
||||
elif(parser.type=="temp_1"):#Get java mode temp
|
||||
search_java_windows_temp('C:\\Program Files\\Java\\','javaw.exe')
|
||||
|
||||
#-------------------------------------------------------#
|
||||
|
||||
#Starting To Save Logs.
|
||||
log("info",'Starting to save logs.')
|
||||
logs_output=open(config['logs_path'] + '/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
try:
|
||||
make_dir_exist("logs")
|
||||
except:
|
||||
pass
|
||||
logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The task has done successfully.')
|
||||
logs_output.close()
|
||||
|
Reference in New Issue
Block a user