This commit is contained in:
Your Name 2025-04-21 11:29:39 +12:00
parent 10d663971c
commit 43a10f5c3f
4 changed files with 36 additions and 1 deletions

View File

@ -34,3 +34,8 @@ install(FILES src/dropshell-completion.bash
DESTINATION /etc/bash_completion.d DESTINATION /etc/bash_completion.d
RENAME dropshell RENAME dropshell
) )
# Install templates
install(DIRECTORY templates/
DESTINATION /opt/dropshell/templates
)

View File

@ -78,11 +78,17 @@ void init_user_directory(const std::string& path) {
// Convert to absolute path // Convert to absolute path
fs::path abs_path = fs::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)) { if (!fs::exists(abs_path)) {
throw std::runtime_error("The user directory does not exist: " + abs_path.string()); 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 // Update config file
std::string config_path; std::string config_path;
if (!get_config_path(config_path)) { if (!get_config_path(config_path)) {

2
src/templates.cpp Normal file
View File

@ -0,0 +1,2 @@
#include "dropshell.hpp"

22
src/templates.hpp Normal file
View File

@ -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<template_info>& templates);
bool get_template_info(const std::string& name, template_info& info);
};