From b9157c241f22513eb576f8654b05cff16c892131 Mon Sep 17 00:00:00 2001 From: Michael Moore Date: Tue, 19 Mar 2024 19:30:58 -0500 Subject: [PATCH] fix(parser): fix localization files that start with comments are not loaded --- src-tauri/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 075893e..5482f6f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -373,6 +373,16 @@ fn get_stellaris_loc(path: String) -> anyhow::Result> { let mut buf_reader = io::BufReader::new(fs::File::open(path)?); let mut first_line = String::new(); let _ = buf_reader.read_line(&mut first_line)?; + // skip BOM + if first_line.as_bytes().starts_with(&[0xEF, 0xBB, 0xBF]) { + first_line = first_line[3..].to_owned(); + } + // skip comments (max 20 lines) + let mut line_number: u8 = 0; + while first_line.trim().starts_with('#') && line_number < 20 { + line_number += 1; + let _ = buf_reader.read_line(&mut first_line)?; + } if first_line.contains("l_english") { let re = Regex::new(r#"(?m)^\s*([\w\.\-]+)\s*:\d*\s*"(.*)".*$"#).unwrap(); let mut raw_content = String::new();