diff --git a/src/Config.cpp b/src/Config.cpp index ba1684566b0cf60fc1dd7f5f4591e0aa4aa3ea33..5e233796d1c55c9e2e15460787f01031834cfdc1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -17,7 +17,7 @@ Config::Config(std::string configPath, std::string type) // Add new HardwareIDs group to vector if vector is empty if (hwdIDs_.empty()) { - Config::HardwareIDs hwdID; + Config::HardwareID hwdID; hwdIDs_.push_back(hwdID); } } @@ -133,7 +133,7 @@ bool Config::readConfigFile(std::string configPath) // Add new HardwareIDs group to vector if vector is not empty if (!hwdIDs_.back().classIDs.empty()) { - Config::HardwareIDs hwdID; + Config::HardwareID hwdID; hwdIDs_.push_back(hwdID); } @@ -144,7 +144,7 @@ bool Config::readConfigFile(std::string configPath) // Add new HardwareIDs group to vector if vector is not empty if (!hwdIDs_.back().vendorIDs.empty()) { - Config::HardwareIDs hwdID; + Config::HardwareID hwdID; hwdIDs_.push_back(hwdID); } @@ -155,7 +155,7 @@ bool Config::readConfigFile(std::string configPath) // Add new HardwareIDs group to vector if vector is not empty if (!hwdIDs_.back().deviceIDs.empty()) { - Config::HardwareIDs hwdID; + Config::HardwareID hwdID; hwdIDs_.push_back(hwdID); } @@ -184,7 +184,7 @@ bool Config::readConfigFile(std::string configPath) } // Append * to all empty vectors - for (std::vector<Config::HardwareIDs>::iterator hwdID = hwdIDs_.begin(); + for (std::vector<Config::HardwareID>::iterator hwdID = hwdIDs_.begin(); hwdID != hwdIDs_.end(); hwdID++) { if ((*hwdID).classIDs.empty()) diff --git a/src/Config.hpp b/src/Config.hpp index fe2dbea81ba5e48bd8734c1bad307400bf942e59..12c445fd4c5444059090d44895a73624c4b944eb 100644 --- a/src/Config.hpp +++ b/src/Config.hpp @@ -19,7 +19,7 @@ struct Config Config(std::string configPath, std::string type); bool readConfigFile(std::string configPath); - struct HardwareIDs + struct HardwareID { std::vector<std::string> classIDs; std::vector<std::string> vendorIDs; @@ -37,7 +37,7 @@ struct Config std::string version_; bool freedriver_ = true; int priority_ = 0; - std::vector<HardwareIDs> hwdIDs_; + std::vector<HardwareID> hwdIDs_; std::vector<std::string> conflicts_; std::vector<std::string> dependencies_; diff --git a/src/Data.cpp b/src/Data.cpp index f4cfc00a2f040704667aec6df720e98857f34fea..ce5ada45d0efcd3f7b1159134e0c51781fc55646 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -165,7 +165,7 @@ void Data::getAllDevicesOfConfig(std::vector<Device*>* devices, Config *config, { foundDevices->clear(); - for (std::vector<Config::HardwareIDs>::const_iterator hwdID = config->hwdIDs_.begin(); + for (std::vector<Config::HardwareID>::const_iterator hwdID = config->hwdIDs_.begin(); hwdID != config->hwdIDs_.end(); ++hwdID) { bool foundDevice = false; @@ -306,7 +306,6 @@ void Data::getAllDevicesOfConfig(std::vector<Device*>* devices, Config *config, } } - std::vector<Config*> Data::getAllDependenciesToInstall(Config *config) { std::vector<Config*> depends; @@ -524,7 +523,6 @@ std::vector<Config*> Data::getAllLocalRequirements(Config *config) return requirements; } - void Data::fillDevices(std::string type) { hw_item hw; @@ -612,7 +610,7 @@ bool Data::fillConfig(Config *config, std::string configPath, std::string type) // Add new HardwareIDs group to vector if vector is empty if (config->hwdIDs_.empty()) { - Config::HardwareIDs hwdID; + Config::HardwareID hwdID; config->hwdIDs_.push_back(hwdID); } @@ -674,189 +672,194 @@ bool Data::readConfigFile(Config *config, std::string configPath) { return false; } - - Vita::string line; - Vita::string key; - Vita::string value; - std::vector<Vita::string> parts; - - while (!file.eof()) + else { - getline(file, line); + Vita::string line; + Vita::string key; + Vita::string value; + std::vector<Vita::string> parts; - size_t pos = line.find_first_of('#'); - if (pos != std::string::npos) + while (!file.eof()) { - line.erase(pos); - } + getline(file, line); - if (line.trim().empty()) - { - continue; - } - else - { - parts = line.explode("="); - key = parts.front().trim().toLower(); - value = parts.back().trim("\"").trim(); + size_t pos = line.find_first_of('#'); + if (pos != std::string::npos) + { + line.erase(pos); + } - // Read in extern file - if (value.size() > 1 && value.substr(0, 1) == ">") + if (line.trim().empty()) { - std::ifstream file(getRightConfigPath(value.substr(1), config->basePath_).c_str(), - std::ios::in); - if (!file.is_open()) + continue; + } + else + { + parts = line.explode("="); + key = parts.front().trim().toLower(); + value = parts.back().trim("\"").trim(); + + // Read in extern file + if ((value.size() > 1) && (value.substr(0, 1) == ">")) { - return false; - } + std::ifstream file( + getRightConfigPath(value.substr(1), config->basePath_).c_str(), + std::ios::in); + if (!file.is_open()) + { + return false; + } + else + { + Vita::string line; + value.clear(); - Vita::string line; - value.clear(); + while (!file.eof()) + { + getline(file, line); - while (!file.eof()) - { - getline(file, line); + size_t pos = line.find_first_of('#'); + if (pos != std::string::npos) + { + line.erase(pos); + } - size_t pos = line.find_first_of('#'); - if (pos != std::string::npos) - { - line.erase(pos); + if (line.trim().empty()) + { + continue; + } + else + { + value += " " + line.trim(); + } + } + + value = value.trim(); + // remove all multiple spaces + while (value.find(" ") != std::string::npos) + { + value = value.replace(" ", " "); + } } + } - if (line.trim().empty()) + if (key == "include") + { + readConfigFile(config, getRightConfigPath(value, config->basePath_)); + } + else if (key == "name") + { + config->name_ = value.toLower(); + } + else if (key == "version") + { + config->version_ = value; + } + else if (key == "info") + { + config->info_ = value; + } + else if (key == "priority") + { + config->priority_ = value.convert<int>(); + } + else if (key == "freedriver") + { + value = value.toLower(); + + if (value == "false") { - continue; + config->freedriver_ = false; } - else + else if (value == "true") { - value += " " + line.trim(); + config->freedriver_ = true; } } - - value = value.trim(); - - // remove all multiple spaces - while (value.find(" ") != std::string::npos) + else if (key == "classids") { - value = value.replace(" ", " "); + // Add new HardwareIDs group to vector if vector is not empty + if (!config->hwdIDs_.back().classIDs.empty()) + { + Config::HardwareID hwdID; + config->hwdIDs_.push_back(hwdID); + } + + config->hwdIDs_.back().classIDs = splitValue(value); } - } + else if (key == "vendorids") + { + // Add new HardwareIDs group to vector if vector is not empty + if (!config->hwdIDs_.back().vendorIDs.empty()) + { + Config::HardwareID hwdID; + config->hwdIDs_.push_back(hwdID); + } - if (key == "include") - { - readConfigFile(config, getRightConfigPath(value, config->basePath_)); - } - else if (key == "name") - { - config->name_ = value.toLower(); - } - else if (key == "version") - { - config->version_ = value; - } - else if (key == "info") - { - config->info_ = value; - } - else if (key == "priority") - { - config->priority_ = value.convert<int>(); - } - else if (key == "freedriver") - { - value = value.toLower(); + config->hwdIDs_.back().vendorIDs = splitValue(value); + } + else if (key == "deviceids") + { + // Add new HardwareIDs group to vector if vector is not empty + if (!config->hwdIDs_.back().deviceIDs.empty()) + { + Config::HardwareID hwdID; + config->hwdIDs_.push_back(hwdID); + } - if (value == "false") + config->hwdIDs_.back().deviceIDs = splitValue(value); + } + else if (key == "blacklistedclassids") { - config->freedriver_ = false; + config->hwdIDs_.back().blacklistedClassIDs = splitValue(value); } - else if (value == "true") + else if (key == "blacklistedvendorids") { - config->freedriver_ = true; + config->hwdIDs_.back().blacklistedVendorIDs = splitValue(value); } - } - else if (key == "classids") - { - // Add new HardwareIDs group to vector if vector is not empty - if (!config->hwdIDs_.back().classIDs.empty()) + else if (key == "blacklisteddeviceids") { - Config::HardwareIDs hwdID; - config->hwdIDs_.push_back(hwdID); + config->hwdIDs_.back().blacklistedDeviceIDs = splitValue(value); } - - config->hwdIDs_.back().classIDs = splitValue(value); - } - else if (key == "vendorids") - { - // Add new HardwareIDs group to vector if vector is not empty - if (!config->hwdIDs_.back().vendorIDs.empty()) + else if (key == "mhwddepends") { - Config::HardwareIDs hwdID; - config->hwdIDs_.push_back(hwdID); + config->dependencies_ = splitValue(value); } - - config->hwdIDs_.back().vendorIDs = splitValue(value); - } - else if (key == "deviceids") - { - // Add new HardwareIDs group to vector if vector is not empty - if (!config->hwdIDs_.back().deviceIDs.empty()) + else if (key == "mhwdconflicts") { - Config::HardwareIDs hwdID; - config->hwdIDs_.push_back(hwdID); + config->conflicts_ = splitValue(value); } - - config->hwdIDs_.back().deviceIDs = splitValue(value); - } - else if (key == "blacklistedclassids") - { - config->hwdIDs_.back().blacklistedClassIDs = splitValue(value); - } - else if (key == "blacklistedvendorids") - { - config->hwdIDs_.back().blacklistedVendorIDs = splitValue(value); } - else if (key == "blacklisteddeviceids") + } + + // Append * to all empty vectors + for (Config::HardwareID& hwdID : config->hwdIDs_) + { + if (hwdID.classIDs.empty()) { - config->hwdIDs_.back().blacklistedDeviceIDs = splitValue(value); + hwdID.classIDs.push_back("*"); } - else if (key == "mhwddepends") + + if (hwdID.vendorIDs.empty()) { - config->dependencies_ = splitValue(value); + hwdID.vendorIDs.push_back("*"); } - else if (key == "mhwdconflicts") + + if (hwdID.deviceIDs.empty()) { - config->conflicts_ = splitValue(value); + hwdID.deviceIDs.push_back("*"); } } - } - // Append * to all empty vectors - for (std::vector<Config::HardwareIDs>::iterator hwdID = config->hwdIDs_.begin(); - hwdID != config->hwdIDs_.end(); hwdID++) - { - if ((*hwdID).classIDs.empty()) + if (config->name_.empty()) { - (*hwdID).classIDs.push_back("*"); + return false; } - - if ((*hwdID).vendorIDs.empty()) - { - (*hwdID).vendorIDs.push_back("*"); - } - - if ((*hwdID).deviceIDs.empty()) + else { - (*hwdID).deviceIDs.push_back("*"); + return true; } } - - if (config->name_.empty()) - { - return false; - } - - return true; } Vita::string Data::getRightConfigPath(Vita::string str, Vita::string baseConfigPath)