|
1 | | -use std::{collections::HashMap, fs::File, io::BufReader}; |
| 1 | +use std::{collections::HashMap, fs::{self, File}, io::BufReader}; |
2 | 2 |
|
3 | 3 | use sqlx::PgPool; |
4 | 4 |
|
@@ -43,27 +43,30 @@ pub async fn update(configs: &Configs, pool: &PgPool) -> anyhow::Result<()> { |
43 | 43 |
|
44 | 44 | info!("Starting {}", language); |
45 | 45 |
|
46 | | - let text_map: HashMap<String, String> = if let Ok(file) = File::open(format!( |
47 | | - "dimbreath/AnimeGameData/TextMap/TextMap{language_str}.json", |
48 | | - )) { |
49 | | - serde_json::from_reader(BufReader::new(file))? |
50 | | - } else { |
51 | | - let mut text_map = HashMap::new(); |
52 | | - |
53 | | - for i in 0.. { |
54 | | - let Ok(file) = File::open(format!( |
55 | | - "dimbreath/AnimeGameData/TextMap/TextMap{language_str}_{i}.json", |
56 | | - )) else { |
57 | | - break; |
58 | | - }; |
59 | | - |
60 | | - let text_map_part: HashMap<String, String> = |
61 | | - serde_json::from_reader(BufReader::new(file))?; |
62 | | - text_map.extend(text_map_part); |
63 | | - } |
64 | | - |
65 | | - text_map |
66 | | - }; |
| 46 | + // Find all text maps for the language, can be multiple files such as TextMapEN, TextMapRU_01, TextMapRU_0, TextMap_MediumRU_1, etc. |
| 47 | + let mut text_map = HashMap::new(); |
| 48 | + let mut text_map_files = fs::read_dir("dimbreath/AnimeGameData/TextMap")? |
| 49 | + .filter_map(Result::ok) |
| 50 | + .map(|entry| entry.path()) |
| 51 | + .filter(|path| { |
| 52 | + path.is_file() |
| 53 | + && path |
| 54 | + .extension() |
| 55 | + .and_then(|ext| ext.to_str()) |
| 56 | + .is_some_and(|ext| ext == "json") |
| 57 | + && path |
| 58 | + .file_name() |
| 59 | + .and_then(|name| name.to_str()) |
| 60 | + .is_some_and(|name| name.contains(language_str)) |
| 61 | + }) |
| 62 | + .collect::<Vec<_>>(); |
| 63 | + |
| 64 | + text_map_files.sort(); |
| 65 | + |
| 66 | + for path in text_map_files { |
| 67 | + let text_map_part: HashMap<String, String> = serde_json::from_reader(BufReader::new(File::open(path)?))?; |
| 68 | + text_map.extend(text_map_part); |
| 69 | + } |
67 | 70 |
|
68 | 71 | info!("Starting {} achievement series", language); |
69 | 72 | for achievement_goal in &configs.achievement_goal_data { |
|
0 commit comments