bleh
This commit is contained in:
parent
dff976ed0e
commit
3ebbb2b3ec
6 changed files with 58 additions and 52 deletions
|
@ -1,26 +1,43 @@
|
|||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using rfl::Result;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
inline fn GetConfigPath() -> string {
|
||||
return getenv(
|
||||
#ifdef __WIN32__
|
||||
"LOCALAPPDATA"
|
||||
inline fn GetConfigPath() -> std::string {
|
||||
#ifdef _WIN32
|
||||
const char* localAppData = std::getenv("LOCALAPPDATA");
|
||||
|
||||
if (!localAppData)
|
||||
throw std::runtime_error("Environment variable LOCALAPPDATA is not set");
|
||||
|
||||
return localAppData;
|
||||
#else
|
||||
"HOME"
|
||||
const char* home = std::getenv("HOME");
|
||||
|
||||
if (!home)
|
||||
throw std::runtime_error("Environment variable HOME is not set");
|
||||
|
||||
return std::string(home) + "/.config";
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
fn Config::getInstance() -> Config {
|
||||
const string path = GetConfigPath() + "\\draconis++\\config.toml";
|
||||
const Result<Config> result = rfl::toml::load<Config>(path);
|
||||
try {
|
||||
fs::path configPath = GetConfigPath();
|
||||
configPath /= "draconis++/config.toml";
|
||||
|
||||
if (result)
|
||||
return result.value();
|
||||
const Result<Config> result = rfl::toml::load<Config>(configPath.string());
|
||||
|
||||
if (result)
|
||||
return result.value();
|
||||
|
||||
fmt::println("Failed to load config file: {}", result.error().value().what());
|
||||
} catch (const std::exception& e) { fmt::println("Error getting config path: {}", e.what()); }
|
||||
|
||||
fmt::println("Failed to load config file: {}", result.error().value().what());
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue