diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 73f69e0..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
-# Editor-based HTTP Client requests
-/httpRequests/
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index d99ee44..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-CachyOS-Installer
\ No newline at end of file
diff --git a/.idea/discord.xml b/.idea/discord.xml
deleted file mode 100644
index a98cb47..0000000
--- a/.idea/discord.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 79b3c94..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index d324358..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/new-installer.iml b/.idea/new-installer.iml
deleted file mode 100644
index f08604b..0000000
--- a/.idea/new-installer.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42bd0ec..895bb2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,7 @@ target_compile_features(project_options INTERFACE cxx_std_20)
##
add_executable(${PROJECT_NAME}
src/definitions.hpp
+ src/config.cpp src/config.hpp
src/utils.cpp src/utils.hpp
src/tui.cpp src/tui.hpp
src/main.cpp
diff --git a/meson.build b/meson.build
index dc888d8..0bb6fbb 100644
--- a/meson.build
+++ b/meson.build
@@ -29,6 +29,7 @@ nlohmann_json = dependency('nlohmann_json', version : ['>=3.10.4'], fallback : [
src_files = files(
'src/definitions.hpp',
+ 'src/config.cpp', 'src/config.hpp',
'src/utils.cpp', 'src/utils.hpp',
'src/tui.cpp', 'src/tui.hpp',
'src/main.cpp',
diff --git a/src/config.cpp b/src/config.cpp
new file mode 100644
index 0000000..07807f7
--- /dev/null
+++ b/src/config.cpp
@@ -0,0 +1,24 @@
+#include "config.hpp"
+#include "definitions.hpp"
+
+#include
+
+static std::unique_ptr s_config = nullptr;
+
+bool Config::initialize() noexcept {
+ if (s_config != nullptr) {
+ error("You should only initialize it once!\n");
+ return false;
+ }
+ s_config = std::make_unique();
+ if (!s_config) {
+ s_config->m_data["H_INIT"] = "openrc";
+ s_config->m_data["SYSTEM"] = "BIOS";
+ }
+
+ return s_config.get();
+}
+
+auto Config::instance() -> Config* {
+ return s_config.get();
+}
diff --git a/src/config.hpp b/src/config.hpp
new file mode 100644
index 0000000..efb8fd5
--- /dev/null
+++ b/src/config.hpp
@@ -0,0 +1,34 @@
+#ifndef CONFIG_HPP
+#define CONFIG_HPP
+
+#include
+#include
+#include
+
+class Config final {
+ public:
+ using value_type = std::unordered_map;
+ using reference = value_type&;
+ using const_reference = const value_type&;
+
+ Config() = default;
+ virtual ~Config() = default;
+
+ static bool initialize() noexcept;
+ static Config* instance();
+
+ /* clang-format off */
+
+ // Element access.
+ auto data() noexcept -> reference
+ { return m_data; }
+ auto data() const noexcept -> const_reference
+ { return m_data; }
+
+ /* clang-format on */
+
+ private:
+ value_type m_data{};
+};
+
+#endif // CONFIG_HPP
diff --git a/src/main.cpp b/src/main.cpp
index 2889a10..e4bb8cf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,5 +1,6 @@
#include "definitions.hpp"
#include "tui.hpp"
+#include "config.hpp"
#include "utils.hpp"
#include
@@ -19,6 +20,10 @@ int main() {
}
#endif
+ if (!Config::initialize()) {
+ return 1;
+ }
+
utils::id_system();
if (!utils::handle_connection()) {
diff --git a/src/utils.cpp b/src/utils.cpp
index 5e636a4..f81365c 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,4 +1,5 @@
#include "utils.hpp"
+#include "config.hpp"
#include
@@ -11,13 +12,9 @@
namespace fs = std::filesystem;
-static std::string_view H_INIT{"openrc"};
-static std::string_view SYSTEM{"BIOS"};
-static std::string_view NW_CMD{};
-
+namespace utils {
static constexpr int32_t CONNECTION_TIMEOUT = 15;
-namespace utils {
bool is_connected() noexcept {
return gethostbyname("google.com");
}
@@ -74,6 +71,9 @@ bool prompt_char(const char* prompt, const char* color, char* read) noexcept {
}
void id_system() noexcept {
+ auto* config_instance = Config::instance();
+ auto& config_data = config_instance->data();
+
// Apple System Detection
const auto& sys_vendor = utils::exec("cat /sys/class/dmi/id/sys_vendor");
if ((sys_vendor == "Apple Inc.\n") || (sys_vendor == "Apple Computer, Inc.\n"))
@@ -92,17 +92,17 @@ void id_system() noexcept {
exit(1);
}
}
- SYSTEM = "UEFI";
+ config_data["SYSTEM"] = "UEFI";
}
// init system
const auto& init_sys = utils::exec("cat /proc/1/comm");
if (init_sys == "systemd\n")
- H_INIT = "systemd";
+ config_data["H_INIT"] = "systemd";
// TODO: Test which nw-client is available, including if the service according to $H_INIT is running
- if (H_INIT == "systemd" && utils::exec("systemctl is-active NetworkManager") == "active\n")
- NW_CMD = "nmtui";
+ if (config_data["H_INIT"] == "systemd" && utils::exec("systemctl is-active NetworkManager") == "active\n")
+ config_data["NW_CMD"] = "nmtui";
}
bool handle_connection() noexcept {