Commit 7fc67cc5 authored by Philip Müller's avatar Philip Müller

Merge branch 'master' of github.com:manjaro/mhwd

parents ba40a69f 1c55f487
......@@ -23,6 +23,7 @@
*/
#include "Config.hpp"
#include "Utils.hpp"
#include <fstream>
#include <string>
......@@ -105,91 +106,72 @@ bool Config::readConfigFile(std::string configPath)
}
}
if (key == "include")
{
readConfigFile(getRightConfigPath(value, basePath_));
}
else if (key == "name")
{
name_ = value.toLower();
}
else if (key == "version")
{
version_ = value;
}
else if (key == "info")
{
info_ = value;
}
else if (key == "priority")
{
priority_ = value.convert<int>();
}
else if (key == "freedriver")
{
value = value.toLower();
if (value == "false")
{
freedriver_ = false;
}
else if (value == "true")
{
freedriver_ = true;
}
}
else if (key == "classids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
switch(MhwdUtils::hash(std::string(key).c_str()))
{
case MhwdUtils::hash_compile_time("include"):
readConfigFile(getRightConfigPath(value, basePath_));
break;
case MhwdUtils::hash_compile_time("name"):
name_ = value.toLower();
break;
case MhwdUtils::hash_compile_time("version"):
version_ = value;
break;
case MhwdUtils::hash_compile_time("info"):
info_ = value;
break;
case MhwdUtils::hash_compile_time("priority"):
priority_ = value.convert<int>();
break;
case MhwdUtils::hash_compile_time("freedriver"):
value = value.toLower();
freedriver_ = value == "false" ? false : true;
break;
case MhwdUtils::hash_compile_time("classids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value);
}
else if (key == "vendorids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("vendorids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
}
else if (key == "deviceids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("deviceids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().deviceIDs = splitValue(value);
}
else if (key == "blacklistedclassids")
{
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
}
else if (key == "blacklistedvendorids")
{
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
}
else if (key == "blacklisteddeviceids")
{
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
}
else if (key == "mhwddepends")
{
dependencies_ = splitValue(value);
}
else if (key == "mhwdconflicts")
{
conflicts_ = splitValue(value);
hwdIDs_.back().deviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedclassids"):
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedvendorids"):
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklisteddeviceids"):
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwddepends"):
dependencies_ = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwdconflicts"):
conflicts_ = splitValue(value);
break;
}
}
......@@ -213,12 +195,7 @@ bool Config::readConfigFile(std::string configPath)
}
}
if (name_.empty())
{
return false;
}
return true;
return ! name_.empty();
}
std::vector<std::string> Config::splitValue(Vita::string str, Vita::string onlyEnding)
......
......@@ -54,29 +54,16 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT
// Print conflicts
if (!transaction.conflictedConfigs_.empty())
{
std::string conflicts;
for (auto&& conflictedConfig : transaction.conflictedConfigs_)
{
conflicts += " " + conflictedConfig->name_;
}
consoleWriter_.printError("config '" + config->name_ + "' conflicts with config(s):" +
conflicts);
gatherConfigContent(transaction.conflictedConfigs_));
return false;
}
// Print dependencies
else if (!transaction.dependencyConfigs_.empty())
{
std::string dependencies;
for (auto&& dependencyConfig : transaction.dependencyConfigs_)
{
dependencies += " " + dependencyConfig->name_;
}
consoleWriter_.printStatus("Dependencies to install:" + dependencies +
consoleWriter_.printStatus("Dependencies to install:" +
gatherConfigContent(transaction.dependencyConfigs_) +
"\nProceed with installation? [Y/n]");
std::string input;
std::getline(std::cin, input);
......@@ -88,15 +75,8 @@ bool Mhwd::performTransaction(std::shared_ptr<Config> config, MHWD::TRANSACTIONT
// Print requirements
if (!transaction.configsRequirements_.empty())
{
std::string requirements;
for (auto&& requirement : transaction.configsRequirements_)
{
requirements += " " + requirement->name_;
}
consoleWriter_.printError("config '" + config->name_ + "' is required by config(s):" +
requirements);
gatherConfigContent(transaction.configsRequirements_));
return false;
}
}
......@@ -1279,3 +1259,13 @@ int Mhwd::launch(int argc, char *argv[])
}
return 0;
}
std::string Mhwd::gatherConfigContent(const std::vector<std::shared_ptr<Config>> & configuration) const
{
std::string config;
for (auto&& c : configuration)
{
config += " " + c->name_;
}
return config;
}
\ No newline at end of file
......@@ -100,6 +100,7 @@ private:
void tryToParseCmdLineOptions(int argc, char* argv[], bool& autoConfigureNonFreeDriver,
std::string& operationType, std::string& autoConfigureClassID);
bool optionsDontInterfereWithEachOther() const;
std::string gatherConfigContent(const std::vector<std::shared_ptr<Config>> & config) const;
};
#endif /* 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>
* Oscar Forner Martinez <oscar.forner.martinez@gmail.com>
*
* 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 MHWDUTILS_HPP_
#define MHWDUTILS_HPP_
#include <string>
#include <cstdint>
namespace MhwdUtils
{
typedef std::uint64_t hash_t;
// Hardcoded values for the prime and the basis to calculate hash values.
constexpr hash_t prime = 0x100000001B3ull;
constexpr hash_t basis = 0xCBF29CE484222325ull;
constexpr hash_t hash_compile_time(char const* str, hash_t last_value = basis)
{
return *str ? hash_compile_time(str+1, (*str ^ last_value) * prime) : last_value;
}
hash_t hash(char const* str)
{
hash_t ret{basis};
while(*str){
ret ^= *str;
ret *= prime;
str++;
}
return ret;
}
}; // End namespace
#endif /* CONFIG_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