This commit is contained in:
j842
2025-04-23 13:57:28 +12:00
parent caf1e87718
commit 88106b3260
6 changed files with 118 additions and 86 deletions

View File

@ -5,6 +5,7 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include "config.hpp"
namespace fs = boost::filesystem;
namespace pt = boost::property_tree;
@ -18,18 +19,14 @@ bool is_config_loaded() {
return config_loaded;
}
bool get_config_path(std::string& path) {
bool get_config_path(std::string &path)
{
// Try ~/.config/dropshell/dropshell.conf
const char* home = std::getenv("HOME");
if (home) {
fs::path user_path = fs::path(home) / ".config" / "dropshell" / "dropshell.conf";
if (!fs::exists(user_path)) {
// create path
fs::create_directories(user_path.parent_path());
}
path = user_path.string();
return true;
return fs::exists(path);
}
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
path = "";
@ -39,12 +36,7 @@ bool get_config_path(std::string& path) {
bool load_config() {
std::string config_path;
if (!get_config_path(config_path))
return true;
if (config_path.empty()) {
// No config file found, but this is not an error
return true;
}
return false;
try {
pt::ptree tree;