X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fstoresession.cpp;h=182642ee9aba08757269c43e208cf3b7147d5ef5;hp=494f2db3b91e7b8fe34ea1cfa56471f5ba4a8fc5;hb=f9319755734823208210b1e244b827ecb6820346;hpb=7b7ab1f5cb3607bf29885eeffcb2cb215b2c9e9f diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 494f2db3..182642ee 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -21,6 +21,8 @@ #include "storesession.hpp" +#include + #include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include @@ -42,7 +45,6 @@ using std::mutex; using std::pair; using std::shared_ptr; using std::string; -using std::unordered_set; using std::vector; using Glib::VariantBase; @@ -90,14 +92,14 @@ const QString& StoreSession::error() const bool StoreSession::start() { - const unordered_set< shared_ptr > sigs(session_.signalbases()); + const vector< shared_ptr > sigs(session_.signalbases()); shared_ptr any_segment; shared_ptr lsegment; vector< shared_ptr > achannel_list; vector< shared_ptr > asegment_list; - for (shared_ptr signal : sigs) { + for (const shared_ptr& signal : sigs) { if (!signal->enabled()) continue; @@ -182,13 +184,27 @@ bool StoreSession::start() {{ConfigKey::SAMPLERATE, Glib::Variant::create( any_segment->samplerate())}}); output_->receive(meta); - } catch (Error error) { + } catch (Error& error) { error_ = tr("Error while saving: ") + error.what(); return false; } thread_ = std::thread(&StoreSession::store_proc, this, achannel_list, asegment_list, lsegment); + + // Save session setup if we're saving to srzip and the user wants it + GlobalSettings settings; + bool save_with_setup = settings.value(GlobalSettings::Key_General_SaveWithSetup).toBool(); + + if ((output_format_->name() == "srzip") && (save_with_setup)) { + QString setup_file_name = QString::fromStdString(file_name_); + setup_file_name.truncate(setup_file_name.lastIndexOf('.')); + setup_file_name.append(".pvs"); + + QSettings settings_storage(setup_file_name, QSettings::IniFormat); + session_.save_setup(settings_storage); + } + return true; } @@ -234,6 +250,7 @@ void StoreSession::store_proc(vector< shared_ptr > achannel_li const unsigned int samples_per_block = min(asamples_per_block, lsamples_per_block); + const auto context = session_.device_manager().context(); while (!interrupt_ && sample_count_) { progress_updated(); @@ -241,8 +258,6 @@ void StoreSession::store_proc(vector< shared_ptr > achannel_li min((uint64_t)samples_per_block, sample_count_); try { - const auto context = session_.device_manager().context(); - for (unsigned int i = 0; i < achannel_list.size(); i++) { shared_ptr achannel = (achannel_list.at(i))->channel(); shared_ptr asegment = asegment_list.at(i); @@ -276,7 +291,7 @@ void StoreSession::store_proc(vector< shared_ptr > achannel_li delete[] ldata; } - } catch (Error error) { + } catch (Error& error) { error_ = tr("Error while saving: ") + error.what(); break; } @@ -286,6 +301,15 @@ void StoreSession::store_proc(vector< shared_ptr > achannel_li units_stored_ = unit_count_ - (sample_count_ >> progress_scale); } + try { + auto dfend = context->create_end_packet(); + const string ldata_str = output_->receive(dfend); + if (output_stream_.is_open()) + output_stream_ << ldata_str; + } catch (Error& error) { + error_ = tr("Error while saving: ") + error.what(); + } + // Zeroing the progress variables indicates completion units_stored_ = unit_count_ = 0;