summaryrefslogtreecommitdiff
path: root/hyprpm/src/core/Manifest.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-12-07 10:41:09 +0000
committerGitHub <noreply@github.com>2023-12-07 10:41:09 +0000
commitd36055054651442db19df046cbdd0697b805c541 (patch)
treed66ec48c6a47cd2b331fe133dc43d57e6d1ec376 /hyprpm/src/core/Manifest.cpp
parent62a8d0be5c1959ade8410f8f964e362288f22175 (diff)
hyprpm: Add hyprpm, a Hyprland Plugin Manager (#4072)
Diffstat (limited to 'hyprpm/src/core/Manifest.cpp')
-rw-r--r--hyprpm/src/core/Manifest.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/hyprpm/src/core/Manifest.cpp b/hyprpm/src/core/Manifest.cpp
new file mode 100644
index 00000000..27ad058a
--- /dev/null
+++ b/hyprpm/src/core/Manifest.cpp
@@ -0,0 +1,104 @@
+#include "Manifest.hpp"
+#include <toml++/toml.hpp>
+#include <iostream>
+
+CManifest::CManifest(const eManifestType type, const std::string& path) {
+ auto manifest = toml::parse_file(path);
+
+ if (type == MANIFEST_HYPRLOAD) {
+ for (auto& [key, val] : manifest) {
+ if (key.str().ends_with(".build"))
+ continue;
+
+ CManifest::SManifestPlugin plugin;
+ plugin.name = key;
+ m_vPlugins.push_back(plugin);
+ }
+
+ for (auto& plugin : m_vPlugins) {
+ plugin.description = manifest[plugin.name]["description"].value_or("?");
+ plugin.version = manifest[plugin.name]["version"].value_or("?");
+ plugin.output = manifest[plugin.name]["build"]["output"].value_or("?");
+ auto authors = manifest[plugin.name]["authors"].as_array();
+ if (authors) {
+ for (auto&& a : *authors) {
+ plugin.authors.push_back(a.as_string()->value_or("?"));
+ }
+ } else {
+ auto author = manifest[plugin.name]["author"].value_or("");
+ if (!std::string{author}.empty())
+ plugin.authors.push_back(author);
+ }
+ auto buildSteps = manifest[plugin.name]["build"]["steps"].as_array();
+ if (buildSteps) {
+ for (auto&& s : *buildSteps) {
+ plugin.buildSteps.push_back(s.as_string()->value_or("?"));
+ }
+ }
+
+ if (plugin.output.empty() || plugin.buildSteps.empty()) {
+ m_bGood = false;
+ return;
+ }
+ }
+ } else if (type == MANIFEST_HYPRPM) {
+ m_sRepository.name = manifest["repository"]["name"].value_or("");
+ auto authors = manifest["repository"]["authors"].as_array();
+ if (authors) {
+ for (auto&& a : *authors) {
+ m_sRepository.authors.push_back(a.as_string()->value_or("?"));
+ }
+ } else {
+ auto author = manifest["repository"]["author"].value_or("");
+ if (!std::string{author}.empty())
+ m_sRepository.authors.push_back(author);
+ }
+
+ auto pins = manifest["repository"]["commit_pins"].as_array();
+ if (pins) {
+ for (auto&& pin : *pins) {
+ auto pinArr = pin.as_array();
+ if (pinArr && pinArr->get(1))
+ m_sRepository.commitPins.push_back(std::make_pair<>(pinArr->get(0)->as_string()->get(), pinArr->get(1)->as_string()->get()));
+ }
+ }
+
+ for (auto& [key, val] : manifest) {
+ if (key.str() == "repository")
+ continue;
+
+ CManifest::SManifestPlugin plugin;
+ plugin.name = key;
+ m_vPlugins.push_back(plugin);
+ }
+
+ for (auto& plugin : m_vPlugins) {
+ plugin.description = manifest[plugin.name]["description"].value_or("?");
+ plugin.output = manifest[plugin.name]["output"].value_or("?");
+ auto authors = manifest[plugin.name]["authors"].as_array();
+ if (authors) {
+ for (auto&& a : *authors) {
+ plugin.authors.push_back(a.as_string()->value_or("?"));
+ }
+ } else {
+ auto author = manifest[plugin.name]["author"].value_or("");
+ if (!std::string{author}.empty())
+ plugin.authors.push_back(author);
+ }
+ auto buildSteps = manifest[plugin.name]["build"].as_array();
+ if (buildSteps) {
+ for (auto&& s : *buildSteps) {
+ plugin.buildSteps.push_back(s.as_string()->value_or("?"));
+ }
+ }
+
+ if (plugin.output.empty() || plugin.buildSteps.empty()) {
+ m_bGood = false;
+ return;
+ }
+ }
+ } else {
+ // ???
+ m_bGood = false;
+ }
+} \ No newline at end of file