From 9ad52d0151086252e6d8a3e60dc5b8cd4bfd5465 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 12 Jul 2026 21:35:25 +0200 Subject: second stable --- src/properties.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/properties.rs (limited to 'src/properties.rs') 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 @@ +use std::collections::HashMap; +use std::path::Path; + +/// Parse a Java .properties file into key-value pairs. +pub fn read_properties(path: &Path) -> HashMap { + let mut map = HashMap::new(); + let Ok(contents) = std::fs::read_to_string(path) else { + return map; + }; + for line in contents.lines() { + let line = line.trim(); + if line.is_empty() || line.starts_with('#') || line.starts_with('!') { + continue; + } + if let Some((key, value)) = line.split_once('=') { + map.insert(key.trim().to_string(), value.trim().to_string()); + } else if let Some((key, value)) = line.split_once(':') { + map.insert(key.trim().to_string(), value.trim().to_string()); + } + } + map +} + +/// Read the level-seed from an instance's server.properties. +/// Returns None if the file doesn't exist or the seed is empty. +pub fn read_instance_seed(server_dir: &Path, instance_name: &str) -> Option { + let props_path = server_dir + .join("instances") + .join(instance_name) + .join("data") + .join("server.properties"); + let props = read_properties(&props_path); + let seed = props.get("level-seed")?; + if seed.is_empty() { + None + } else { + Some(seed.clone()) + } +} -- cgit v1.2.3