config file: try to detect Wine executable's path

pull/41/head
jackun 4 years ago
parent ca738c4126
commit 6086a6b9ab
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -39,7 +39,7 @@ void parseConfigLine(std::string line){
void parseConfigFile() {
std::vector<std::string> paths;
std::string home;
static const char *config_dir = "/.config/MangoHud";
static const char *config_dir = "/.config/MangoHud/";
const char *env_home = std::getenv("HOME");
if (env_home)
@ -51,13 +51,34 @@ void parseConfigFile() {
std::string exe_path = get_exe_path();
auto n = exe_path.find_last_of('/');
if (!exe_path.empty() && n != std::string::npos) {
if (!exe_path.empty() && n != std::string::npos && n < exe_path.size() - 1) {
// as executable's name
std::string basename = exe_path.substr(n + 1);
if (!home.empty())
paths.push_back(home + config_dir + exe_path.substr(n) + ".conf");
paths.push_back(home + config_dir + basename + ".conf");
// in executable's folder though not much sense in /usr/bin/
paths.push_back(exe_path.substr(0, n) + "/MangoHud.conf");
// find executable's path when run in Wine
if (!home.empty() && (basename == "wine-preloader" || basename == "wine64-preloader")) {
std::string line;
std::ifstream stream("/proc/self/cmdline");
while (std::getline(stream, line, '\0'))
{
if (!line.empty()
&& (n = line.find_last_of('\\')) != std::string::npos
&& n < line.size() - 1) // have at least one character
{
auto dot = line.find_last_of('.');
if (dot < n)
dot = line.size();
paths.push_back(home + config_dir + "wine-" + line.substr(n + 1, dot - n - 1) + ".conf");
break;
}
}
}
}
std::string line;

Loading…
Cancel
Save