69 lines
1.8 KiB
Rust
69 lines
1.8 KiB
Rust
use serde::Deserialize;
|
|
use serde_json::Result;
|
|
use serde_json;
|
|
use std::fs::File;
|
|
use std::io::Seek;
|
|
use std::io::{BufRead, BufReader, BufWriter, SeekFrom};
|
|
use std::path::PathBuf;
|
|
use std::str;
|
|
use std::time::Instant;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Coords {
|
|
x: f32,
|
|
y: f32,
|
|
z: f32,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct Body {
|
|
name: String,
|
|
#[serde(rename = "type")]
|
|
body_type: String,
|
|
subType: String,
|
|
#[serde(rename = "distanceToArrival")]
|
|
distance: f32,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct System {
|
|
coords: Coords,
|
|
name: String,
|
|
bodies: Vec<Body>,
|
|
}
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
better_panic::install();
|
|
let mut buffer = String::new();
|
|
let mut bz2_reader = std::process::Command::new("bzip2").args(
|
|
&["-d","-c",r#"E:\EDSM\galaxy.json.bz2"#]
|
|
).stdout(std::process::Stdio::piped())
|
|
.spawn()
|
|
.expect("Failed to spawn execute bzip2!");
|
|
let mut reader = BufReader::new(bz2_reader.stdout.as_mut().expect("Failed to open stdout of child process"));
|
|
let mut count = 0;
|
|
while let Ok(n) = reader.read_line(&mut buffer) {
|
|
if n==0 {
|
|
break;
|
|
}
|
|
buffer = buffer
|
|
.trim()
|
|
.trim_end_matches(|c| c == ',')
|
|
.trim()
|
|
.to_string();
|
|
if let Ok(sys) = serde_json::from_str::<System>(&buffer) {
|
|
for b in &sys.bodies {
|
|
if b.body_type == "Star" {
|
|
count += 1;
|
|
if (count % 100_000) == 0 {
|
|
println!("{}: {:?}", count, b);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
buffer.clear();
|
|
}
|
|
println!("Total: {}", count);
|
|
Ok(())
|
|
}
|