=$d && !$force && $d!=false && $ld!=false) { echo "Local file is the same or newer, aborting. ($repos)"; return false; } $req="$repos?file=$file&type=getGzip"; $data=http_download($req); // we got nothing if($data===false) { echo "FAILED: Cannot retrieve $file ($repos)"; return false; } // if we got an error message if(substr($data,0,6)=="FAILED") { // not very safe on a rogue server echo $data." ($repos)"; return false; } echo "OK ($repos)"; // let's update the file with data $data=gzdecode($data); $fp=@fopen($local,"wb"); if(!$fp) die("FAILED: Cannot create output file '$path$file', aborting."); fwrite($fp,$data); fclose($fp); return true; } // Retrieves a file from the internet using HTTP. Return the file as a string function http_download($url) { $ch = curl_init(); if (defined($GLOBALS['raydium_proxy'])) curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['raydium_proxy']); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); $result = curl_exec ($ch); if (curl_errno($ch)) { print "ERROR downloading file: " . curl_error($ch); return false; } else { curl_close($ch); return $result; } } function read_repositories_file_internal($repos,&$repos_list) { $list=@file($repos); if(count($list)==0) die("Cannot open $repos"); // let's clean up the list for($i=0;$i0) return true; else return false; } // unzip a given input function gzdecode($in) { $tmp=str_pad("",256); raydium_file_home_path_cpy("tmp.tmp.gz",$tmp); $fp=fopen($tmp,"wb"); if(!$fp) return false; fwrite($fp,$in); fclose($fp); $fp=gzopen($tmp,"rb"); if(!$fp) return false; while(!gzeof($fp)) { $data.=gzread($fp,128); } gzclose($fp); unlink($tmp); return $data; } function ftp_upload($repos,$local,$distant) { $url=parse_url($repos); $conn_id = ftp_connect($url["host"],$url["port"]); $login_result = ftp_login($conn_id, $url["user"], $url["pass"]); ftp_pasv($conn_id, true); if (ftp_put($conn_id,$url["path"].$distant, $local, FTP_ASCII)) { echo "$repos: SUCCESS"; ftp_close($conn_id); return true; } else { echo "Failed contacting $repos"; ftp_close($conn_id); return false; } } function http_upload($repos,$local,$distant) { // creating temporary files is a little crappy, but it works $data=@file_get_contents($local); $data=gzencode($data); $zfilename = $local . ".gz"; $fp=fopen($zfilename,"wb"); if(!$fp) { print "FAILED: Cannot create zipped file $zfilename"; return false; } fwrite($fp,$data); fclose($fp); $url=parse_url($repos); $user=rawurlencode($url["user"]); $pass=rawurlencode($url["pass"]); $path=$url["path"]; $host=$url["host"]; $post = Array(); $post[ 'file' ] = $distant; $post[ 'type' ] = "putGzip"; $post[ 'username' ] = $user; $post[ 'password' ] = $pass; $post[ 'data' ] = "@".$zfilename; $ch = curl_init(); if (defined($GLOBALS['raydium_proxy'])) curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['raydium_proxy']); curl_setopt($ch, CURLOPT_URL, "http://".$host.$path ); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1 ); // seems no need to tell it enctype='multipart/data' it already knows curl_setopt($ch, CURLOPT_POSTFIELDS, $post ); $response = curl_exec( $ch ); unlink($zfilename); if($response[0]=='+') { return true; } else { echo "HTTP reply: $response"; return false; } } // supported files : (depends_xxx style) function depends_tri($filename) { $fp=fopen($filename,"rt"); if($fp==false) { echo "Cannot open $filename"; } fgets($fp, 4096); // skip first line (version number) while (!feof($fp)) { $line = trim(fgets($fp, 4096)); $line=explode(" ",$line); $tex=trim($line[count($line)-1]); if(substr($tex,0,4)!="rgb(") { $tex=trim($tex); $ok=false; if(strpos($tex,';') && !$ok) // is multitextured with ";" ? { $ok=true; $texs=explode(";",$tex); if(strlen($texs[0])) $ret[]=$texs[0]; // yes, and it's a "detail texture" if(strlen($texs[1])) // yes and it's a lightmap { if(strpos($texs[1],"|")!==false) { $lm=explode("|",$texs[1]); $ret[]=$lm[2]; } else $ret[]=$texs[1]; } } if(strpos($tex,'#') && !$ok) // is an environment map ? { $ok=true; $texs=explode("#",$tex); $ret[]=$texs[0]; $ret[]=$texs[1]; } if(!$ok && strlen($tex)) $ret[]=$tex; $ret=@array_values(array_unique($ret)); } } fclose($fp); $ret[]=$filename; return $ret; } function depends_prt($filename) { $f=@file($filename); for($i=0;$i