diff options
author | Vaxry <[email protected]> | 2023-12-06 17:23:02 +0000 |
---|---|---|
committer | Vaxry <[email protected]> | 2023-12-06 23:31:03 +0000 |
commit | 02eae0a10769b1dc2f57a3545b9d82aa960ac0b8 (patch) | |
tree | d25d57dbedf1bb9cf9b89f1d0c2815dbac8f1eb1 | |
parent | e13cc2e71b03e72f54b62e1ddee7963acbc356ea (diff) | |
download | Hyprland-02eae0a10769b1dc2f57a3545b9d82aa960ac0b8.tar.gz Hyprland-02eae0a10769b1dc2f57a3545b9d82aa960ac0b8.zip |
ensure state store always exists
-rw-r--r-- | hyprpm/src/core/DataState.cpp | 24 | ||||
-rw-r--r-- | hyprpm/src/core/DataState.hpp | 1 |
2 files changed, 25 insertions, 0 deletions
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 <filesystem> #include <fstream> +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<SPluginRepository> DataState::getAllRepositories() { + ensureStateStoreExists(); + const auto HOME = getenv("HOME"); if (!HOME) { std::cerr << "DataState: no $HOME\n"; @@ -149,6 +171,8 @@ std::vector<SPluginRepository> 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); |