modify game.getFileList.
This commit is contained in:
parent
7ba2d5e596
commit
9bcedbc919
51
game/game.js
51
game/game.js
|
@ -8389,13 +8389,13 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
game.getFileList=function(dir,callback){
|
game.getFileList=(dir,success,failure)=>{
|
||||||
var files=[],folders=[];
|
var files=[],folders=[];
|
||||||
window.resolveLocalFileSystemURL(lib.assetURL+dir,function(entry){
|
window.resolveLocalFileSystemURL(lib.assetURL+dir,entry=>{
|
||||||
var dirReader=entry.createReader();
|
var dirReader=entry.createReader();
|
||||||
var entries=[];
|
var entries=[];
|
||||||
var readEntries=function(){
|
var readEntries=()=>{
|
||||||
dirReader.readEntries(function(results){
|
dirReader.readEntries(results=>{
|
||||||
if(!results.length){
|
if(!results.length){
|
||||||
entries.sort();
|
entries.sort();
|
||||||
for(var i=0;i<entries.length;i++){
|
for(var i=0;i<entries.length;i++){
|
||||||
|
@ -8406,16 +8406,16 @@
|
||||||
files.push(entries[i].name);
|
files.push(entries[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(folders,files);
|
success(folders,files);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
entries=entries.concat(Array.from(results));
|
entries=entries.concat(Array.from(results));
|
||||||
readEntries();
|
readEntries();
|
||||||
}
|
}
|
||||||
});
|
},failure);
|
||||||
};
|
};
|
||||||
readEntries();
|
readEntries();
|
||||||
});
|
},failure);
|
||||||
};
|
};
|
||||||
game.ensureDirectory=function(list,callback,file){
|
game.ensureDirectory=function(list,callback,file){
|
||||||
var directorylist;
|
var directorylist;
|
||||||
|
@ -8577,21 +8577,36 @@
|
||||||
game.removeFile=function(filename,callback){
|
game.removeFile=function(filename,callback){
|
||||||
lib.node.fs.unlink(__dirname+'/'+filename,callback||function(){});
|
lib.node.fs.unlink(__dirname+'/'+filename,callback||function(){});
|
||||||
};
|
};
|
||||||
game.getFileList=function(dir,callback){
|
game.getFileList=(dir,success,failure)=>{
|
||||||
var files=[],folders=[];
|
var files=[],folders=[];
|
||||||
dir=__dirname+'/'+dir;
|
dir=__dirname+'/'+dir;
|
||||||
lib.node.fs.readdir(dir,function(err,filelist){
|
if(!failure){
|
||||||
for(var i=0;i<filelist.length;i++){
|
failure=function(err){
|
||||||
if(filelist[i][0]!='.'&&filelist[i][0]!='_'){
|
throw err;
|
||||||
if(lib.node.fs.statSync(dir+'/'+filelist[i]).isDirectory()){
|
};
|
||||||
folders.push(filelist[i]);
|
}
|
||||||
}
|
lib.node.fs.access(dir,lib.node.fs.constants.F_OK|lib.node.fs.constants.R_OK,err=>{
|
||||||
else{
|
if(err) {
|
||||||
files.push(filelist[i]);
|
failure(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lib.node.fs.readdir(dir,(err,filelist)=>{
|
||||||
|
if(err){
|
||||||
|
failure(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i=0;i<filelist.length;i++){
|
||||||
|
if(filelist[i][0]!='.'&&filelist[i][0]!='_'){
|
||||||
|
if(lib.node.fs.statSync(dir+'/'+filelist[i]).isDirectory()){
|
||||||
|
folders.push(filelist[i]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
files.push(filelist[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
success(folders,files);
|
||||||
callback(folders,files);
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
game.ensureDirectory=function(list,callback,file){
|
game.ensureDirectory=function(list,callback,file){
|
||||||
|
|
Loading…
Reference in New Issue