102 lines
2.5 KiB
Rust
102 lines
2.5 KiB
Rust
// This file is part of Deja-Vu.
|
|
//
|
|
// Deja-Vu is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Deja-Vu is distributed in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
// See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
pub enum Type {
|
|
Bitlocker,
|
|
BootConfigData,
|
|
FileSystem,
|
|
FilesAndFolders,
|
|
Registry,
|
|
Unknown,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Groups {
|
|
items: HashMap<String, Line>,
|
|
order: Vec<String>,
|
|
}
|
|
|
|
impl Groups {
|
|
pub fn new() -> Self {
|
|
Groups {
|
|
items: HashMap::new(),
|
|
order: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn get(&self) -> Vec<&Line> {
|
|
let mut lines = Vec::new();
|
|
self.order.iter().for_each(|key| {
|
|
if let Some(line) = self.items.get(key) {
|
|
lines.push(line);
|
|
}
|
|
});
|
|
lines
|
|
}
|
|
|
|
pub fn update(&mut self, title: String, passed: bool, info: String) {
|
|
if let Some(line) = self.items.get_mut(&title) {
|
|
line.update(passed, info);
|
|
} else {
|
|
self.order.push(title.clone());
|
|
self.items.insert(
|
|
title.clone(),
|
|
Line {
|
|
title,
|
|
passed,
|
|
info: vec![info],
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Line {
|
|
pub title: String,
|
|
pub passed: bool,
|
|
pub info: Vec<String>,
|
|
}
|
|
|
|
impl Line {
|
|
pub fn update(&mut self, passed: bool, info: String) {
|
|
self.passed &= passed; // We fail if any tests in this group fail
|
|
self.info.push(info);
|
|
}
|
|
}
|
|
|
|
pub fn get_type(cmd_name: &str) -> Type {
|
|
if cmd_name == "exa" {
|
|
return Type::BootConfigData;
|
|
}
|
|
if cmd_name == "bcdedit.exe" {
|
|
return Type::BootConfigData;
|
|
}
|
|
if cmd_name == "dir" {
|
|
return Type::FilesAndFolders;
|
|
}
|
|
if cmd_name == "reg.exe" {
|
|
return Type::Registry;
|
|
}
|
|
if cmd_name == "chkdsk.exe" {
|
|
return Type::FileSystem;
|
|
}
|
|
if cmd_name == "manage-bde.exe" {
|
|
return Type::Bitlocker;
|
|
}
|
|
Type::Unknown
|
|
}
|