diff --git a/src/Config.cpp b/src/Config.cpp index e019b57c3880347d0af0f0065539ffd50dd0cbe6..42209cfe04d25b3cb32609005ee5b0265a8a005e 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -22,28 +22,22 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "Config.hpp" + #include <fstream> #include <string> #include <vector> -#include "Config.hpp" - Config::Config(std::string configPath, std::string type) : type_(type), basePath_(configPath.substr(0, configPath.find_last_of('/'))), - configPath_(configPath) -{ - if (hwdIDs_.empty()) - { - Config::HardwareID hwdID; - hwdIDs_.push_back(hwdID); - } -} + configPath_(configPath), hwdIDs_(1) +{} bool Config::readConfigFile(std::string configPath) { - std::ifstream file(configPath.c_str()); + std::ifstream file(configPath); - if (!file.is_open()) + if (!file) { return false; } diff --git a/src/Data.cpp b/src/Data.cpp index 4b56a7ec078a99307683ccf6eb0b1ab71dd30c75..8dfd7f62b446aaa8016c1ca0d90ed7eee080ed3e 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -22,6 +22,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "Data.hpp" + #include <dirent.h> #include <algorithm> @@ -31,20 +33,14 @@ #include <string> #include <vector> -#include "Data.hpp" - Data::Data() { - fillDevices("PCI"); - fillDevices("USB"); + fillDevices(hw_pci, PCIDevices); + fillDevices(hw_usb, USBDevices); updateConfigData(); } -Data::~Data() -{ -} - void Data::updateInstalledConfigData() { // Clear config vectors in each device element @@ -133,17 +129,10 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev for (auto&& i_device = devices.begin(); i_device != devices.end(); ++i_device) { - bool found = false; // Check class ids - for (auto&& classID = hwdID->classIDs.begin(); - classID != hwdID->classIDs.end(); ++classID) - { - if (*classID == "*" || *classID == (*i_device)->classID_) - { - found = true; - break; - } - } + bool found = std::find_if(hwdID->classIDs.begin(), hwdID->classIDs.end(), [i_device](const std::string& classID){ + return (("*" == classID) || (classID == (*i_device)->classID_)); + }) != hwdID->classIDs.end(); if (!found) { @@ -152,19 +141,9 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev else { // Check blacklisted class ids - found = false; - - for (auto&& blacklistedClassID = - (*hwdID).blacklistedClassIDs.begin(); - blacklistedClassID != (*hwdID).blacklistedClassIDs.end(); - ++blacklistedClassID) - { - if (*blacklistedClassID == (*i_device)->classID_) - { - found = true; - break; - } - } + found = std::find_if(hwdID->blacklistedClassIDs.begin(), hwdID->blacklistedClassIDs.end(), [i_device](const std::string& blacklistedClassID){ + return (blacklistedClassID == (*i_device)->classID_); + }) != hwdID->blacklistedClassIDs.end(); if (found) { @@ -173,17 +152,9 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev else { // Check vendor ids - found = false; - - for (auto&& vendorID = hwdID->vendorIDs.begin(); - vendorID != hwdID->vendorIDs.end(); ++vendorID) - { - if (("*" == *vendorID) || (*vendorID == (*i_device)->vendorID_)) - { - found = true; - break; - } - } + found = std::find_if(hwdID->vendorIDs.begin(), hwdID->vendorIDs.end(), [i_device](const std::string& vendorID){ + return (("*" == vendorID) || (vendorID == (*i_device)->vendorID_)); + }) != hwdID->vendorIDs.end(); if (!found) { @@ -192,19 +163,9 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev else { // Check blacklisted vendor ids - found = false; - - for (auto&& blacklistedVendorID = - hwdID->blacklistedVendorIDs.begin(); - blacklistedVendorID != hwdID->blacklistedVendorIDs.end(); - ++blacklistedVendorID) - { - if (*blacklistedVendorID == (*i_device)->vendorID_) - { - found = true; - break; - } - } + found = std::find_if(hwdID->blacklistedVendorIDs.begin(), hwdID->blacklistedVendorIDs.end(), [i_device](const std::string& blacklistedVendorID){ + return (blacklistedVendorID == (*i_device)->vendorID_); + }) != hwdID->blacklistedVendorIDs.end(); if (found) { @@ -213,17 +174,9 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev else { // Check device ids - found = false; - - for (auto&& deviceID = hwdID->deviceIDs.begin(); - deviceID != hwdID->deviceIDs.end(); ++deviceID) - { - if (("*" == *deviceID) || (*deviceID == (*i_device)->deviceID_)) - { - found = true; - break; - } - } + found = std::find_if(hwdID->deviceIDs.begin(), hwdID->deviceIDs.end(), [i_device](const std::string& deviceID){ + return (("*" == deviceID) || (deviceID == (*i_device)->deviceID_)); + }) != hwdID->deviceIDs.end(); if (!found) { @@ -232,20 +185,9 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev else { // Check blacklisted device ids - found = false; - - for (auto&& blacklistedDeviceID = - hwdID->blacklistedDeviceIDs.begin(); - blacklistedDeviceID != hwdID->blacklistedDeviceIDs.end(); - ++blacklistedDeviceID) - { - if (*blacklistedDeviceID == (*i_device)->deviceID_) - { - found = true; - break; - } - } - + found = std::find_if(hwdID->blacklistedDeviceIDs.begin(), hwdID->blacklistedDeviceIDs.end(), [i_device](const std::string& blacklistedDeviceID){ + return (blacklistedDeviceID == (*i_device)->deviceID_); + }) != hwdID->blacklistedDeviceIDs.end(); if (found) { continue; @@ -300,8 +242,8 @@ void Data::getAllDependenciesToInstall(std::shared_ptr<Config> config, configDependency != config->dependencies_.end(); ++configDependency) { auto found = std::find_if(installedConfigs.begin(), installedConfigs.end(), - [configDependency](const std::shared_ptr<Config>& rhs) -> bool { - return (rhs->name_ == *configDependency); + [configDependency](const std::shared_ptr<Config>& config) -> bool { + return (config->name_ == *configDependency); }); if (found != installedConfigs.end()) @@ -311,8 +253,8 @@ void Data::getAllDependenciesToInstall(std::shared_ptr<Config> config, else { found = std::find_if(dependencies->begin(), dependencies->end(), - [configDependency](const std::shared_ptr<Config>& rhs) -> bool { - return (rhs->name_ == *configDependency); + [configDependency](const std::shared_ptr<Config>& config) -> bool { + return (config->name_ == *configDependency); }); if (found != dependencies->end()) @@ -479,22 +421,8 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalRequirements(std::shared_p return requirements; } -void Data::fillDevices(std::string type) +void Data::fillDevices(hw_item hw, std::vector<std::shared_ptr<Device>>& devices) { - hw_item hw; - std::vector<std::shared_ptr<Device>>* devices; - - if ("USB" == type) - { - hw = hw_usb; - devices = &USBDevices; - } - else - { - hw = hw_pci; - devices = &PCIDevices; - } - // Get the hardware devices std::unique_ptr<hd_data_t> hd_data{new hd_data_t()}; hd_t *hd = hd_list(hd_data.get(), hw, 1, nullptr); @@ -503,7 +431,7 @@ void Data::fillDevices(std::string type) for (hd_t *hdIter = hd; hdIter; hdIter = hdIter->next) { device.reset(new Device()); - device->type_ = type; + device->type_ = (hw == hw_usb ? "USB" : "PCI"); device->classID_ = from_Hex(hdIter->base_class.id, 2) + from_Hex(hdIter->sub_class.id, 2).toLower(); device->vendorID_ = from_Hex(hdIter->vendor.id, 4).toLower(); device->deviceID_ = from_Hex(hdIter->device.id, 4).toLower(); @@ -512,7 +440,7 @@ void Data::fillDevices(std::string type) device->deviceName_ = from_CharArray(hdIter->device.name); device->sysfsBusID_ = from_CharArray(hdIter->sysfs_bus_id); device->sysfsID_ = from_CharArray(hdIter->sysfs_id); - devices->emplace_back(device.release()); + devices.emplace_back(device.release()); } hd_free_hd_list(hd); @@ -551,23 +479,6 @@ void Data::fillAllConfigs(std::string type) } } -bool Data::fillConfig(std::shared_ptr<Config> config, std::string configPath, std::string type) -{ - config->type_ = type; - config->priority_ = 0; - config->freedriver_ = true; - config->basePath_ = configPath.substr(0, configPath.find_last_of('/')); - config->configPath_ = configPath; - - // Add new HardwareIDs group to vector if vector is empty - if (config->hwdIDs_.empty()) - { - config->hwdIDs_.emplace_back(); - } - - return config->readConfigFile(config->configPath_); -} - std::vector<std::string> Data::getRecursiveDirectoryFileList(const std::string& directoryPath, std::string onlyFilename) { @@ -578,15 +489,14 @@ std::vector<std::string> Data::getRecursiveDirectoryFileList(const std::string& { while (nullptr != (dir = readdir(d))) { - std::string filename = dir->d_name; - std::string filepath = directoryPath + "/" + filename; - + std::string filename {dir->d_name}; if (("." == filename) || (".." == filename) || ("" == filename)) { continue; } else { + std::string filepath {directoryPath + "/" + filename}; struct stat filestatus; lstat(filepath.c_str(), &filestatus); @@ -627,7 +537,7 @@ Vita::string Data::getRightConfigPath(Vita::string str, Vita::string baseConfigP std::vector<std::string> Data::splitValue(Vita::string str, Vita::string onlyEnding) { - std::vector<Vita::string> work = str.toLower().explode(" "); + std::vector<Vita::string> work {str.toLower().explode(" ")}; std::vector<std::string> final; for (auto&& iterator = work.begin(); iterator != work.end(); diff --git a/src/Data.hpp b/src/Data.hpp index 6f49ca24479009d917fc25cd58f1d770a09d8bb5..abcb5f0487b8fdf6458a5b5f840210338542ee80 100644 --- a/src/Data.hpp +++ b/src/Data.hpp @@ -34,16 +34,18 @@ #include <vector> #include "Config.hpp" -#include "Device.hpp" #include "const.h" +#include "Device.hpp" #include "vita/string.hpp" -class Data { +class Data +{ public: Data(); - ~Data(); + ~Data() = default; - struct Environment { + struct Environment + { std::string PMCachePath {MHWD_PM_CACHE_DIR}; std::string PMConfigPath {MHWD_PM_CONFIG}; std::string PMRootPath {MHWD_PM_ROOT}; @@ -61,7 +63,6 @@ public: void updateInstalledConfigData(); void getAllDevicesOfConfig(std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices); - bool fillConfig(std::shared_ptr<Config> config, std::string configPath, std::string type); std::vector<std::shared_ptr<Config>> getAllDependenciesToInstall(std::shared_ptr<Config> config); void getAllDependenciesToInstall(std::shared_ptr<Config> config, @@ -76,7 +77,7 @@ private: void getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& devices, std::shared_ptr<Config> config, std::vector<std::shared_ptr<Device>>& foundDevices); void fillInstalledConfigs(std::string type); - void fillDevices(std::string type); + void fillDevices(hw_item hw, std::vector<std::shared_ptr<Device>>& devices); void fillAllConfigs(std::string type); void setMatchingConfigs(const std::vector<std::shared_ptr<Device>>& devices, std::vector<std::shared_ptr<Config>>& configs, bool setAsInstalled); diff --git a/src/Mhwd.cpp b/src/Mhwd.cpp index 02c975ea8ca8546bfbf899f47d3c208419aef2ad..dcb245be1036697fe96a8c6af99c857c43026718 100644 --- a/src/Mhwd.cpp +++ b/src/Mhwd.cpp @@ -23,7 +23,6 @@ */ #include "Mhwd.hpp" -#include "vita/string.hpp" #include <unistd.h> #include <sys/stat.h> @@ -42,9 +41,7 @@ #include <string> #include <vector> -Mhwd::Mhwd() : arguments_(), data_(), printer_() -{ -} +#include "vita/string.hpp" bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE transactionType) { @@ -167,53 +164,27 @@ bool Mhwd::isUserRoot() const return true; } -std::string Mhwd::checkEnvironment() +std::vector<std::string> Mhwd::checkEnvironment() const { - std::string missingDir; - - // Check if required directories exists. Otherwise return missing directory... + std::vector<std::string> missingDirs; if (!dirExists(MHWD_USB_CONFIG_DIR)) { - missingDir = MHWD_USB_CONFIG_DIR; + missingDirs.emplace_back(MHWD_USB_CONFIG_DIR); } if (!dirExists(MHWD_PCI_CONFIG_DIR)) { - missingDir = MHWD_PCI_CONFIG_DIR; + missingDirs.emplace_back(MHWD_PCI_CONFIG_DIR); } if (!dirExists(MHWD_USB_DATABASE_DIR)) { - missingDir = MHWD_USB_DATABASE_DIR; + missingDirs.emplace_back(MHWD_USB_DATABASE_DIR); } if (!dirExists(MHWD_PCI_DATABASE_DIR)) { - missingDir = MHWD_PCI_DATABASE_DIR; - } - - return missingDir; -} - -void Mhwd::printDeviceDetails(std::string type, FILE *f) -{ - hw_item hw; - if ("USB" == type) - { - hw = hw_usb; - } - else - { - hw = hw_pci; + missingDirs.emplace_back(MHWD_PCI_DATABASE_DIR); } - std::unique_ptr<hd_data_t> hd_data{new hd_data_t()}; - hd_t *hd = hd_list(hd_data.get(), hw, 1, nullptr); - - for (hd_t* hdIter = hd; hdIter; hdIter = hdIter->next) - { - hd_dump_entry(hd_data.get(), hdIter, f); - } - - hd_free_hd_list(hd); - hd_free_hd_data(hd_data.get()); + return missingDirs; } std::shared_ptr<Config> Mhwd::getInstalledConfig(const std::string& configName, @@ -231,15 +202,15 @@ std::shared_ptr<Config> Mhwd::getInstalledConfig(const std::string& configName, installedConfigs = &data_.installedPCIConfigs; } - for (auto&& installedConfig = installedConfigs->begin(); - installedConfig != installedConfigs->end(); installedConfig++) + auto installedConfig = std::find_if(installedConfigs->begin(), installedConfigs->end(), + [configName](const std::shared_ptr<Config>& config) { + return configName == config->name_; + }); + + if (installedConfig != installedConfigs->end()) { - if (configName == (*installedConfig)->name_) - { - return (*installedConfig); - } + return *installedConfig; } - return nullptr; } @@ -258,15 +229,14 @@ std::shared_ptr<Config> Mhwd::getDatabaseConfig(const std::string& configName, allConfigs = &data_.allPCIConfigs; } - for (auto&& iterator = allConfigs->begin(); - iterator != allConfigs->end(); ++iterator) + auto config = std::find_if(allConfigs->begin(), allConfigs->end(), + [configName](const std::shared_ptr<Config>& config) { + return config->name_ == configName; + }); + if (config != allConfigs->end()) { - if (configName == (*iterator)->name_) - { - return (*iterator); - } + return *config; } - return nullptr; } @@ -294,13 +264,14 @@ std::shared_ptr<Config> Mhwd::getAvailableConfig(const std::string& configName, } else { - for (auto&& availableConfig = (*device)->availableConfigs_.begin(); - availableConfig != (*device)->availableConfigs_.end(); availableConfig++) + auto& availableConfigs = (*device)->availableConfigs_; + auto availableConfig = std::find_if(availableConfigs.begin(), availableConfigs.end(), + [configName](const std::shared_ptr<Config>& config){ + return config->name_ == configName; + }); + if (availableConfig != availableConfigs.end()) { - if (configName == (*availableConfig)->name_) - { - return (*availableConfig); - } + return *availableConfig; } } } @@ -430,8 +401,6 @@ bool Mhwd::copyDirectory(const std::string& source, const std::string& destinati while ((dir = readdir(d)) != nullptr) { std::string filename {dir->d_name}; - std::string sourcePath {source + "/" + filename}; - std::string destinationPath {destination + "/" + filename}; if (("." == filename) || (".." == filename) || ("" == filename)) { @@ -439,6 +408,8 @@ bool Mhwd::copyDirectory(const std::string& source, const std::string& destinati } else { + std::string sourcePath {source + "/" + filename}; + std::string destinationPath {destination + "/" + filename}; lstat(sourcePath.c_str(), &filestatus); if (S_ISREG(filestatus.st_mode)) @@ -492,8 +463,7 @@ bool Mhwd::removeDirectory(const std::string& directory) struct dirent *dir; while ((dir = readdir(d)) != nullptr) { - std::string filename = std::string(dir->d_name); - std::string filepath = directory + "/" + filename; + std::string filename {dir->d_name}; if (("." == filename) || (".." == filename) || ("" == filename)) { @@ -501,6 +471,7 @@ bool Mhwd::removeDirectory(const std::string& directory) } else { + std::string filepath {directory + "/" + filename}; struct stat filestatus; lstat(filepath.c_str(), &filestatus); @@ -530,7 +501,7 @@ bool Mhwd::removeDirectory(const std::string& directory) } } -bool Mhwd::dirExists(const std::string& path) +bool Mhwd::dirExists(const std::string& path) const { struct stat filestatus; if (0 != stat(path.c_str(), &filestatus)) @@ -956,6 +927,17 @@ bool Mhwd::optionsDontInterfereWithEachOther() const int Mhwd::launch(int argc, char *argv[]) { + std::vector<std::string> missingDirs { checkEnvironment() }; + if (!missingDirs.empty()) + { + printer_.printError("Following directories do not exist:"); + for (const auto& dir : missingDirs) + { + printer_.printStatus(dir); + } + return 1; + } + std::string operationType; bool autoConfigureNonFreeDriver = false; std::string autoConfigureClassID; @@ -977,14 +959,6 @@ int Mhwd::launch(int argc, char *argv[]) return 1; } - // Check environment - std::string missingDir { checkEnvironment() }; - if (!missingDir.empty()) - { - printer_.printError("directory '" + missingDir + "' does not exist!"); - return 1; - } - // Check for invalid configs for (auto&& invalidConfig : data_.invalidConfigs) { @@ -1104,7 +1078,7 @@ int Mhwd::launch(int argc, char *argv[]) { if (arguments_.DETAIL) { - printDeviceDetails("PCI"); + printer_.printDeviceDetails(hw_pci); } else { @@ -1115,7 +1089,7 @@ int Mhwd::launch(int argc, char *argv[]) { if (arguments_.DETAIL) { - printDeviceDetails("USB"); + printer_.printDeviceDetails(hw_usb); } else { @@ -1171,8 +1145,6 @@ int Mhwd::launch(int argc, char *argv[]) } else { - bool alreadyInList = std::find(configs_.begin(), configs_.end(), config->name_) != configs_.end(); - // If force is not set then skip found config bool skip = false; if (!arguments_.FORCE) @@ -1180,8 +1152,7 @@ int Mhwd::launch(int argc, char *argv[]) skip = std::find_if(installedConfigs->begin(), installedConfigs->end(), [&config](const std::shared_ptr<Config>& conf) -> bool { return conf->name_ == config->name_; - }) - != installedConfigs->end(); + }) != installedConfigs->end(); } // Print found config if (skip) @@ -1203,6 +1174,7 @@ int Mhwd::launch(int argc, char *argv[]) device->deviceName_); } + bool alreadyInList = std::find(configs_.begin(), configs_.end(), config->name_) != configs_.end(); if (!alreadyInList && !skip) { configs_.push_back(config->name_); @@ -1224,7 +1196,11 @@ int Mhwd::launch(int argc, char *argv[]) // Transaction if (arguments_.INSTALL || arguments_.REMOVE) { - if (isUserRoot()) + if (!isUserRoot()) + { + printer_.printError("You cannot perform this operation unless you are root!"); + } + else { for (auto&& configName = configs_.begin(); configName != configs_.end(); configName++) @@ -1248,7 +1224,7 @@ int Mhwd::launch(int argc, char *argv[]) else { config_.reset(new Config(filepath, operationType)); - if (!data_.fillConfig(config_, filepath, operationType)) + if (!config_->readConfigFile(filepath)) { printer_.printError("failed to read custom config '" + filepath + "'!"); return 1; @@ -1300,10 +1276,6 @@ int Mhwd::launch(int argc, char *argv[]) } } } - else - { - printer_.printError("You cannot perform this operation unless you are root!"); - } } return 0; } diff --git a/src/Mhwd.hpp b/src/Mhwd.hpp index 6d04d06480f620c50446680307449d475297d339..4cf99bf6634b307315c8fefd5b420da80a333232 100644 --- a/src/Mhwd.hpp +++ b/src/Mhwd.hpp @@ -48,7 +48,7 @@ class Mhwd { public: - Mhwd(); + Mhwd() = default; ~Mhwd() = default; void setVersionMhwd(std::string versionOfSoftware, std::string yearCopyright); int launch(int argc, char *argv[]); @@ -77,9 +77,7 @@ private: bool performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE type); bool isUserRoot() const; - std::string checkEnvironment(); - - void printDeviceDetails(std::string type, FILE *f = stdout); + std::vector<std::string> checkEnvironment() const; std::shared_ptr<Config> getInstalledConfig(const std::string& configName, const std::string& configType); std::shared_ptr<Config> getDatabaseConfig(const std::string& configName, const std::string& configType); @@ -94,7 +92,7 @@ private: bool copyFile(const std::string& source, const std::string destination, const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH); bool removeDirectory(const std::string& directory); - bool dirExists(const std::string& path); + bool dirExists(const std::string& path) const; bool createDir(const std::string& path, const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH | S_IXGRP | S_IXOTH); diff --git a/src/Printer.cpp b/src/Printer.cpp index bac91f5530fb209c7fbe6ab1c63e2f87f5f29327..69a4590cc4a3245901853d5dee8dda270569b422 100644 --- a/src/Printer.cpp +++ b/src/Printer.cpp @@ -22,28 +22,31 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "Printer.hpp" + +#include <hd.h> + #include <iomanip> #include <iostream> +#include <memory> #include <string> #include <vector> -#include "Printer.hpp" - void Printer::printStatus(std::string statusMsg) const { - std::cout << CONSOLE_MESSAGE_COLOR << "> " + std::cout << CONSOLE_RED_MESSAGE_COLOR << "> " << CONSOLE_COLOR_RESET << statusMsg << std::endl; } void Printer::printError(std::string errorMsg) const { - std::cout << CONSOLE_MESSAGE_COLOR << "Error: " + std::cout << CONSOLE_RED_MESSAGE_COLOR << "Error: " << CONSOLE_COLOR_RESET << errorMsg << std::endl; } void Printer::printWarning(std::string warningMsg) const { - std::cout << CONSOLE_MESSAGE_COLOR << "Warning: " + std::cout << CONSOLE_RED_MESSAGE_COLOR << "Warning: " << CONSOLE_COLOR_RESET << warningMsg << std::endl; } @@ -102,9 +105,9 @@ void Printer::printHelp() const void Printer::printVersion(std::string versionMhwd, std::string yearCopy) const { - std::cout << "Manjaro Hardware Detection version "<< versionMhwd <<"\n\n" + std::cout << "Manjaro Hardware Detection v"<< versionMhwd <<"\n\n" << "Copyright (C) "<< yearCopy <<" Manjaro Linux Developers\n" - << "This is free software licensed under GNU GPL v.3\n" + << "This is free software licensed under GNU GPL v3.0\n" << "FITNESS FOR A PARTICULAR PURPOSE.\n" << std::endl; } @@ -268,3 +271,17 @@ void Printer::printLine() const { std::cout << std::setfill('-') << std::setw(80) << "-" << std::setfill(' ') << std::endl; } + +void Printer::printDeviceDetails(hw_item hw, FILE *f) const +{ + std::unique_ptr<hd_data_t> hd_data{new hd_data_t()}; + hd_t *hd = hd_list(hd_data.get(), hw, 1, nullptr); + + for (hd_t* hdIter = hd; hdIter; hdIter = hdIter->next) + { + hd_dump_entry(hd_data.get(), hdIter, f); + } + + hd_free_hd_list(hd); + hd_free_hd_data(hd_data.get()); +} diff --git a/src/Printer.hpp b/src/Printer.hpp index 20f7f326b030c5d4d92271146e857c9dae90e4b9..8bfa64f358e0e85e7d4bc41e6355ae032f46ccb1 100644 --- a/src/Printer.hpp +++ b/src/Printer.hpp @@ -25,6 +25,8 @@ #ifndef PRINTER_HPP_ #define PRINTER_HPP_ +#include <hd.h> + #include <string> #include <vector> @@ -50,11 +52,12 @@ public: void printInstalledConfigs(const std::string& deviceType, const std::vector<std::shared_ptr<Config>>& installedConfigs) const; void printConfigDetails(const Config& config) const; + void printDeviceDetails(hw_item hw, FILE *f = stdout) const; private: void printLine() const; const char* CONSOLE_COLOR_RESET {"\033[m"}; - const char* CONSOLE_MESSAGE_COLOR {"\033[1m\033[31m"}; + const char* CONSOLE_RED_MESSAGE_COLOR {"\033[1m\033[31m"}; const char* CONSOLE_TEXT_OUTPUT_COLOR {"\033[0;32m"}; }; diff --git a/src/main.cpp b/src/main.cpp index 20a723700a52da3b59261ec94057c3fe49322a53..73f1a218882685fcc2b655163d79f6e84d930d0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,16 +22,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Mhwd.hpp" - #include <iostream> +#include "Mhwd.hpp" + int main(int argc, char *argv[]) { try { Mhwd mhwd; - mhwd.setVersionMhwd("0.5.2","2012 2013 2014 2015"); + mhwd.setVersionMhwd("0.5.3","2012-2015"); return mhwd.launch(argc, argv); } catch(...)