[dxvk] Add support for per-app configuration

Feature request by Alexandr Oleynikov (@tannisroot).
This commit is contained in:
Philip Rebohle 2019-04-26 19:17:32 +02:00
parent e2ebfa9012
commit ed0719432d
1 changed files with 39 additions and 15 deletions

View File

@ -161,26 +161,46 @@ namespace dxvk {
}
static void parseUserConfigLine(Config& config, const std::string& line) {
struct ConfigContext {
bool active;
};
static void parseUserConfigLine(Config& config, ConfigContext& ctx, const std::string& line) {
std::stringstream key;
std::stringstream value;
// Extract the key
size_t n = skipWhitespace(line, 0);
while (n < line.size() && isValidKeyChar(line[n]))
key << line[n++];
// Check whether the next char is a '='
n = skipWhitespace(line, n);
if (n >= line.size() || line[n] != '=')
return;
// Extract the value
n = skipWhitespace(line, n + 1);
while (n < line.size() && !isWhitespace(line[n]))
value << line[n++];
config.setOption(key.str(), value.str());
if (n < line.size() && line[n] == '[') {
n += 1;
size_t e = line.size() - 1;
while (e > n && line[e] != ']')
e -= 1;
while (n < e)
key << line[n++];
ctx.active = key.str() == env::getExeName();
} else {
while (n < line.size() && isValidKeyChar(line[n]))
key << line[n++];
// Check whether the next char is a '='
n = skipWhitespace(line, n);
if (n >= line.size() || line[n] != '=')
return;
// Extract the value
n = skipWhitespace(line, n + 1);
while (n < line.size() && !isWhitespace(line[n]))
value << line[n++];
if (ctx.active)
config.setOption(key.str(), value.str());
}
}
@ -316,11 +336,15 @@ namespace dxvk {
// help when debugging configuration issues
Logger::info(str::format("Found config file: ", filePath));
// Initialize parser context
ConfigContext ctx;
ctx.active = true;
// Parse the file line by line
std::string line;
while (std::getline(stream, line))
parseUserConfigLine(config, line);
parseUserConfigLine(config, ctx, line);
return config;
}