Revision 13f1ac5a
Added by David Sorber almost 8 years ago
| software/photo_compress_archiver/PhotoCompressArchiver.cc | ||
|---|---|---|
|
#include <iostream>
|
||
|
#include <limits.h>
|
||
|
#include <thread>
|
||
|
#include <sstream>
|
||
|
#include <sys/stat.h>
|
||
|
#include <sys/wait.h>
|
||
|
#include <unistd.h>
|
||
| ... | ... | |
|
|
||
|
// Display status
|
||
|
std::cout << BOLD << "\n>>> Status:" << ENDC << std::endl;
|
||
|
std::string line(100, '-');
|
||
|
std::cout << line << std::endl;
|
||
|
std::cout << LINE << std::endl;
|
||
|
if (! m_verbose)
|
||
|
{
|
||
|
// If not in verbose mode display running status
|
||
| ... | ... | |
|
|
||
|
double ratio = ((double)m_total_compressed_size /
|
||
|
m_running_compressed_size) * 100;
|
||
|
|
||
|
// This looks odd but in fact checks for NaN which we don't want to
|
||
|
// display in the status
|
||
|
if (ratio != ratio)
|
||
|
{
|
||
|
ratio = 0.0;
|
||
|
}
|
||
|
|
||
|
// Highlight and non-zero number of errors in bold red for emphasis
|
||
|
uint32_t num_errors = m_errors.size();
|
||
|
std::ostringstream formatted_errors;
|
||
|
if (num_errors > 0)
|
||
|
{
|
||
|
formatted_errors << "Errors: " << BOLD << RED << num_errors
|
||
|
<< ENDC;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
formatted_errors << "Errors: " << num_errors ;
|
||
|
}
|
||
|
|
||
|
std::cout << "Elapsed time: " << std::fixed
|
||
|
<< std::setprecision(3) << duration << " s "
|
||
|
<< "Files processed: "
|
||
|
<< m_files_processed << " / "
|
||
|
<< m_num_input_files << " "
|
||
|
<< "Errors: " << num_errors << " "
|
||
|
<< formatted_errors.str() << " "
|
||
|
<< std::endl;
|
||
|
|
||
|
pbar.update(std::lround(percent_done));
|
||
| ... | ... | |
|
<< std::setprecision(2) << ratio << "% "
|
||
|
<< std::endl;
|
||
|
|
||
|
std::cout << line << std::endl;
|
||
|
std::cout << LINE << std::endl;
|
||
|
|
||
|
// Delay slightly to prevent flickering
|
||
|
// Delay slightly to prevent cursor flickering
|
||
|
if (percent_done < 100.0)
|
||
|
{
|
||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||
| software/photo_compress_archiver/PhotoCompressArchiver.hh | ||
|---|---|---|
|
const std::string UP_ONE = "\033[1A";
|
||
|
const std::string DOWN_ONE = "\033[1B";
|
||
|
|
||
|
const std::string version("v0.3.5");
|
||
|
const std::string version("v0.4.1");
|
||
|
|
||
|
const boost::regex JPEG_REGEX("^.+\\.(jpg)|(jpeg)$", boost::regex::icase);
|
||
|
const boost::regex PJG_REGEX("^.+\\.pjg$", boost::regex::icase);
|
||
| ... | ... | |
|
const std::string PJG_EXTENSION(".pjg");
|
||
|
|
||
|
const uint32_t PROGRESS_BAR_WIDTH = 80;
|
||
|
const std::string LINE(100, '-');
|
||
|
|
||
|
class WorkUnit
|
||
|
{
|
||
| ... | ... | |
|
uint32_t m_num_threads; // number of processing threads to use
|
||
|
bool m_decompress; // decompress files instead of compress them
|
||
|
bool m_delete_orig; // delete original files after de/compression
|
||
|
bool m_verbose ; // verbose processing output
|
||
|
bool m_verbose; // verbose processing output
|
||
|
|
||
|
std::mutex m_output_mutex; // output mutex
|
||
|
|
||
Minor formatting changes for running status output.