blob: 0c106629134e5331e9620c76c2821467591abcbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "ConfigManager.hpp"
#include "supplementary/jeremy/Jeremy.hpp"
#include "legacy/ConfigManager.hpp"
#include "../debug/log/Logger.hpp"
#include <hyprutils/path/Path.hpp>
#include <filesystem>
using namespace Config;
static UP<IConfigManager> g_mgr;
//
bool Config::initConfigManager() {
if (mgr())
return true;
// run this bitch
const auto CFG_PATH = Supplementary::Jeremy::getMainConfigPath();
if (!CFG_PATH) {
Log::logger->log(Log::CRIT, "Couldn't load config: {}", CFG_PATH.error());
return false;
}
std::filesystem::path filePath = *CFG_PATH;
// TODO:
// filePath.replace_extension(".lua");
g_mgr = makeUnique<Legacy::CConfigManager>();
std::error_code ec;
if (!std::filesystem::exists(filePath, ec) || ec) {
if (ec) {
Log::logger->log(Log::CRIT, "Couldn't load config: {}", ec.message());
return false;
}
// generate default
if (const auto v = g_mgr->generateDefaultConfig(filePath); !v) {
Log::logger->log(Log::CRIT, "Couldn't generate default config: {}", v.error());
return false;
}
}
return true;
}
UP<IConfigManager>& Config::mgr() {
return g_mgr;
}
|