From 43a10f5c3f49c586d0bc6b817182dc677bf6520b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 21 Apr 2025 11:29:39 +1200 Subject: [PATCH] . --- CMakeLists.txt | 5 +++++ src/config.cpp | 8 +++++++- src/templates.cpp | 2 ++ src/templates.hpp | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/templates.cpp create mode 100644 src/templates.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c955c1b..93cad71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,3 +34,8 @@ install(FILES src/dropshell-completion.bash DESTINATION /etc/bash_completion.d RENAME dropshell ) + +# Install templates +install(DIRECTORY templates/ + DESTINATION /opt/dropshell/templates +) diff --git a/src/config.cpp b/src/config.cpp index 4d91a84..e73981a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -78,11 +78,17 @@ void init_user_directory(const std::string& path) { // Convert to absolute path fs::path abs_path = fs::absolute(path); - // Create directory if it doesn't exist + // The directory must exist if (!fs::exists(abs_path)) { throw std::runtime_error("The user directory does not exist: " + abs_path.string()); } + // create the servers subdirectory if it doesn't exist + fs::path servers_dir = abs_path / "servers"; + if (!fs::exists(servers_dir)) { + fs::create_directories(servers_dir); + } + // Update config file std::string config_path; if (!get_config_path(config_path)) { diff --git a/src/templates.cpp b/src/templates.cpp new file mode 100644 index 0000000..9d41c0c --- /dev/null +++ b/src/templates.cpp @@ -0,0 +1,2 @@ +#include "dropshell.hpp" + diff --git a/src/templates.hpp b/src/templates.hpp new file mode 100644 index 0000000..1bfca10 --- /dev/null +++ b/src/templates.hpp @@ -0,0 +1,22 @@ + +class template_info { + public: + std::string name; + std::string path; +}; + +// templates are stored in two locations: +// 1. /opt/dropshell/templates +// 2. CONFIG_DIR/usertemplates (if it exists) +// we aggregate the templates from both locations and return them in the order of priority. +// if a template exists in both locations, the one in the user directory takes precedence. +// the template name is just the subfolder name in the templates directory. +// the template path is the path of that subfolder. +class template_manager { + public: + template_manager(); + ~template_manager(); + + bool get_templates(std::vector& templates); + bool get_template_info(const std::string& name, template_info& info); +};