diff --git a/game/game.js b/game/game.js index a060439c3..15d0d6397 100755 --- a/game/game.js +++ b/game/game.js @@ -2802,7 +2802,7 @@ } var noname_inited=localStorage.getItem('noname_inited'); - if(noname_inited){ + if(noname_inited&&noname_inited!=='nodejs'){ var ua=navigator.userAgent.toLowerCase(); if(ua.indexOf('android')!=-1){ lib.device='android'; @@ -3128,7 +3128,7 @@ }); } } - if(window.require){ + if(typeof window.require=='function'&&!lib.device){ lib.node={ fs:require('fs'), http:require('http'), @@ -3137,7 +3137,44 @@ } } game.download=function(url,folder,onsuccess,onerror){ - + url=lib.updateURL+url; + var dir=folder.split('/'); + var str=''; + var download=function(){ + try{ + var file = lib.node.fs.createWriteStream(__dirname+'/'+folder); + } + catch(e){ + onerror(); + } + var request = lib.node.http.get(url, function(response) { + var stream=response.pipe(file); + stream.on('finish',onsuccess); + stream.on('error',onerror); + }); + } + var access=function(){ + if(dir.length<=1){ + download(); + } + else{ + str+='/'+dir.shift(); + lib.node.fs.access(__dirname+str,function(e){ + if(e){ + try{ + lib.node.fs.mkdir(__dirname+str,access); + } + catch(e){ + onerror(); + } + } + else{ + access(); + } + }); + } + } + access(); } } lib.cardSelectObserver=new MutationObserver(function(mutations){ @@ -10477,6 +10514,25 @@ zipReady(); } }, + multiDownload:function(list,onsuccess,onerror,onfinish){ + list=list.slice(0); + var download=function(){ + if(list.length){ + var current=list.shift(); + game.download(current,current,function(){ + if(onsuccess) onsuccess(); + download(); + },function(){ + if(onerror) onerror(); + download(); + }); + } + else{ + if(onfinish) onfinish(); + } + } + download(); + }, playVideo:function(time,mode){ if(!_status.replayvideo){ localStorage.setItem(lib.configprefix+'playbackmode',lib.config.mode); @@ -17763,7 +17819,6 @@ var span=document.createElement('span'); var n1=0; var n2=updates.length; - var n=n2; span.innerHTML='正在下载文件('+n1+'/'+n2+')'; p.appendChild(span); var finish=function(){ @@ -17774,23 +17829,14 @@ button.onclick=game.reload; p.appendChild(button); } - for(var i=0;i