| 429 | |
| 430 | #[cfg(not(target_arch = "wasm32"))] |
| 431 | fn platform_app_data_dir() -> Result<PathBuf, String> { |
| 432 | #[cfg(target_os = "windows")] |
| 433 | { |
| 434 | if let Some(appdata) = std::env::var_os("APPDATA") { |
| 435 | return Ok(PathBuf::from(appdata)); |
| 436 | } |
| 437 | if let Some(home) = std::env::var_os("USERPROFILE") { |
| 438 | return Ok(PathBuf::from(home).join("AppData").join("Roaming")); |
| 439 | } |
| 440 | return Err("Could not resolve %APPDATA% on Windows".to_owned()); |
| 441 | } |
| 442 | |
| 443 | #[cfg(target_os = "macos")] |
| 444 | { |
| 445 | if let Some(home) = std::env::var_os("HOME") { |
| 446 | return Ok(PathBuf::from(home) |
| 447 | .join("Library") |
| 448 | .join("Application Support")); |
| 449 | } |
| 450 | return Err("Could not resolve HOME on macOS".to_owned()); |
| 451 | } |
| 452 | |
| 453 | #[cfg(target_os = "linux")] |
| 454 | { |
| 455 | if let Some(xdg_data_home) = std::env::var_os("XDG_DATA_HOME") { |
| 456 | return Ok(PathBuf::from(xdg_data_home)); |
| 457 | } |
| 458 | if let Some(home) = std::env::var_os("HOME") { |
| 459 | return Ok(PathBuf::from(home).join(".local").join("share")); |
| 460 | } |
| 461 | return Err("Could not resolve data directory on Linux".to_owned()); |
| 462 | } |
| 463 | |
| 464 | #[cfg(target_os = "android")] |
| 465 | { |
| 466 | unsafe { |
| 467 | let env = macroquad::miniquad::native::android::attach_jni_env(); |
| 468 | let activity = macroquad::miniquad::native::android::ACTIVITY; |
| 469 | |
| 470 | if activity.is_null() { |
| 471 | return Err("Android activity is not available".to_owned()); |
| 472 | } |
| 473 | |
| 474 | let get_object_class = (**env).GetObjectClass.unwrap(); |
| 475 | let get_method_id = (**env).GetMethodID.unwrap(); |
| 476 | let call_object_method = (**env).CallObjectMethod.unwrap(); |
| 477 | let get_string_utf_chars = (**env).GetStringUTFChars.unwrap(); |
| 478 | let release_string_utf_chars = (**env).ReleaseStringUTFChars.unwrap(); |
| 479 | let delete_local_ref = (**env).DeleteLocalRef.unwrap(); |
| 480 | let exception_check = (**env).ExceptionCheck.unwrap(); |
| 481 | let exception_describe = (**env).ExceptionDescribe.unwrap(); |
| 482 | let exception_clear = (**env).ExceptionClear.unwrap(); |
| 483 | |
| 484 | let class = get_object_class(env, activity); |
| 485 | if class.is_null() { |
| 486 | return Err("Failed to access Android activity class".to_owned()); |
| 487 | } |
| 488 | |