module Berka module NetError ErrConIn="Unable to connect to Internet" ErrConHttp="Unable to connect to the Server" ErrTranHttp="Http Download is failed" ErrNoFile="No file to be download" ErrMkdir="Unable to create a new directory" HTTPSync=false #true: the game is faster but download are very slower: #false: 20secs & true: 1min endendinclude Berka::NetErrormodule Net W='wininet' SPC=Win32API.new('kernel32','SetPriorityClass','pi','i').call(-1,128) IOA=Win32API.new(W,'InternetOpenA','plppl','l').call('',0,'','',0) IC=Win32API.new(W,'InternetConnectA','lplpplll','l') print(ErrConIn)if IOA==0 module HTTP IOU=Win32API.new(W,'InternetOpenUrl','lppllp','l') IRF=Win32API.new(W,'InternetReadFile','lpip','l') ICH=Win32API.new(W,'InternetCloseHandle','l','l') HQI=Win32API.new(W,'HttpQueryInfo','llppp','i') module_function def sizeloaded(i='');@read[i];end def transfered;@dloaded;end def transfers;@dls;end def progress(i='');(@read[i].to_f/@size[i]*100);end def loaded?(i='');@read[i]>=@size[i]rescue nil;end def temps(i='');@tps[i]if loaded?(i);end def size(i='');@size[i];end def download(url,int='./') @dloaded||=0;@dls||={};@i||=-1;@size||={};@read||={};@tps={} a=url.split('/');serv,root,fich=a[2],a[3..a.size].join('/'),a[-1] print(ErrNoFile)if fich.nil? @dls[fich]=Thread.start(url,int){|url,int|txt='';t=Time.now ErrConHttp if(e=IC.call(IOA,serv,80,'','',3,1,0))==0 f=IOU.call(IOA,url,nil,0,0,0) HQI.call(f,5,k="\0"*1024,[k.size-1].pack('l'),nil) @read[fich],@size[fich]=0,k.delete!("\0").to_i loop do buf,n=' '*1024,0 r=IRF.call(f,buf,1024,o=[n].pack('i!')) n=o.unpack('i!')[0] break if r&&n==0 txt<<buf[0,n] @read[fich]=txt.size sleep(0.001)if HTTPSync end (File.open(int+fich,'wb')<<txt).close @dloaded+=@read[fich] ICH.call(f);sleep(0.01) @tps[fich]=Time.now-t} end endend