tidy
This commit is contained in:
parent
f9b67ff4c0
commit
986b9be2b4
@ -25,7 +25,7 @@ config::~config() {
|
|||||||
|
|
||||||
bool config::load_config() {
|
bool config::load_config() {
|
||||||
std::string config_path = get_local_dropshell_config_path();
|
std::string config_path = get_local_dropshell_config_path();
|
||||||
if (config_path.empty())
|
if (config_path.empty() || !fs::exists(config_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
envmanager config_env(config_path);
|
envmanager config_env(config_path);
|
||||||
@ -35,8 +35,8 @@ bool config::load_config() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
local_config_directory = config_env.get_variable_substituted("local.config.directory");
|
mLocalConfigPath = config_env.get_variable_substituted("local.config.directory");
|
||||||
if (local_config_directory.empty())
|
if (mLocalConfigPath.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "Warning: User directory not set in config" << std::endl;
|
std::cerr << "Warning: User directory not set in config" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -46,39 +46,42 @@ bool config::load_config() {
|
|||||||
|
|
||||||
void config::save_config()
|
void config::save_config()
|
||||||
{
|
{
|
||||||
std::string config_path = get_local_dropshell_config_path();
|
if (mLocalConfigPath.empty())
|
||||||
if (config_path.empty())
|
|
||||||
{
|
{
|
||||||
std::cerr << "Warning: Unable to save configuration file, as DropShell has not been initialised."<< std::endl;
|
std::cerr << "Warning: Unable to save configuration file, as DropShell has not been initialised."<< std::endl;
|
||||||
std::cerr << "Please run 'dropshell init <path>' to initialise DropShell." << std::endl;
|
std::cerr << "Please run 'dropshell init <path>' to initialise DropShell." << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string config_path = get_local_dropshell_config_path();
|
||||||
envmanager config_env(config_path);
|
envmanager config_env(config_path);
|
||||||
config_env.set_variable("local.config.directory", local_config_directory);
|
config_env.set_variable("local.config.directory", mLocalConfigPath);
|
||||||
config_env.save();
|
config_env.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool config::is_config_set() const
|
bool config::is_config_set() const
|
||||||
{
|
{
|
||||||
return !local_config_directory.empty();
|
return !mLocalConfigPath.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool config::get_local_config_directory(std::string& path) const {
|
bool config::get_local_config_directory(std::string& path) const {
|
||||||
path = local_config_directory;
|
path = mLocalConfigPath;
|
||||||
return !path.empty();
|
return !path.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void config::init_local_config_directory(const std::string& path) {
|
void config::init_local_config_directory(const std::string& path) {
|
||||||
|
if (path.empty())
|
||||||
|
throw std::runtime_error("Warning: Unable to initialise local config directory, as the path is empty.");
|
||||||
|
|
||||||
// Convert to canonical path
|
// Convert to canonical path
|
||||||
fs::path abs_path = fs::canonical(path);
|
fs::path abs_path = fs::canonical(path);
|
||||||
|
|
||||||
// The directory must exist
|
// The directory must exist
|
||||||
if (!fs::exists(abs_path)) {
|
if (!fs::exists(abs_path)) {
|
||||||
throw std::runtime_error("The specifieduser directory does not exist: " + abs_path.string());
|
throw std::runtime_error("The local config directory does not exist: " + abs_path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
local_config_directory = abs_path.string();
|
mLocalConfigPath = abs_path.string();
|
||||||
save_config();
|
save_config();
|
||||||
std::cout << "Local config directory initialized to: " << abs_path.string() << std::endl;
|
std::cout << "Local config directory initialized to: " << abs_path.string() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class config {
|
|||||||
void init_local_config_directory(const std::string& path);
|
void init_local_config_directory(const std::string& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string local_config_directory;
|
std::string mLocalConfigPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ int main(int argc, char* argv[]) {
|
|||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// from here we require the config file to be loaded.
|
// from here we require the config file to be loaded.
|
||||||
if (!cfg->is_config_set()) {
|
if (!cfg->is_config_set()) {
|
||||||
std::cerr << "Error: Failed to load configuration." << std::endl << "Please run 'dropshell init <path>' to initialise the user directory and create a configuration file." << std::endl;
|
std::cerr << "Please run 'dropshell init <path>' to initialise the user directory and create a configuration file." << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ std::vector<ServerInfo> get_configured_servers() {
|
|||||||
|
|
||||||
std::string servers_dir = get_local_config_servers_path();
|
std::string servers_dir = get_local_config_servers_path();
|
||||||
if (servers_dir.empty()) {
|
if (servers_dir.empty()) {
|
||||||
std::cerr << "Error: Servers directory not found" << std::endl;
|
|
||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user