26 const std::filesystem::path& engineDirectory,
27 const std::string& css)
29 if (engineDirectory.empty() || css.size() >
maximumStyleSize || css.find(
'\0') != std::string::npos)
31 log::engineError(
"Cannot save button stylesheet: invalid directory or contents.");
32 return errors::FAILED_SAVE_STATE;
35 std::error_code error;
36 std::filesystem::create_directories(directory, error);
37 if (error || !std::filesystem::is_directory(directory, error) || error)
39 log::engineError(
"Cannot create button stylesheet directory: %s", error.message().c_str());
40 return errors::FAILED_SAVE_STATE;
42 const auto status = std::filesystem::symlink_status(directory /
buttonFile, error);
43 if ((error && error != std::errc::no_such_file_or_directory) ||
44 (!error && status.type() != std::filesystem::file_type::not_found &&
45 !std::filesystem::is_regular_file(status)))
47 log::engineError(
"Cannot save button stylesheet: destination is not a regular file.");
48 return errors::FAILED_SAVE_STATE;
61 const std::filesystem::path& engineDirectory,
62 const std::string& defaults,
65 if (engineDirectory.empty() || defaults.size() >
maximumStyleSize || defaults.find(
'\0') != std::string::npos)
67 log::engineError(
"Cannot load button stylesheet: invalid directory or defaults.");
68 return errors::FAILED_OPEN_STORE;
71 std::error_code error;
72 auto status = std::filesystem::symlink_status(file, error);
73 if (error == std::errc::no_such_file_or_directory ||
74 (!error && status.type() == std::filesystem::file_type::not_found))
76 const auto directory = file.parent_path();
78 std::filesystem::create_directories(directory, error);
79 if (error || !std::filesystem::is_directory(directory, error) || error)
81 log::engineError(
"Cannot create button stylesheet directory: %s", error.message().c_str());
82 return errors::FAILED_SAVE_STATE;
85 if (result != errors::NONE)
return result;
86 status = std::filesystem::symlink_status(file, error);
88 if (error || !std::filesystem::is_regular_file(status))
90 log::engineError(
"Cannot load button stylesheet: destination is not a regular file.");
91 return errors::FAILED_OPEN_STORE;
93 const auto size = std::filesystem::file_size(file, error);
97 return errors::FAILED_OPEN_STORE;
99 std::ifstream input(file, std::ios::binary);
103 return errors::FAILED_OPEN_STORE;
105 std::string value(
static_cast<std::size_t
>(size),
'\0');
106 input.read(value.data(),
static_cast<std::streamsize
>(value.size()));
107 if (input.gcount() !=
static_cast<std::streamsize
>(value.size()) ||
108 input.peek() != std::char_traits<char>::eof() || input.bad() || value.find(
'\0') != std::string::npos)
111 return errors::FAILED_OPEN_STORE;
113 css = std::move(value);