Update Some Modules
This commit is contained in:
parent
1a7ed4243a
commit
15c072a4f4
142
command.py
142
command.py
@ -2,144 +2,4 @@
|
|||||||
import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading
|
import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading
|
||||||
#------------------#
|
#------------------#
|
||||||
|
|
||||||
class MultiThreadDownload(threading.Thread):
|
print(float(psutil.virtual_memory().free / 1024 ** 3) * 0.8)
|
||||||
'''class for Multi-Thread Download'''
|
|
||||||
def __init__(self,url,startpos,endpos,f):
|
|
||||||
super(MultiThreadDownload,self).__init__()
|
|
||||||
self.url = url
|
|
||||||
self.startpos = startpos
|
|
||||||
self.endpos = endpos
|
|
||||||
self.fd = f
|
|
||||||
|
|
||||||
def download(self):
|
|
||||||
headers = {"Range":"bytes=%s-%s"%(self.startpos,self.endpos)}
|
|
||||||
res = requests.get(self.url,headers=headers)
|
|
||||||
self.fd.seek(self.startpos)
|
|
||||||
self.fd.write(res.content)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
self.download()
|
|
||||||
|
|
||||||
class GMCLCore(object):
|
|
||||||
'''The Main Class of the Launcher Core'''
|
|
||||||
'''AuthWay="offline",Account="Steve",Password="",GamePath=".minecraft",Memory="1GB",Version="",Java=""'''
|
|
||||||
'''
|
|
||||||
self.GetAuthWay(AuthWay)
|
|
||||||
self.GetAccoutn(Account)
|
|
||||||
self.__Password=Password
|
|
||||||
self.__GamePath=GamePath
|
|
||||||
self.GetMemory(Memory)
|
|
||||||
self.__Version=Version
|
|
||||||
self.__Java=Java
|
|
||||||
'''
|
|
||||||
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
|
|
||||||
self.__LauncherName=LauncherName
|
|
||||||
self.__LauncherVersion=LauncherVersion
|
|
||||||
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
|
||||||
def GetAuthWay(self,AuthWay):
|
|
||||||
if(AuthWay=="offline"):
|
|
||||||
self.__AuthWay="offline"
|
|
||||||
elif(AuthWay=="online"):
|
|
||||||
self.__AuthWay="online"
|
|
||||||
else:
|
|
||||||
return "Error:Wrong Auth Way."
|
|
||||||
def GetMemory(self,Memory):
|
|
||||||
if(Memory.count("B")>1 or Memory.count("b")>1):
|
|
||||||
return "Error:Wrong Memory Unit"
|
|
||||||
else:
|
|
||||||
if(Memory.count("GB")==1):
|
|
||||||
self.__Memory=Memory.replace("GB","")
|
|
||||||
elif(Memory.count("MB")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("MB",""))/1024)
|
|
||||||
elif(Memory.count("Gb")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("Gb",""))/8)
|
|
||||||
elif(Memory.count("Mb")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("Mb",""))/8/1024)
|
|
||||||
else:
|
|
||||||
return "Error:Wrong Memory Unit."
|
|
||||||
def GetAccount(self,Account):
|
|
||||||
if(self.__AuthWay=="online"):
|
|
||||||
if(Account.count("@")==1):
|
|
||||||
self.OnlineAuth(Account,self._Password)
|
|
||||||
else:
|
|
||||||
return "Error:Wrong Account."
|
|
||||||
elif(self.__AuthWay=="offline"):
|
|
||||||
if(Account.count("@")==1):
|
|
||||||
return "Error:Wrong Account."
|
|
||||||
else:
|
|
||||||
self.OfflineAuth(Account)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
def GetUUID(self,Account):
|
|
||||||
if(self.__AuthWay=="offline"):
|
|
||||||
result="OfflinePlayer:"+Account
|
|
||||||
md5=hashlib.md5()
|
|
||||||
md5.update(result.encode(encoding='utf-8'))
|
|
||||||
return md5.hexdigest()
|
|
||||||
else:
|
|
||||||
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):
|
|
||||||
self.__ID=Account
|
|
||||||
self.__UUID=self.GetUUID(Account)
|
|
||||||
self.__Token=""
|
|
||||||
def GetJavaPath(self):
|
|
||||||
if(platform.system()=="Windows"):
|
|
||||||
path="C:/"
|
|
||||||
elif(platform.system()=="Linux"):
|
|
||||||
path="/"
|
|
||||||
else:
|
|
||||||
path="/"
|
|
||||||
i=0
|
|
||||||
for ipath in os.listdir(Path):
|
|
||||||
FullDir=os.path.join(path,ipath)
|
|
||||||
if(os.path.isfile(FullDir)):
|
|
||||||
if("javaw.exe" in os.path.split(FullDir)[1]):
|
|
||||||
return FullDir
|
|
||||||
i+=1
|
|
||||||
if(i==1):
|
|
||||||
break
|
|
||||||
def SetJavaPath(self,path):
|
|
||||||
if(path==None):
|
|
||||||
return "Error:Wrong local address for java."
|
|
||||||
else:
|
|
||||||
self.__JAVA=path
|
|
||||||
def Download(self,DownloadFrom,DownloadTo,ThreadNum=3):
|
|
||||||
if(DownloadFrom=="" or DownloadTo==""):
|
|
||||||
return "Error:Wrong online address or local address for download."
|
|
||||||
else:
|
|
||||||
url = DownloadFrom
|
|
||||||
filename = DownloadTo
|
|
||||||
filesize = int(requests.head(url).headers['Content-Length'])
|
|
||||||
|
|
||||||
threadnum = ThreadNum
|
|
||||||
threading.BoundedSemaphore(threadnum)
|
|
||||||
step = filesize // threadnum
|
|
||||||
mtd_list = []
|
|
||||||
start = 0
|
|
||||||
end = -1
|
|
||||||
|
|
||||||
tempf = open(filename,'w')
|
|
||||||
tempf.close()
|
|
||||||
with open(filename,'rb+') as f:
|
|
||||||
fileno = f.fileno()
|
|
||||||
while end < filesize -1:
|
|
||||||
start = end +1
|
|
||||||
end = start + step -1
|
|
||||||
if end > filesize:
|
|
||||||
end = filesize
|
|
||||||
dup = os.dup(fileno)
|
|
||||||
fd = os.fdopen(dup,'rb+',-1)
|
|
||||||
t = MultiThreadDownload(url,start,end,fd)
|
|
||||||
t.start()
|
|
||||||
mtd_list.append(t)
|
|
||||||
|
|
||||||
for i in mtd_list:
|
|
||||||
i.join()
|
|
56
main.py
56
main.py
@ -22,15 +22,9 @@ class MultiThreadDownload(threading.Thread):
|
|||||||
|
|
||||||
class GMCLCore(object):
|
class GMCLCore(object):
|
||||||
'''The Main Class of the Launcher Core'''
|
'''The Main Class of the Launcher Core'''
|
||||||
'''AuthWay="offline",Account="Steve",Password="",GamePath=".minecraft",Memory="1GB",Version="",Java=""'''
|
|
||||||
'''
|
'''
|
||||||
self.GetAuthWay(AuthWay)
|
|
||||||
self.GetAccoutn(Account)
|
|
||||||
self.__Password=Password
|
|
||||||
self.__GamePath=GamePath
|
self.__GamePath=GamePath
|
||||||
self.GetMemory(Memory)
|
|
||||||
self.__Version=Version
|
self.__Version=Version
|
||||||
self.__Java=Java
|
|
||||||
'''
|
'''
|
||||||
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
|
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0"):
|
||||||
self.__LauncherName=LauncherName
|
self.__LauncherName=LauncherName
|
||||||
@ -43,21 +37,7 @@ class GMCLCore(object):
|
|||||||
self.__AuthWay="online"
|
self.__AuthWay="online"
|
||||||
else:
|
else:
|
||||||
return "Error:Wrong Auth Way."
|
return "Error:Wrong Auth Way."
|
||||||
def GetMemory(self,Memory):
|
def GetAccount(self,Account="Steve"):
|
||||||
if(Memory.count("B")>1 or Memory.count("b")>1):
|
|
||||||
return "Error:Wrong Memory Unit"
|
|
||||||
else:
|
|
||||||
if(Memory.count("GB")==1):
|
|
||||||
self.__Memory=Memory.replace("GB","")
|
|
||||||
elif(Memory.count("MB")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("MB",""))/1024)
|
|
||||||
elif(Memory.count("Gb")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("Gb",""))/8)
|
|
||||||
elif(Memory.count("Mb")==1):
|
|
||||||
self.__Memory=str(float(Memory.replace("Mb",""))/8/1024)
|
|
||||||
else:
|
|
||||||
return "Error:Wrong Memory Unit."
|
|
||||||
def GetAccount(self,Account):
|
|
||||||
if(self.__AuthWay=="online"):
|
if(self.__AuthWay=="online"):
|
||||||
if(Account.count("@")==1):
|
if(Account.count("@")==1):
|
||||||
self.OnlineAuth(Account,self._Password)
|
self.OnlineAuth(Account,self._Password)
|
||||||
@ -70,7 +50,7 @@ class GMCLCore(object):
|
|||||||
self.OfflineAuth(Account)
|
self.OfflineAuth(Account)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
def GetUUID(self,Account):
|
def GetUUID(self,Account="Steve"):
|
||||||
if(self.__AuthWay=="offline"):
|
if(self.__AuthWay=="offline"):
|
||||||
result="OfflinePlayer:"+Account
|
result="OfflinePlayer:"+Account
|
||||||
md5=hashlib.md5()
|
md5=hashlib.md5()
|
||||||
@ -86,11 +66,27 @@ class GMCLCore(object):
|
|||||||
self.__ID=result['selectedProfile']['name']
|
self.__ID=result['selectedProfile']['name']
|
||||||
else:
|
else:
|
||||||
return "Error:Fail to request Mojang\'s Auth Server."
|
return "Error:Fail to request Mojang\'s Auth Server."
|
||||||
def OfflineAuth(self,Account):
|
def OfflineAuth(self,Account="Steve"):
|
||||||
self.__ID=Account
|
self.__ID=Account
|
||||||
self.__UUID=self.GetUUID(Account)
|
self.__UUID=self.GetUUID(Account)
|
||||||
self.__Token=""
|
self.__Token=""
|
||||||
def GetJavaPath(self):
|
def GetJavaPath(self,Num=1):
|
||||||
|
if(platform.system()=="Windows"):
|
||||||
|
path="C:/"
|
||||||
|
elif(platform.system()=="Linux"):
|
||||||
|
path="/"
|
||||||
|
else:
|
||||||
|
path="/"
|
||||||
|
i=0
|
||||||
|
for ipath in os.listdir(Path):
|
||||||
|
FullDir=os.path.join(path,ipath)
|
||||||
|
if(os.path.isfile(FullDir)):
|
||||||
|
if("javaw.exe" in os.path.split(FullDir)[1]):
|
||||||
|
return FullDir
|
||||||
|
i+=1
|
||||||
|
if(i==Num):
|
||||||
|
break
|
||||||
|
def SetRecomMem(self):
|
||||||
if(platform.system()=="Windows"):
|
if(platform.system()=="Windows"):
|
||||||
path="C:/"
|
path="C:/"
|
||||||
elif(platform.system()=="Linux"):
|
elif(platform.system()=="Linux"):
|
||||||
@ -106,11 +102,21 @@ class GMCLCore(object):
|
|||||||
i+=1
|
i+=1
|
||||||
if(i==1):
|
if(i==1):
|
||||||
break
|
break
|
||||||
|
def SetRecomMem(self):
|
||||||
|
self.__Memory = float(psutil.virtual_memory().free / 1024 ** 3) * 0.8
|
||||||
def SetJavaPath(self,path):
|
def SetJavaPath(self,path):
|
||||||
if(path==None):
|
if(path==None):
|
||||||
return "Error:Wrong local address for java."
|
return "Error:Wrong local address for java."
|
||||||
else:
|
else:
|
||||||
self.__JAVA=path
|
if(os.path.exists(path)):
|
||||||
|
self.__JAVA=path
|
||||||
|
else:
|
||||||
|
return "Error:Wrong local address for java."
|
||||||
|
def SetGameMem(self,Memory):
|
||||||
|
try:
|
||||||
|
self.__Memory=float(Memory)
|
||||||
|
except:
|
||||||
|
return "Error:Wrong parameter for game memory."
|
||||||
def Download(self,DownloadFrom,DownloadTo,ThreadNum=3):
|
def Download(self,DownloadFrom,DownloadTo,ThreadNum=3):
|
||||||
if(DownloadFrom=="" or DownloadTo==""):
|
if(DownloadFrom=="" or DownloadTo==""):
|
||||||
return "Error:Wrong online address or local address for download."
|
return "Error:Wrong online address or local address for download."
|
||||||
|
Reference in New Issue
Block a user