1use std::collections::HashMap;
2use std::path::PathBuf;
3
4pub fn generate_ids(paths: &[PathBuf]) -> HashMap<PathBuf, String> {
5 let mut map = HashMap::new();
6 let mut counters: HashMap<String, usize> = HashMap::new();
7
8 let mut sorted_paths = paths.to_vec();
10 sorted_paths.sort();
11
12 for path in sorted_paths {
13 if path.is_dir() {
15 continue;
16 }
17 let file_name = path
19 .file_name()
20 .unwrap_or_default()
21 .to_string_lossy()
22 .to_string();
23
24 let path_str = path.to_string_lossy().replace('\\', "/");
26
27 if file_name == "Cargo.toml" {
29 map.insert(path.clone(), "TomlCargo".to_string());
30 continue;
31 }
32 if file_name == "Makefile.toml" {
33 map.insert(path.clone(), "TomlMakefile".to_string());
34 continue;
35 }
36 if file_name == "build.rs" {
37 map.insert(path.clone(), "RustBuild".to_string());
38 continue;
39 }
40 if path_str.contains("src/ui/index.slint") {
41 map.insert(path.clone(), "SlintIndex".to_string());
42 continue;
43 }
44
45 let prefix = if path_str.contains("src/lib") {
47 if file_name == "mod.rs" {
48 "RustLibMod".to_string()
49 } else {
50 "RustLibPub".to_string()
51 }
52 } else if path_str.contains("src/bin") || path_str.contains("src/main.rs") {
53 "RustBin".to_string()
54 } else if path_str.contains("src/ui") {
55 "Slint".to_string()
56 } else {
57 let ext = path.extension().unwrap_or_default().to_string_lossy();
58 format!("File{}", capitalize(&ext))
59 };
60
61 let count = counters.entry(prefix.clone()).or_insert(1);
63
64 let id = if file_name == "mod.rs" && prefix == "RustLibMod" {
65 format!("{}_00", prefix) } else {
67 format!("{}_{:02}", prefix, count)
68 };
69
70 map.insert(path, id);
71 if !(file_name == "mod.rs" && prefix == "RustLibMod") {
72 *count += 1;
73 }
74 }
75
76 map
77}
78
79fn capitalize(s: &str) -> String {
80 let mut c = s.chars();
81 match c.next() {
82 None => String::new(),
83 Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
84 }
85}