Skip to content

Commit

Permalink
default --data to DDNet data dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
k2d222 committed Oct 28, 2024
1 parent 1319d80 commit 32589a3
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 253 deletions.
26 changes: 25 additions & 1 deletion desktop/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ twwe-server = { path = "../server", features = ["bridge_out"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tokio = "1.32.0"
platform-dirs = "0.3.0"
env_logger = "0.10.2"
tauri = { version = "2", features = [] }
tauri-plugin-fs = "2"
Expand Down
40 changes: 2 additions & 38 deletions desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,15 @@

use std::{collections::BTreeSet, path::PathBuf, sync::Arc};

use platform_dirs::AppDirs;

fn get_data_dirs() -> Vec<PathBuf> {
// like ddnet's storage.cfg, the last path has the highest priority.
let mut data_dirs = BTreeSet::new();

// ddnet's $USERDIR
if let Some(dirs) = AppDirs::new(Some("ddnet"), false) {
data_dirs.insert(dirs.config_dir);
data_dirs.insert(dirs.data_dir);
}
// ddnet's $DATADIR
let known_ddnets = [
"/usr/share/ddnet/data",
"/usr/share/games/ddnet/data",
"/usr/local/share/ddnet/data",
"/usr/local/share/games/ddnet/data",
"/usr/pkg/share/ddnet/data",
"/usr/pkg/share/games/ddnet/data",
"/opt/ddnet/data",
];
known_ddnets.iter().for_each(|str| {
let path = PathBuf::from(str);
data_dirs.insert(path);
});
// ddnet's $CURRENTDIR
if let Ok(dir) = std::env::current_dir() {
data_dirs.insert(dir.join("data"));
data_dirs.insert(dir);
}

let maps_dirs = data_dirs
.into_iter()
.filter(|path| path.join("maps").is_dir())
.collect();
maps_dirs
}
use twwe_server::find_data_dirs;

#[tokio::main]
async fn server_main() {
let cli = twwe_server::cli::Cli {
addr: "127.0.0.1:16800".to_string(),
cert: None,
key: None,
data_dirs: get_data_dirs(),
data_dirs: find_data_dirs(),
maps_dirs: vec![],
static_dir: None,
rpp_path: None,
Expand Down
72 changes: 72 additions & 0 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ twmap = "0.12"
env_logger = "0.11"
log = "0.4"
parking_lot = "0.12"
clap = { version = "4.5", features = ["derive"] }
clap = { version = "4.5", features = ["derive", "wrap_help"] }
regex = "1.6"
axum = { version = "0.7", features = ["tokio", "multipart", "ws"] }
axum-server = { version = "0.7", features = ["tls-rustls"] }
Expand All @@ -44,12 +44,12 @@ tower_governor = { version = "0.4.3", features = ["axum"] }
tokio-tungstenite = { version = "0.24.0", features = ["rustls-tls-webpki-roots"] }
bcrypt = "0.15.1"
lazy_static = "1.5.0"
platform-dirs = "0.3.0"


[lib]

[features]
default = []
bridge = []
bridge_out = ["bridge"]
bridge_in = ["bridge"]
default = ["bridge_in"]
bridge_out = []
bridge_in = []
Loading

0 comments on commit 32589a3

Please sign in to comment.