コード例 #1
0
void ConsoleUpdater::printProgress()
{
	// Progress bar
	Logger::update( "\r" );

  std::size_t numTicks = static_cast<std::size_t>(floor(_d->info.progressFraction * PROGRESS_METER_WIDTH));
	std::string progressBar(numTicks, '=');
	std::string progressSpace(PROGRESS_METER_WIDTH - numTicks, ' ');

	std::string line = " [" + progressBar + progressSpace + "]";
	
	// Percent
  line += utils::format( 0xff, " %2.1f%%", _d->info.progressFraction*100 );

  switch (_d->info.type)
	{
	case ProgressInfo::FileDownload:	
	{
    line += " at " + Util::getHumanReadableBytes( _d->info.connection.speed ) + "/sec ";
	}
	break;

	case ProgressInfo::FileOperation:
	{
		std::string verb;

    switch (_d->info.operationType)
		{
		case ProgressInfo::Check: 			verb = "Checking: "; 			break;
		case ProgressInfo::Remove: 			verb = "Removing: ";			break;
    case ProgressInfo::Replace: 			verb = "Replacing: ";		break;
    case ProgressInfo::Add: 			verb = "Adding: ";    			break;
		case ProgressInfo::RemoveFilesFromPK4: 			verb = "Preparing PK4: ";			break;
    default: 			verb = "File: ";
    };

		line += " " + verb;

		std::size_t remainingLength = line.length() > 79 ? 0 : 79 - line.length();
    line += utils::toShortString( _d->info.file.baseName().toString(), remainingLength);
	}
	break;

	default: break;
	};

	// Expand the line length to 79 characters
	if (line.length() < 79)
	{
		line += std::string(79 - line.length(), ' ');
	}
	else if (line.length() > 79)
	{
		line = line.substr(0, 79);
	}

	Logger::update( line );
}
コード例 #2
0
void ConsoleUpdater::PrintProgress()
{
	TraceLog::Write(LOG_PROGRESS, "\r");

	// Progress bar
	std::size_t numTicks = static_cast<std::size_t>(floor(_info.progressFraction * PROGRESS_METER_WIDTH));
	std::string progressBar(numTicks, '=');
	std::string progressSpace(PROGRESS_METER_WIDTH - numTicks, ' ');

	std::string line = " [" + progressBar + progressSpace + "]";
	
	// Percent
	line += (boost::format(" %2.1f%%") % (_info.progressFraction*100)).str();

	switch (_info.type)
	{
	case ProgressInfo::FileDownload:	
	{
		line += " at " + Util::GetHumanReadableBytes(static_cast<std::size_t>(_info.downloadSpeed)) + "/sec ";
	}
	break;

	case ProgressInfo::FileOperation:
	{
		std::string verb;

		switch (_info.operationType)
		{
		case ProgressInfo::Check: 
			verb = "Checking: "; 
			break;
		case ProgressInfo::Remove: 
			verb = "Removing: ";
			break;
		case ProgressInfo::Replace: 
			verb = "Replacing: ";
			break;
		case ProgressInfo::Add: 
			verb = "Adding: ";
			break;
		case ProgressInfo::RemoveFilesFromPK4: 
			verb = "Preparing PK4: ";
			break;
		default: 
			verb = "File: ";
		};

		line += " " + verb;

		std::size_t remainingLength = line.length() > 79 ? 0 : 79 - line.length();
		line += GetShortenedString(_info.file.leaf().string(), remainingLength);
	}
	break;
	};

	// Expand the line length to 79 characters
	if (line.length() < 79)
	{
		line += std::string(79 - line.length(), ' ');
	}
	else if (line.length() > 79)
	{
		line = line.substr(0, 79);
	}

	TraceLog::Write(LOG_PROGRESS, line);
}