Function tauri::api::path::app_data_dir
source · Expand description
Returns the path to the suggested directory for your app’s data files.
Resolves to data_dir
/${bundle_identifier}
.
See PathResolver::app_data_dir
for a more convenient helper function.
Examples found in repository?
More examples
src/api/path.rs (line 298)
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
pub fn resolve_path<P: AsRef<Path>>(
config: &Config,
package_info: &PackageInfo,
env: &Env,
path: P,
dir: Option<BaseDirectory>,
) -> crate::api::Result<PathBuf> {
if let Some(base_dir) = dir {
let resolve_resource = matches!(base_dir, BaseDirectory::Resource);
let base_dir_path = match base_dir {
BaseDirectory::Audio => audio_dir(),
BaseDirectory::Cache => cache_dir(),
BaseDirectory::Config => config_dir(),
BaseDirectory::Data => data_dir(),
BaseDirectory::LocalData => local_data_dir(),
BaseDirectory::Desktop => desktop_dir(),
BaseDirectory::Document => document_dir(),
BaseDirectory::Download => download_dir(),
BaseDirectory::Executable => executable_dir(),
BaseDirectory::Font => font_dir(),
BaseDirectory::Home => home_dir(),
BaseDirectory::Picture => picture_dir(),
BaseDirectory::Public => public_dir(),
BaseDirectory::Runtime => runtime_dir(),
BaseDirectory::Template => template_dir(),
BaseDirectory::Video => video_dir(),
BaseDirectory::Resource => resource_dir(package_info, env),
#[allow(deprecated)]
BaseDirectory::App => app_config_dir(config),
#[allow(deprecated)]
BaseDirectory::Log => app_log_dir(config),
BaseDirectory::Temp => Some(temp_dir()),
BaseDirectory::AppConfig => app_config_dir(config),
BaseDirectory::AppData => app_data_dir(config),
BaseDirectory::AppLocalData => app_local_data_dir(config),
BaseDirectory::AppCache => app_cache_dir(config),
BaseDirectory::AppLog => app_log_dir(config),
};
if let Some(mut base_dir_path_value) = base_dir_path {
// use the same path resolution mechanism as the bundler's resource injection algorithm
if resolve_resource {
let mut resource_path = PathBuf::new();
for component in path.as_ref().components() {
match component {
Component::Prefix(_) => {}
Component::RootDir => resource_path.push("_root_"),
Component::CurDir => {}
Component::ParentDir => resource_path.push("_up_"),
Component::Normal(p) => resource_path.push(p),
}
}
base_dir_path_value.push(resource_path);
} else {
base_dir_path_value.push(path);
}
Ok(base_dir_path_value)
} else {
Err(crate::api::Error::Path(
"unable to determine base dir path".to_string(),
))
}
} else {
let mut dir_path = PathBuf::new();
dir_path.push(path);
Ok(dir_path)
}
}