Fixed many bugs and improved 'SearchFile' function :)
This commit is contained in:
parent
97ad20fc72
commit
6fed8ed75e
109
main.py
109
main.py
@ -3,20 +3,19 @@ import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hash
|
|||||||
#------------------#
|
#------------------#
|
||||||
|
|
||||||
class MultiThreadDownload(threading.Thread):
|
class MultiThreadDownload(threading.Thread):
|
||||||
'''class for Multi-Thread Download'''
|
'''The Class for Multi-Thread Download'''
|
||||||
|
'''Get from Internet and improved by Ghink Network Studio'''
|
||||||
def __init__(self,url,startpos,endpos,f):
|
def __init__(self,url,startpos,endpos,f):
|
||||||
super(MultiThreadDownload,self).__init__()
|
super(MultiThreadDownload,self).__init__()
|
||||||
self.url = url
|
self.url = url
|
||||||
self.startpos = startpos
|
self.startpos = startpos
|
||||||
self.endpos = endpos
|
self.endpos = endpos
|
||||||
self.fd = f
|
self.fd = f
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
headers = {"Range":"bytes=%s-%s"%(self.startpos,self.endpos)}
|
headers = {"Range":"bytes=%s-%s"%(self.startpos,self.endpos)}
|
||||||
res = requests.get(self.url,headers=headers)
|
res = requests.get(self.url,headers=headers)
|
||||||
self.fd.seek(self.startpos)
|
self.fd.seek(self.startpos)
|
||||||
self.fd.write(res.content)
|
self.fd.write(res.content)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.download()
|
self.download()
|
||||||
|
|
||||||
@ -27,30 +26,31 @@ class GMCLCore(object):
|
|||||||
self.__Version=Version
|
self.__Version=Version
|
||||||
'''
|
'''
|
||||||
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
|
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
|
||||||
|
'''The global variable set function'''
|
||||||
|
''':LauncherName The name of your launcher,default value is "GMCLCore".'''
|
||||||
|
''':LauncherVersion The version of your launcher,default value is the version of core.'''
|
||||||
self.__LauncherName=LauncherName
|
self.__LauncherName=LauncherName
|
||||||
self.__LauncherVersion=LauncherVersion
|
self.__LauncherVersion=LauncherVersion
|
||||||
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
||||||
def GetAuthWay(self,AuthWay):
|
def SearchFile(self,Path,Tag,Num=1):
|
||||||
if(AuthWay=="offline"):
|
'''The function which was used to search files'''
|
||||||
self.__AuthWay="offline"
|
''':Path The root path you want to search'''
|
||||||
elif(AuthWay=="online"):
|
''':Tag The name keyword of the file you want to search'''
|
||||||
self.__AuthWay="online"
|
''':Num How much result you want to get,you should set as "all" if you want to return all result,the default value is 1'''
|
||||||
else:
|
List=[]
|
||||||
return "Error:Wrong Auth Way."
|
i=0
|
||||||
def GetAccount(self,Account="Steve"):
|
for root,dirs,files in os.walk(Path,topdown=True):
|
||||||
if(self.__AuthWay=="online"):
|
if Tag in files:
|
||||||
if(Account.count("@")==1):
|
i+=1
|
||||||
self.OnlineAuth(Account,self._Password)
|
List.append(root+'\\'+Tag)
|
||||||
|
if(i==Num):
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
return "Error:Wrong Account."
|
pass
|
||||||
elif(self.__AuthWay=="offline"):
|
return List
|
||||||
if(Account.count("@")==1):
|
|
||||||
return "Error:Wrong Account."
|
|
||||||
else:
|
|
||||||
self.OfflineAuth(Account)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
def GetUUID(self,Account="Steve"):
|
def GetUUID(self,Account="Steve"):
|
||||||
|
'''The function which was used to generate UUID'''
|
||||||
|
''':Account Your account,the default value is "Steve"'''
|
||||||
if(self.__AuthWay=="offline"):
|
if(self.__AuthWay=="offline"):
|
||||||
result="OfflinePlayer:"+Account
|
result="OfflinePlayer:"+Account
|
||||||
md5=hashlib.md5()
|
md5=hashlib.md5()
|
||||||
@ -58,34 +58,48 @@ class GMCLCore(object):
|
|||||||
return md5.hexdigest()
|
return md5.hexdigest()
|
||||||
else:
|
else:
|
||||||
return "Error:Wrong Auth Way."
|
return "Error:Wrong Auth Way."
|
||||||
def OnlineAuth(self,Account,Password):
|
|
||||||
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)
|
|
||||||
self.__Token=result['accessToken']
|
|
||||||
self.__UUID=result['selectedProfile']['id']
|
|
||||||
self.__ID=result['selectedProfile']['name']
|
|
||||||
else:
|
|
||||||
return "Error:Fail to request Mojang\'s Auth Server."
|
|
||||||
def OfflineAuth(self,Account="Steve"):
|
|
||||||
self.__ID=Account
|
|
||||||
self.__UUID=self.GetUUID(Account)
|
|
||||||
self.__Token=""
|
|
||||||
def GetJavaPath(self,Num=1):
|
def GetJavaPath(self,Num=1):
|
||||||
|
'''The function which was used to search java'''
|
||||||
|
''':Num How much result you want to get,you should set as "all" if you want to return all result,the default value is 1'''
|
||||||
if(platform.system()=="Windows"):
|
if(platform.system()=="Windows"):
|
||||||
path="C:/"
|
return self.SearchFile('C:\\','javaw.exe',Num)
|
||||||
elif(platform.system()=="Linux"):
|
elif(platform.system()=="Linux"):
|
||||||
path="/"
|
return self.SearchFile('\\','java',Num)
|
||||||
else:
|
else:
|
||||||
path="/"
|
return self.SearchFile('\\','java',Num)
|
||||||
i=0
|
def SetAccount(self,Account="Steve",Password=""):
|
||||||
for ipath in os.listdir(Path):
|
'''The function which was used to set game account data'''
|
||||||
FullDir=os.path.join(path,ipath)
|
''':Account Your account,the default value is "Steve"'''
|
||||||
if(os.path.isfile(FullDir)):
|
''':Password Your password'''
|
||||||
if("javaw.exe" in os.path.split(FullDir)[1]):
|
if(self.__AuthWay=="online"):
|
||||||
return FullDir
|
if(Account.count("@")==1):
|
||||||
i+=1
|
if(json.loads(requests.get("https://authserver.mojang.com/",headers=self.__UserAgent).text)['status']=="OK"):
|
||||||
if(i==Num):
|
result=json.loads(requests.post("https://authserver.mojang.com/authenticate",'{"agent":{"name":"Minecraft","Version":1},"username":"'+Account+'","password":"'+Password+'"}',headers=self.__UserAgent).text)
|
||||||
break
|
self.__Token=result['accessToken']
|
||||||
|
self.__UUID=result['selectedProfile']['id']
|
||||||
|
self.__ID=result['selectedProfile']['name']
|
||||||
|
else:
|
||||||
|
return "Error:Fail to request Mojang\'s Auth Server."
|
||||||
|
else:
|
||||||
|
return "Error:Wrong Account."
|
||||||
|
elif(self.__AuthWay=="offline"):
|
||||||
|
if(Account.count("@")==1):
|
||||||
|
return "Error:Wrong Account."
|
||||||
|
else:
|
||||||
|
self.__ID=Account
|
||||||
|
self.__UUID=self.GetUUID(Account)
|
||||||
|
self.__Token=""
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
def SetAuthWay(self,AuthWay):
|
||||||
|
'''The auth way set function'''
|
||||||
|
''':AuthWay Your auth way,must be "offline" or "online"'''
|
||||||
|
if(AuthWay=="offline"):
|
||||||
|
self.__AuthWay="offline"
|
||||||
|
elif(AuthWay=="online"):
|
||||||
|
self.__AuthWay="online"
|
||||||
|
else:
|
||||||
|
return "Error:Wrong Auth Way."
|
||||||
def SetRecomMem(self):
|
def SetRecomMem(self):
|
||||||
if(platform.system()=="Windows"):
|
if(platform.system()=="Windows"):
|
||||||
path="C:/"
|
path="C:/"
|
||||||
@ -149,3 +163,6 @@ class GMCLCore(object):
|
|||||||
|
|
||||||
for i in mtd_list:
|
for i in mtd_list:
|
||||||
i.join()
|
i.join()
|
||||||
|
|
||||||
|
launcher=GMCLCore()
|
||||||
|
print(launcher.GetJavaPath(2))
|
Reference in New Issue
Block a user