Commit 6517c1bd authored by Filipe Marques's avatar Filipe Marques
Browse files

Merge branch 'development'

parents 20e6c2a8 b17339cf
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......@@ -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;
}
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......@@ -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();
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......@@ -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);
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......
......@@ -4,7 +4,7 @@
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
......@@ -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;
}