Commit a19a8430 authored by Filipe Marques's avatar Filipe Marques

merge development branch

parent c5659747
/*
* Config.cpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fstream>
......
/*
* Config.hpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_HPP_
......
/*
* Data.cpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dirent.h>
......@@ -32,13 +49,13 @@ void Data::updateInstalledConfigData()
{
// Clear config vectors in each device element
for (auto&& PCIDevice = PCIDevices.begin();
PCIDevice != PCIDevices.end(); PCIDevice++)
PCIDevice != PCIDevices.end(); ++PCIDevice)
{
(*PCIDevice)->installedConfigs_.clear();
}
for (auto&& USBDevice = USBDevices.begin();
USBDevice != USBDevices.end(); USBDevice++)
USBDevice != USBDevices.end(); ++USBDevice)
{
(*USBDevice)->installedConfigs_.clear();
}
......@@ -280,12 +297,11 @@ void Data::getAllDependenciesToInstall(std::shared_ptr<Config> config,
std::vector<std::shared_ptr<Config>> *dependencies)
{
for (auto&& configDependency = config->dependencies_.begin();
configDependency != config->dependencies_.end(); configDependency++)
configDependency != config->dependencies_.end(); ++configDependency)
{
auto found = std::find_if(installedConfigs.begin(), installedConfigs.end(),
[configDependency](const std::shared_ptr<Config> rhs)->bool
{
return (*configDependency == rhs->name_);
[configDependency](const std::shared_ptr<Config>& rhs) -> bool {
return (rhs->name_ == *configDependency);
});
if (found != installedConfigs.end())
......@@ -295,9 +311,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 (*configDependency == rhs->name_);
[configDependency](const std::shared_ptr<Config>& rhs) -> bool {
return (rhs->name_ == *configDependency);
});
if (found != dependencies->end())
......@@ -315,7 +330,7 @@ void Data::getAllDependenciesToInstall(std::shared_ptr<Config> config,
}
else
{
dependencies->push_back(std::shared_ptr<Config>{dependconfig});
dependencies->emplace_back(dependconfig);
getAllDependenciesToInstall(dependconfig, installedConfigs, dependencies);
}
}
......@@ -339,7 +354,7 @@ std::shared_ptr<Config> Data::getDatabaseConfig(const std::string configName,
}
for (auto&& config = allConfigs.begin(); config != allConfigs.end();
config++)
++config)
{
if (configName == (*config)->name_)
{
......@@ -366,17 +381,16 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalConflicts(std::shared_ptr<
installedConfigs = installedPCIConfigs;
}
dependencies.push_back(std::shared_ptr<Config>{config});
dependencies.emplace_back(config);
for (auto&& dependency = dependencies.begin();
dependency != dependencies.end(); dependency++)
dependency != dependencies.end(); ++dependency)
{
for (auto&& dependencyConflict =
(*dependency)->conflicts_.begin();
dependencyConflict != (*dependency)->conflicts_.end(); dependencyConflict++)
for (auto&& dependencyConflict = (*dependency)->conflicts_.begin();
dependencyConflict != (*dependency)->conflicts_.end(); ++dependencyConflict)
{
for (auto&& installedConfig = installedConfigs.begin();
installedConfig != installedConfigs.end(); installedConfig++)
installedConfig != installedConfigs.end(); ++installedConfig)
{
if ((*dependencyConflict) != (*installedConfig)->name_)
{
......@@ -387,7 +401,7 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalConflicts(std::shared_ptr<
// Check if already in vector
bool found = false;
for (auto&& conflict = conflicts.begin();
conflict != conflicts.end(); conflict++)
conflict != conflicts.end(); ++conflict)
{
if ((*conflict)->name_ == (*dependencyConflict))
{
......@@ -402,7 +416,7 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalConflicts(std::shared_ptr<
}
else
{
conflicts.push_back(std::shared_ptr<Config>{*installedConfig});
conflicts.emplace_back(*installedConfig);
break;
}
}
......@@ -430,7 +444,7 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalRequirements(std::shared_p
// Check if this config is required by another installed config
for (auto&& installedConfig = installedConfigs.begin();
installedConfig != installedConfigs.end(); installedConfig++)
installedConfig != installedConfigs.end(); ++installedConfig)
{
for (auto&& dependency = (*installedConfig)->dependencies_.begin();
dependency != (*installedConfig)->dependencies_.end(); dependency++)
......@@ -444,7 +458,7 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalRequirements(std::shared_p
// Check if already in vector
bool found = false;
for (auto&& requirement = requirements.begin();
requirement != requirements.end(); requirement++)
requirement != requirements.end(); ++requirement)
{
if ((*requirement)->name_ == (*installedConfig)->name_)
{
......@@ -455,7 +469,7 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalRequirements(std::shared_p
if (!found)
{
requirements.push_back(std::shared_ptr<Config>{*installedConfig});
requirements.emplace_back(*installedConfig);
break;
}
}
......@@ -482,29 +496,27 @@ void Data::fillDevices(std::string type)
}
// Get the hardware devices
hd_data_t *hd_data = new hd_data_t();
hd_t *hd = hd_list(hd_data, hw, 1, nullptr);
hd_t *beginningOfhd = hd;
std::unique_ptr<hd_data_t> hd_data{new hd_data_t()};
hd_t *hd = hd_list(hd_data.get(), hw, 1, nullptr);
Device *device;
for (; hd; hd = hd->next)
std::unique_ptr<Device> device;
for (hd_t *hdIter = hd; hdIter; hdIter = hdIter->next)
{
device = new Device();
device.reset(new Device());
device->type_ = type;
device->classID_ = from_Hex(hd->base_class.id, 2) + from_Hex(hd->sub_class.id, 2).toLower();
device->vendorID_ = from_Hex(hd->vendor.id, 4).toLower();
device->deviceID_ = from_Hex(hd->device.id, 4).toLower();
device->className_ = from_CharArray(hd->base_class.name);
device->vendorName_ = from_CharArray(hd->vendor.name);
device->deviceName_ = from_CharArray(hd->device.name);
device->sysfsBusID_ = from_CharArray(hd->sysfs_bus_id);
device->sysfsID_ = from_CharArray(hd->sysfs_id);
devices->push_back(std::shared_ptr<Device>{device});
}
hd_free_hd_list(beginningOfhd);
hd_free_hd_data(hd_data);
delete hd_data;
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();
device->className_ = from_CharArray(hdIter->base_class.name);
device->vendorName_ = from_CharArray(hdIter->vendor.name);
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());
}
hd_free_hd_list(hd);
hd_free_hd_data(hd_data.get());
}
void Data::fillAllConfigs(std::string type)
......@@ -526,15 +538,15 @@ void Data::fillAllConfigs(std::string type)
for (auto&& configPath = configPaths.begin();
configPath != configPaths.end(); ++configPath)
{
Config *config = new Config((*configPath), type);
std::unique_ptr<Config> config{new Config((*configPath), type)};
if (config->readConfigFile((*configPath)))
{
configs->push_back(std::shared_ptr<Config>{config});
configs->emplace_back(config.release());
}
else
{
invalidConfigs.push_back(std::shared_ptr<Config>{config});
invalidConfigs.emplace_back(config.release());
}
}
}
......@@ -550,8 +562,7 @@ bool Data::fillConfig(std::shared_ptr<Config> config, std::string configPath, st
// Add new HardwareIDs group to vector if vector is empty
if (config->hwdIDs_.empty())
{
Config::HardwareID hwdID;
config->hwdIDs_.push_back(hwdID);
config->hwdIDs_.emplace_back();
}
return config->readConfigFile(config->configPath_);
......@@ -562,8 +573,7 @@ std::vector<std::string> Data::getRecursiveDirectoryFileList(const std::string&
{
std::vector<std::string> list;
struct dirent *dir = nullptr;
DIR *d = opendir(directoryPath.c_str());
DIR* d = opendir(directoryPath.c_str());
if (d)
{
while (nullptr != (dir = readdir(d)))
......@@ -719,7 +729,7 @@ void Data::addConfigSorted(std::vector<std::shared_ptr<Config>>& configs,
}
}
configs.push_back(std::shared_ptr<Config>(config));
configs.emplace_back(config);
}
Vita::string Data::from_Hex(std::uint16_t hexnum, int fill)
......@@ -729,12 +739,12 @@ Vita::string Data::from_Hex(std::uint16_t hexnum, int fill)
return stream.str();
}
Vita::string Data::from_CharArray(char* c)
std::string Data::from_CharArray(char* c)
{
if (nullptr == c)
{
return "";
}
return Vita::string(c);
return std::string(c);
}
/*
* Data.hpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DATA_HPP_
......@@ -74,7 +91,7 @@ private:
void updateConfigData();
Vita::string from_Hex(uint16_t hexnum, int fill);
Vita::string from_CharArray(char* c);
std::string from_CharArray(char* c);
};
#endif /* DATA_HPP_ */
/*
* Device.cpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Device.hpp"
......
/*
* Device.hpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DEVICE_HPP_
......@@ -13,7 +30,6 @@
#include <vector>
#include "Config.hpp"
#include "Enums.hpp"
struct Device
{
......
/*
* Enums.hpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ENUMS_HPP_
......
This diff is collapsed.
/*
* Mhwd.hpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 26 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MHWD_HPP_
......@@ -32,29 +49,33 @@ class Mhwd
{
public:
Mhwd();
~Mhwd();
~Mhwd() = default;
void set_version_mhwd(std::string version_of_software, std::string year_copyright);
int launch(int argc, char *argv[]);
private:
struct Arguments
{
bool SHOWPCI = false;
bool SHOWUSB = false;
bool SHOW_PCI = false;
bool SHOW_USB = false;
bool INSTALL = false;
bool REMOVE = false;
bool DETAIL = false;
bool FORCE = false;
bool LISTALL = false;
bool LISTINSTALLED = false;
bool LISTAVAILABLE = false;
bool LISTHARDWARE = false;
bool CUSTOMINSTALL = false;
bool LIST_ALL = false;
bool LIST_INSTALLED = false;
bool LIST_AVAILABLE = false;
bool LIST_HARDWARE = false;
bool CUSTOM_INSTALL = false;
bool AUTOCONFIGURE = false;
} arguments_;
std::shared_ptr<Config> config_;
Data data_;
Printer printer_;
std::vector<std::string> configs_;
std::string version_, year_;
bool performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE type);
bool isUserRoot() const;
std::string checkEnvironment();
......@@ -81,6 +102,9 @@ private:
MHWD::STATUS installConfig(std::shared_ptr<Config> config);
MHWD::STATUS uninstallConfig(Config *config);
bool runScript(std::shared_ptr<Config> config, MHWD::TRANSACTIONTYPE operationType);
void tryToParseCmdLineOptions(int argc, char* argv[], bool& autoConfigureNonFreeDriver,
std::string& operationType, std::string& autoConfigureClassID);
bool optionsDontInterfereWithEachOther() const;
};
#endif /* MHWD_HPP_ */
/*
* Printer.cpp
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Created on: 28 sie 2014
* Author: dec
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iomanip>
......@@ -32,38 +49,33 @@ void Printer::printWarning(std::string warningMsg) const
void Printer::printMessage(MHWD::MESSAGETYPE type, std::string msg) const
{
if (type == MHWD::MESSAGETYPE::CONSOLE_OUTPUT)
{
std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET;
}
else if (type == MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START)
{
printStatus("Installing dependency " + msg + "...");
}
else if (type == MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END)
{
printStatus("Successfully installed dependency " + msg);
}
else if (type == MHWD::MESSAGETYPE::INSTALL_START)
{
printStatus("Installing " + msg + "...");
}
else if (type == MHWD::MESSAGETYPE::INSTALL_END)
{
printStatus("Successfully installed " + msg);
}
else if (type == MHWD::MESSAGETYPE::REMOVE_START)
{
printStatus("Removing " + msg + "...");
}
else if (type == MHWD::MESSAGETYPE::REMOVE_END)
{
printStatus("Successfully removed " + msg);
}
else
{
printError("You shouldn't see this?! Unknown message type!");
}
switch(type)
{
case MHWD::MESSAGETYPE::CONSOLE_OUTPUT:
std::cout << CONSOLE_TEXT_OUTPUT_COLOR << msg << CONSOLE_COLOR_RESET;
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_START:
printStatus("Installing dependency " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALLDEPENDENCY_END:
printStatus("Successfully installed dependency " + msg);
break;
case MHWD::MESSAGETYPE::INSTALL_START:
printStatus("Installing " + msg + "...");
break;
case MHWD::MESSAGETYPE::INSTALL_END:
printStatus("Successfully installed " + msg);
break;
case MHWD::MESSAGETYPE::REMOVE_START:
printStatus("Removing " + msg + "...");
break;
case MHWD::MESSAGETYPE::REMOVE_END:
printStatus("Successfully removed " + msg);
break;
default:
printError("You shouldn't see this?! Unknown message type!");
break;
}
}
void Printer::printHelp() const
......@@ -72,6 +84,7 @@ void Printer::printHelp() const
<< " --pci\t\t\t\t\tlist only pci devices and driver configs\n"