diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index 7b29b862..562dc880 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -4,7 +4,21 @@ #include #include +void DataState::ensureStateStoreExists() { + const auto HOME = getenv("HOME"); + if (!HOME) { + std::cerr << "DataState: no $HOME\n"; + return; + } + const auto PATH = std::string(HOME) + "/.hyprpm/"; + + if (!std::filesystem::exists(PATH)) + std::filesystem::create_directories(PATH); +} + void DataState::addNewPluginRepo(const SPluginRepository& repo) { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -38,6 +52,8 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) { } bool DataState::pluginRepoExists(const std::string& urlOrName) { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -62,6 +78,8 @@ bool DataState::pluginRepoExists(const std::string& urlOrName) { } void DataState::removePluginRepo(const std::string& urlOrName) { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -86,6 +104,8 @@ void DataState::removePluginRepo(const std::string& urlOrName) { } void DataState::updateGlobalState(const SGlobalState& state) { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -108,6 +128,8 @@ void DataState::updateGlobalState(const SGlobalState& state) { } std::vector DataState::getAllRepositories() { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -149,6 +171,8 @@ std::vector DataState::getAllRepositories() { } bool DataState::setPluginEnabled(const std::string& name, bool enabled) { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; diff --git a/hyprpm/src/core/DataState.hpp b/hyprpm/src/core/DataState.hpp index be8792bb..f789c530 100644 --- a/hyprpm/src/core/DataState.hpp +++ b/hyprpm/src/core/DataState.hpp @@ -8,6 +8,7 @@ struct SGlobalState { }; namespace DataState { + void ensureStateStoreExists(); void addNewPluginRepo(const SPluginRepository& repo); void removePluginRepo(const std::string& urlOrName); bool pluginRepoExists(const std::string& urlOrName);