bp3d_fs/dirs/system/
mod.rs

1// Copyright (c) 2021, BlockProject 3D
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification,
6// are permitted provided that the following conditions are met:
7//
8//     * Redistributions of source code must retain the above copyright notice,
9//       this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above copyright notice,
11//       this list of conditions and the following disclaimer in the documentation
12//       and/or other materials provided with the distribution.
13//     * Neither the name of BlockProject 3D nor the names of its contributors
14//       may be used to endorse or promote products derived from this software
15//       without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29//! Low-level access to standard system directories.
30//!
31//! Unsupported directories are returned as None.
32
33use std::path::PathBuf;
34
35#[cfg(target_vendor = "apple")]
36mod apple_shared;
37#[cfg(target_os = "ios")]
38mod ios;
39#[cfg(all(
40    unix,
41    not(any(target_os = "macos", target_os = "ios", target_os = "android"))
42))]
43mod linux;
44#[cfg(target_os = "macos")]
45mod macos;
46#[cfg(windows)]
47mod windows;
48
49#[cfg(target_os = "ios")]
50use ios as _impl;
51#[cfg(all(
52    unix,
53    not(any(target_os = "macos", target_os = "ios", target_os = "android"))
54))]
55use linux as _impl;
56#[cfg(target_os = "macos")]
57use macos as _impl;
58#[cfg(windows)]
59use windows as _impl;
60
61pub fn get_app_cache() -> Option<PathBuf> {
62    _impl::get_app_cache()
63}
64
65pub fn get_app_config() -> Option<PathBuf> {
66    _impl::get_app_config()
67}
68
69pub fn get_app_data() -> Option<PathBuf> {
70    _impl::get_app_data()
71}
72
73pub fn get_app_logs() -> Option<PathBuf> {
74    _impl::get_app_logs()
75}
76
77pub fn get_app_documents() -> Option<PathBuf> {
78    _impl::get_app_documents()
79}
80
81pub fn get_user_home() -> Option<PathBuf> {
82    _impl::get_user_home()
83}
84
85pub fn get_user_documents() -> Option<PathBuf> {
86    _impl::get_user_documents()
87}
88
89pub fn get_user_downloads() -> Option<PathBuf> {
90    _impl::get_user_downloads()
91}
92
93/// Returns the path to an asset of the application.
94///
95/// On supported platforms this returns an asset bundled in the application. Supported platforms are:
96/// - Any Linux/Unix when app is packaged as an AppImage,
97/// - macOS (when app is packaged as a .app),
98/// - iOS
99///
100/// In the case a platform/packaging method isn't supported this function still returns a path based
101/// on executable location.
102///
103/// For macOS and iOS, localization is still supported by the app however assets could also be localized
104/// in the app bundle as this function uses Apple APIs (CFBundleCopyResourceURL) to obtain the location
105/// of resources.
106///
107/// Returns None if there is a system issue, ex: the system didn't return a proper path to the current
108/// executing application. This should rarely occur.
109pub fn get_app_bundled_asset(file_name: &str) -> Option<PathBuf> {
110    _impl::get_app_bundled_asset(file_name)
111}