This commit is contained in:
Bigsk 2021-01-02 15:02:26 +08:00
parent 55bd04a382
commit 4bf71599c1
35 changed files with 74 additions and 9369 deletions

View File

@ -5,20 +5,39 @@ 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=None,LauncherVersion=None): def __init__(self,LauncherName=None,LauncherVersion=None,LauncherConfig=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.__CoreName="GMCLCore" ''':LauncherConfig The custom config you want to post in'''
self.__CoreVersion=["A0.2.0","Alpha"] CoreName="GMCLCore"
self.__LauncherName=LauncherName if(LauncherName!=None) else self.__CoreName CoreVersion=("A0.2.0","Alpha")
self.__LauncherVersion=LauncherVersion if(LauncherVersion!=None) else self.__CoreVersion LauncherName=CoreName if(LauncherName==None) else LauncherName
self.__UserAgent={'User-Agent':self.__LauncherName+'/'+self.__LauncherVersion[0]+' (('+self.__CoreName+' '+self.__CoreVersion[0]+';'+self.__CoreVersion[1]+'))'} LauncherVersion=CoreVersion if(LauncherVersion==None) else LauncherVersion
LauncherConfig={} if(LauncherConfig==None) else LauncherConfig
self.__SystemConfig={
"Core":{
"Name":CoreName,
"Version":CoreVersion,
"Header":{'User-Agent':LauncherName+'/'+LauncherVersion[0]+' (('+CoreName+' '+CoreVersion[0]+';'+CoreVersion[1]+'))'},
"Functions":{
"Log":{
"AutoPrint":False,
"ErrorOutput":False
},
"Debug":False,
"Aria":False
},
"Users":[]
},
"Launcher":{
"Name":LauncherName,
"Version":LauncherVersion,
"Config":LauncherConfig,
}
}
self.__Log=[] self.__Log=[]
self.__AuthWay="" self.__AuthWay=""
self.__AutoLogOutput=False
self.__AutoLogPrint=False
self.__AriaDownload=False
self.Log("info","Successful.","__init__") self.Log("info","Successful.","__init__")
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
#Log Functions #Log Functions
@ -29,37 +48,35 @@ class GMCLCore(object):
''':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!=""): if(Text!=""):
if(Type=="info"): if(Type=="deadly"):
self.__Log.append(("INFO",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) self.__Log.append(("DEADLY_ERROR",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text,ErrorType))
if(self.__AutoLogPrint==True): if(self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]):
print("[INFO]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs")
return ("INFO",Text) self.OutputLog('.'+self.__SystemConfig["Launcher"]["Name"]+"\\logs\\"+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+".txt")
elif(Type=="warn"):
self.__Log.append(("WARN",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text))
if(self.__AutoLogPrint==True):
print("[WARN]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text)
return ("WARN",Text)
elif(Type=="error"):
self.__Log.append(("ERROR",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text,ErrorType))
if(ErrorType=="TypeError"): if(ErrorType=="TypeError"):
raise TypeError(Text) raise TypeError(Text)
elif(ErrorType=="ValueError"): elif(ErrorType=="ValueError"):
raise ValueError(Text) raise ValueError(Text)
else: else:
raise UserWarning(Text) raise UserWarning(Text)
elif(Type=="info" or "warn" or "error"):
self.__Log.append((Type.upper(),time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text))
if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True):
print("["+Type.upper()+"]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text)
return (Type.upper(),Text)
else: else:
self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text)) self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),Function,Text))
if(self.__AutoLogPrint==True): if(self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]==True):
print("[OTHER]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text) print("[OTHER]["+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"]["+Function+"]"+Text)
return ("OTHER",Text) return ("OTHER",Text)
def OutputLog(self,Path): def OutputLog(self,Path):
'''The function which was used to output text file of program logs''' '''The function which was used to output text file of program logs'''
if(os.path.isdir(Path)): if(os.path.isdir(Path)):
return self.Log("warn","Not File.","OutputLog") return self.Log("warn","Exist duplication name dir.","OutputLog")
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[0]+" "+self.__LauncherVersion[1]+" | "+self.__CoreName+"/"+self.__CoreVersion[0]+" "+self.__CoreVersion[1]+" Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n") FileObject.write(self.__SystemConfig["Launcher"]["Name"]+"/"+self.__SystemConfig["Launcher"]["Version"][0]+" "+self.__SystemConfig["Launcher"]["Version"][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):
@ -77,12 +94,20 @@ class GMCLCore(object):
print("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3]) print("["+text[0]+"]["+text[1]+"]["+text[2]+"]"+text[3])
def EnableAutoLogPrint(self): def EnableAutoLogPrint(self):
'''The function which was used to enable the function of log auto print''' '''The function which was used to enable the function of log auto print'''
self.__AutoLogPrint=True self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=True
self.Log("info","Successful.","EnableAutoLogPrint") self.Log("info","Successful.","EnableAutoLogPrint")
def DisableAutoLogPrint(self): def DisableAutoLogPrint(self):
'''The function which was used to disable the function of log auto print''' '''The function which was used to disable the function of log auto print'''
self.__AutoLogPrint=False self.__SystemConfig["Core"]["Functions"]["Log"]["AutoPrint"]=False
self.Log("info","Successful.","DisableAutoLogPrint") self.Log("info","Successful.","DisableAutoLogPrint")
def EnableErrorLogOutput(self):
'''The function which was used to enable the function of error log output'''
self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=True
self.Log("info","Successful.","EnableErrorLogOutput")
def DisableErrorLogOutput(self):
'''The function which was used to disable the function of error log output'''
self.__SystemConfig["Core"]["Functions"]["Log"]["ErrorOutput"]=False
self.Log("info","Successful.","DisableErrorLogOutput")
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
#Download Functions #Download Functions
def Download(self,DownloadFrom,DownloadTo): def Download(self,DownloadFrom,DownloadTo):
@ -93,17 +118,17 @@ class GMCLCore(object):
self.Log("warn","Wrong online address or local address for download.","Download") self.Log("warn","Wrong online address or local address for download.","Download")
else: else:
StartTime=time.time() StartTime=time.time()
FileSize=int(requests.head(DownloadFrom,headers=self.__UserAgent).headers['Content-Length']) FileSize=int(requests.head(DownloadFrom,headers=self.__SystemConfig["Core"]["Header"]).headers['Content-Length'])
if(self.__AriaDownload==True): if(self.__SystemConfig["Core"]["Functions"]["Aria"]==True):
if(platform.system()=="Windows"): if(platform.system()=="Windows"):
if(os.path.isfile(self.__LauncherName+"\\rely\\"+"aria2c.exe")): if(os.path.isfile('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe")):
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"") os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"")
else: else:
self.Log("warn","Missed Aria.","Download") self.Log("warn","Missed Aria.","Download")
self.DownloadAriaWin() self.DownloadAriaWin()
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"") os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"")
else: else:
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"") os.system('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__SystemConfig["Core"]["Header"]['User-Agent']+"\"")
else: else:
with open(DownloadTo,"wb") as FileObject: with open(DownloadTo,"wb") as FileObject:
FileObject.write(requests.get(DownloadFrom).content) FileObject.write(requests.get(DownloadFrom).content)
@ -111,23 +136,23 @@ 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(not os.path.isdir(self.__LauncherName+"\\rely")): if(not os.path.isdir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely")):
self.MakeDir(self.__LauncherName+"\\rely") self.MakeDir('.'+self.__SystemConfig["Launcher"]["Name"]+"\\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.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject:
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__UserAgent).content) FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content)
else: else:
with open(self.__LauncherName+"\\rely\\"+"aria2c.exe","wb") as FileObject: with open('.'+self.__SystemConfig["Launcher"]["Name"]+"\\rely\\"+"aria2c.exe","wb") as FileObject:
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__UserAgent).content) FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__SystemConfig["Core"]["Header"]).content)
self.Log("info","Success.","DownloadAriaWin") self.Log("info","Success.","DownloadAriaWin")
def EnableAriaDownload(self): def EnableAria(self):
'''The function which was used to enable the function of Aria download''' '''The function which was used to enable the function of Aria'''
self.__AriaDownload=True self.__SystemConfig["Core"]["Functions"]["Aria"]=True
self.Log("info","Successful.","EnableAriaDownload") self.Log("info","Successful.","EnableAria")
def DisableAriaDownload(self): def DisableAria(self):
'''The function which was used to disable the function of Aria download''' '''The function which was used to disable the function of Aria'''
self.__AriaDownload=False self.__SystemConfig["Core"]["Functions"]["Aria"]=False
self.Log("info","Successful.","DisbleAriaDownload") self.Log("info","Successful.","DisbleAria")
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
#File and Dir Functions #File and Dir Functions
def MakeDir(self,Path): def MakeDir(self,Path):
@ -186,8 +211,8 @@ class GMCLCore(object):
''':Password Your password''' ''':Password Your password'''
if(self.__AuthWay=="online_mojang"): 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.__SystemConfig["Core"]["Header"]).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.__SystemConfig["Core"]["Header"]).text)
self.__Token=result['accessToken'] self.__Token=result['accessToken']
self.__UUID=result['selectedProfile']['id'] self.__UUID=result['selectedProfile']['id']
self.__ID=result['selectedProfile']['name'] self.__ID=result['selectedProfile']['name']

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="gmclc_w" processorArchitecture="amd64" type="win32" version="1.0.0.0"/>
<dependency>
<dependentAssembly>
<assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="gmclc_w" processorArchitecture="amd64" type="win32" version="1.0.0.0"/>
<dependency>
<dependentAssembly>
<assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

Binary file not shown.

Binary file not shown.

Binary file not shown.