use std::path::PathBuf; #[derive(Debug, Clone)] pub struct Paths { pub config_dir: PathBuf, pub profile_dir: PathBuf, pub marker_path: PathBuf, } impl Paths { pub fn resolve() -> Self { let config_dir = std::env::var_os("ICLOUD_NOTES_CONFIG") .map(PathBuf::from) .unwrap_or_else(|| { dirs::config_dir() .unwrap_or_else(|| PathBuf::from(".").join(".config")) .join("icloud-notes") }); Self { profile_dir: config_dir.join("browser-profile"), marker_path: config_dir.join("session.ok"), config_dir, } } pub fn ensure(&self) -> std::io::Result<()> { std::fs::create_dir_all(&self.config_dir)?; std::fs::create_dir_all(&self.profile_dir)?; #[cfg(unix)] { use std::os::unix::fs::PermissionsExt; let _ = std::fs::set_permissions(&self.config_dir, std::fs::Permissions::from_mode(0o700)); let _ = std::fs::set_permissions(&self.profile_dir, std::fs::Permissions::from_mode(0o700)); } Ok(()) } pub fn has_session(&self) -> bool { self.marker_path.is_file() || self.profile_dir.join("Default").is_dir() || self.profile_dir.join("Cookies").is_file() } } pub fn dry_run() -> bool { matches!(std::env::var("ICLOUD_NOTES_DRY_RUN").as_deref(), Ok("1")) } pub fn notes_url() -> &'static str { "https://www.icloud.com/notes/" }