Skip to content

Commit

Permalink
loglevel from config
Browse files Browse the repository at this point in the history
  • Loading branch information
shevernitskiy committed Oct 2, 2023
1 parent d3e9e76 commit 5d75fc2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ mod hooks;
mod utils;
mod watchdog;

use log::LevelFilter;
use log::{error, info, trace};
use log::{debug, error, info};

use crate::config::CONFIG;
use crate::dictionary::DICTIONARY;
Expand All @@ -26,18 +25,15 @@ extern "C" fn attach() {
// unsafe {
// crash::install();
// }
if CONFIG.settings.watchdog {
watchdog::install();
}
simple_logging::log_to_file(&CONFIG.settings.log_file, LevelFilter::Trace).unwrap();
simple_logging::log_to_file(&CONFIG.settings.log_file, utils::log_level(CONFIG.settings.log_level)).unwrap();
if CONFIG.metadata.name != "dfint localization hook" {
error!("unable to find config file");
utils::message_box(
"unable to find config file",
"Unable to find config file, translation unavaible",
"dfint hook error",
utils::MessageIconType::Error,
);
std::process::exit(2);
return;
}
info!("pe checksum: 0x{:x}", CONFIG.offset_metadata.checksum);
info!("offsets version: {}", CONFIG.offset_metadata.version);
Expand All @@ -47,19 +43,29 @@ extern "C" fn attach() {
CONFIG.settings.dictionary,
DICTIONARY.size()
);
unsafe {
hooks::attach_all().unwrap();
match unsafe { hooks::attach_all() } {
Ok(_) => debug!("hooks attached"),
Err(err) => {
error!("unable to attach hooks, {:?}", err);
utils::message_box(
"Unable to attach hooks, translation unavaible",
"dfint hook error",
utils::MessageIconType::Error,
);
return;
}
};
if CONFIG.settings.watchdog {
watchdog::install();
}
trace!("hooks attached");
}

#[static_init::destructor]
#[no_mangle]
extern "C" fn detach() {
unsafe {
match hooks::disable_all() {
_ => (),
_ => debug!("hooks detached"),
};
}
trace!("hooks detached");
}
12 changes: 12 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ pub static UTF_TO_CP1251: std::collections::HashMap<u32, u8> = HashMap::from([
(36560, 161),
(40657, 162),
]);

pub fn log_level(level: usize) -> log::LevelFilter {
match level {
0 => log::LevelFilter::Trace,
1 => log::LevelFilter::Debug,
2 => log::LevelFilter::Info,
3 => log::LevelFilter::Warn,
4 => log::LevelFilter::Error,
5 => log::LevelFilter::Off,
_ => log::LevelFilter::Info,
}
}

0 comments on commit 5d75fc2

Please sign in to comment.