internal static void GetTrack(MtpDeviceHandle handle, uint trackId, string destPath, ProgressFunction callback, IntPtr data) { if (LIBMTP_Get_Track_To_File(handle, trackId, destPath, callback, data) != 0) { LibMtpException.CheckErrorStack(handle); throw new LibMtpException(ErrorCode.General, "Could not download track from the device"); } }
internal static void SendTrack(MtpDeviceHandle handle, string path, ref TrackStruct metadata, ProgressFunction callback, IntPtr data) { if (LIBMTP_Send_Track_From_File(handle, path, ref metadata, callback, data) != 0) { LibMtpException.CheckErrorStack(handle); throw new LibMtpException(ErrorCode.General, "Could not upload the track"); } }
internal static void DeleteObject(MtpDeviceHandle handle, uint object_id) { if (LIBMTP_Delete_Object(handle, object_id) != 0) { LibMtpException.CheckErrorStack(handle); throw new LibMtpException(ErrorCode.General, "Could not delete the track"); } }
internal static void GetBatteryLevel(MtpDeviceHandle handle, out ushort maxLevel, out ushort currentLevel) { int result = LIBMTP_Get_Batterylevel(handle, out maxLevel, out currentLevel); if (result != 0) { LibMtpException.CheckErrorStack(handle); throw new LibMtpException(ErrorCode.General, "Could not retrieve battery stats"); } }
internal static uint CreateFolder(MtpDeviceHandle handle, string name, uint parentId) { uint result = LIBMTP_Create_Folder(handle, name, parentId, 0); if (result == 0) { LibMtpException.CheckErrorStack(handle); throw new LibMtpException(ErrorCode.General, "Could not create folder on the device"); } return(result); }
internal static void CheckErrorStack(MtpDeviceHandle handle) { IntPtr ptr = MtpDevice.GetErrorStack(handle); if (ptr == IntPtr.Zero) { return; } LibMtpException ex = null; while (ptr != IntPtr.Zero) { Error e = (Error)Marshal.PtrToStructure(ptr, typeof(Error)); ex = new LibMtpException(e.errornumber, e.error_text, ex); ptr = e.next; } // Once we throw the exception, clear the error stack MtpDevice.ClearErrorStack(handle); throw ex; }
internal static void CheckErrorStack(MtpDeviceHandle handle) { IntPtr ptr = MtpDevice.GetErrorStack (handle); if (ptr == IntPtr.Zero) return; LibMtpException ex = null; while (ptr != IntPtr.Zero) { Error e = (Error)Marshal.PtrToStructure (ptr, typeof(Error)); ex = new LibMtpException (e.errornumber, e.error_text, ex); ptr = e.next; } // Once we throw the exception, clear the error stack MtpDevice.ClearErrorStack (handle); throw ex; }