diff --git a/src/config.hpp b/src/config.hpp new file mode 100644 index 0000000..b559f69 --- /dev/null +++ b/src/config.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace dropshell { + +// Configuration functions +bool get_config_path(std::string& path); +bool load_config(); +bool is_config_loaded(); +bool get_user_directory(std::string& path); +void init_user_directory(const std::string& path); + +} // namespace dropshell \ No newline at end of file diff --git a/src/dropshell.hpp b/src/dropshell.hpp index 0971ea8..eeba8c1 100644 --- a/src/dropshell.hpp +++ b/src/dropshell.hpp @@ -3,6 +3,7 @@ #include #include #include +#include "config.hpp" namespace dropshell { @@ -23,13 +24,8 @@ void print_help(const boost::program_options::options_description& desc); void print_version(); void check_status(); void list_servers(); -void init_user_directory(const std::string& path); // Utility functions std::vector get_configured_servers(); -bool get_config_path(std::string& path); -bool load_config(); -bool is_config_loaded(); -bool get_user_directory(std::string& path); } // namespace dropshell \ No newline at end of file diff --git a/src/templates.cpp b/src/templates.cpp index 9d41c0c..286c73e 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -1,2 +1,76 @@ -#include "dropshell.hpp" +#include "templates.hpp" +#include "config.hpp" +#include +#include +#include +#include + +template_manager::template_manager() { + // Constructor implementation +} + +template_manager::~template_manager() { + // Destructor implementation +} + +bool template_manager::get_templates(std::vector& templates) { + templates.clear(); + + // System templates directory + const std::string system_templates_dir = "/opt/dropshell/templates"; + // User templates directory (from config) + std::string user_templates_dir; + if (!get_user_directory(user_templates_dir)) { + return false; + } + user_templates_dir += "/usertemplates"; + + // Helper function to add templates from a directory + auto add_templates_from_dir = [&templates](const std::string& dir_path) { + if (!std::filesystem::exists(dir_path)) { + return; + } + + for (const auto& entry : std::filesystem::directory_iterator(dir_path)) { + if (entry.is_directory()) { + template_info info; + info.name = entry.path().filename().string(); + info.path = entry.path().string(); + + // Check if template with same name already exists + auto it = std::find_if(templates.begin(), templates.end(), + [&info](const template_info& t) { return t.name == info.name; }); + + if (it == templates.end()) { + templates.push_back(info); + } + } + } + }; + + // First add system templates + add_templates_from_dir(system_templates_dir); + + // Then add user templates (which will override system templates with same name) + add_templates_from_dir(user_templates_dir); + + return true; +} + +bool template_manager::get_template_info(const std::string& name, template_info& info) { + std::vector templates; + if (!get_templates(templates)) { + return false; + } + + auto it = std::find_if(templates.begin(), templates.end(), + [&name](const template_info& t) { return t.name == name; }); + + if (it != templates.end()) { + info = *it; + return true; + } + + return false; +}