Create a file in the project `contents` - Bytes of the file that will be created `folder` - Folder to place the created file in `name` - Name to assign to the created file `description` - Description to assign to the created file `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being created
(
&self,
contents: &[u8],
folder: Option<&ProjectFolder>,
name: N,
description: D,
mut progress: P,
)
| 514 | /// * `description` - Description to assign to the created file |
| 515 | /// * `progress` - [`ProgressCallback`] that will be called as the [`ProjectFile`] is being created |
| 516 | pub fn create_file_with_progress<N, D, P>( |
| 517 | &self, |
| 518 | contents: &[u8], |
| 519 | folder: Option<&ProjectFolder>, |
| 520 | name: N, |
| 521 | description: D, |
| 522 | mut progress: P, |
| 523 | ) -> Result<Ref<ProjectFile>, ()> |
| 524 | where |
| 525 | N: BnStrCompatible, |
| 526 | D: BnStrCompatible, |
| 527 | P: ProgressCallback, |
| 528 | { |
| 529 | let name_raw = name.into_bytes_with_nul(); |
| 530 | let description_raw = description.into_bytes_with_nul(); |
| 531 | let folder_ptr = folder.map(|p| p.handle.as_ptr()).unwrap_or(null_mut()); |
| 532 | |
| 533 | unsafe { |
| 534 | let result = BNProjectCreateFile( |
| 535 | self.handle.as_ptr(), |
| 536 | contents.as_ptr(), |
| 537 | contents.len(), |
| 538 | folder_ptr, |
| 539 | name_raw.as_ref().as_ptr() as *const c_char, |
| 540 | description_raw.as_ref().as_ptr() as *const c_char, |
| 541 | &mut progress as *mut P as *mut c_void, |
| 542 | Some(P::cb_progress_callback), |
| 543 | ); |
| 544 | Ok(ProjectFile::ref_from_raw(NonNull::new(result).ok_or(())?)) |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | /// Create a file in the project |
| 549 | /// |