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