diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-05 13:22:34 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-05 13:22:34 +0100 |
commit | 1f8da4902761fc6f6eaf39b8711107c6b48a9c9a (patch) | |
tree | a0a4f0a1c164080fc313fe37cbb5a91f6ce883d1 /config.cpp | |
parent | 770540693fd4a5f9b64c1b2bc8183be3f72ab314 (diff) |
Debian build, colors, config filename
Diffstat (limited to 'config.cpp')
-rw-r--r-- | config.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -2,6 +2,9 @@ #include "log.h" +#include <filesystem> +#include <string> + #include <libreichwein/file.h> #include <libreichwein/stringhelper.h> @@ -9,6 +12,8 @@ #include <string> +using namespace std::string_literals; + const char *device = "default"; // playback device std::string config_filename = "click.cfg"; @@ -33,7 +38,7 @@ void Config::recover() m_mode = default_mode; m_output = default_output; - std::string config = Reichwein::File::getFile(config_filename); + std::string config = Reichwein::File::getFile(get_config_filename()); std::vector<std::string> lines = Reichwein::Stringhelper::split(config, "\n"); @@ -73,7 +78,7 @@ void Config::persist() fmt::format("mode={}\n", m_mode) + fmt::format("output={}\n", m_output); - Reichwein::File::setFile(config_filename, config); + Reichwein::File::setFile(get_config_filename(), config); } int Config::get_midi_channel() @@ -131,3 +136,12 @@ void Config::set_output(int output) signal_output(output); } +std::string Config::get_config_filename() +{ + char* envvar = getenv("HOME"); + if (envvar == nullptr || !std::filesystem::exists(envvar)) { + return config_filename; + } else { + return std::filesystem::path(getenv("HOME")) / ("."s + config_filename); + } +} |