+void Session::load_init_file(const string &file_name, const string &format)
+{
+ shared_ptr<InputFormat> input_format;
+
+ if (!format.empty()) {
+ const map<string, shared_ptr<InputFormat> > formats =
+ device_manager_.context()->input_formats();
+ const auto iter = find_if(formats.begin(), formats.end(),
+ [&](const pair<string, shared_ptr<InputFormat> > f) {
+ return f.first == format; });
+ if (iter == formats.end()) {
+ main_bar_->session_error(tr("Error"),
+ tr("Unexpected input format: %s").arg(QString::fromStdString(format)));
+ return;
+ }
+
+ input_format = (*iter).second;
+ }
+
+ load_file(QString::fromStdString(file_name), input_format);
+}
+
+void Session::load_file(QString file_name,
+ shared_ptr<sigrok::InputFormat> format,
+ const map<string, Glib::VariantBase> &options)
+{
+ const QString errorMessage(
+ QString("Failed to load file %1").arg(file_name));
+
+ try {
+ if (format)
+ set_device(shared_ptr<devices::Device>(
+ new devices::InputFile(
+ device_manager_.context(),
+ file_name.toStdString(),
+ format, options)));
+ else
+ set_device(shared_ptr<devices::Device>(
+ new devices::SessionFile(
+ device_manager_.context(),
+ file_name.toStdString())));
+ } catch (Error e) {
+ main_bar_->session_error(tr("Failed to load ") + file_name, e.what());
+ set_default_device();
+ main_bar_->update_device_list();
+ return;
+ }
+
+ main_bar_->update_device_list();
+
+ start_capture([&, errorMessage](QString infoMessage) {
+ main_bar_->session_error(errorMessage, infoMessage); });
+
+ set_name(QFileInfo(file_name).fileName());
+}
+