mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Fix scan progress messages not clearing up correctly
This commit is contained in:
parent
42acc42d8f
commit
43cbad47cb
1 changed files with 24 additions and 7 deletions
|
@ -36,19 +36,24 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
|
# include <sstream>
|
||||||
|
# include <functional>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDBSettings, bool parForce=false );
|
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDBSettings, bool parForce=false );
|
||||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
void print_progress ( const boost::string_ref parPath, uint64_t parFileBytes, uint64_t parTotalBytes, uint32_t parFileNum );
|
void print_progress ( const boost::string_ref parPath, uint64_t parFileBytes, uint64_t parTotalBytes, uint32_t parFileNum, std::size_t& parClearCount );
|
||||||
#endif
|
#endif
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
namespace stask = mchlib::scantask;
|
namespace stask = mchlib::scantask;
|
||||||
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
|
namespace ph = std::placeholders;
|
||||||
|
#endif
|
||||||
|
|
||||||
int main (int parArgc, char* parArgv[]) {
|
int main (int parArgc, char* parArgv[]) {
|
||||||
using std::placeholders::_1;
|
|
||||||
using std::placeholders::_2;
|
|
||||||
using boost::program_options::variables_map;
|
using boost::program_options::variables_map;
|
||||||
using FileRecordDataFiller = stask::GeneralFiller<stask::DirTree::PathList>;
|
using FileRecordDataFiller = stask::GeneralFiller<stask::DirTree::PathList>;
|
||||||
using SetRecordDataFiller = stask::GeneralFiller<mchlib::SetRecordDataFull>;
|
using SetRecordDataFiller = stask::GeneralFiller<mchlib::SetRecordDataFull>;
|
||||||
|
@ -92,10 +97,14 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
std::shared_ptr<SetRecordDataFiller> setrecdata(new SetRecordDataFiller(media_type, content_type));
|
std::shared_ptr<SetRecordDataFiller> setrecdata(new SetRecordDataFiller(media_type, content_type));
|
||||||
|
|
||||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
hashing->set_progress_callback(&print_progress);
|
hashing->set_progress_callback(std::bind(&print_progress, ph::_1, ph::_2, ph::_3, ph::_4, std::size_t(0)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (not add_to_db(filerecdata->get_or_create(), setrecdata->get_or_create(), settings.db)) {
|
const bool added_to_db = add_to_db(filerecdata->get_or_create(), setrecdata->get_or_create(), settings.db);
|
||||||
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
|
std::cout << '\n';
|
||||||
|
#endif
|
||||||
|
if (not added_to_db) {
|
||||||
std::cerr << "Not written to DB, likely because a set with the same hash already exists\n";
|
std::cerr << "Not written to DB, likely because a set with the same hash already exists\n";
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -126,8 +135,16 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
void print_progress (const boost::string_ref parPath, uint64_t /*parFileBytes*/, uint64_t parTotalBytes, uint32_t parFileNum) {
|
void print_progress (const boost::string_ref parPath, uint64_t /*parFileBytes*/, uint64_t parTotalBytes, uint32_t parFileNum, std::size_t& parClearCount) {
|
||||||
std::cout << "Hashing file " << parFileNum << " \"" << parPath << "\" (" << parTotalBytes << " bytes hashed)\r";
|
std::ostringstream oss;
|
||||||
|
|
||||||
|
std::fill_n(std::ostream_iterator<char>(std::cout), parClearCount, ' ');
|
||||||
|
std::cout << '\r';
|
||||||
|
oss << "Hashing file " << parFileNum << " \"" << parPath << "\" (" << parTotalBytes << " bytes hashed)";
|
||||||
|
const auto msg = oss.str();
|
||||||
|
parClearCount = msg.size();
|
||||||
|
|
||||||
|
std::cout << msg << '\r';
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue