Commit 0376ee15 authored by TotallyNotElite's avatar TotallyNotElite

Added basic wildcard (GLOB) support

parent 26f159cf
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "Data.hpp" #include "Data.hpp"
#include <dirent.h> #include <dirent.h>
#include <fnmatch.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
...@@ -129,42 +130,42 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev ...@@ -129,42 +130,42 @@ void Data::getAllDevicesOfConfig(const std::vector<std::shared_ptr<Device>>& dev
{ {
// Check class ids // Check class ids
bool found = std::find_if(hwdID->classIDs.begin(), hwdID->classIDs.end(), [i_device](const std::string& classID){ bool found = std::find_if(hwdID->classIDs.begin(), hwdID->classIDs.end(), [i_device](const std::string& classID){
return (("*" == classID) || (classID == (*i_device)->classID_)); return !fnmatch(classID.c_str(), (*i_device)->classID_.c_str(), FNM_CASEFOLD);
}) != hwdID->classIDs.end(); }) != hwdID->classIDs.end();
if (found) if (found)
{ {
// Check blacklisted class ids // Check blacklisted class ids
found = std::find_if(hwdID->blacklistedClassIDs.begin(), hwdID->blacklistedClassIDs.end(), [i_device](const std::string& blacklistedClassID){ found = std::find_if(hwdID->blacklistedClassIDs.begin(), hwdID->blacklistedClassIDs.end(), [i_device](const std::string& blacklistedClassID){
return (blacklistedClassID == (*i_device)->classID_); return !fnmatch(blacklistedClassID.c_str(), (*i_device)->classID_.c_str(), FNM_CASEFOLD);
}) != hwdID->blacklistedClassIDs.end(); }) != hwdID->blacklistedClassIDs.end();
if (!found) if (!found)
{ {
// Check vendor ids // Check vendor ids
found = std::find_if(hwdID->vendorIDs.begin(), hwdID->vendorIDs.end(), [i_device](const std::string& vendorID){ found = std::find_if(hwdID->vendorIDs.begin(), hwdID->vendorIDs.end(), [i_device](const std::string& vendorID){
return (("*" == vendorID) || (vendorID == (*i_device)->vendorID_)); return !fnmatch(vendorID.c_str(), (*i_device)->vendorID_.c_str(), FNM_CASEFOLD);
}) != hwdID->vendorIDs.end(); }) != hwdID->vendorIDs.end();
if (found) if (found)
{ {
// Check blacklisted vendor ids // Check blacklisted vendor ids
found = std::find_if(hwdID->blacklistedVendorIDs.begin(), hwdID->blacklistedVendorIDs.end(), [i_device](const std::string& blacklistedVendorID){ found = std::find_if(hwdID->blacklistedVendorIDs.begin(), hwdID->blacklistedVendorIDs.end(), [i_device](const std::string& blacklistedVendorID){
return (blacklistedVendorID == (*i_device)->vendorID_); return !fnmatch(blacklistedVendorID.c_str(), (*i_device)->vendorID_.c_str(), FNM_CASEFOLD);
}) != hwdID->blacklistedVendorIDs.end(); }) != hwdID->blacklistedVendorIDs.end();
if (!found) if (!found)
{ {
// Check device ids // Check device ids
found = std::find_if(hwdID->deviceIDs.begin(), hwdID->deviceIDs.end(), [i_device](const std::string& deviceID){ found = std::find_if(hwdID->deviceIDs.begin(), hwdID->deviceIDs.end(), [i_device](const std::string& deviceID){
return (("*" == deviceID) || (deviceID == (*i_device)->deviceID_)); return !fnmatch(deviceID.c_str(), (*i_device)->deviceID_.c_str(), FNM_CASEFOLD);
}) != hwdID->deviceIDs.end(); }) != hwdID->deviceIDs.end();
if (found) if (found)
{ {
// Check blacklisted device ids // Check blacklisted device ids
found = std::find_if(hwdID->blacklistedDeviceIDs.begin(), hwdID->blacklistedDeviceIDs.end(), [i_device](const std::string& blacklistedDeviceID){ found = std::find_if(hwdID->blacklistedDeviceIDs.begin(), hwdID->blacklistedDeviceIDs.end(), [i_device](const std::string& blacklistedDeviceID){
return (blacklistedDeviceID == (*i_device)->deviceID_); return !fnmatch(blacklistedDeviceID.c_str(), (*i_device)->deviceID_.c_str(), FNM_CASEFOLD);
}) != hwdID->blacklistedDeviceIDs.end(); }) != hwdID->blacklistedDeviceIDs.end();
if (!found) if (!found)
{ {
...@@ -281,22 +282,28 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalConflicts(std::shared_ptr< ...@@ -281,22 +282,28 @@ std::vector<std::shared_ptr<Config>> Data::getAllLocalConflicts(std::shared_ptr<
installedConfigs = installedPCIConfigs; installedConfigs = installedPCIConfigs;
} }
// Add self to local dependencies vector
dependencies.emplace_back(config); dependencies.emplace_back(config);
// Loop thru all MHWD config dependencies (not pacman dependencies)
for (const auto& dependency : dependencies) for (const auto& dependency : dependencies)
{ {
// Loop thru all MHWD config conflicts
for (const auto& dependencyConflict : dependency->conflicts_) for (const auto& dependencyConflict : dependency->conflicts_)
{ {
// Then loop thru all already installed configs. If there are no configs installed, there can not be a conflict
for (auto& installedConfig : installedConfigs) for (auto& installedConfig : installedConfigs)
{ {
if (dependencyConflict == installedConfig->name_) // Does one of the installed configs conflict one of the to-be-installed configs?
if (!fnmatch(dependencyConflict.c_str(),installedConfig->name_.c_str(), FNM_CASEFOLD))
{ {
// Check if conflicts is already in the conflicts vector
bool found = std::find_if(conflicts.begin(), conflicts.end(), bool found = std::find_if(conflicts.begin(), conflicts.end(),
[&dependencyConflict](const std::shared_ptr<Config>& conflict) [&dependencyConflict](const std::shared_ptr<Config>& conflict)
{ {
return conflict->name_ == dependencyConflict; return conflict->name_ == dependencyConflict;
}) != conflicts.end(); }) != conflicts.end();
// If not, add it to the conflicts vector. This will now be shown to the user.
if (!found) if (!found)
{ {
conflicts.emplace_back(installedConfig); conflicts.emplace_back(installedConfig);
......
...@@ -58,4 +58,4 @@ hash_t hash(char const* str) ...@@ -58,4 +58,4 @@ hash_t hash(char const* str)
}; // End namespace }; // End namespace
#endif /* CONFIG_HPP_ */ #endif /* MHWDUTILS_HPP_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment