diff --git a/src/detections/configs.rs b/src/detections/configs.rs index 8603300e..31dd83ee 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -241,16 +241,20 @@ impl ConfigReader<'_> { args: parse, headless_help: String::default(), event_timeline_config: load_eventcode_info( - CURRENT_EXE_PATH - .join("rules/config/statistics_event_info.txt") - .to_str() - .unwrap(), + utils::check_setting_path( + &CURRENT_EXE_PATH.to_path_buf(), + "rules/config/statistics_event_info.txt", + ) + .to_str() + .unwrap(), ), target_eventids: load_target_ids( - CURRENT_EXE_PATH - .join("rules/config/target_event_IDs.txt") - .to_str() - .unwrap(), + utils::check_setting_path( + &CURRENT_EXE_PATH.to_path_buf(), + "rules/config/target_event_IDs.txt", + ) + .to_str() + .unwrap(), ), } } diff --git a/src/detections/print.rs b/src/detections/print.rs index 4d0daf2d..96014349 100644 --- a/src/detections/print.rs +++ b/src/detections/print.rs @@ -54,18 +54,19 @@ lazy_static! { pub static ref STATISTICS_FLAG: bool = configs::CONFIG.read().unwrap().args.statistics; pub static ref LOGONSUMMARY_FLAG: bool = configs::CONFIG.read().unwrap().args.logon_summary; pub static ref TAGS_CONFIG: HashMap = Message::create_output_filter_config( - CURRENT_EXE_PATH - .join("config/output_tag.txt") + utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "config/output_tag.txt") .to_str() .unwrap(), true, configs::CONFIG.read().unwrap().args.all_tags ); pub static ref CH_CONFIG: HashMap = Message::create_output_filter_config( - CURRENT_EXE_PATH - .join("rules/config/channel_abbreviations.txt") - .to_str() - .unwrap(), + utils::check_setting_path( + &CURRENT_EXE_PATH.to_path_buf(), + "rules/config/channel_abbreviations.txt" + ) + .to_str() + .unwrap(), false, configs::CONFIG.read().unwrap().args.all_tags ); diff --git a/src/detections/utils.rs b/src/detections/utils.rs index df2e3677..1dec5959 100644 --- a/src/detections/utils.rs +++ b/src/detections/utils.rs @@ -71,8 +71,7 @@ pub fn value_to_string(value: &Value) -> Option { pub fn read_txt(filename: &str) -> Result, String> { let filepath = if filename.starts_with("./") { - CURRENT_EXE_PATH - .join(filename) + check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), filename) .to_str() .unwrap() .to_string() diff --git a/src/main.rs b/src/main.rs index 509c513b..949baee8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -144,30 +144,15 @@ impl App { return; } // カレントディレクトリ以外からの実行の際にrules-configオプションの指定がないとエラーが発生することを防ぐための処理 - if configs::CONFIG - .read() - .unwrap() - .args - .config - .to_str() - .unwrap() - == "./rules/config" - { - configs::CONFIG.write().unwrap().args.config = CURRENT_EXE_PATH.join("rules/config"); - // hayabusa.exeが存在するパスにrules/configがない場合はカレントディレクトリのrules/configを確認する - if !configs::CONFIG.read().unwrap().args.config.exists() { - configs::CONFIG.write().unwrap().args.config = - Path::new("./rules/config").to_path_buf(); - } + if configs::CONFIG.read().unwrap().args.config == Path::new("./rules/config") { + configs::CONFIG.write().unwrap().args.config = + utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "./rules/config"); } // カレントディレクトリ以外からの実行の際にrulesオプションの指定がないとエラーが発生することを防ぐための処理 - if configs::CONFIG.read().unwrap().args.rules.to_str().unwrap() == "./rules" { - configs::CONFIG.write().unwrap().args.rules = CURRENT_EXE_PATH.join("rules"); - // hayabusa.exeが存在するパスにrulesがない場合はカレントディレクトリのrulesを確認する - if !configs::CONFIG.read().unwrap().args.rules.exists() { - configs::CONFIG.write().unwrap().args.rules = Path::new("./rules").to_path_buf(); - } + if configs::CONFIG.read().unwrap().args.rules == Path::new("./rules") { + configs::CONFIG.write().unwrap().args.rules = + utils::check_setting_path(&CURRENT_EXE_PATH.to_path_buf(), "./rules"); } if let Some(csv_path) = &configs::CONFIG.read().unwrap().args.output {