From c057c28743b45914a139af3b17e27d04cda141b1 Mon Sep 17 00:00:00 2001 From: Maciej Szeptuch Date: Sat, 28 Oct 2023 13:34:46 +0200 Subject: [PATCH] bunch more code smells --- .github/workflows/qt_update.yml | 5 ++ doc/screenshot.json | 9 ++- include/bootentry.h | 10 +-- include/bootentrylistmodel.h | 2 +- include/bootentrylistview.h | 2 +- include/commands.h | 21 ++---- include/compat.h | 18 +++++- include/devicepathview.h | 2 +- include/disableundoredo.h | 7 +- include/efiboot.h | 106 +++++++++++++++---------------- include/efibootdata.h | 4 +- include/efibooteditor.h | 2 +- include/efibooteditorcli.h | 6 +- include/filepathdialog.h | 6 +- include/qwidgetitemdelegate.h | 16 ++--- misc/qt-updater/requirements.txt | 14 ++-- src/bootentry.cpp | 38 +++++------ src/bootentrydelegate.cpp | 7 +- src/bootentrylistview.cpp | 8 +-- src/devicepathview.cpp | 1 - src/driveinfo.win32.cpp | 6 +- src/efibootdata.cpp | 51 +++++++-------- src/efibooteditor.cpp | 19 +++--- src/efibooteditorcli.cpp | 6 +- src/efivar-lite.darwin.c | 4 +- src/efivar-lite.win32.c | 2 +- src/filepathdialog.cpp | 11 ++-- 27 files changed, 186 insertions(+), 197 deletions(-) diff --git a/.github/workflows/qt_update.yml b/.github/workflows/qt_update.yml index 7f7eadd9..af4036dd 100644 --- a/.github/workflows/qt_update.yml +++ b/.github/workflows/qt_update.yml @@ -13,6 +13,11 @@ jobs: check-qt-updates: name: Check Qt updates runs-on: ubuntu-latest + + permissions: + actions: read + contents: read + steps: - name: Checkout source code uses: actions/checkout@v4 diff --git a/doc/screenshot.json b/doc/screenshot.json index 8ee18952..c9634c2e 100644 --- a/doc/screenshot.json +++ b/doc/screenshot.json @@ -1,4 +1,5 @@ { + "AuditMode": false, "Boot": { "0000": { "attributes": 1, @@ -10,7 +11,7 @@ "partition_number": 1, "partition_signature": "{721c8b66-426c-4e86-8e99-3457c46ab0b9}", "partition_size": "0x32", - "partition_start": "0x1cd6", + "partition_start": "0x1CD6", "signature_type": 2, "subtype": "HD", "type": "MEDIA" @@ -185,5 +186,9 @@ 0, 1 ], - "Timeout": 10 + "DeployedMode": false, + "SecureBoot": true, + "SetupMode": false, + "Timeout": 10, + "VendorKeys": false } diff --git a/include/bootentry.h b/include/bootentry.h index 44091e2c..d6876ec9 100644 --- a/include/bootentry.h +++ b/include/bootentry.h @@ -156,8 +156,8 @@ class IPv4 bool static_ip_address = false; public: - IPv4() = default; - IPv4(const EFIBoot::File_path::IPv4 &ipv4); + IPv4() noexcept = default; + IPv4(const EFIBoot::File_path::IPv4 &ipv4) noexcept; EFIBoot::File_path::IPv4 toEFIBootFilePath() const; static std::optional fromJSON(const QJsonObject &obj); @@ -186,8 +186,8 @@ class IPv6 QHostAddress gateway_ip_address = {}; public: - IPv6() = default; - IPv6(const EFIBoot::File_path::IPv6 &ipv6); + IPv6() noexcept = default; + IPv6(const EFIBoot::File_path::IPv6 &ipv6) noexcept; EFIBoot::File_path::IPv6 toEFIBootFilePath() const; static std::optional fromJSON(const QJsonObject &obj); @@ -353,7 +353,7 @@ class End mutable QString string = ""; public: - uint8_t _subtype = EFIBoot::File_path::End_entire::SUBTYPE; + uint8_t _subtype = 0; public: End() = default; diff --git a/include/bootentrylistmodel.h b/include/bootentrylistmodel.h index c3cc793d..a4489ba5 100644 --- a/include/bootentrylistmodel.h +++ b/include/bootentrylistmodel.h @@ -27,7 +27,7 @@ class BootEntryListModel: public QAbstractListModel friend class MoveBootEntryFilePathCommand; public: - enum Option + enum class Option : uint8_t { ReadOnly = 0x1, IsBoot = 0x2, diff --git a/include/bootentrylistview.h b/include/bootentrylistview.h index 9513b0b3..b82d6f80 100644 --- a/include/bootentrylistview.h +++ b/include/bootentrylistview.h @@ -19,7 +19,7 @@ class BootEntryListView: public QListView BootEntryListView(const BootEntryListView &) = delete; BootEntryListView &operator=(const BootEntryListView &) = delete; - virtual void setModel(QAbstractItemModel *model) override { QListView::setModel(model); } + void setModel(QAbstractItemModel *model) override { QListView::setModel(model); } void setModel(BootEntryListModel *model); protected: diff --git a/include/commands.h b/include/commands.h index c535ec61..c169f97a 100644 --- a/include/commands.h +++ b/include/commands.h @@ -4,11 +4,10 @@ #include "efibootdata.h" #include -template +template class SetEFIBootDataValueCommand: public QUndoCommand { using PropertyPtr = Type EFIBootData::*; - using SignalPtr = void (EFIBootData::*)(const Type &); EFIBootData &data; const QString name; @@ -50,7 +49,7 @@ class SetEFIBootDataValueCommand: public QUndoCommand bool mergeWith(const QUndoCommand *command) override { - auto cmd = static_cast *>(command); + const auto cmd = static_cast>(command); if(&cmd->data != &data) return false; @@ -129,18 +128,6 @@ class MoveBootEntryCommand: public QUndoCommand bool mergeWith(const QUndoCommand *command) override; }; -template -struct type_identity -{ - using type = Type; -}; - -template -struct underlying_type -{ - using type = typename std::conditional_t, std::underlying_type, type_identity>::type; -}; - template class SetBootEntryValueCommand: public QUndoCommand { @@ -163,7 +150,7 @@ class SetBootEntryValueCommand: public QUndoCommand , property{property_} , value{value_} { - setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast::type>(value))); + setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast>(value))); } SetBootEntryValueCommand(const SetBootEntryValueCommand &) = delete; @@ -204,7 +191,7 @@ class SetBootEntryValueCommand: public QUndoCommand if(value == entry.*property) setObsolete(true); - setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast::type>(entry.*property))); + setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast>(entry.*property))); return true; } }; diff --git a/include/compat.h b/include/compat.h index 617aa49b..96647d64 100644 --- a/include/compat.h +++ b/include/compat.h @@ -194,9 +194,9 @@ inline bool toUnicode(QString &output, const Container &input, const char *codec output = decoder.decode(input); return !decoder.hasError(); #else - QTextCodec *codec = QTextCodec::codecForName(codec_name); + auto codec = QTextCodec::codecForName(codec_name); QTextCodec::ConverterState state; - output = codec->toUnicode(reinterpret_cast(input.data()), static_cast(input.size()), &state); + output = codec->toUnicode(reinterpret_cast(std::data(input)), static_cast(std::size(input)), &state); return state.invalidChars == 0; #endif } @@ -211,6 +211,20 @@ inline QByteArray fromUnicode(const QString &input, const char *codec_name = "UT return encoder->fromUnicode(input); #endif } + +template +struct type_identity +{ + using type = Type; +}; + +// Like std::underlying_type but also works for non enums +template +using underlying_type_t = typename std::conditional_t, std::underlying_type, type_identity>::type; + +// like std::add_const but forces const also for pointer types +template +using add_const_t = typename std::conditional_t, std::add_pointer_t>>, std::add_const_t>; #endif #if defined(__clang__) diff --git a/include/devicepathview.h b/include/devicepathview.h index eb28ae35..03637697 100644 --- a/include/devicepathview.h +++ b/include/devicepathview.h @@ -10,7 +10,7 @@ class DevicePathView: public QListView Q_OBJECT private: - FilePathDelegate delegate; + FilePathDelegate delegate{}; std::unique_ptr dialog = nullptr; bool readonly = false; diff --git a/include/disableundoredo.h b/include/disableundoredo.h index 79edb0cd..304a92a3 100644 --- a/include/disableundoredo.h +++ b/include/disableundoredo.h @@ -9,12 +9,9 @@ class DisableUndoRedo: public QObject { Q_OBJECT -public: - explicit DisableUndoRedo(QObject *parent = nullptr) - : QObject{parent} - { - } + using QObject::QObject; +public: DisableUndoRedo(const DisableUndoRedo &) = delete; DisableUndoRedo &operator=(const DisableUndoRedo &) = delete; diff --git a/include/efiboot.h b/include/efiboot.h index d555bb0f..9cc2f4e6 100644 --- a/include/efiboot.h +++ b/include/efiboot.h @@ -268,8 +268,6 @@ struct Load_option Load_option_attribute attributes = Load_option_attribute::EMPTY; }; -using Advance_fn = std::function; -using Size_fn = std::function; using Progress_fn = std::function; template @@ -280,8 +278,8 @@ std::optional init(); template std::optional> deserialize_list(const void *data, size_t data_size); -template -std::optional> deserialize_list_ex(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element); +template +std::optional> deserialize_list_ex(const void *data, size_t data_size, const Size_fn &get_element_size, const Advance_fn &get_next_element); template size_t serialize(Raw_data &output, const Type &value); @@ -302,8 +300,8 @@ std::optional> get_variable(const efi_guid_t &guid, const tstring template std::optional>> get_list_variable(const efi_guid_t &guid, const tstring &name); -template -std::optional>> get_list_variable_ex(const efi_guid_t &guid, const tstring &name, Size_fn get_element_size, Advance_fn get_next_element); +template +std::optional>> get_list_variable_ex(const efi_guid_t &guid, const tstring &name, const Size_fn &get_element_size, const Advance_fn &get_next_element); template bool set_variable(const efi_guid_t &guid, const tstring &name, const Variable &variable, mode_t mode); @@ -407,8 +405,8 @@ inline size_t serialize(Raw_data &output, const std::u16string &value) return bytes; } -template -inline std::optional> deserialize_list_ex(const void *data, size_t data_size, Size_fn get_element_size, Advance_fn get_next_element) +template +inline std::optional> deserialize_list_ex(const void *data, size_t data_size, const Size_fn &get_element_size, const Advance_fn &get_next_element) { std::vector values; const void *data_end = advance_bytes(data, data_size); @@ -436,11 +434,11 @@ inline std::optional> deserialize_list(const void *data, size_ { return deserialize_list_ex( data, data_size, - [](const void *) -> size_t + [](const void *) { return sizeof(Type); }, - [](const void *ptr, size_t) -> const void * + [](const void *ptr, size_t) { return advance_bytes(ptr, sizeof(const Type)); }); @@ -459,7 +457,7 @@ size_t serialize_list(Raw_data &output, const std::vector &value) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_header *dp = static_cast(data); + auto dp = static_cast(data); if(dp->length != data_size) return std::nullopt; @@ -481,7 +479,7 @@ inline size_t serialize(Raw_data &output, const File_path::End_instance &) bytes += serialize(output, type); uint8_t subtype = File_path::End_instance::SUBTYPE; bytes += serialize(output, subtype); - uint16_t length = static_cast(bytes + sizeof(uint16_t)); + auto length = static_cast(bytes + sizeof(uint16_t)); bytes += serialize(output, length); return bytes; } @@ -489,7 +487,7 @@ inline size_t serialize(Raw_data &output, const File_path::End_instance &) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_header *dp = static_cast(data); + auto dp = static_cast(data); if(dp->length != data_size) return std::nullopt; @@ -511,7 +509,7 @@ inline size_t serialize(Raw_data &output, const File_path::End_entire &) bytes += serialize(output, type); uint8_t subtype = File_path::End_entire::SUBTYPE; bytes += serialize(output, subtype); - uint16_t length = static_cast(bytes + sizeof(uint16_t)); + auto length = static_cast(bytes + sizeof(uint16_t)); bytes += serialize(output, length); return bytes; } @@ -520,8 +518,8 @@ template <> inline std::optional deserialize(const void *data, size_t data_size) { Load_option value{}; - ssize_t ssize = static_cast(data_size); - efi_load_option *load_option = const_cast(static_cast(data)); + auto ssize = static_cast(data_size); + auto load_option = const_cast(static_cast(data)); #if defined(__clang__) #pragma clang diagnostic push @@ -538,14 +536,14 @@ inline std::optional deserialize(const void *data, size_t data_size auto file_paths = deserialize_list_ex( device_path, device_path_size, - [](const void *ptr) -> size_t + [](const void *ptr) { auto size = efidp_node_size(static_cast(ptr)); return static_cast(size); }, [](const void *ptr, size_t bytes_left) -> const void * { - const_efidp dp = static_cast(ptr); + auto dp = static_cast(ptr); ssize_t size = efidp_node_size(dp); if(size < 0 || static_cast(size) > bytes_left) return nullptr; @@ -584,20 +582,19 @@ inline size_t serialize(Raw_data &output, const Load_option &load_option) size += serialize(output, load_option.description); std::u16string::value_type zero = 0; size += serialize(output, zero); + + file_path_list_size = static_cast(serialize_list(output, load_option.device_path)); + // Always set END_ENTIRE tag at the end of device path + if(!load_option.device_path.size() || std::visit([](const auto &file_path) + { return file_path.SUBTYPE; }, + load_option.device_path.back()) + != File_path::End_entire::SUBTYPE) { - file_path_list_size = static_cast(serialize_list(output, load_option.device_path)); - // Always set END_ENTIRE tag at the end of device path - if(!load_option.device_path.size() || std::visit([](const auto &file_path) - { return file_path.SUBTYPE; }, - load_option.device_path.back()) - != File_path::End_entire::SUBTYPE) - { - File_path::End_entire end{}; - file_path_list_size = static_cast(file_path_list_size + static_cast(serialize(output, end))); // Older GCC complains about conversion when using += `conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value` - } - size += file_path_list_size; - memcpy(&output[file_path_list_length_pos], &file_path_list_size, sizeof(file_path_list_size)); + File_path::End_entire end{}; + file_path_list_size = static_cast(file_path_list_size + static_cast(serialize(output, end))); // Older GCC complains about conversion when using += `conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value` } + size += file_path_list_size; + memcpy(&output[file_path_list_length_pos], &file_path_list_size, sizeof(file_path_list_size)); size += serialize(output, load_option.optional_data); return size; @@ -606,7 +603,7 @@ inline size_t serialize(Raw_data &output, const Load_option &load_option) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_pci *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -643,7 +640,7 @@ inline size_t serialize(Raw_data &output, const File_path::PCI &pci) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_vendor *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -682,7 +679,7 @@ inline size_t serialize(Raw_data &output, const File_path::HWVendor &vendor) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_hid *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -719,7 +716,7 @@ inline size_t serialize(Raw_data &output, const File_path::HID &hid) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_usb *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -756,7 +753,7 @@ inline size_t serialize(Raw_data &output, const File_path::USB &usb) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_vendor *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -795,7 +792,7 @@ inline size_t serialize(Raw_data &output, const File_path::MSGVendor &vendor) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_mac_address *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -832,7 +829,7 @@ inline size_t serialize(Raw_data &output, const File_path::MAC_address &mac_addr template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_ipv4 *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -881,7 +878,7 @@ inline size_t serialize(Raw_data &output, const File_path::IPv4 &ipv4) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_ipv6 *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -930,7 +927,7 @@ inline size_t serialize(Raw_data &output, const File_path::IPv6 &ipv6) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_sata *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -969,7 +966,7 @@ inline size_t serialize(Raw_data &output, const File_path::SATA &sata) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_hd *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1014,7 +1011,7 @@ inline size_t serialize(Raw_data &output, const File_path::HD &hd) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_vendor *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1053,7 +1050,7 @@ inline size_t serialize(Raw_data &output, const File_path::MEDIAVendor &vendor) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_file *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1090,7 +1087,7 @@ inline size_t serialize(Raw_data &output, const File_path::File &file) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_firmware_file *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1125,7 +1122,7 @@ inline size_t serialize(Raw_data &output, const File_path::Firmware_file &firmwa template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_firmware_volume *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1160,7 +1157,7 @@ inline size_t serialize(Raw_data &output, const File_path::Firmware_volume &firm template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_bios_boot_specification *dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1201,7 +1198,7 @@ inline size_t serialize(Raw_data &output, const File_path::BIOS_boot_specificati template <> inline std::optional deserialize(const void *data, size_t data_size) { - const efidp_header *dp = static_cast(data); + auto dp = static_cast(data); if(dp->length != data_size) return std::nullopt; @@ -1233,7 +1230,7 @@ inline size_t serialize(Raw_data &output, const File_path::Unknown &unknown) template <> inline std::optional deserialize(const void *data, size_t data_size) { - const_efidp dp = static_cast(data); + auto dp = static_cast(data); if(dp->header.length != data_size) return std::nullopt; @@ -1288,7 +1285,7 @@ inline std::unordered_map get_variables(const Filter_fn &fi TCHAR *name = nullptr; _get_variables_progress_fn = progress_fn; efi_set_get_next_variable_name_progress_cb([](size_t step, size_t total) noexcept - { try { if(_get_variables_progress_fn)_get_variables_progress_fn(step, total); } catch (...) {} }); + { try { if(_get_variables_progress_fn)_get_variables_progress_fn(step, total); } catch (...) {/* ignore */} }); while(efi_get_next_variable_name(&guid, &name) > 0) { @@ -1323,8 +1320,7 @@ inline std::optional> get_variable(const efi_guid_t &guid, const uint8_t *data = nullptr; size_t data_size = 0; uint32_t attributes = 0; - int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); - if(ret < 0) + if(int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); ret < 0) return std::nullopt; auto value = deserialize(data, data_size); @@ -1340,8 +1336,7 @@ inline std::optional>> get_list_variable(const efi_gu uint8_t *data = nullptr; size_t data_size = 0; uint32_t attributes = 0; - int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); - if(ret < 0) + if(int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); ret < 0) return std::nullopt; auto value = deserialize_list(data, data_size); @@ -1351,14 +1346,13 @@ inline std::optional>> get_list_variable(const efi_gu return {{*value, attributes}}; } -template -inline std::optional>> get_list_variable_ex(const efi_guid_t &guid, const tstring &name, Size_fn get_element_size, Advance_fn get_next_element) +template +inline std::optional>> get_list_variable_ex(const efi_guid_t &guid, const tstring &name, const Size_fn &get_element_size, const Advance_fn &get_next_element) { uint8_t *data = nullptr; size_t data_size = 0; uint32_t attributes = 0; - int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); - if(ret < 0) + if(int ret = efi_get_variable(guid, name.c_str(), &data, &data_size, &attributes); ret < 0) return std::nullopt; auto value = deserialize_list_ex(data, data_size, get_element_size, get_next_element); diff --git a/include/efibootdata.h b/include/efibootdata.h index 8488c56a..d35c9a5d 100644 --- a/include/efibootdata.h +++ b/include/efibootdata.h @@ -11,10 +11,10 @@ class EFIBootData: public QObject Q_OBJECT public: - BootEntryListModel boot_entries_list_model{tr("Boot"), BootEntryListModel::IsBoot, this}; + BootEntryListModel boot_entries_list_model{tr("Boot"), BootEntryListModel::Option::IsBoot, this}; BootEntryListModel driver_entries_list_model{tr("Driver"), {}, this}; BootEntryListModel sysprep_entries_list_model{tr("System Preparation"), {}, this}; - BootEntryListModel platform_recovery_entries_list_model{tr("Platform Recovery"), BootEntryListModel::ReadOnly, this}; + BootEntryListModel platform_recovery_entries_list_model{tr("Platform Recovery"), BootEntryListModel::Option::ReadOnly, this}; const std::vector> BOOT_ENTRIES{ {"Boot", boot_entries_list_model}, diff --git a/include/efibooteditor.h b/include/efibooteditor.h index 0792565f..171bb1b6 100644 --- a/include/efibooteditor.h +++ b/include/efibooteditor.h @@ -37,7 +37,7 @@ class EFIBootEditor: public QMainWindow std::unique_ptr confirmation; std::unique_ptr error; std::unique_ptr progress; - std::unique_ptr disable_undo_redo; + std::unique_ptr disable_undo_redo{std::make_unique()}; QUndoStack undo_stack{this}; diff --git a/include/efibooteditorcli.h b/include/efibooteditorcli.h index 933671db..73c65d1e 100644 --- a/include/efibooteditorcli.h +++ b/include/efibooteditorcli.h @@ -32,7 +32,7 @@ class EFIBootEditorCLI: public QObject bool process(const QCoreApplication &app); public slots: - void showError(const QString &message, const QString &details); - void showProgress(size_t step, size_t total, const QString &details); - void hideProgress(); + void showError(const QString &message, const QString &details) const; + void showProgress(size_t step, size_t total, const QString &details) const; + void hideProgress() const; }; diff --git a/include/filepathdialog.h b/include/filepathdialog.h index 4340c04e..17edee53 100644 --- a/include/filepathdialog.h +++ b/include/filepathdialog.h @@ -66,10 +66,10 @@ class FilePathDialog: public QDialog using VendorDataFormat = DataFormat; using UnknownDataFormat = DataFormat; - HorizontalTabStyle horizontal_tab_style; + HorizontalTabStyle horizontal_tab_style{}; std::unique_ptr ui; - int vendor_data_format_combo_index; - int unknown_data_format_combo_index; + int vendor_data_format_combo_index = 0; + int unknown_data_format_combo_index = 0; public: explicit FilePathDialog(QWidget *parent = nullptr); diff --git a/include/qwidgetitemdelegate.h b/include/qwidgetitemdelegate.h index 989b6015..9ed02239 100644 --- a/include/qwidgetitemdelegate.h +++ b/include/qwidgetitemdelegate.h @@ -18,9 +18,9 @@ class QWidgetItemDelegate: public QStyledItemDelegate private: friend class Guard; - mutable Widget renderer; - mutable Widget painter; - Widget event_handler; + mutable Widget renderer{}; + mutable Widget painter{}; + Widget event_handler{}; public: explicit QWidgetItemDelegate(QObject *parent = nullptr); @@ -30,7 +30,7 @@ class QWidgetItemDelegate: public QStyledItemDelegate void paint(QPainter *_painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; - virtual void setupWidgetFromItem(Widget &, const Item &) const { } + virtual void setupWidgetFromItem(Widget &, const Item &) const { return; } virtual bool handleWidgetDelegateEventResult(const QEvent *, QAbstractItemModel *, const QStyleOptionViewItem &, const QModelIndex &, const Widget &, bool result) const { return result; } protected: @@ -40,9 +40,6 @@ class QWidgetItemDelegate: public QStyledItemDelegate template QWidgetItemDelegate::QWidgetItemDelegate(QObject *parent) : QStyledItemDelegate(parent) - , renderer() - , painter() - , event_handler() { } @@ -94,10 +91,9 @@ bool QWidgetItemDelegate::editorEvent(QEvent *event, QAbstractItem event_handler.setGeometry(option.rect); event_handler.grab(); // force layout - const auto passthrough_events = {QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, QEvent::MouseMove}; - if(std::find(std::begin(passthrough_events), std::end(passthrough_events), event->type()) != std::end(passthrough_events)) + if(const auto passthrough_events = {QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, QEvent::MouseMove}; std::find(std::begin(passthrough_events), std::end(passthrough_events), event->type()) != std::end(passthrough_events)) { - QMouseEvent *mouse_event = static_cast(event); + auto mouse_event = static_cast(event); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) auto position = event_handler.mapFromParent(mouse_event->position()); QWidget *child = event_handler.childAt(position.toPoint()); diff --git a/misc/qt-updater/requirements.txt b/misc/qt-updater/requirements.txt index 6ba90e12..13476520 100644 --- a/misc/qt-updater/requirements.txt +++ b/misc/qt-updater/requirements.txt @@ -4,13 +4,13 @@ # # pip-compile --all-extras --output-file=requirements.txt pyproject.toml # -black==23.9.1 +black==23.10.1 # via qt-updater (pyproject.toml) build==1.0.3 # via pip-tools certifi==2023.7.22 # via requests -charset-normalizer==3.3.0 +charset-normalizer==3.3.1 # via requests click==8.1.7 # via @@ -18,7 +18,7 @@ click==8.1.7 # pip-tools idna==3.4 # via requests -mypy==1.6.0 +mypy==1.6.1 # via qt-updater (pyproject.toml) mypy-extensions==1.0.0 # via @@ -38,17 +38,17 @@ pyproject-hooks==1.0.0 # via build requests==2.31.0 # via qt-updater (pyproject.toml) -ruamel-yaml==0.17.35 +ruamel-yaml==0.18.2 # via qt-updater (pyproject.toml) ruamel-yaml-clib==0.2.8 # via ruamel-yaml -ruff==0.0.292 +ruff==0.1.3 # via qt-updater (pyproject.toml) -types-requests==2.31.0.8 +types-requests==2.31.0.10 # via qt-updater (pyproject.toml) typing-extensions==4.8.0 # via mypy -urllib3==2.0.6 +urllib3==2.0.7 # via # requests # types-requests diff --git a/src/bootentry.cpp b/src/bootentry.cpp index 0fbd22d1..913ff85f 100644 --- a/src/bootentry.cpp +++ b/src/bootentry.cpp @@ -26,16 +26,11 @@ auto BootEntry::fromEFIBootLoadOption( value.description = QString::fromStdU16String(load_option.description); value.optional_data_format = OptionalDataFormat::Base64; - { - if(toUnicode(value.optional_data, load_option.optional_data, "UTF-8") && !value.optional_data.contains(QChar(0))) - value.optional_data_format = OptionalDataFormat::Utf8; - } + if(toUnicode(value.optional_data, load_option.optional_data, "UTF-8") && !value.optional_data.contains(QChar(0))) + value.optional_data_format = OptionalDataFormat::Utf8; - if(value.optional_data_format == OptionalDataFormat::Base64 && load_option.optional_data.size() % sizeof(char16_t) == 0) - { - if(toUnicode(value.optional_data, load_option.optional_data, "UTF-16") && !value.optional_data.contains(QChar(0))) - value.optional_data_format = OptionalDataFormat::Utf16; - } + if(value.optional_data_format == OptionalDataFormat::Base64 && load_option.optional_data.size() % sizeof(char16_t) == 0 && toUnicode(value.optional_data, load_option.optional_data, "UTF-16") && !value.optional_data.contains(QChar(0))) + value.optional_data_format = OptionalDataFormat::Utf16; if(value.optional_data_format == OptionalDataFormat::Base64) value.optional_data = QByteArray::fromRawData(reinterpret_cast(load_option.optional_data.data()), static_cast(load_option.optional_data.size())).toBase64(); @@ -160,7 +155,7 @@ auto BootEntry::changeOptionalDataFormat(BootEntry::OptionalDataFormat format, b auto bytes = getRawOptionalData(); QString temp_optional_data; - switch(static_cast(format)) + switch(format) { case OptionalDataFormat::Base64: temp_optional_data = bytes.toBase64(); @@ -200,7 +195,7 @@ auto BootEntry::changeOptionalDataFormat(BootEntry::OptionalDataFormat format, b auto BootEntry::getRawOptionalData() const -> QByteArray { QByteArray bytes; - switch(static_cast(optional_data_format)) + switch(optional_data_format) { case OptionalDataFormat::Base64: bytes = QByteArray::fromBase64(optional_data.toUtf8()); @@ -353,7 +348,7 @@ static_assert(sizeof(File_path::Vendor::guid) == sizeof(EFIBoot::File_path::MEDI File_path::Vendor::Vendor(const EFIBoot::File_path::HWVendor &vendor) : data{QByteArray::fromRawData(reinterpret_cast(vendor.data.data()), static_cast(vendor.data.size()))} - , _type{vendor.TYPE} + , _type{EFIBoot::File_path::HWVendor::TYPE} { data.detach(); static_assert(sizeof(vendor.guid) == sizeof(guid)); @@ -362,7 +357,7 @@ File_path::Vendor::Vendor(const EFIBoot::File_path::HWVendor &vendor) File_path::Vendor::Vendor(const EFIBoot::File_path::MSGVendor &vendor) : data{QByteArray::fromRawData(reinterpret_cast(vendor.data.data()), static_cast(vendor.data.size()))} - , _type{vendor.TYPE} + , _type{EFIBoot::File_path::MSGVendor::TYPE} { data.detach(); static_assert(sizeof(vendor.guid) == sizeof(guid)); @@ -371,7 +366,7 @@ File_path::Vendor::Vendor(const EFIBoot::File_path::MSGVendor &vendor) File_path::Vendor::Vendor(const EFIBoot::File_path::MEDIAVendor &vendor) : data{QByteArray::fromRawData(reinterpret_cast(vendor.data.data()), static_cast(vendor.data.size()))} - , _type{vendor.TYPE} + , _type{EFIBoot::File_path::MEDIAVendor::TYPE} { data.detach(); static_assert(sizeof(vendor.guid) == sizeof(guid)); @@ -411,9 +406,10 @@ auto File_path::Vendor::toEFIBootFilePath() const -> EFIBoot::File_path::ANY std::copy(std::begin(data), std::end(data), std::begin(value.data)); return value; } - } - return {}; + default: + return {}; + } } auto File_path::Vendor::fromJSON(const QJsonObject &obj) -> std::optional @@ -444,7 +440,7 @@ auto File_path::Vendor::toString(bool refresh) const -> QString if(string.size() && !refresh) return string; - const char *type_string = "Unk"; + const char *type_string = nullptr; switch(_type) { case EFIBoot::File_path::HWVendor::TYPE: @@ -458,6 +454,10 @@ auto File_path::Vendor::toString(bool refresh) const -> QString case EFIBoot::File_path::MEDIAVendor::TYPE: type_string = "Media"; break; + + default: + type_string = "Unk"; + break; } return string = QString("Ven%1(%2,[%3B])").arg(type_string, guid.toString(QUuid::WithoutBraces)).arg(data.size()); @@ -510,7 +510,7 @@ static_assert(sizeof(File_path::IPv4::remote_ip_address.toIPv4Address()) == size static_assert(sizeof(File_path::IPv4::gateway_ip_address.toIPv4Address()) == sizeof(EFIBoot::File_path::IPv4::gateway_ip_address)); static_assert(sizeof(File_path::IPv4::subnet_mask.toIPv4Address()) == sizeof(EFIBoot::File_path::IPv4::subnet_mask)); -File_path::IPv4::IPv4(const EFIBoot::File_path::IPv4 &ipv4) +File_path::IPv4::IPv4(const EFIBoot::File_path::IPv4 &ipv4) noexcept : local_ip_address{*reinterpret_cast(ipv4.local_ip_address.data())} , remote_ip_address{*reinterpret_cast(ipv4.remote_ip_address.data())} , gateway_ip_address{*reinterpret_cast(ipv4.gateway_ip_address.data())} @@ -587,7 +587,7 @@ static_assert(sizeof(File_path::IPv6::local_ip_address.toIPv6Address()) == sizeo static_assert(sizeof(File_path::IPv6::remote_ip_address.toIPv6Address()) == sizeof(EFIBoot::File_path::IPv6::remote_ip_address)); static_assert(sizeof(File_path::IPv6::gateway_ip_address.toIPv6Address()) == sizeof(EFIBoot::File_path::IPv6::gateway_ip_address)); -File_path::IPv6::IPv6(const EFIBoot::File_path::IPv6 &ipv6) +File_path::IPv6::IPv6(const EFIBoot::File_path::IPv6 &ipv6) noexcept : local_ip_address{ipv6.local_ip_address.data()} , remote_ip_address{ipv6.remote_ip_address.data()} , local_port{ipv6.local_port} diff --git a/src/bootentrydelegate.cpp b/src/bootentrydelegate.cpp index a2ea98e9..407c8aa9 100644 --- a/src/bootentrydelegate.cpp +++ b/src/bootentrydelegate.cpp @@ -11,13 +11,13 @@ void BootEntryDelegate::setOptions(const BootEntryListModel::Options &options_) void BootEntryDelegate::setupWidgetFromItem(Widget &widget, const Item &item) const { - widget.setReadOnly(options & BootEntryListModel::ReadOnly); + widget.setReadOnly(options & BootEntryListModel::Option::ReadOnly); widget.setIndex(item->index); widget.setDescription(item->description); widget.setData(!item->is_error ? item->optional_data : item->error); widget.showDevicePath(!item->is_error); widget.setDevicePath(item->formatDevicePath(false)); - widget.showBootOptions(options & BootEntryListModel::IsBoot); + widget.showBootOptions(options & BootEntryListModel::Option::IsBoot); widget.setCurrentBoot(item->is_current_boot); widget.setNextBoot(item->is_next_boot); } @@ -27,8 +27,7 @@ auto BootEntryDelegate::handleWidgetDelegateEventResult(const QEvent *event, QAb if(event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease) return result; - auto item = index.data().value(); - if(widget.getNextBoot() != item->is_next_boot) + if(auto item = index.data().value(); widget.getNextBoot() != item->is_next_boot) { auto entries_list_model = static_cast(model); entries_list_model->setNextBootEntry(index, widget.getNextBoot()); diff --git a/src/bootentrylistview.cpp b/src/bootentrylistview.cpp index cfe2bb53..ee9beffa 100644 --- a/src/bootentrylistview.cpp +++ b/src/bootentrylistview.cpp @@ -22,7 +22,7 @@ void BootEntryListView::setModel(BootEntryListModel *model) void BootEntryListView::insertRow() { - if(options & BootEntryListModel::ReadOnly) + if(options & BootEntryListModel::Option::ReadOnly) return; auto row = currentIndex().row(); @@ -32,7 +32,7 @@ void BootEntryListView::insertRow() void BootEntryListView::removeCurrentRow() { - if(options & BootEntryListModel::ReadOnly) + if(options & BootEntryListModel::Option::ReadOnly) return; auto index = currentIndex(); @@ -50,7 +50,7 @@ void BootEntryListView::removeCurrentRow() void BootEntryListView::moveCurrentRowUp() { - if(options & BootEntryListModel::ReadOnly) + if(options & BootEntryListModel::Option::ReadOnly) return; auto index = currentIndex(); @@ -64,7 +64,7 @@ void BootEntryListView::moveCurrentRowUp() void BootEntryListView::moveCurrentRowDown() { - if(options & BootEntryListModel::ReadOnly) + if(options & BootEntryListModel::Option::ReadOnly) return; auto index = currentIndex(); diff --git a/src/devicepathview.cpp b/src/devicepathview.cpp index 592c93f2..410ef29d 100644 --- a/src/devicepathview.cpp +++ b/src/devicepathview.cpp @@ -4,7 +4,6 @@ DevicePathView::DevicePathView(QWidget *parent) : QListView(parent) - , delegate{} , dialog{std::make_unique(this)} { setItemDelegate(&delegate); diff --git a/src/driveinfo.win32.cpp b/src/driveinfo.win32.cpp index f6b99692..d98248ea 100644 --- a/src/driveinfo.win32.cpp +++ b/src/driveinfo.win32.cpp @@ -12,7 +12,7 @@ QVector DriveInfo::getAll(bool refresh) all.clear(); - std::array volume_name; + std::array volume_name{}; HANDLE volume_handle = FindFirstVolume(volume_name.data(), static_cast(volume_name.size())); if(volume_handle == INVALID_HANDLE_VALUE) @@ -21,7 +21,7 @@ QVector DriveInfo::getAll(bool refresh) for(BOOL volume_found = true; volume_found; volume_found = FindNextVolume(volume_handle, volume_name.data(), static_cast(volume_name.size()))) { DriveInfo driveinfo{}; - std::array device_name; + std::array device_name{}; size_t length = _tcsnccnt(volume_name.data(), volume_name.size()); if(length != 49u) continue; @@ -32,7 +32,7 @@ QVector DriveInfo::getAll(bool refresh) volume_name[length - 1u] = _T('\\'); - PARTITION_INFORMATION_EX partition_information; + PARTITION_INFORMATION_EX partition_information{}; device_name[4] = _T('\\'); device_name[5] = _T('\\'); diff --git a/src/efibootdata.cpp b/src/efibootdata.cpp index 0b9ab8f8..670df4f8 100644 --- a/src/efibootdata.cpp +++ b/src/efibootdata.cpp @@ -14,10 +14,7 @@ static bool is_bootentry(const tstring_view &name, const tstring_view &prefix) return false; auto suffix = name.substr(prefix.length()); - if(!isxnumber(suffix)) - return false; - - return true; + return isxnumber(suffix); } EFIBootData::EFIBootData(QObject *parent) @@ -206,7 +203,7 @@ void EFIBootData::reload() if(!is_bootentry(tname, QStringToStdTString(prefix))) continue; - const uint16_t index = static_cast(std::stoul(tname.substr(static_cast(prefix.size())), nullptr, HEX_BASE)); + const auto index = static_cast(std::stoul(tname.substr(static_cast(prefix.size())), nullptr, HEX_BASE)); if(ordered_entry.count(index)) continue; @@ -227,7 +224,7 @@ void EFIBootData::reload() auto entry = BootEntry::fromEFIBootLoadOption(value); entry.index = index; entry.efi_attributes = attributes; - if(model.options & BootEntryListModel::IsBoot) + if(model.options & BootEntryListModel::Option::IsBoot) { entry.is_current_boot = current_boot == static_cast(index); entry.is_next_boot = next_boot == static_cast(index); @@ -239,7 +236,7 @@ void EFIBootData::reload() errors.push_back(error); auto entry = BootEntry::fromError(error); entry.index = index; - if(model.options & BootEntryListModel::IsBoot) + if(model.options & BootEntryListModel::Option::IsBoot) { entry.is_current_boot = current_boot == static_cast(index); entry.is_next_boot = next_boot == static_cast(index); @@ -251,8 +248,7 @@ void EFIBootData::reload() // Apple emit progress(step++, total_steps, tr("Processing EFI Boot Manager entries (%1)…").arg("Apple/boot-args")); - const auto boot_args = EFIBoot::get_variable(EFIBoot::efi_guid_apple, _T("boot-args")); - if(boot_args) + if(const auto boot_args = EFIBoot::get_variable(EFIBoot::efi_guid_apple, _T("boot-args")); boot_args) { const auto &[value, attributes] = *boot_args; (void)attributes; @@ -278,7 +274,7 @@ void EFIBootData::save() for(const auto &[prefix, model]: BOOT_ENTRIES) { - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) continue; if(is_bootentry(tname, QStringToStdTString(prefix))) @@ -304,7 +300,7 @@ void EFIBootData::save() // Save entries for(const auto &[prefix, model]: BOOT_ENTRIES) { - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) continue; const QString order_name = QString("%1Order").arg(prefix); @@ -595,7 +591,7 @@ void EFIBootData::export_(const QString &file_name) if((entry.attributes & EFIBoot::Load_option_attribute::CATEGORY_MASK) == EFIBoot::Load_option_attribute::CATEGORY_BOOT) { order.push_back(entry.index); - if(model.options & BootEntryListModel::IsBoot) + if(model.options & BootEntryListModel::Option::IsBoot) { if(entry.is_current_boot) current_boot = entry.index; @@ -635,8 +631,7 @@ void EFIBootData::export_(const QString &file_name) output["Apple"] = apple; } - QJsonDocument json_document(output); - if(!export_file.write(json_document.toJson())) + if(QJsonDocument json_document(output); !export_file.write(json_document.toJson())) { emit error(tr("Error exporting boot configuration"), tr("Couldn't write into file (%1): %2.").arg(file_name, export_file.errorString())); return; @@ -728,8 +723,7 @@ void EFIBootData::dump(const QString &file_name) // Apple emit progress(step++, total_steps, tr("Exporting EFI Boot Manager entries (%1)…").arg("Apple/boot-args")); - const auto boot_args = EFIBoot::get_variable(EFIBoot::efi_guid_apple, _T("boot-args")); - if(boot_args) + if(const auto boot_args = EFIBoot::get_variable(EFIBoot::efi_guid_apple, _T("boot-args")); boot_args) { QJsonObject apple; const auto &[value, attributes] = *boot_args; @@ -740,8 +734,7 @@ void EFIBootData::dump(const QString &file_name) output["Apple"] = apple; } - QJsonDocument json_document(output); - if(!dump_file.write(json_document.toJson())) + if(QJsonDocument json_document(output); !dump_file.write(json_document.toJson())) { emit error(tr("Error dumping raw EFI data"), tr("Couldn't write into file (%1): %2.").arg(file_name, dump_file.errorString())); return; @@ -759,7 +752,7 @@ void EFIBootData::setTimeout(uint16_t value) if(timeout == value) return; - auto command = new SetEFIBootDataValueCommand{*this, tr("Timeout"), &EFIBootData::timeout, &EFIBootData::timeoutChanged, static_cast(value)}; + auto command = new SetEFIBootDataValueCommand{*this, tr("Timeout"), &EFIBootData::timeout, &EFIBootData::timeoutChanged, value}; if(!undo_stack) { command->redo(); @@ -775,7 +768,7 @@ void EFIBootData::setAppleBootArgs(const QString &text) if(apple_boot_args == text) return; - auto command = new SetEFIBootDataValueCommand{*this, tr("Apple boot-args"), &EFIBootData::apple_boot_args, &EFIBootData::appleBootArgsChanged, text}; + auto command = new SetEFIBootDataValueCommand{*this, tr("Apple boot-args"), &EFIBootData::apple_boot_args, &EFIBootData::appleBootArgsChanged, text}; if(!undo_stack) { command->redo(); @@ -791,7 +784,7 @@ void EFIBootData::setOsIndications(uint64_t value) if(indications == value) return; - auto command = new SetEFIBootDataValueCommand{*this, tr("Firmware actions"), &EFIBootData::indications, &EFIBootData::osIndicationsChanged, value}; + auto command = new SetEFIBootDataValueCommand{*this, tr("Firmware actions"), &EFIBootData::indications, &EFIBootData::osIndicationsChanged, value}; if(!undo_stack) { command->redo(); @@ -873,7 +866,7 @@ void EFIBootData::importJSONEFIData(const QJsonObject &input) QStringList errors; size_t step = 1; - size_t total_steps = static_cast(input.size()) + 1u; + auto total_steps = static_cast(input.size()) + 1u; auto process_entry = [&](const QJsonObject &root, const auto &name, const auto &type_fn, const QString &type_name, const auto &process_fn, const QString &name_prefix = "", bool optional = false) { @@ -1081,7 +1074,7 @@ void EFIBootData::importJSONEFIData(const QJsonObject &input) continue; } - const uint16_t idx = static_cast(index.toInt()); + const auto idx = static_cast(index.toInt()); order.push_back(idx); ordered_entry.insert(idx); } @@ -1099,7 +1092,7 @@ void EFIBootData::importJSONEFIData(const QJsonObject &input) for(const auto &name: keys) { bool success = false; - const uint16_t index = static_cast(name.toULong(&success, HEX_BASE)); + const auto index = static_cast(name.toULong(&success, HEX_BASE)); if(!success) { errors.push_back(tr("%1: %2 expected").arg(full_prefix + name, tr("hexadecimal number"))); @@ -1129,7 +1122,7 @@ void EFIBootData::importJSONEFIData(const QJsonObject &input) } entry->index = index; - if(model.options & BootEntryListModel::IsBoot) + if(model.options & BootEntryListModel::Option::IsBoot) { entry->is_current_boot = current_boot == static_cast(index); entry->is_next_boot = next_boot == static_cast(index); @@ -1168,7 +1161,7 @@ void EFIBootData::importRawEFIData(const QJsonObject &input) QStringList errors; size_t step = 1; - size_t total_steps = static_cast(input.size()) + 1u; + auto total_steps = static_cast(input.size()) + 1u; auto process_entry = [&](const QJsonObject &root, const auto &name, const auto &deserialize_fn, const auto &process_fn, const QString &name_prefix = "", bool optional = false) { @@ -1306,7 +1299,7 @@ void EFIBootData::importRawEFIData(const QJsonObject &input) for(const auto &name: keys) { bool success = false; - const uint16_t index = static_cast(name.toULong(&success, HEX_BASE)); + const auto index = static_cast(name.toULong(&success, HEX_BASE)); if(!success) { errors.push_back(tr("%1: %2 expected").arg(full_prefix + name, tr("hexadecimal number"))); @@ -1331,8 +1324,8 @@ void EFIBootData::importRawEFIData(const QJsonObject &input) // Translate STL to QTL auto entry = BootEntry::fromEFIBootLoadOption(value); entry.index = index; - entry.efi_attributes = static_cast(efi_attributes); - if(model.options & BootEntryListModel::IsBoot) + entry.efi_attributes = efi_attributes; + if(model.options & BootEntryListModel::Option::IsBoot) { entry.is_current_boot = current_boot == static_cast(index); entry.is_next_boot = next_boot == static_cast(index); diff --git a/src/efibooteditor.cpp b/src/efibooteditor.cpp index ef522c15..df534912 100644 --- a/src/efibooteditor.cpp +++ b/src/efibooteditor.cpp @@ -19,10 +19,9 @@ EFIBootEditor::EFIBootEditor(const std::optional &efi_error_message, QWidget *parent) : QMainWindow{parent} , ui{std::make_unique()} - , confirmation{std::make_unique(QMessageBox::Question, qApp->applicationName(), "", QMessageBox::NoButton, this)} - , error{std::make_unique(QMessageBox::Critical, qApp->applicationName(), "", QMessageBox::NoButton, this)} + , confirmation{std::make_unique(QMessageBox::Question, QApplication::applicationName(), "", QMessageBox::NoButton, this)} + , error{std::make_unique(QMessageBox::Critical, QApplication::applicationName(), "", QMessageBox::NoButton, this)} , progress{std::make_unique(tr("Working…"), nullptr, 0, 0, this)} - , disable_undo_redo{std::make_unique()} { data.setUndoStack(&undo_stack); ui->setupUi(this); @@ -165,7 +164,7 @@ void EFIBootEditor::enableBootEntryEditor(const QModelIndex &index) auto [name, list, model] = currentBootEntryList(); (void)name; (void)list; - ui->entry_form->setReadOnly((model.options & BootEntryListModel::ReadOnly) || item->is_error); + ui->entry_form->setReadOnly((model.options & BootEntryListModel::Option::ReadOnly) || item->is_error); } void EFIBootEditor::disableBootEntryEditor() @@ -188,7 +187,7 @@ void EFIBootEditor::switchBootEntryEditor(int index) ui->entry_form->setBootEntryListModel(model); list.setCurrentIndex(list.currentIndex()); enableBootEntryEditor(list.currentIndex()); - ui->entries_actions->setDisabled(model.options & BootEntryListModel::ReadOnly); + ui->entries_actions->setDisabled(model.options & BootEntryListModel::Option::ReadOnly); } void EFIBootEditor::save() @@ -314,7 +313,7 @@ void EFIBootEditor::undoViewChanged(const QModelIndex &) void EFIBootEditor::reorderBootEntries() { auto [name, list, model] = currentBootEntryList(); - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) return; disableBootEntryEditor(); @@ -350,7 +349,7 @@ void EFIBootEditor::removeCurrentBootEntry() { auto [name, list, model] = currentBootEntryList(); (void)name; - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) return; list.removeCurrentRow(); @@ -360,7 +359,7 @@ void EFIBootEditor::moveCurrentBootEntryUp() { auto [name, list, model] = currentBootEntryList(); (void)name; - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) return; list.moveCurrentRowUp(); @@ -370,7 +369,7 @@ void EFIBootEditor::moveCurrentBootEntryDown() { auto [name, list, model] = currentBootEntryList(); (void)name; - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) return; list.moveCurrentRowDown(); @@ -380,7 +379,7 @@ void EFIBootEditor::insertBootEntry() { auto [name, list, model] = currentBootEntryList(); (void)name; - if(model.options & BootEntryListModel::ReadOnly) + if(model.options & BootEntryListModel::Option::ReadOnly) return; list.insertRow(); diff --git a/src/efibooteditorcli.cpp b/src/efibooteditorcli.cpp index c6257010..3d0ad16a 100644 --- a/src/efibooteditorcli.cpp +++ b/src/efibooteditorcli.cpp @@ -83,13 +83,13 @@ bool EFIBootEditorCLI::process(const QCoreApplication &app) return processed; } -void EFIBootEditorCLI::showError(const QString &message, const QString &details) +void EFIBootEditorCLI::showError(const QString &message, const QString &details) const { QTextStream ts{stderr}; ts << tr("ERROR: %0! %1").arg(message, details) << Qt::endl; } -void EFIBootEditorCLI::showProgress(size_t step, size_t total, const QString &details) +void EFIBootEditorCLI::showProgress(size_t step, size_t total, const QString &details) const { if(step >= total) total = step + 1; @@ -98,7 +98,7 @@ void EFIBootEditorCLI::showProgress(size_t step, size_t total, const QString &de ts << QString("\r[%0%]\t(%1/%2)\t%3").arg(100 * step / total).arg(step).arg(total).arg(details); } -void EFIBootEditorCLI::hideProgress() +void EFIBootEditorCLI::hideProgress() const { QTextStream ts{stdout}; ts << "\33[2K\r[100%]\t" << tr("Finished") << Qt::endl; diff --git a/src/efivar-lite.darwin.c b/src/efivar-lite.darwin.c index f04fbebc..58605493 100644 --- a/src/efivar-lite.darwin.c +++ b/src/efivar-lite.darwin.c @@ -171,8 +171,8 @@ int efi_error_get(unsigned int n, char **const filename, char **const function, *filename = "IOKitLib.h"; *line = -1; - *error = (int)errno; // FIXME - *function = (char *)last_iokit_function; + *error = errno; // FIXME + *function = last_iokit_function; *message = mach_error_string(err); return 1; } diff --git a/src/efivar-lite.win32.c b/src/efivar-lite.win32.c index fd6ab089..2e61d5c6 100644 --- a/src/efivar-lite.win32.c +++ b/src/efivar-lite.win32.c @@ -163,7 +163,7 @@ int efi_error_get(unsigned int n, TCHAR **const filename, TCHAR **const function *line = -1; DWORD err = GetLastError(); *error = (int)err; - *function = (TCHAR *)last_winapi_function; + *function = last_winapi_function; if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_buffer, 1024, NULL)) return -1; diff --git a/src/filepathdialog.cpp b/src/filepathdialog.cpp index 9e4a0a1c..c68d92f5 100644 --- a/src/filepathdialog.cpp +++ b/src/filepathdialog.cpp @@ -38,10 +38,7 @@ void HorizontalTabStyle::drawControl(ControlElement element, const QStyleOption FilePathDialog::FilePathDialog(QWidget *parent) : QDialog(parent) - , horizontal_tab_style{} , ui{std::make_unique()} - , vendor_data_format_combo_index{} - , unknown_data_format_combo_index{} { ui->setupUi(this); setFilePath(nullptr); @@ -253,7 +250,7 @@ void FilePathDialog::setFilePath(const File_path::ANY *_file_path) struct Visitor { FilePathDialog *parent; - Visitor(FilePathDialog *parent_) + explicit Visitor(FilePathDialog *parent_) : parent{parent_} { } @@ -304,7 +301,7 @@ void FilePathDialog::setUSBForm(const File_path::USB &usb) void FilePathDialog::setVendorForm(const File_path::Vendor &vendor) { ui->options->setCurrentIndex(FormIndex::Vendor); - VendorTypeIndex index = VendorTypeIndex::HW; + VendorTypeIndex index{}; switch(vendor._type) { case EFIBoot::File_path::HWVendor::TYPE: @@ -318,6 +315,10 @@ void FilePathDialog::setVendorForm(const File_path::Vendor &vendor) case EFIBoot::File_path::MEDIAVendor::TYPE: index = VendorTypeIndex::MEDIA; break; + + default: + index = VendorTypeIndex::HW; + break; } ui->vendor_type_combo->setCurrentIndex(static_cast(index));