Added file downloads progress
This commit is contained in:
parent
09b8c091c6
commit
1212ab49c5
2 changed files with 25 additions and 29 deletions
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [1.0.1] - Unreleased
|
## [1.0.1] - Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added file downloads progress
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Bug fix where resources are not decoded correctly when installing packages [#31](https://git.n64.cc/nosial/ncc/-/issues/42)
|
- Bug fix where resources are not decoded correctly when installing packages [#31](https://git.n64.cc/nosial/ncc/-/issues/42)
|
||||||
|
|
|
@ -54,6 +54,28 @@ namespace ncc\Classes;
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $request->Headers);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $request->Headers);
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->Type);
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->Type);
|
||||||
|
curl_setopt($curl, CURLOPT_NOPROGRESS, false);
|
||||||
|
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, function($curl, $downloadSize, $downloaded, $uploadSize, $uploaded) use ($request)
|
||||||
|
{
|
||||||
|
if($downloadSize > 0 && ($downloaded !== $downloadSize))
|
||||||
|
{
|
||||||
|
if(Main::getLogLevel() !== null)
|
||||||
|
{
|
||||||
|
switch(Main::getLogLevel())
|
||||||
|
{
|
||||||
|
case LogLevel::Verbose:
|
||||||
|
case LogLevel::Debug:
|
||||||
|
case LogLevel::Silent:
|
||||||
|
Console::outVerbose(sprintf(' <= %s of %s bytes downloaded', $downloaded, $downloadSize));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Console::inlineProgressBar($downloaded, $downloadSize + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
switch($request->Type)
|
switch($request->Type)
|
||||||
{
|
{
|
||||||
|
@ -188,35 +210,6 @@ namespace ncc\Classes;
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays the download progress in the console
|
|
||||||
*
|
|
||||||
* @param $downloadSize
|
|
||||||
* @param $downloaded
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function displayProgress($downloadSize, $downloaded): void
|
|
||||||
{
|
|
||||||
if(Main::getLogLevel() !== null)
|
|
||||||
{
|
|
||||||
switch(Main::getLogLevel())
|
|
||||||
{
|
|
||||||
case LogLevel::Verbose:
|
|
||||||
case LogLevel::Debug:
|
|
||||||
case LogLevel::Silent:
|
|
||||||
Console::outVerbose(sprintf(' <= %s of %s bytes downloaded', $downloaded, $downloadSize));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if ($downloadSize > 0)
|
|
||||||
Console::inlineProgressBar($downloaded, $downloadSize);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes the return headers of a cURL request and parses them into an array.
|
* Takes the return headers of a cURL request and parses them into an array.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue