diff --git a/src/qt/qt_util.cpp b/src/qt/qt_util.cpp index 0a59cdf5d..5c9059272 100644 --- a/src/qt/qt_util.cpp +++ b/src/qt/qt_util.cpp @@ -14,6 +14,8 @@ * * Copyright 2022 Teemu Korhonen */ +#include +#include #include #include #include @@ -70,7 +72,11 @@ DlgFilter(std::initializer_list extensions, bool last) QString currentUuid() { - return QUuid::createUuidV5(QUuid{}, QString(usr_path)).toString(QUuid::WithoutBraces); + auto configPath = QFileInfo(cfg_path).dir().canonicalPath(); + if(!configPath.endsWith("/")) { + configPath.append("/"); + } + return QUuid::createUuidV5(QUuid{}, configPath).toString(QUuid::WithoutBraces); } bool compareUuid() @@ -82,6 +88,11 @@ bool compareUuid() storeCurrentUuid(); return true; } + // Do not prompt on mismatch if the system does not have any configured NICs. Just update the uuid + if(!hasConfiguredNICs() && uuid != currentUuid()) { + storeCurrentUuid(); + return true; + } // The uuid appears to be a valid, at least by length. // Compare with a simple string match return uuid == currentUuid(); @@ -99,14 +110,24 @@ generateNewMacAdresses() for (int i = 0; i < NET_CARD_MAX; ++i) { auto net_card = net_cards_conf[i]; if (net_card.device_num != 0) { - const auto network_device = network_card_getdevice(net_card.device_num); + const auto network_device = network_card_getdevice(net_card.device_num); device_context_t device_context; - - device_set_context(&device_context, network_device, i+1); + device_set_context(&device_context, network_device, i + 1); auto generatedMac = QString::asprintf("%02X:%02X:%02X", random_generate(), random_generate(), random_generate()).toLower(); config_set_string(device_context.name, "mac", generatedMac.toUtf8().constData()); } } } +bool +hasConfiguredNICs() +{ + for (int i = 0; i < NET_CARD_MAX; ++i) { + if (const auto net_card = net_cards_conf[i]; net_card.device_num != 0) { + return true; + } + } + return false; +} + } diff --git a/src/qt/qt_util.hpp b/src/qt/qt_util.hpp index 07e44b621..6a0bdc30b 100644 --- a/src/qt/qt_util.hpp +++ b/src/qt/qt_util.hpp @@ -17,6 +17,7 @@ QString currentUuid(); void storeCurrentUuid(); bool compareUuid(); void generateNewMacAdresses(); +bool hasConfiguredNICs(); }; #endif