Exemple #1
0
 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");
     }
 }
Exemple #2
0
 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");
     }
 }
Exemple #3
0
 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");
     }
 }
Exemple #4
0
        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");
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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;
        }
Exemple #7
0
        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;
        }