
var fileSystem = WScript.CreateObject("Scripting.FileSystemObject");

function findErrorDll(gdalFolder){
	
	var gdalFiles = new Enumerator(gdalFolder.files);
	var listDll=[];

	for (i=0; !gdalFiles.atEnd(); gdalFiles.moveNext()){
		
		var nameFile=gdalFiles.item().Name.toLowerCase();
		
		if (nameFile.substr(0,4)!="msvc" && nameFile.slice(-3)=="dll"){
			if(fileSystem.FileExists("C:\\Windows\\System32\\"+nameFile)){
				listDll.push(nameFile);
			}
		}	
	}
	
	return listDll;
	
}

function copyDlls(listDll,sourceFolder){
	
	var targetFolder=fileSystem.GetFolder(fileSystem.GetParentFolderName(WScript.ScriptFullName)+"\\..\\gvSIG\\extensiones\\jre\\bin\\");

	for (j=0; j<listDll.length; j++){
		
		var fileName=listDll[j];
		var source=sourceFolder+"\\"+fileName;
		var target=targetFolder+"\\"+fileName;

		if (!fileSystem.FileExists(target)){
				fileSystem.CopyFile(source,target,false);
			}
		
	}	
	
}	
	
function main(){
	
	var gdalFolder=fileSystem.GetFolder(fileSystem.GetParentFolderName(WScript.ScriptFullName)+"\\..\\gvSIG\\extensiones\\org.gvsig.gdal.app.mainplugin\\gdal\\bin\\");
	
	WScript.Echo("La ejecucion de este script puede causar problemas a tu pc.");
	
	var dlls=findErrorDll(gdalFolder);
	
	copyDlls(dlls,gdalFolder);
	
	WScript.Echo("Operacion finalizada");
	
}
	
main();



