diff options
Diffstat (limited to 'server/src/main.rs')
| -rw-r--r-- | server/src/main.rs | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 0236ebe4..727ad4b1 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -99,44 +99,7 @@ fn main() -> Result<()> { let data_path = if let Some(d) = args.data_dir.clone() { d } else { - let mut test_order = Vec::new(); - - if let Ok(path) = var("HURRYCURRY_DATA_PATH") { - test_order.push(path); - } - - if let Some(path) = option_env!("HURRYCURRY_DATA_PATH") { - test_order.push(path.to_owned()); - } - - #[cfg(debug_assertions)] - test_order.push("data".to_string()); - - #[cfg(windows)] - match read_windows_reg_datadir() { - Ok(path) => test_order.push(path), - Err(e) => warn!("Cannot find read datadir from windows registry: {e}"), - }; - - #[cfg(not(windows))] - test_order.extend([ - "/usr/local/share/hurrycurry/data".to_string(), - "/usr/share/hurrycurry/data".to_string(), - "/opt/hurrycurry/data".to_string(), - ]); - - let Some(d) = test_order - .iter() - .find(|p| PathBuf::from_str(p).unwrap().join("index.yaml").exists()) - else { - warn!("The following paths were tested without success: {test_order:#?}",); - bail!( - "Could not find the data directory. Use the --data-dir option to specify a path." - ); - }; - - info!("Selected data dir {d:?}"); - PathBuf::from_str(d)? + find_data_path()? }; tokio::runtime::Builder::new_multi_thread() @@ -308,6 +271,45 @@ async fn send_packet( } } +fn find_data_path() -> Result<PathBuf> { + let mut test_order = Vec::new(); + + if let Ok(path) = var("HURRYCURRY_DATA_PATH") { + test_order.push(path); + } + + if let Some(path) = option_env!("HURRYCURRY_DATA_PATH") { + test_order.push(path.to_owned()); + } + + #[cfg(debug_assertions)] + test_order.push("data".to_string()); + + #[cfg(windows)] + match read_windows_reg_datadir() { + Ok(path) => test_order.push(path), + Err(e) => warn!("Cannot find read datadir from windows registry: {e}"), + }; + + #[cfg(not(windows))] + test_order.extend([ + "/usr/local/share/hurrycurry/data".to_string(), + "/usr/share/hurrycurry/data".to_string(), + "/opt/hurrycurry/data".to_string(), + ]); + + let Some(d) = test_order + .iter() + .find(|p| PathBuf::from_str(p).unwrap().join("index.yaml").exists()) + else { + warn!("The following paths were tested without success: {test_order:#?}",); + bail!("Could not find the data directory. Use the --data-dir option to specify a path."); + }; + + info!("Selected data dir {d:?}"); + Ok(PathBuf::from_str(d)?) +} + #[cfg(test)] mod test { use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID}; |