From ade001359bdd2fd7c340d6bb89aede822eb74091 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Tue, 14 May 2024 16:57:01 +0400 Subject: [PATCH] Implemented loading virtual drives from JSON. --- src/applib/gsc_settings.h | 2 +- src/applib/smartctl_text_basic_parser.cpp | 2 +- src/applib/storage_device.cpp | 2 +- src/gsc_executor_log_window.cpp | 9 +++++---- src/gsc_info_window.cpp | 7 ++++--- src/gsc_main_window.cpp | 3 ++- src/gsc_text_window.h | 7 ++++--- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/applib/gsc_settings.h b/src/applib/gsc_settings.h index d6f35e8..499aeae 100644 --- a/src/applib/gsc_settings.h +++ b/src/applib/gsc_settings.h @@ -68,7 +68,7 @@ inline void init_default_settings() rconfig::set_default_data("gui/show_smart_capable_only", false); // show smart-capable drives only rconfig::set_default_data("gui/scan_on_startup", true); // scan drives on startup - rconfig::set_default_data("gui/smartctl_output_filename_format", "{model}_{serial}_{date}.txt"); // when suggesting filename + rconfig::set_default_data("gui/smartctl_output_filename_format", "{model}_{serial}_{date}.json"); // when suggesting filename rconfig::set_default_data("gui/icons_show_device_name", false); // text under icons rconfig::set_default_data("gui/icons_show_serial_number", false); // text under icons diff --git a/src/applib/smartctl_text_basic_parser.cpp b/src/applib/smartctl_text_basic_parser.cpp index 5cf3217..925e212 100644 --- a/src/applib/smartctl_text_basic_parser.cpp +++ b/src/applib/smartctl_text_basic_parser.cpp @@ -153,7 +153,7 @@ hz::ExpectedVoid SmartctlTextBasicParser::parse(std::string model = hz::string_remove_adjacent_duplicates_copy(hz::string_trim_copy(model), ' '); StorageProperty p; p.set_name("Device Model", "model_name", "Device Model"); - p.value = p.reported_value; // string-type value + p.value = model; // string-type value add_property(p); } else if (app_pcre_match("/^(?:Device|Product):[ \\t]*(.*)$/mi", output, &model)) { // usb flash drives diff --git a/src/applib/storage_device.cpp b/src/applib/storage_device.cpp index 815e1e4..9f6a8ef 100644 --- a/src/applib/storage_device.cpp +++ b/src/applib/storage_device.cpp @@ -417,7 +417,7 @@ hz::ExpectedVoid StorageDevice::parse_any_data_for_virtual() } // This will add some properties and emit signal_changed(). - auto basic_parse_status = this->parse_basic_data(); + auto basic_parse_status = basic_parser->parse(this->full_output_); if (!basic_parse_status) { return hz::Unexpected(StorageDeviceError::ParseError, std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(basic_parse_status.error().message()))); diff --git a/src/gsc_executor_log_window.cpp b/src/gsc_executor_log_window.cpp index a9b8aa1..1554a42 100644 --- a/src/gsc_executor_log_window.cpp +++ b/src/gsc_executor_log_window.cpp @@ -197,7 +197,8 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() int result = 0; const Glib::RefPtr specific_filter = Gtk::FileFilter::create(); - specific_filter->set_name(_("Text Files")); + specific_filter->set_name(_("JSON and Text Files")); + specific_filter->add_pattern("*.json"); specific_filter->add_pattern("*.txt"); const Glib::RefPtr all_filter = Gtk::FileFilter::create(); @@ -237,7 +238,7 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() if (!last_dir.empty()) dialog.set_current_folder(last_dir); - dialog.set_current_name(".txt"); + dialog.set_current_name(".json"); // Show the dialog and wait for a user response result = dialog.run(); // the main cycle blocks here @@ -257,8 +258,8 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); - if (file.extension() != ".txt") { - file += ".txt"; + if (file.extension() != ".json" && file.extension() != ".txt") { + file += ".json"; } auto ec = hz::fs_file_put_contents(file, entry->std_output); diff --git a/src/gsc_info_window.cpp b/src/gsc_info_window.cpp index eb764bc..695aa2f 100644 --- a/src/gsc_info_window.cpp +++ b/src/gsc_info_window.cpp @@ -836,7 +836,8 @@ void GscInfoWindow::on_save_info_button_clicked() const std::string filename = drive->get_save_filename(); Glib::RefPtr specific_filter = Gtk::FileFilter::create(); - specific_filter->set_name(_("Text Files")); + specific_filter->set_name(_("JSON and Text Files")); + specific_filter->add_pattern("*.json"); specific_filter->add_pattern("*.txt"); Glib::RefPtr all_filter = Gtk::FileFilter::create(); @@ -898,8 +899,8 @@ void GscInfoWindow::on_save_info_button_clicked() #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); - if (file.extension() != ".txt") { - file += ".txt"; + if (file.extension() != ".json" && file.extension() != ".txt") { + file += ".json"; } std::string data = this->drive->get_full_output(); diff --git a/src/gsc_main_window.cpp b/src/gsc_main_window.cpp index 3c82d5a..14399dc 100644 --- a/src/gsc_main_window.cpp +++ b/src/gsc_main_window.cpp @@ -1303,7 +1303,8 @@ void GscMainWindow::show_load_virtual_file_chooser() int result = 0; Glib::RefPtr specific_filter = Gtk::FileFilter::create(); - specific_filter->set_name(_("Text Files")); + specific_filter->set_name(_("JSON and Text Files")); + specific_filter->add_pattern("*.json"); specific_filter->add_pattern("*.txt"); Glib::RefPtr all_filter = Gtk::FileFilter::create(); diff --git a/src/gsc_text_window.h b/src/gsc_text_window.h index ae645ef..e18fc2e 100644 --- a/src/gsc_text_window.h +++ b/src/gsc_text_window.h @@ -159,7 +159,8 @@ class GscTextWindow : public AppBuilderWidget, Ins int result = 0; Glib::RefPtr specific_filter = Gtk::FileFilter::create(); - specific_filter->set_name(_("Text Files")); + specific_filter->set_name(_("JSON and Text Files")); + specific_filter->add_pattern("*.json"); specific_filter->add_pattern("*.txt"); Glib::RefPtr all_filter = Gtk::FileFilter::create(); @@ -221,8 +222,8 @@ class GscTextWindow : public AppBuilderWidget, Ins #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); - if (file.extension() != ".txt") { - file += ".txt"; + if (file.extension() != ".json" && file.extension() != ".txt") { + file += ".json"; } std::string text;