tempaltes
This commit is contained in:
parent
43a10f5c3f
commit
0eacb838ce
14
src/config.hpp
Normal file
14
src/config.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/program_options.hpp>
|
||||
#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<ServerInfo> 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
|
@ -1,2 +1,76 @@
|
||||
#include "dropshell.hpp"
|
||||
#include "templates.hpp"
|
||||
#include "config.hpp"
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
template_manager::template_manager() {
|
||||
// Constructor implementation
|
||||
}
|
||||
|
||||
template_manager::~template_manager() {
|
||||
// Destructor implementation
|
||||
}
|
||||
|
||||
bool template_manager::get_templates(std::vector<template_info>& 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<template_info> 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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user