add: used check path func base on execution path #618

This commit is contained in:
DastInDark
2022-07-03 20:51:00 +09:00
parent 60a12cb1ff
commit f43b39af15
4 changed files with 26 additions and 37 deletions

View File

@@ -241,14 +241,18 @@ impl ConfigReader<'_> {
args: parse,
headless_help: String::default(),
event_timeline_config: load_eventcode_info(
CURRENT_EXE_PATH
.join("rules/config/statistics_event_info.txt")
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")
utils::check_setting_path(
&CURRENT_EXE_PATH.to_path_buf(),
"rules/config/target_event_IDs.txt",
)
.to_str()
.unwrap(),
),

View File

@@ -54,16 +54,17 @@ 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<String, String> = 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<String, String> = Message::create_output_filter_config(
CURRENT_EXE_PATH
.join("rules/config/channel_abbreviations.txt")
utils::check_setting_path(
&CURRENT_EXE_PATH.to_path_buf(),
"rules/config/channel_abbreviations.txt"
)
.to_str()
.unwrap(),
false,

View File

@@ -71,8 +71,7 @@ pub fn value_to_string(value: &Value) -> Option<String> {
pub fn read_txt(filename: &str) -> Result<Vec<String>, 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()

View File

@@ -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() {
if configs::CONFIG.read().unwrap().args.config == Path::new("./rules/config") {
configs::CONFIG.write().unwrap().args.config =
Path::new("./rules/config").to_path_buf();
}
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 {