#include #include #include #include #include #include #include static bool ExtractFile(const XContentFileSystem& content, const std::string& sourcePath, const std::filesystem::path& outputPath) { size_t dataSize = content.getSize(sourcePath); if (dataSize == 0) { std::cerr << "File not found in XContent package: " << sourcePath << "\n"; return false; } std::vector data(dataSize); if (!content.load(sourcePath, data.data(), data.size())) { std::cerr << "Failed to read XContent file: " << sourcePath << "\n"; return false; } std::error_code ec; std::filesystem::create_directories(outputPath.parent_path(), ec); if (ec) { std::cerr << "Failed to create output directory: " << outputPath.parent_path() << "\n"; return false; } std::ofstream output(outputPath, std::ios::binary); if (!output) { std::cerr << "Failed to open output file: " << outputPath << "\n"; return false; } output.write(reinterpret_cast(data.data()), static_cast(data.size())); if (!output) { std::cerr << "Failed to write output file: " << outputPath << "\n"; return false; } return true; } int main(int argc, char** argv) { if (argc < 4 || ((argc - 2) % 2) != 0) { std::cerr << "Usage: xcontent_extract [ ...]\n"; return 2; } auto content = XContentFileSystem::create(argv[1]); if (!content) { std::cerr << "Failed to open XContent package: " << argv[1] << "\n"; return 1; } bool ok = true; for (int i = 2; i < argc; i += 2) { ok = ExtractFile(*content, argv[i], argv[i + 1]) && ok; } return ok ? 0 : 1; }