config file: respect XDG dirs · flightlessmango/MangoHud@65b90fc

@@ -38,30 +38,30 @@ void parseConfigLine(std::string line){

38383939

void parseConfigFile() {

4040

std::vector<std::string> paths;

41-

std::string home;

42-

static const char *config_dir = "/.config/MangoHud/";

41+

static const char *mangohud_dir = "/MangoHud/";

434244-

const char *env_home = std::getenv("HOME");

45-

if (env_home)

46-

home = env_home;

47-

if (!home.empty()) {

48-

paths.push_back(home + "/.local/share/MangoHud/MangoHud.conf");

49-

paths.push_back(home + config_dir + "MangoHud.conf");

50-

}

43+

std::string env_data = get_data_dir();

44+

std::string env_config = get_config_dir();

45+46+

if (!env_data.empty())

47+

paths.push_back(env_data + mangohud_dir + "MangoHud.conf");

48+49+

if (!env_config.empty())

50+

paths.push_back(env_config + mangohud_dir + "MangoHud.conf");

51515252

std::string exe_path = get_exe_path();

5353

auto n = exe_path.find_last_of('/');

5454

if (!exe_path.empty() && n != std::string::npos && n < exe_path.size() - 1) {

5555

// as executable's name

5656

std::string basename = exe_path.substr(n + 1);

57-

if (!home.empty())

58-

paths.push_back(home + config_dir + basename + ".conf");

57+

if (!env_config.empty())

58+

paths.push_back(env_config + mangohud_dir + basename + ".conf");

59596060

// in executable's folder though not much sense in /usr/bin/

6161

paths.push_back(exe_path.substr(0, n) + "/MangoHud.conf");

62626363

// find executable's path when run in Wine

64-

if (!home.empty() && (basename == "wine-preloader" || basename == "wine64-preloader")) {

64+

if (!env_config.empty() && (basename == "wine-preloader" || basename == "wine64-preloader")) {

6565

std::string line;

6666

std::ifstream stream("/proc/self/cmdline");

6767

while (std::getline(stream, line, '\0'))

@@ -73,7 +73,7 @@ void parseConfigFile() {

7373

auto dot = line.find_last_of('.');

7474

if (dot < n)

7575

dot = line.size();

76-

paths.push_back(home + config_dir + "wine-" + line.substr(n + 1, dot - n - 1) + ".conf");

76+

paths.push_back(env_config + mangohud_dir + "wine-" + line.substr(n + 1, dot - n - 1) + ".conf");

7777

break;

7878

}

7979

}

@@ -98,4 +98,4 @@ void parseConfigFile() {

9898

std::cerr << " [ ok ]" << std::endl;

9999100100

}

101-

}

101+

}