Advertisement
Guest User

Untitled

a guest
May 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. fn extract<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(
  2. &self,
  3. path: Option<&P>,
  4. file_callback: Option<&mut dyn (FnMut(&File) -> bool)>,
  5. progress_callback: Option<&mut dyn (FnMut(i64, i64))>,
  6. cancellable: Option<&Q>,
  7. ) -> Result<(), Error> {
  8. let file_callback_data: &Option<&mut dyn (FnMut(&File) -> bool)> = &file_callback;
  9. unsafe extern "C" fn file_callback_func<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(file: *mut gcab_sys::GCabFile, user_data: glib_sys::gpointer) -> glib_sys::gboolean {
  10. let file = from_glib_borrow(file);
  11. let callback: Box_<(Option<&mut dyn (FnMut(&File) -> bool)>, Option<&mut dyn (FnMut(i64, i64))>)> = *(user_data as *mut _);
  12. let res = if let Some(ref mut callback) = (*callback).0 {
  13. callback(&file)
  14. } else {
  15. panic!("cannot get closure...")
  16. };
  17. res.to_glib()
  18. }
  19. let file_callback = if file_callback_data.is_some() { Some(file_callback_func::<P, Q> as _) } else { None };
  20. let progress_callback_data: &Option<&mut dyn (FnMut(i64, i64))> = &progress_callback;
  21. unsafe extern "C" fn progress_callback_func<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(current_num_bytes: i64, total_num_bytes: i64, user_data: glib_sys::gpointer) {
  22. let callback: Box_<(Option<&mut dyn (FnMut(&File) -> bool)>, Option<&mut dyn (FnMut(i64, i64))>)> = *(user_data as *mut _);
  23. if let Some(ref mut callback) = (*callback).1 {
  24. callback(current_num_bytes, total_num_bytes)
  25. } else {
  26. panic!("cannot get closure...")
  27. };
  28. }
  29. let progress_callback = if progress_callback_data.is_some() { Some(progress_callback_func::<P, Q> as _) } else { None };
  30. let super_callback0: Box_<(Option<&mut dyn (FnMut(&File) -> bool)>, Option<&mut dyn (FnMut(i64, i64))>)> = Box_::new(Box_::new((file_callback_data, progress_callback_data)));
  31. unsafe {
  32. let mut error = ptr::null_mut();
  33. let _ = gcab_sys::gcab_cabinet_extract(self.as_ref().to_glib_none().0, path.map(|p| p.as_ref()).to_glib_none().0, file_callback, progress_callback, super_callback0 as *const _ a\
  34. s usize as *mut _, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
  35. if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement