update minor bugs

This commit is contained in:
Derek Macias
2015-12-14 01:28:47 -07:00
parent e33f7ce6b5
commit 5b016ac943
8 changed files with 69 additions and 112 deletions

View File

@ -1,5 +1,5 @@
<?php
function progressBar($download_size, $downloaded_size, $upload_size, $uploaded_size)
function progress_bar($download_size, $downloaded_size, $upload_size = null, $uploaded_size = null)
{
static $previousProgress = 0;
@ -10,15 +10,12 @@ function progressBar($download_size, $downloaded_size, $upload_size, $uploaded_s
if ( $progress > $previousProgress){
$previousProgress = $progress;
$pct=(double)($progress/100);
$bar=round($pct * 30);
$pct_disp=number_format($pct * 100, 0);
$status_bar="\r[";
$status_bar.=str_repeat("|", $bar);
if($bar < 30){
$status_bar.=">";
$status_bar.=str_repeat("-", 30 - $bar);
@ -29,40 +26,36 @@ function progressBar($download_size, $downloaded_size, $upload_size, $uploaded_s
$status_bar.="] $pct_disp%";
echo $status_bar;
ob_flush();
flush();
if($progress == 100) {
echo "\n";
}
}
flush();
}
function get_file_from_url($file, $url) {
flush();
$chfile = fopen($file, 'w');
$ch = curl_init();
$ch_vers = curl_version();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_NOPROGRESS, false );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] );
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progressBar' );
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress_bar' );
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $chfile );
curl_exec($ch);
curl_close($ch);
fclose($chfile);
flush();
}
function get_content_from_github($repo, $file){
flush();
$ch = curl_init();
$ch_vers = curl_version();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, 'curl/' . $ch_vers['version'] );
@ -71,6 +64,16 @@ function get_content_from_github($repo, $file){
curl_close($ch);
if (!empty($content))
file_put_contents($file, $content);
flush();
}
?>
function file_check_sha($file, $sha){
$size = filesize($file);
$handle = fopen($file, "rb");
$contents = fread($handle, $size);
fclose($handle);
$str = "blob ".$size."\0".$contents;
$sha_file = sha1($str);
$return = ($sha_file == $sha) ? true : false;
return $return;
}
?>