diff options
author | metamuffin <metamuffin@disroot.org> | 2025-06-20 18:21:11 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-06-20 18:21:11 +0200 |
commit | 071dba66042381950c361cdf8e83b1d07720d1d8 (patch) | |
tree | aa385c6643c7f6e1cda76b5062ace7c432e750d1 | |
parent | 090d419f3d66e4a758ec9b8ae9fb37bbf24d7830 (diff) | |
download | hurrycurry-071dba66042381950c361cdf8e83b1d07720d1d8.tar hurrycurry-071dba66042381950c361cdf8e83b1d07720d1d8.tar.bz2 hurrycurry-071dba66042381950c361cdf8e83b1d07720d1d8.tar.zst |
replace xdg crate with directories for wider platform support
-rw-r--r-- | Cargo.lock | 52 | ||||
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/src/scoreboard.rs | 26 |
3 files changed, 70 insertions, 10 deletions
@@ -647,6 +647,27 @@ dependencies = [ ] [[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.59.0", +] + +[[package]] name = "displaydoc" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1268,6 +1289,7 @@ dependencies = [ "anyhow", "bincode", "clap", + "directories", "env_logger", "futures-util", "get_if_addrs", @@ -1287,7 +1309,6 @@ dependencies = [ "shlex", "tokio", "tokio-tungstenite", - "xdg", ] [[package]] @@ -1718,7 +1739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1728,6 +1749,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.9.1", + "libc", +] + +[[package]] name = "libyml" version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2037,6 +2068,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2483,6 +2520,17 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom 0.2.16", + "libredox", + "thiserror 2.0.12", +] + +[[package]] name = "ref-cast" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/server/Cargo.toml b/server/Cargo.toml index f23c2c7c..a90496d0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -26,7 +26,7 @@ reqwest = { version = "0.12.19", optional = true, default-features = false, feat ] } pollster = "0.4.0" bincode = "2.0.1" -xdg = "3.0.0" +directories = "6.0.0" igd = { version = "0.12.1", optional = true, features = ["aio"] } get_if_addrs = { version = "0.5.3", optional = true } mdns-sd = { version = "0.13.9", optional = true } diff --git a/server/src/scoreboard.rs b/server/src/scoreboard.rs index f2fb86a2..421a110e 100644 --- a/server/src/scoreboard.rs +++ b/server/src/scoreboard.rs @@ -16,11 +16,13 @@ */ use anyhow::Result; +use directories::ProjectDirs; use hurrycurry_protocol::Score; +use log::warn; use serde::{Deserialize, Serialize}; use std::{cmp::Reverse, collections::HashMap}; use tokio::{ - fs::{read_to_string, rename, File}, + fs::{create_dir_all, read_to_string, rename, File}, io::AsyncWriteExt, }; @@ -39,22 +41,32 @@ pub struct ScoreboardEntry { pub score: Score, } +fn project_dirs() -> Option<ProjectDirs> { + ProjectDirs::from("org", "hurrycurry", "hurrycurry") +} + impl ScoreboardStore { pub async fn load() -> Result<Self> { - let path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json")?; + let Some(dir) = project_dirs() else { + warn!("scoreboard load skipped; no data dir for this platform"); + return Ok(Self::default()); + }; // TOCTOU because its easier that way + let path = dir.data_dir().join("scoreboards.json"); if !path.exists() { + create_dir_all(dir.data_dir()).await?; ScoreboardStore::default().save().await?; } let s = read_to_string(path).await?; Ok(serde_json::from_str(&s)?) } pub async fn save(&self) -> Result<()> { - let path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json")?; - let buffer_path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json~")?; + let Some(dir) = project_dirs() else { + warn!("scoreboard save skipped; no data dir for this platform"); + return Ok(()); + }; + let path = dir.data_dir().join("scoreboards.json"); + let buffer_path = dir.data_dir().join("scoreboards.json~"); File::create(&buffer_path) .await? .write_all(serde_json::to_string(self)?.as_bytes()) |