Changed some functions

This commit is contained in:
Bigsk 2020-12-06 11:48:13 +08:00
parent 16db80c63a
commit f8317fd34a

View File

@ -5,13 +5,15 @@ class GMCLCore(object):
'''The Main Class of the Launcher Core'''
#-----------------------------------------------------------------------#
#Class Functions
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
def __init__(self,LauncherName=None,LauncherVersion=None):
'''The global variable set function'''
''':LauncherName The name of your launcher,the default value is "GMCLCore"'''
''':LauncherVersion The version of your launcher,the default value is the version of core'''
self.__LauncherName=LauncherName
self.__LauncherVersion=LauncherVersion
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
self.__CoreName="GMCLCore"
self.__CoreVersion=["A0.2.0","Alpha"]
self.__LauncherName=LauncherName if(LauncherName!=None) else self.__CoreName
self.__LauncherVersion=LauncherVersion if(LauncherVersion!=None) else self.__CoreVersion
self.__UserAgent={'User-Agent':self.__LauncherName+'/'+self.__LauncherVersion[0]+' (('+self.__CoreName+' '+self.__CoreVersion[0]+';'+self.__CoreVersion[1]+'))'}
self.__Log=[]
self.__AuthWay=""
self.__AutoLogOutput=False
@ -26,7 +28,7 @@ class GMCLCore(object):
''':Text The main text of log info'''
''':Function The function that cause the log,the default value is "Anonymous Function"'''
''':Type The type of the error,the default value is "TypeError",Support "TypeError","ValueError","UserWarning"'''
if(Text!="" or None):
if(Text!=""):
if(Type=="info"):
self.__Log.append(("INFO",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text))
if(self.__AutoLogPrint==True):
@ -57,7 +59,7 @@ class GMCLCore(object):
else:
self.Log("info","Successful.","OutputLog")
with open(Path,"w+") as FileObject:
FileObject.write(self.__LauncherName+"/"+self.__LauncherVersion+" Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n")
FileObject.write(self.__LauncherName+"/"+self.__LauncherVersion[0]+" "+self.__LauncherVersion[1]+" | "+self.__CoreName+"/"+self.__CoreVersion[0]+" "+self.__CoreVersion[1]+" Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n")
for text in self.__Log:
FileObject.write("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]+"\n")
def ReturnLog(self):
@ -109,7 +111,7 @@ class GMCLCore(object):
return (str(time.time()-StartTime),FileSize // (time.time()-StartTime))
def DownloadAriaWin(self):
'''The function which was used to download Aria environment for windows'''
if(os.path.isdir(self.__LauncherName+"\\rely")==False):
if(not os.path.isdir(self.__LauncherName+"\\rely")):
self.MakeDir(self.__LauncherName+"\\rely")
if(os.path.isdir("C:\\Program Files (x86)")):
with open(self.__LauncherName+"\\rely\\"+"aria2c.exe","wb") as FileObject:
@ -131,7 +133,7 @@ class GMCLCore(object):
def MakeDir(self,Path):
'''The function which was used to create a dir with determination'''
''':Path The path of the dir you want to create'''
if(os.path.isdir(Path)==False):
if(not os.path.isdir(Path)):
os.makedirs(Path)
self.Log("info","Successful.","MakeDir")
else:
@ -182,7 +184,7 @@ class GMCLCore(object):
'''The function which was used to set game account data'''
''':Account Your account,the default value is "Steve"'''
''':Password Your password'''
if(self.__AuthWay=="online"):
if(self.__AuthWay=="online_mojang"):
if(Account.count("@")==1):
if(json.loads(requests.get("https://authserver.mojang.com/",headers=self.__UserAgent).text)['status']=="OK"):
result=json.loads(requests.post("https://authserver.mojang.com/authenticate",'{"agent":{"name":"Minecraft","Version":1},"username":"'+Account+'","password":"'+Password+'"}',headers=self.__UserAgent).text)
@ -242,3 +244,6 @@ class GMCLCore(object):
#Game Resouces Functions
#-----------------------------------------------------------------------#
#Game Launch Function
l=GMCLCore()
l.EnableAutoLogPrint()
l.OutputLog("1.txt")