Skip to content

Commit

Permalink
app: config-manager load rec-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Feb 13, 2025
1 parent 00665bc commit 67949f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/include/irritator/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class config_manager

/** Build a @c variables object from the file @c config_path. If it fail,
the default object from static data is build. */
config_manager(const std::string config_path) noexcept;
explicit config_manager(const std::string config_path) noexcept;

config_manager(config_manager&&) noexcept = delete;
config_manager& operator=(config_manager&&) noexcept = delete;
Expand Down
36 changes: 33 additions & 3 deletions lib/src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct membuf : std::streambuf {
this->setg(p, p, p + size);
}
};

struct imemstream
: virtual membuf
, std::istream {
Expand Down Expand Up @@ -65,9 +66,36 @@ static std::shared_ptr<variables> do_build_default() noexcept
{
auto v = std::make_shared<variables>();

v->rec_paths.ids.reserve(16);
v->rec_paths.paths.resize(16);
v->rec_paths.priorities.resize(16);

if (auto sys = get_system_component_dir(); sys.has_value()) {
const auto idx = v->rec_paths.ids.alloc();
v->rec_paths.paths[get_index(idx)] =
(const char*)sys->u8string().c_str();
v->rec_paths.priorities[get_index(idx)] = 20;
v->rec_paths.names[get_index(idx)] = "system";
}

if (auto sys = get_system_prefix_component_dir(); sys.has_value()) {
const auto idx = v->rec_paths.ids.alloc();
v->rec_paths.paths[get_index(idx)] =
(const char*)sys->u8string().c_str();
v->rec_paths.priorities[get_index(idx)] = 10;
v->rec_paths.names[get_index(idx)] = "local system";
}

if (auto sys = get_default_user_component_dir(); sys.has_value()) {
const auto idx = v->rec_paths.ids.alloc();
v->rec_paths.paths[get_index(idx)] =
(const char*)sys->u8string().c_str();
v->rec_paths.priorities[get_index(idx)] = 0;
v->rec_paths.names[get_index(idx)] = "user";
}

v->g_themes.ids.reserve(16);
v->g_themes.names.resize(16);

v->g_themes.selected = alloc_gui_theme("Modern", v->g_themes);
alloc_gui_theme("Dark", v->g_themes);
alloc_gui_theme("Light", v->g_themes);
Expand Down Expand Up @@ -116,7 +144,7 @@ static std::error_code do_save(const char* filename,
return std::make_error_code(
std::errc(std::errc::no_such_file_or_directory));

file << "# irritator 0.x\n;\n";
file << "# irritator 0.x\n";
if (file.bad())
return std::make_error_code(std::errc(std::errc::io_error));

Expand Down Expand Up @@ -339,7 +367,9 @@ config_manager::config_manager(const std::string config_path) noexcept
: m_path{ config_path }
, m_vars{ do_build_default() }
{
(void)do_load(config_path.c_str(), m_vars);
if (do_load(config_path.c_str(), m_vars)) {
(void)save();
}
}

std::error_code config_manager::save() const noexcept
Expand Down

0 comments on commit 67949f6

Please sign in to comment.