aboutsummaryrefslogtreecommitdiff
path: root/server/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs53
1 files changed, 39 insertions, 14 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 528ee69b..7fbc044a 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use anyhow::{anyhow, Result};
+use anyhow::{bail, Result};
use clap::Parser;
use futures_util::{SinkExt, StreamExt};
use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
@@ -100,21 +100,36 @@ fn main() -> Result<()> {
let data_dir = if let Some(d) = args.data_dir.clone() {
d
} else {
- let d = PathBuf::from_str(
- [
- option_env!("DATA_SEARCH_PATH").unwrap_or("data"),
- "/usr/local/share/hurrycurry/data",
- "/usr/share/hurrycurry/data",
- "/opt/hurrycurry/data",
- ]
- .into_iter()
+ let mut test_order = Vec::new();
+
+ #[cfg(debug_assertions)]
+ test_order.push("data".to_string());
+
+ #[cfg(not(windows))]
+ test_order.extend([
+ "/usr/local/share/hurrycurry/data".to_string(),
+ "/usr/share/hurrycurry/data".to_string(),
+ "/opt/hurrycurry/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}"),
+ };
+
+ let Some(d) = test_order
+ .iter()
.find(|p| PathBuf::from_str(p).unwrap().join("index.yaml").exists())
- .ok_or(anyhow!(
- "Could not find the data directory. Please run the server next to the `data` directory or specify a path to it via arguments."
- ))?,
- )?;
+ 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!("Detected data dir to be {d:?}");
- d
+ PathBuf::from_str(d)?
};
*DATA_DIR.lock().unwrap() = Some(data_dir);
@@ -379,3 +394,13 @@ mod test {
});
}
}
+
+#[cfg(windows)]
+fn read_windows_reg_datadir() -> Result<String> {
+ use anyhow::Context;
+ Ok(windows_registry::CURRENT_USER
+ .open("Software\\Hurry Curry!")
+ .context("HKCU\\Hurry Curry!")?
+ .get_string("datadir")
+ .context("datadir subkey")?)
+}