chore: split color_scheme_editor

This commit is contained in:
2025-12-17 01:41:44 +03:00
parent 659c5f28e5
commit f7c290110e
17 changed files with 617 additions and 453 deletions

View File

@@ -9,6 +9,7 @@
#ifdef _WIN32
#include "windows.h"
#endif
#include <iostream>
namespace clrsync::core
{
@@ -22,9 +23,10 @@ void config::initialize(std::unique_ptr<clrsync::core::io::file> file)
{
copy_default_configs();
m_file = std::move(file);
if (m_file)
if (!m_file->parse())
throw std::runtime_error{"Could not parse config file"};
if (!m_file)
throw std::runtime_error{"Config file is missing"};
if (!m_file->parse())
throw std::runtime_error{"Could not parse config file"};
}
std::filesystem::path config::get_user_config_dir()
@@ -62,13 +64,32 @@ void config::copy_file(const std::filesystem::path &src, const std::filesystem::
if (std::filesystem::exists(dst))
return;
if (!std::filesystem::exists(src))
{
std::cerr << "Warning: Source file does not exist: " << src << std::endl;
return;
}
std::ifstream in(src, std::ios::binary);
std::ofstream out(dst, std::ios::binary);
if (!in || !out)
{
std::cerr << "Warning: Failed to copy file from " << src << " to " << dst << std::endl;
return;
}
out << in.rdbuf();
}
void config::copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst)
{
if (!std::filesystem::exists(src))
{
std::cerr << "Warning: Source directory does not exist: " << src << std::endl;
return;
}
for (auto const &entry : std::filesystem::recursive_directory_iterator(src))
{
auto rel = std::filesystem::relative(entry.path(), src);
@@ -92,6 +113,12 @@ void config::copy_default_configs()
std::filesystem::create_directories(user_dir);
if (system_dir.empty())
{
std::cerr << "Warning: No system data directory found, skipping default config copy\n";
return;
}
{
auto src = system_dir / "config.toml";
auto dst = user_dir / "config.toml";

View File

@@ -47,12 +47,15 @@ void theme_template::load_template()
{
if (!std::filesystem::exists(m_template_path))
{
std::cerr << "Template file '" << m_template_path << "' is missing\n";
std::cerr << "Warning: Template file '" << m_template_path << "' is missing\n";
return;
}
std::ifstream input(m_template_path, std::ios::binary);
if (!input)
throw std::runtime_error("Failed to open template file: " + m_template_path);
{
std::cerr << "Warning: Failed to open template file: " << m_template_path << std::endl;
return;
}
m_template_data.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>());
}
@@ -89,10 +92,22 @@ void theme_template::apply_palette(const core::palette &palette)
void theme_template::save_output() const
{
std::filesystem::create_directories(std::filesystem::path(m_output_path).parent_path());
try
{
std::filesystem::create_directories(std::filesystem::path(m_output_path).parent_path());
}
catch (const std::exception& e)
{
std::cerr << "Warning: Failed to create output directory for " << m_output_path << ": " << e.what() << std::endl;
return;
}
std::ofstream output(m_output_path, std::ios::binary);
if (!output)
throw std::runtime_error("Failed to write output file: " + m_output_path);
{
std::cerr << "Warning: Failed to write output file: " << m_output_path << std::endl;
return;
}
output << m_processed_data;
}

View File

@@ -13,6 +13,10 @@ void print_color_keys()
std::string get_default_config_path()
{
const char* env_path = std::getenv("CLRSYNC_CONFIG_PATH");
if (env_path && env_path[0] != '\0')
return expand_user(env_path);
auto home = expand_user("~");
#ifdef _WIN32
return home + "\\.config\\clrsync\\config.toml";

View File

@@ -7,7 +7,7 @@
namespace clrsync::core
{
const std::string GIT_SEMVER = "0.1.4+git.gcd81744";
const std::string GIT_SEMVER = "0.1.4+git.g659c5f2";
const std::string version_string();
} // namespace clrsync::core