Ejemplo n.º 1
0
Vita::string Data::getRightConfigPath(Vita::string str, Vita::string baseConfigPath)
{
	str = str.trim();

	if (str.size() <= 0 || str.substr(0, 1) == "/")
		return str;

	return baseConfigPath + "/" + str;
}
Ejemplo n.º 2
0
std::vector<std::string> mhwd::splitValue(Vita::string str, Vita::string onlyEnding) {
    std::vector<Vita::string> work = str.toLower().explode(" ");
    std::vector<std::string> final;

    for (std::vector<Vita::string>::const_iterator iterator = work.begin(); iterator != work.end(); iterator++) {
        if (*iterator != "" && onlyEnding.empty())
            final.push_back(*iterator);
        else if (*iterator != "" && Vita::string(*iterator).explode(".").back() == onlyEnding && (*iterator).size() > 5)
            final.push_back(Vita::string(*iterator).substr(0, (*iterator).size() - 5));
    }
Ejemplo n.º 3
0
bool Config::readConfigFile(std::string configPath)
{
	std::ifstream file(configPath.c_str(), std::ios::in);

	if (!file.is_open())
	{
		return false;
	}

	Vita::string line;
	Vita::string key;
	Vita::string value;
	std::vector<Vita::string> parts;

	while (!file.eof())
	{
		getline(file, line);

		size_t pos = line.find_first_of('#');
		if (pos != std::string::npos)
		{
			line.erase(pos);
		}

		if (line.trim().empty())
		{
			continue;
		}

		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) == ">")
		{
			std::ifstream file(getRightConfigPath(value.substr(1), basePath_).c_str(),
					std::ios::in);
			if (!file.is_open())
			{
				return false;
			}

			Vita::string line;
			value.clear();

			while (!file.eof())
			{
				getline(file, line);

				size_t pos = line.find_first_of('#');
				if (pos != std::string::npos)
				{
					line.erase(pos);
				}

				if (line.trim().empty())
				{
					continue;
				}

				value += " " + line.trim();
			}

			value = value.trim();

			// remove all multiple spaces
			while (value.find("  ") != std::string::npos)
			{
				value = value.replace("  ", " ");
			}
		}

		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::HardwareIDs 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::HardwareIDs 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::HardwareIDs 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);
		}
	}

	// Append * to all empty vectors
	for (std::vector<Config::HardwareIDs>::iterator hwdID = hwdIDs_.begin();
			hwdID != hwdIDs_.end(); hwdID++)
	{
		if ((*hwdID).classIDs.empty())
		{
			(*hwdID).classIDs.push_back("*");
		}

		if ((*hwdID).vendorIDs.empty())
		{
			(*hwdID).vendorIDs.push_back("*");
		}

		if ((*hwdID).deviceIDs.empty())
		{
			(*hwdID).deviceIDs.push_back("*");
		}
	}

	if (name_.empty())
	{
		return false;
	}

	return true;
}
Ejemplo n.º 4
0
bool mhwd::readConfigFile(mhwd::Config *config, std::string configPath) {
    std::ifstream file(configPath.c_str(), std::ios::in);

    if (!file.is_open())
        return false;

    Vita::string line, key, value;
    std::vector<Vita::string> parts;

    while (!file.eof()) {
        getline(file, line);

        size_t pos = line.find_first_of('#');
        if (pos != std::string::npos)
            line.erase(pos);

        if (line.trim().empty())
            continue;

        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) == ">") {
            std::ifstream file(getRightConfigPath(value.substr(1), config->basePath).c_str(), std::ios::in);
            if (!file.is_open())
                return false;

            Vita::string line;
            value.clear();

            while (!file.eof()) {
                getline(file, line);

                size_t pos = line.find_first_of('#');
                if (pos != std::string::npos)
                    line.erase(pos);

                if (line.trim().empty())
                    continue;

                value += " " + line.trim();
            }

            file.close();

            value = value.trim();

            // remove all multiple spaces
            while (value.find("  ") != std::string::npos) {
                value = value.replace("  ", " ");
            }
        }


        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")
                config->freedriver = false;
            else if (value == "true")
                config->freedriver = true;
        }
        else if (key == "classids") {
            // Add new HardwareIDs group to vector if vector is not empty
            if (!config->hwdIDs.back().classIDs.empty()) {
                mhwd::Config::HardwareIDs 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()) {
                mhwd::Config::HardwareIDs hwdID;
                config->hwdIDs.push_back(hwdID);
            }

            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()) {
                mhwd::Config::HardwareIDs hwdID;
                config->hwdIDs.push_back(hwdID);
            }

            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") {
            config->hwdIDs.back().blacklistedDeviceIDs = splitValue(value);
        }
        else if (key == "mhwddepends") {
            config->dependencies = splitValue(value);
        }
        else if (key == "mhwdconflicts") {
            config->conflicts = splitValue(value);
        }
    }

    file.close();

    // Append * to all empty vectors
    for (std::vector<mhwd::Config::HardwareIDs>::iterator iterator = config->hwdIDs.begin(); iterator != config->hwdIDs.end(); iterator++) {
        if ((*iterator).classIDs.empty())
            (*iterator).classIDs.push_back("*");

        if ((*iterator).vendorIDs.empty())
            (*iterator).vendorIDs.push_back("*");

        if ((*iterator).deviceIDs.empty())
            (*iterator).deviceIDs.push_back("*");
    }

    if (config->name.empty())
        return false;

    return true;
}