Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from weitcis/main
Browse files Browse the repository at this point in the history
add linux convention config paths
  • Loading branch information
pierr3 authored Apr 11, 2023
2 parents afe2045 + 4fcc63e commit 6fe46b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class configuration {

static std::string get_resource_folder();

static std::string get_linux_config_folder();

static void build_logger();

//
Expand Down
21 changes: 20 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif

#ifdef SFML_SYSTEM_LINUX
#include <cstdlib>
#include <limits.h>
#include <unistd.h>
#endif
Expand All @@ -18,7 +19,7 @@ toml::value configuration::config;

void configuration::build_config()
{
#ifdef SFML_SYSTEM_MACOS
#if defined(SFML_SYSTEM_MACOS)
std::filesystem::path folder_path = std::filesystem::path(sago::getConfigHome()) / std::filesystem::path("VectorAudio");

// On macOS we cannot be sure the folder exists as we don't use the folder of
Expand All @@ -28,6 +29,12 @@ void configuration::build_config()
}

file_path = folder_path / std::filesystem::path(file_path);
#elif defined(SFML_SYSTEM_LINUX)
std::string config_path = get_linux_config_folder();
if (!std::filesystem::exists(config_path)) {
std::filesystem::create_directory(config_path);
}
file_path = config_path + file_path;
#else
file_path = get_resource_folder() + file_path;
#endif
Expand Down Expand Up @@ -68,6 +75,18 @@ std::string configuration::get_resource_folder()
#endif
}

std::string configuration::get_linux_config_folder()
{
char* xdg_config_home_chars = getenv("XDG_CONFIG_HOME");
std::string suffix = "/vector_audio/";
if (xdg_config_home_chars) {
std::string xdg_config_home(xdg_config_home_chars);
return xdg_config_home + suffix;
}
std::string home(getenv("HOME"));
return home + "/.config" + suffix;
}

void configuration::write_config_async()
{
std::thread([]() {
Expand Down

0 comments on commit 6fe46b1

Please sign in to comment.