Skip to content

Commit

Permalink
NavData update
Browse files Browse the repository at this point in the history
  • Loading branch information
laxentis committed Jan 1, 2023
1 parent 6e84c03 commit fed8baf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "es-sector-updater"
version = "1.0.1"
version = "1.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
30 changes: 29 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let sector_file_name = get_sector_file_name(&tmp_path).unwrap();
change_prf_sectors(es_path, sector_file_name, prf_prefix).await?;
// Clear ASRs from sector definitions
println!("Clearing ASRs");
let asr_path = es_path.join(format!("{}\\ASR", fir));
clear_asr(asr_path).await?;
// Copy NavData
copy_navdata(es_path, tmp_path, fir).await?;
Ok(())
}

Expand Down Expand Up @@ -222,6 +223,7 @@ async fn change_prf_sectors(
}

async fn clear_asr(asr_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
println!("Clearing ASRs");
let asr_regex = Regex::new(r"SECTORFILE:.*\nSECTORTITLE:.\n").unwrap();
for entry in fs::read_dir(asr_path)? {
let entry = entry?;
Expand All @@ -240,3 +242,29 @@ async fn clear_asr(asr_path: PathBuf) -> Result<(), Box<dyn std::error::Error>>
}
Ok(())
}

async fn copy_navdata(es_path: &Path, tmp_path: PathBuf, fir: &str) -> Result<(), Box<dyn std::error::Error>> {
println! {"Copying NavData to ES dir"};
let es_navdata = es_path.join("NavData");
let tmp_navdata = tmp_path.join(fir).join("NavData");
// Copy all files to Euroscope directory
for entry in fs::read_dir(&tmp_navdata)? {
let entry = entry?;
let ftyp = entry.file_type()?;
let dest = es_navdata.join(entry.file_name());
if ftyp.is_dir() {
fs::create_dir_all(&dest).unwrap();
} else {
if let Some(p) = dest.parent() {
if !p.exists() {
fs::create_dir_all(p).unwrap();
}
println!("\t{}", entry.file_name().to_str().unwrap().to_owned());
let mut file = File::open(entry.path())?;
let mut dest_file = File::create(&dest)?;
copy(&mut file, &mut dest_file)?;
}
}
}
Ok(())
}

0 comments on commit fed8baf

Please sign in to comment.