Revision 328d0fa5
Added by David Sorber over 9 years ago
| software/photo_compress_archiver/main.cc | ||
|---|---|---|
|
#include <string>
|
||
|
|
||
|
#include <boost/filesystem.hpp>
|
||
|
#include <boost/program_options.hpp>
|
||
|
#include <boost/regex.hpp>
|
||
|
|
||
|
#include "PhotoCompressArchiver.hh"
|
||
|
|
||
|
// clang++ -std=c++11 -L. -l packjpg -I/opt/local/include -L/opt/local/lib
|
||
|
// -lboost_system-mt -lboost_regex-mt -lboost_filesystem-mt -o pca main.cc
|
||
|
int main(int argc, char** argv)
|
||
|
// Alias the namespace for readability
|
||
|
namespace bpo = boost::program_options;
|
||
|
|
||
|
void header()
|
||
|
{
|
||
|
std::cout << "Photo Compress Archiver -- v0.1.0" << std::endl;
|
||
|
std::cout << BOLD << "Photo Compress Archiver -- " << version << "\n" << ENDC;
|
||
|
std::cout << " Copyright 2017 - David Sorber\n";
|
||
|
std::cout << " >>> Utilizing packJPG by Matthias Stirner\n" << std::endl;
|
||
|
}
|
||
|
|
||
|
void usage(char** argv)
|
||
|
{
|
||
|
// Remove leading "./" if it exits
|
||
|
char* app_name = argv[0];
|
||
|
if (argv[0][0] == '.' && argv[0][1] == '/')
|
||
|
{
|
||
|
char* app_name = &argv[0][2];
|
||
|
}
|
||
|
|
||
|
uint32_t num_cores = std::thread::hardware_concurrency();
|
||
|
std::cout << " [" << num_cores << " cores detected]\n" << std::endl;
|
||
|
header();
|
||
|
std::cout << "USAGE: " << app_name << " [-hkd] <file path>\n\n";
|
||
|
std::cout << "Positional arguments:\n";
|
||
|
std::cout << " <file path> path in which to recursively look "
|
||
|
<< "for input files\n\n";
|
||
|
std::cout << "General options:\n";
|
||
|
std::cout << " -h [ --help ] display this help message\n";
|
||
|
std::cout << " -d [ --decompress ] find '*.pjg' files and decompress them\n";
|
||
|
std::cout << " -k [ --keep-orig ] keep original files; don't delete them\n";
|
||
|
std::cout << std::endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
bpo::variables_map general_opts_vm;
|
||
|
|
||
|
// Make sure the correct number of arguments were specified
|
||
|
if (argc < 2)
|
||
|
try
|
||
|
{
|
||
|
std::cerr << "ERROR: Not enough arguments" << std::endl;
|
||
|
// General options
|
||
|
bpo::options_description general_opts("General options");
|
||
|
general_opts.add_options()
|
||
|
("help,h", "display this help message")
|
||
|
("decompress,d", "find '*.pjg' files and decompress them")
|
||
|
("keep-orig,k", "keep orignal files")
|
||
|
("file_path", "path in which to recursively look for input files")
|
||
|
;
|
||
|
|
||
|
// Positional arguments
|
||
|
bpo::positional_options_description pos_opts;
|
||
|
pos_opts.add("file_path", 1);
|
||
|
|
||
|
// Parse general/positional options
|
||
|
bpo::store(bpo::command_line_parser(argc, argv).options(general_opts)
|
||
|
.positional(pos_opts).allow_unregistered().run(),
|
||
|
general_opts_vm);
|
||
|
|
||
|
|
||
|
// Display help if the option is listed or if no arguments are provided
|
||
|
if (general_opts_vm.count("help") || (argc == 1))
|
||
|
{
|
||
|
usage(argv);
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
catch (std::exception& e)
|
||
|
{
|
||
|
std::cerr << BOLD << RED << "ERROR: " << ENDC << e.what() << "\n";
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
// Make sure that path specified actually exists
|
||
|
if (! bfs::exists(argv[1]))
|
||
|
|
||
|
// Make a copy of the file search path for passing into the object below
|
||
|
std::string search_path(general_opts_vm["file_path"].as<std::string>());
|
||
|
|
||
|
// Make sure that path specified actually exists before proceeding
|
||
|
if (! bfs::exists(search_path))
|
||
|
{
|
||
|
std::cerr << "ERROR: the path \"" << argv[1] << "\" does not exist"
|
||
|
<< std::endl;
|
||
|
std::cerr << BOLD << RED << "ERROR: " << ENDC << "the path \""
|
||
|
<< search_path << "\" does not exist" << std::endl;
|
||
|
return -2;
|
||
|
}
|
||
|
|
||
|
auto pca = new PhotoCompressArchiver(argv[1], num_cores);
|
||
|
pca->execute();
|
||
|
// Display header and
|
||
|
header();
|
||
|
uint32_t num_cores = std::thread::hardware_concurrency();
|
||
|
std::cout << " [" << num_cores << " cores detected]\n";
|
||
|
|
||
|
//~ delete pca;
|
||
|
// Decode/store decompress option
|
||
|
bool decompress = false;
|
||
|
if (general_opts_vm.count("decompress"))
|
||
|
{
|
||
|
decompress = true;
|
||
|
std::cout << " decompress mode => ON\n";
|
||
|
}
|
||
|
|
||
|
// Decode/store keep-orig option
|
||
|
bool keep_orig = false;
|
||
|
if (general_opts_vm.count("keep-orig"))
|
||
|
{
|
||
|
keep_orig = true;
|
||
|
std::cout << " keep original files => ON\n";
|
||
|
}
|
||
|
|
||
|
std::cout << std::endl;
|
||
|
|
||
|
auto pca = new PhotoCompressArchiver(search_path, num_cores, decompress,
|
||
|
keep_orig);
|
||
|
pca->execute();
|
||
|
delete pca;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
Adding proper option parsing and some general improvements. I've added an option for decompression but I still need to implement it.