Skip to content
API Documentation
BastionGuard™
ReportExporter Class Reference

#include <report_exporter.hpp>

Static Public Member Functions

static bool save_json (const ScanReport &report, const std::string &path, std::string &error_out)
static bool save_text (const ScanReport &report, const std::string &path, std::string &error_out)

Detailed Description

Definition at line 7 of file report_exporter.hpp.

Member Function Documentation

◆ save_json()

bool ReportExporter::save_json ( const ScanReport & report,
const std::string & path,
std::string & error_out )
static

Definition at line 62 of file report_exporter.cpp.

64 {
65 std::ofstream out(path, std::ios::binary);
66 if (!out) {
67 error_out = trs("Unable to open destination file");
68 return false;
69 }
70
71 out << "{\n";
72 out << " \"input_path\": \"" << escape_json(report.input_path) << "\",\n";
73 out << " \"input_size\": " << report.input_size << ",\n";
74 out << " \"logs\": [\n";
75 for (size_t i = 0; i < report.logs.size(); ++i) {
76 out << " \"" << escape_json(report.logs[i]) << "\""
77 << (i + 1 < report.logs.size() ? "," : "") << "\n";
78 }
79 out << " ],\n";
80 out << " \"results\": [\n";
81 for (size_t i = 0; i < report.results.size(); ++i) {
82 const auto& r = report.results[i];
83 out << " {\n";
84 out << " \"kind\": \"" << kind_to_string(r.kind) << "\",\n";
85 out << " \"offset_bytes\": " << r.offset_bytes << ",\n";
86 out << " \"size_bytes\": " << r.size_bytes << ",\n";
87 out << " \"type\": \"" << escape_json(r.type) << "\",\n";
88 out << " \"source\": \"" << escape_json(r.source) << "\",\n";
89 out << " \"detail\": \"" << escape_json(r.detail) << "\",\n";
90 out << " \"confidence\": " << r.confidence << "\n";
91 out << " }" << (i + 1 < report.results.size() ? "," : "") << "\n";
92 }
93 out << " ]\n";
94 out << "}\n";
95 return true;
96 }
std::string trs(const char *msgid)
Definition i18n.cpp:22
const char * kind_to_string(ResultKind kind)
std::string escape_json(const std::string &s)
std::vector< ScanResult > results
Definition models.hpp:40
std::vector< std::string > logs
Definition models.hpp:41
std::string input_path
Definition models.hpp:38
uint64_t input_size
Definition models.hpp:39

References ScanReport::input_path, ScanReport::input_size, ScanReport::logs, ScanReport::results, and trs().

Referenced by AppWindow::on_report_file_chosen().

◆ save_text()

bool ReportExporter::save_text ( const ScanReport & report,
const std::string & path,
std::string & error_out )
static

Definition at line 98 of file report_exporter.cpp.

100 {
101 std::ofstream out(path);
102 if (!out) {
103 error_out = trs("Unable to open destination file");
104 return false;
105 }
106
107 out << "BastionGuard Recovery Data\n";
108 out << "Input path: " << report.input_path << "\n";
109 out << "Input size: " << report.input_size << " bytes\n\n";
110 out << "Logs\n----\n";
111 for (const auto& line : report.logs) {
112 out << line << '\n';
113 }
114
115 out << "\nResults\n-------\n";
116 for (const auto& r : report.results) {
117 out << '[' << kind_to_string(r.kind) << "] "
118 << r.type
119 << " | source=" << r.source
120 << " | offset=" << r.offset_bytes
121 << " | size=" << r.size_bytes
122 << " | confidence=" << r.confidence
123 << " | detail=" << r.detail
124 << '\n';
125 }
126
127 return true;
128 }

References ScanReport::input_path, ScanReport::input_size, ScanReport::logs, ScanReport::results, and trs().

Referenced by AppWindow::on_report_file_chosen().


The documentation for this class was generated from the following files: