ferroui_base/platform/storage/i_storage_provider.rs
1use super::{
2 FilePickerOpenOptions, FilePickerSaveOptions, FolderPickerOpenOptions, IStorageBookmarkFile,
3 IStorageBookmarkFolder, IStorageFile, IStorageFolder, OpenFilePickerResult, SaveFilePickerResult,
4 WellKnownFolder,
5};
6use crate::input::LocalBoxFuture;
7use crate::utilities::Uri;
8use std::rc::Rc;
9
10/// Opens file and folder pickers and gives access to storage items.
11///
12/// The picker operations fail with an I/O error when no picker can be
13/// shown.
14///
15/// This interface is not meant to be implemented by applications.
16pub trait IStorageProvider {
17 /// Returns `true` if it is possible to open a file picker on the
18 /// current platform.
19 fn can_open(&self) -> bool;
20
21 /// Opens a file picker dialog.
22 ///
23 /// Resolves to the list of files, empty if the user canceled the
24 /// dialog.
25 fn open_file_picker_async(
26 &self,
27 options: FilePickerOpenOptions,
28 ) -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn IStorageFile>>>>;
29
30 /// Opens a file picker dialog and returns the selected files along with
31 /// additional information.
32 ///
33 /// This method allows retrieving additional details about the picked
34 /// files, such as the selected file type.
35 fn open_file_picker_with_result_async(
36 &self,
37 options: FilePickerOpenOptions,
38 ) -> LocalBoxFuture<std::io::Result<OpenFilePickerResult>>;
39
40 /// Returns `true` if it is possible to open a save file picker on the
41 /// current platform.
42 fn can_save(&self) -> bool;
43
44 /// Opens a save file picker dialog.
45 ///
46 /// Resolves to the saved [`IStorageFile`], or `None` if the user
47 /// canceled the dialog.
48 fn save_file_picker_async(
49 &self,
50 options: FilePickerSaveOptions,
51 ) -> LocalBoxFuture<std::io::Result<Option<Rc<dyn IStorageFile>>>>;
52
53 /// Opens a save file picker dialog and returns the selected file along
54 /// with additional information.
55 ///
56 /// This method allows retrieving additional details about the saved
57 /// file, such as the selected file type.
58 fn save_file_picker_with_result_async(
59 &self,
60 options: FilePickerSaveOptions,
61 ) -> LocalBoxFuture<std::io::Result<SaveFilePickerResult>>;
62
63 /// Returns `true` if it is possible to open a folder picker on the
64 /// current platform.
65 fn can_pick_folder(&self) -> bool;
66
67 /// Opens a folder picker dialog.
68 ///
69 /// Resolves to the list of folders, empty if the user canceled the
70 /// dialog.
71 fn open_folder_picker_async(
72 &self,
73 options: FolderPickerOpenOptions,
74 ) -> LocalBoxFuture<std::io::Result<Vec<Rc<dyn IStorageFolder>>>>;
75
76 /// Opens an [`IStorageBookmarkFile`] from the bookmark ID.
77 ///
78 /// Resolves to the bookmarked file, or `None` if the OS denied the
79 /// request or the bookmark is invalid.
80 fn open_file_bookmark_async(&self, bookmark: &str) -> LocalBoxFuture<Option<Rc<dyn IStorageBookmarkFile>>>;
81
82 /// Opens an [`IStorageBookmarkFolder`] from the bookmark ID.
83 ///
84 /// Resolves to the bookmarked folder, or `None` if the OS denied the
85 /// request or the bookmark is invalid.
86 fn open_folder_bookmark_async(&self, bookmark: &str) -> LocalBoxFuture<Option<Rc<dyn IStorageBookmarkFolder>>>;
87
88 /// Attempts to read a file from the file-system by its path.
89 ///
90 /// `file_path` is the path of the item to retrieve in URI format.
91 ///
92 /// The URI must be an absolute path. It also might ask the user for a
93 /// permission, and resolve to `None` if it was denied.
94 fn try_get_file_from_path_async(&self, file_path: &Uri) -> LocalBoxFuture<Option<Rc<dyn IStorageFile>>>;
95
96 /// Attempts to read a folder from the file-system by its path.
97 ///
98 /// `folder_path` is the path of the folder to retrieve in URI format.
99 ///
100 /// The URI must be an absolute path. It also might ask the user for a
101 /// permission, and resolve to `None` if it was denied.
102 fn try_get_folder_from_path_async(&self, folder_path: &Uri) -> LocalBoxFuture<Option<Rc<dyn IStorageFolder>>>;
103
104 /// Attempts to read a folder from the file-system by its well-known
105 /// folder identifier.
106 fn try_get_well_known_folder_async(
107 &self,
108 well_known_folder: WellKnownFolder,
109 ) -> LocalBoxFuture<Option<Rc<dyn IStorageFolder>>>;
110
111 /// Whether the provider is the file-system backed one
112 /// (C# `provider is BclStorageProvider`).
113 ///
114 /// Answered with `true` by the implementations of
115 /// [`BclStorageProvider`](super::file_io::BclStorageProvider).
116 fn is_file_system_backed(&self) -> bool {
117 false
118 }
119}