| 36 | } |
| 37 | |
| 38 | bool CopyIfProvided(const std::string& source, const fs::path& destination_dir, std::string* out, std::string* error) { |
| 39 | if (source.empty()) return true; |
| 40 | std::error_code ec; |
| 41 | fs::path src(source); |
| 42 | if (!fs::exists(src, ec)) { |
| 43 | if (error) *error = "source file not found: " + source; |
| 44 | return false; |
| 45 | } |
| 46 | fs::path dst = destination_dir / src.filename(); |
| 47 | fs::copy_file(src, dst, fs::copy_options::overwrite_existing, ec); |
| 48 | if (ec) { |
| 49 | if (error) *error = "failed to copy " + source + ": " + ec.message(); |
| 50 | return false; |
| 51 | } |
| 52 | *out = PathToUtf8(dst); |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | std::vector<uint8_t> HexDecode(const std::string& value) { |
| 57 | auto digit = [](char ch) -> int { |