mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 14:52:11 +01:00
[dxvk] Add support for per-app configuration
Feature request by Alexandr Oleynikov (@tannisroot).
This commit is contained in:
parent
e2ebfa9012
commit
ed0719432d
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user