added process case of no exist config files #347
This commit is contained in:
@@ -114,8 +114,17 @@ impl TargetEventIds {
|
|||||||
|
|
||||||
fn load_target_ids(path: &str) -> TargetEventIds {
|
fn load_target_ids(path: &str) -> TargetEventIds {
|
||||||
let mut ret = TargetEventIds::new();
|
let mut ret = TargetEventIds::new();
|
||||||
let lines = utils::read_txt(path).unwrap(); // ファイルが存在しなければエラーとする
|
let lines = utils::read_txt(path); // ファイルが存在しなければエラーとする
|
||||||
for line in lines {
|
if lines.is_err() {
|
||||||
|
AlertMessage::alert(
|
||||||
|
&mut BufWriter::new(std::io::stderr().lock()),
|
||||||
|
&lines.as_ref().unwrap_err(),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for line in lines.unwrap() {
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -226,6 +235,14 @@ fn load_eventkey_alias(path: &str) -> EventKeyAliasConfig {
|
|||||||
let mut config = EventKeyAliasConfig::new();
|
let mut config = EventKeyAliasConfig::new();
|
||||||
|
|
||||||
let read_result = utils::read_csv(path);
|
let read_result = utils::read_csv(path);
|
||||||
|
if read_result.is_err() {
|
||||||
|
AlertMessage::alert(
|
||||||
|
&mut BufWriter::new(std::io::stderr().lock()),
|
||||||
|
&read_result.as_ref().unwrap_err(),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
// eventkey_aliasが読み込めなかったらエラーで終了とする。
|
// eventkey_aliasが読み込めなかったらエラーで終了とする。
|
||||||
read_result.unwrap().into_iter().for_each(|line| {
|
read_result.unwrap().into_iter().for_each(|line| {
|
||||||
if line.len() != 2 {
|
if line.len() != 2 {
|
||||||
@@ -290,6 +307,15 @@ fn load_eventcode_info(path: &str) -> EventInfoConfig {
|
|||||||
let mut infodata = EventInfo::new();
|
let mut infodata = EventInfo::new();
|
||||||
let mut config = EventInfoConfig::new();
|
let mut config = EventInfoConfig::new();
|
||||||
let read_result = utils::read_csv(path);
|
let read_result = utils::read_csv(path);
|
||||||
|
if read_result.is_err() {
|
||||||
|
AlertMessage::alert(
|
||||||
|
&mut BufWriter::new(std::io::stderr().lock()),
|
||||||
|
&read_result.as_ref().unwrap_err(),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
// timeline_event_infoが読み込めなかったらエラーで終了とする。
|
// timeline_event_infoが読み込めなかったらエラーで終了とする。
|
||||||
read_result.unwrap().into_iter().for_each(|line| {
|
read_result.unwrap().into_iter().for_each(|line| {
|
||||||
if line.len() != 4 {
|
if line.len() != 4 {
|
||||||
|
|||||||
@@ -76,11 +76,14 @@ pub fn read_txt(filename: &str) -> Result<Vec<String>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_csv(filename: &str) -> Result<Vec<Vec<String>>, String> {
|
pub fn read_csv(filename: &str) -> Result<Vec<Vec<String>>, String> {
|
||||||
let mut f = File::open(filename).expect("File not found!!!");
|
let f = File::open(filename);
|
||||||
|
if f.is_err() {
|
||||||
|
return Result::Err(format!("Cannot open file. [file:{}]", filename));
|
||||||
|
}
|
||||||
let mut contents: String = String::new();
|
let mut contents: String = String::new();
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
let read_res = f.read_to_string(&mut contents);
|
let read_res = f.unwrap().read_to_string(&mut contents);
|
||||||
if f.read_to_string(&mut contents).is_err() {
|
if read_res.is_err() {
|
||||||
return Result::Err(read_res.unwrap_err().to_string());
|
return Result::Err(read_res.unwrap_err().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user