Skip to content

Commit

Permalink
feat(Report): generated report now has incorrect checksum list
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon9991 committed May 4, 2024
1 parent 62a314a commit d17b25e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/file_integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use std::{
};
use thiserror::Error;

use crate::config::Config;
use crate::{
config::Config,
report::{ChecksumReport, Report},
};

/// TODO: how to retrieve the actual pure checksum (reference value)
Expand Down Expand Up @@ -106,12 +109,19 @@ impl FileIntegrity {
}

/// Checking if EVERY file is actully matching the expected checksum
pub fn check(&self) -> bool {
pub fn check(&self, report: &mut Report) -> bool {
let mut res = true;

for f in self.game_files.iter() {
if !f.checksums_match() {
report.set_file_checksum(&ChecksumReport::new(
f.path.to_str().unwrap().to_string(),
false,
f.compute_real_checksum().to_string(), // wouldn't it be better to change
// return type instead of calling twice this fn?
));
res = false;
return res; // to be removed later, this is to stop the loop
}
}
res
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ fn main() -> anyhow::Result<()> {
.init();

match FileIntegrity::new(&Config::new()?) {
Ok(_app) => {
// let res = app.check();
Ok(app) => {
let mut report = Report::new();
let _res = app.check(&mut report);
// println!("File check result: {}", res);

let report = Report::new();
report.generate_report()?;
}
Err(e) => {
Expand Down
21 changes: 20 additions & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ pub struct ChecksumReport {
got: String,
}

impl ChecksumReport {
pub fn new(file_path: String, matching: bool, got: String) -> Self {
Self {
file_path,
matching,
got,
}
}
}

/// A report of all the tool's analysis results.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Report {
Expand Down Expand Up @@ -57,7 +67,16 @@ impl Report {
std::fs::create_dir_all(REPORT_FOLDER)?;

let mut file = std::fs::File::create(file_path)?;
file.write("hello world\n".as_bytes())?;

writeln!(file, "Report generated on: {}\n\n## Checksums", utc_date)?;

for checksum_report in &self.files_checksums {
writeln!(
file,
"[incorrect] --> {}: {}",
checksum_report.file_path, checksum_report.got
)?;
}

Ok(())
}
Expand Down

0 comments on commit d17b25e

Please sign in to comment.