21#include <system_error>
28void write_file(
const std::filesystem::path& path, std::string_view content) {
29 std::filesystem::create_directories(path.parent_path());
30 std::ofstream stream(path, std::ios::binary);
34 stream.write(content.data(),
static_cast<std::streamsize
>(content.size()));
37std::string read_file(
const std::filesystem::path& path) {
38 std::ifstream stream(path, std::ios::binary);
39 std::ostringstream buffer;
40 buffer << stream.rdbuf();
47bool differs_from_embedded(
const std::filesystem::path& dir,
48 const std::vector<assets::EmbeddedFile>& files) {
49 if (!std::filesystem::exists(dir))
return false;
50 for (
const auto& file : files) {
51 const std::filesystem::path target = dir / file.name;
52 if (!std::filesystem::exists(target))
return true;
53 if (read_file(target) != file.content)
return true;
58void write_all(
const std::filesystem::path& dir,
59 const std::vector<assets::EmbeddedFile>& files) {
60 std::filesystem::create_directories(dir);
61 for (
const auto& file : files) {
62 write_file(dir / file.name, file.content);
64 PLOG_DEBUG <<
"Wrote " << files.size() <<
" embedded file(s) into '"
65 << dir.string() <<
"'.";
71bool confirm_overwrite_if_needed(
const std::filesystem::path& dir,
72 const std::vector<assets::EmbeddedFile>& files,
74 if (!differs_from_embedded(dir, files) || force)
return true;
77 "A different NoTeX installation already exists at '" + dir.string() +
81 PLOG_WARNING <<
"Installation cancelled by the user for '"
82 << dir.string() <<
"'.";
106 PLOG_WARNING <<
"Could not refresh the TeX filename database after "
109 ui::warning(std::string(
"could not refresh the TeX filename "
119 const std::filesystem::path settings_dir = target_dir /
"settings";
120 const std::filesystem::path fonts_dir = target_dir /
"fonts";
132 const bool already_project =
133 std::filesystem::is_directory(target_dir /
".notex");
135 if (already_project) {
150 PLOG_WARNING <<
"Global uninstall cancelled by the user.";
163 PLOG_WARNING <<
"Could not refresh the TeX filename database after "
164 "a global uninstall: "
166 ui::warning(std::string(
"could not refresh the TeX filename "
177 !
ui::confirm(
"Remove the local NoTeX installation from '" +
178 (target_dir /
"settings").
string() +
"' and '" +
179 (target_dir /
"fonts").
string() +
"'?",
181 PLOG_WARNING <<
"Local uninstall cancelled by the user for '"
182 << target_dir.string() <<
"'.";
188 std::filesystem::remove_all(target_dir /
"settings", ec);
189 std::filesystem::remove_all(target_dir /
"fonts", ec);
191 if (std::filesystem::is_directory(target_dir /
".notex")) {
201 const std::filesystem::path& fonts_dir) {
Accessor over the LaTeX template and font files embedded into the binary.
Represents the surrounding system as NoTeX perceives it: where TeX expects user files to live,...
const std::filesystem::path & global_fonts_dir() const noexcept
const std::filesystem::path & texmf_home() const noexcept
const std::filesystem::path & global_latex_dir() const noexcept
Raised when a filesystem operation (copy, write, remove) fails.
static bool install_local(const std::filesystem::path &target_dir, bool force=false)
Installs the template locally into target_dir.
static bool installation_differs(const std::filesystem::path &latex_dir, const std::filesystem::path &fonts_dir)
Reports whether an installation at latex_dir/fonts_dir differs from what would be freshly installed.
static bool uninstall_global(const Environment &environment, bool force=false)
Removes a global installation: every embedded LaTeX and font file's target directory inside environme...
static bool uninstall_local(const std::filesystem::path &target_dir, bool force=false)
Removes a local installation: target_dir's settings/ and fonts/ directories, then clears installation...
static bool install_global(const Environment &environment, bool force=false)
Installs the template globally, using environment to resolve the target directories inside the TeX tr...
Represents a single NoTeX project: its location and metadata.
void save() const
Persists the current metadata back to .notex/notex.json.
static void write_config(const std::filesystem::path &root_dir, const ProjectConfig &config)
Writes config as <root_dir>/.notex/notex.json, creating <root_dir>/.notex/ first if it does not alrea...
const ProjectConfig & config() const noexcept
Base class for every exception raised by the NoTeX core library.
Exception hierarchy and process exit codes used throughout NoTeX.
Installer: deploys the NoTeX LaTeX template, globally into the TeX tree or locally into a project.
Logging utility with plog initialization.
Manager: represents and operates on a single NoTeX project.
const std::vector< EmbeddedFile > & latex_files()
const std::vector< EmbeddedFile > & font_files()
std::string run_command(const std::string &command)
Runs command through the shell and returns everything it wrote to standard output (and standard error...
void warning(std::string_view message)
bool confirm(std::string_view prompt, bool default_answer=false)
Asks the user to confirm an action.
Styled terminal output and interactive confirmation prompts.
Persisted metadata for a single NoTeX project, stored as JSON in .notex/notex.json.
std::string installation_type
Process execution and environment-variable access.