diff options
author | zjp <jiping_zhou@foxmail.com> | 2023-05-13 11:27:27 +0800 |
---|---|---|
committer | zjp <jiping_zhou@foxmail.com> | 2023-05-13 11:27:27 +0800 |
commit | 8a2bf7d1eb1c82ed227f44955849082b4093b124 (patch) | |
tree | c4fc4b97ce5b51c660ef2f07202a25108437ed02 | |
parent | 2755d51b38a9badf28fa2b041b533aa7f0e8998d (diff) |
Fix multiple paths: define the platform-specific join separator
-rw-r--r-- | src/config/mod.rs | 2 | ||||
-rw-r--r-- | src/filesystem.rs | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 68638cf..b652608 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -70,7 +70,7 @@ impl Config { if p.is_empty() { None } else { - Some(p.join(":")) + Some(p.join(crate::filesystem::JOIN_SEPARATOR)) } }) .or_else(|| self.yaml.cheats.path.clone()) diff --git a/src/filesystem.rs b/src/filesystem.rs index bebe1d8..a53f246 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,6 +12,13 @@ use std::path::MAIN_SEPARATOR; use walkdir::WalkDir; +/// Multiple paths are joint by a platform-specific separator. +/// FIXME: it's actually incorrect to assume a path doesn't containing this separator +#[cfg(target_family = "windows")] +pub const JOIN_SEPARATOR: &str = ";"; +#[cfg(not(target_family = "windows"))] +pub const JOIN_SEPARATOR: &str = ":"; + pub fn all_cheat_files(path: &Path) -> Vec<String> { WalkDir::new(path) .follow_links(true) @@ -23,7 +30,7 @@ pub fn all_cheat_files(path: &Path) -> Vec<String> { } fn paths_from_path_param(env_var: &str) -> impl Iterator<Item = &str> { - env_var.split(':').filter(|folder| folder != &"") + env_var.split(JOIN_SEPARATOR).filter(|folder| folder != &"") } fn compiled_default_path(path: Option<&str>) -> Option<PathBuf> { @@ -284,4 +291,12 @@ mod tests { assert_eq!(expected, cheats.to_string_lossy().to_string()) } + + #[test] + #[cfg(target_family = "windows")] + fn multiple_paths() { + let p = r#"C:\Users\Administrator\AppData\Roaming\navi\config.yaml"#; + let paths = &[p; 2].join(JOIN_SEPARATOR); + assert_eq!(paths_from_path_param(paths).collect::<Vec<_>>(), [p; 2]); + } } |