summaryrefslogtreecommitdiffstats
path: root/src/properties.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-12 21:35:25 +0200
committersalmonik <salmonik@tuta.io>2026-07-12 21:35:25 +0200
commit9ad52d0151086252e6d8a3e60dc5b8cd4bfd5465 (patch)
tree2e638c274e0ab9dc4f3812e8ece6c603d854e1fd /src/properties.rs
parentfirst stable (diff)
downloadminecraft-ui-9ad52d0151086252e6d8a3e60dc5b8cd4bfd5465.tar.gz
minecraft-ui-9ad52d0151086252e6d8a3e60dc5b8cd4bfd5465.zip
second stable
Diffstat (limited to '')
-rw-r--r--src/properties.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/properties.rs b/src/properties.rs
new file mode 100644
index 0000000..de391cc
--- /dev/null
+++ b/src/properties.rs
@@ -0,0 +1,39 @@
1use std::collections::HashMap;
2use std::path::Path;
3
4/// Parse a Java .properties file into key-value pairs.
5pub fn read_properties(path: &Path) -> HashMap<String, String> {
6 let mut map = HashMap::new();
7 let Ok(contents) = std::fs::read_to_string(path) else {
8 return map;
9 };
10 for line in contents.lines() {
11 let line = line.trim();
12 if line.is_empty() || line.starts_with('#') || line.starts_with('!') {
13 continue;
14 }
15 if let Some((key, value)) = line.split_once('=') {
16 map.insert(key.trim().to_string(), value.trim().to_string());
17 } else if let Some((key, value)) = line.split_once(':') {
18 map.insert(key.trim().to_string(), value.trim().to_string());
19 }
20 }
21 map
22}
23
24/// Read the level-seed from an instance's server.properties.
25/// Returns None if the file doesn't exist or the seed is empty.
26pub fn read_instance_seed(server_dir: &Path, instance_name: &str) -> Option<String> {
27 let props_path = server_dir
28 .join("instances")
29 .join(instance_name)
30 .join("data")
31 .join("server.properties");
32 let props = read_properties(&props_path);
33 let seed = props.get("level-seed")?;
34 if seed.is_empty() {
35 None
36 } else {
37 Some(seed.clone())
38 }
39}