Ejemplo n.º 1
0
 internal Playlist (MtpDevice device, PlaylistStruct playlist) : base (device, playlist.tracks, playlist.no_tracks)
 {
     // Once we've loaded the tracks, set the TracksPtr to NULL as it
     // will be freed when the Playlist constructor is finished.
     this.playlist = playlist;
     TracksPtr = IntPtr.Zero;
 }
Ejemplo n.º 2
0
 internal Playlist(MtpDevice device, PlaylistStruct playlist) : base(device, playlist.tracks, playlist.no_tracks)
 {
     // Once we've loaded the tracks, set the TracksPtr to NULL as it
     // will be freed when the Playlist constructor is finished.
     this.playlist = playlist;
     TracksPtr     = IntPtr.Zero;
 }
Ejemplo n.º 3
0
 internal Folder(uint folderId, uint parentId, string name, MtpDevice device)
 {
     this.device   = device;
     this.folderId = folderId;
     this.parentId = parentId;
     this.name     = name;
 }
Ejemplo n.º 4
0
 internal Album(MtpDevice device, AlbumStruct album) : base(device, album.tracks, album.no_tracks)
 {
     // Once we've loaded the tracks, set the TracksPtr to NULL as it
     // will be freed when the Album constructor is finished.
     this.album = album;
     TracksPtr  = IntPtr.Zero;
 }
Ejemplo n.º 5
0
 public Playlist(MtpDevice device, string name) : base(device, name)
 {
     this.playlist = new PlaylistStruct();
     TracksPtr     = IntPtr.Zero;
     Name          = name;
     Count         = 0;
 }
Ejemplo n.º 6
0
 internal Folder (uint folderId, uint parentId, string name, MtpDevice device)
 {
     this.device = device;
     this.folderId = folderId;
     this.parentId = parentId;
     this.name = name;
 }
Ejemplo n.º 7
0
 public Playlist (MtpDevice device, string name) : base (device, name)
 {
     this.playlist = new PlaylistStruct ();
     TracksPtr = IntPtr.Zero;
     Name = name;
     Count = 0;
 }
Ejemplo n.º 8
0
 public Playlist(MtpDevice device, string name)
     : base(device)
 {
     this.playlist = new PlaylistStruct ();
     Name = name;
     Count = 0;
 }
Ejemplo n.º 9
0
 public Album(MtpDevice device, string name, string artist, string genre, string composer) : base(device)
 {
     Name     = name;
     Artist   = artist;
     Genre    = genre;
     Composer = composer;
     Count    = 0;
 }
Ejemplo n.º 10
0
 internal Album(MtpDevice device, AlbumStruct album)
     : base(device, album.tracks, album.no_tracks)
 {
     // Once we've loaded the tracks, set the TracksPtr to NULL as it
     // will be freed when the Album constructor is finished.
     this.album = album;
     TracksPtr = IntPtr.Zero;
 }
Ejemplo n.º 11
0
 public Album(MtpDevice device, string name, string artist, string genre, string composer) : base(device, name)
 {
     Name      = name;
     Artist    = artist;
     Genre     = genre;
     Composer  = composer;
     Count     = 0;
     TracksPtr = IntPtr.Zero;
 }
Ejemplo n.º 12
0
 public Album(MtpDevice device, string name, string artist, string genre, string composer)
     : base(device)
 {
     Name = name;
     Artist = artist;
     Genre = genre;
     Composer = composer;
     Count = 0;
 }
Ejemplo n.º 13
0
        internal AbstractTrackList (MtpDevice device, IntPtr tracks, uint count)
        {
            this.device = device;
            this.saved = true;
            this.track_ids = new List<uint> ();

            if (tracks != IntPtr.Zero) {
                for (int i = 0; i < (int) count; i++)
                    track_ids.Add ((uint) Marshal.ReadInt32 (tracks, sizeof (int) * i));
            }
        }
Ejemplo n.º 14
0
 internal static List<Playlist> GetPlaylists (MtpDevice device)
 {
     List<Playlist> playlists = new List<Playlist> ();
     IntPtr ptr = Playlist.LIBMTP_Get_Playlist_List (device.Handle);
     while (ptr != IntPtr.Zero) {
         PlaylistStruct d = (PlaylistStruct)Marshal.PtrToStructure(ptr, typeof(PlaylistStruct));
         LIBMTP_destroy_playlist_t (ptr);
         playlists.Add (new Playlist (device, d));
         ptr = d.next;
     }
     return playlists;
 }
Ejemplo n.º 15
0
        internal AbstractTrackList(MtpDevice device, IntPtr tracks, uint count) : this(device)
        {
            this.saved     = true;
            this.track_ids = new List <uint> ();

            if (tracks != IntPtr.Zero)
            {
                for (int i = 0; i < (int)count; i++)
                {
                    track_ids.Add((uint)Marshal.ReadInt32(tracks, sizeof(int) * i));
                }
            }
        }
Ejemplo n.º 16
0
        public static Album GetById(MtpDevice device, uint id)
        {
            IntPtr ptr = Album.LIBMTP_Get_Album(device.Handle, id);

            if (ptr == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                return(new Album(device, (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct))));
            }
        }
        internal AbstractTrackList (MtpDevice device, IntPtr tracks, uint count)
        {
            this.device = device;
            this.saved = true;

            if (tracks != IntPtr.Zero) {
                int [] vals = new int [count];
                Marshal.Copy ((IntPtr)tracks, (int[])vals, 0, (int)count);
                track_ids = new List<int> (vals);
            } else {
                track_ids = new List<int> ();
            }
        }
Ejemplo n.º 18
0
 internal static List<Playlist> GetPlaylists (MtpDevice device)
 {
     List<Playlist> playlists = new List<Playlist> ();
     IntPtr ptr = Playlist.LIBMTP_Get_Playlist_List (device.Handle);
     while (ptr != IntPtr.Zero) {
         // Destroy the struct *after* we use it to ensure we don't access freed memory
         // for the 'tracks' variable
         PlaylistStruct d = (PlaylistStruct)Marshal.PtrToStructure(ptr, typeof(PlaylistStruct));
         playlists.Add (new Playlist (device, d));
         LIBMTP_destroy_playlist_t (ptr);
         ptr = d.next;
     }
     return playlists;
 }
Ejemplo n.º 19
0
        protected AbstractTrackList(MtpDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            this.device = device;

            if (track_ids == null)
            {
                track_ids = new List <uint> ();
            }
        }
Ejemplo n.º 20
0
        internal static List<Album> GetAlbums (MtpDevice device)
        {
            List<Album> albums = new List<Album> ();

            IntPtr ptr = LIBMTP_Get_Album_List (device.Handle);
            while (ptr != IntPtr.Zero) {
                AlbumStruct d = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct));
                LIBMTP_destroy_album_t (ptr);
                albums.Add (new Album (device, d));
                ptr = d.next;
            }

            return albums;
        }
Ejemplo n.º 21
0
        internal static List <Folder> GetRootFolders(MtpDevice device)
        {
            List <Folder> folders = new List <Folder>();

            using (FolderHandle handle = GetFolderList(device.Handle))
            {
                for (IntPtr ptr = handle.DangerousGetHandle(); ptr != IntPtr.Zero;)
                {
                    FolderStruct folder = (FolderStruct)Marshal.PtrToStructure(ptr, typeof(FolderStruct));
                    folders.Add(new Folder(folder, device));
                    ptr = folder.sibling;
                }
                return(folders);
            }
        }
Ejemplo n.º 22
0
        internal static List <Playlist> GetPlaylists(MtpDevice device)
        {
            List <Playlist> playlists = new List <Playlist> ();
            IntPtr          ptr       = Playlist.LIBMTP_Get_Playlist_List(device.Handle);

            while (ptr != IntPtr.Zero)
            {
                // Destroy the struct *after* we use it to ensure we don't access freed memory
                // for the 'tracks' variable
                PlaylistStruct d = (PlaylistStruct)Marshal.PtrToStructure(ptr, typeof(PlaylistStruct));
                playlists.Add(new Playlist(device, d));
                LIBMTP_destroy_playlist_t(ptr);
                ptr = d.next;
            }
            return(playlists);
        }
Ejemplo n.º 23
0
        internal static List<Album> GetAlbums (MtpDevice device)
        {
            List<Album> albums = new List<Album> ();

            IntPtr ptr = LIBMTP_Get_Album_List (device.Handle);
            while (ptr != IntPtr.Zero) {
                // Destroy the struct *after* we use it to ensure we don't access freed memory
                // for the 'tracks' variable
                AlbumStruct d = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct));
                albums.Add (new Album (device, d));
                LIBMTP_destroy_album_t (ptr);
                ptr = d.next;
            }

            return albums;
        }
Ejemplo n.º 24
0
        internal AbstractTrackList(MtpDevice device, IntPtr tracks, uint count)
        {
            this.device = device;
            this.saved  = true;

            if (tracks != IntPtr.Zero)
            {
                int [] vals = new int [count];
                Marshal.Copy((IntPtr)tracks, (int[])vals, 0, (int)count);
                track_ids = new List <int> (vals);
            }
            else
            {
                track_ids = new List <int> ();
            }
        }
Ejemplo n.º 25
0
        internal static List <Folder> GetRootFolders(MtpDevice device)
        {
            List <Folder> folders = new List <Folder>();
            IntPtr        root    = GetFolderList(device.Handle);

            try {
                for (IntPtr ptr = root; ptr != IntPtr.Zero;)
                {
                    FolderStruct folder = (FolderStruct)Marshal.PtrToStructure(ptr, typeof(FolderStruct));
                    folders.Add(new Folder(folder, device));
                    ptr = folder.sibling;
                }
            } finally {
                // Recursively destroy the folder tree
                LIBMTP_destroy_folder_t(root);
            }
            return(folders);
        }
Ejemplo n.º 26
0
        internal static List <Album> GetAlbums(MtpDevice device)
        {
            List <Album> albums = new List <Album> ();

            IntPtr ptr = LIBMTP_Get_Album_List(device.Handle);

            while (ptr != IntPtr.Zero)
            {
                // Destroy the struct *after* we use it to ensure we don't access freed memory
                // for the 'tracks' variable
                AlbumStruct d = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct));
                albums.Add(new Album(device, d));
                LIBMTP_destroy_album_t(ptr);
                ptr = d.next;
            }

            return(albums);
        }
Ejemplo n.º 27
0
        public static Album GetById(MtpDevice device, uint id)
        {
            IntPtr ptr = Album.LIBMTP_Get_Album(device.Handle, id);

            if (ptr == IntPtr.Zero)
            {
                return(null);
            }
            else
            {
                // Destroy the struct after we use it to prevent accessing freed memory
                // in the 'tracks' variable
                AlbumStruct album = (AlbumStruct)Marshal.PtrToStructure(ptr, typeof(AlbumStruct));
                var         ret   = new Album(device, album);
                LIBMTP_destroy_album_t(ptr);
                return(ret);
            }
        }
Ejemplo n.º 28
0
        public MtpTrackInfo(MtpDevice device, Track file)
            : base()
        {
            this.file = file;
            ExternalId = file.FileId;

            AlbumTitle = file.Album;
            ArtistName = file.Artist;
            Duration = TimeSpan.FromMilliseconds (file.Duration);
            Genre = file.Genre;
            PlayCount = file.UseCount < 0 ? 0 : (int) file.UseCount;
            Rating = file.Rating < 0 ? 0 : (file.Rating / 20);
            TrackTitle = file.Title;
            TrackNumber = file.TrackNumber < 0 ? 0 : (int)file.TrackNumber;
            Year = file.Year;
            BitRate = (int)file.Bitrate;
            SampleRate = (int)file.SampleRate;
            FileSize = (long)file.FileSize;

            MediaAttributes = TrackMediaAttributes.AudioStream;
            if (device != null) {
                SetAttributeIf (file.InFolder (device.PodcastFolder, true) || Genre == "Podcast", TrackMediaAttributes.Podcast);
                SetAttributeIf (file.InFolder (device.MusicFolder, true), TrackMediaAttributes.Music);
                SetAttributeIf (file.InFolder (device.VideoFolder, true), TrackMediaAttributes.VideoStream);
            }

            // This can be implemented if there's enough people requesting it
            CanPlay = false;
            CanSaveToDatabase = true;
            //NeedSync = false;

            // TODO detect if this is a video file and set the MediaAttributes appropriately?
            /*Profile profile = ServiceManager.Get<MediaProfileManager> ().GetProfileForExtension (System.IO.Path.GetExtension (file.FileName));
            if (profile != null) {
                profile.
            }*/

            // Set a URI even though it's not actually accessible through normal API's.
            Uri = new SafeUri (GetPathFromMtpTrack (file));
        }
Ejemplo n.º 29
0
        internal static Folder Find(MtpDevice device, uint folderId)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            Folder folder = null;
            IntPtr root   = GetFolderList(device.Handle);

            try {
                IntPtr ptr = Find(root, folderId);
                if (ptr != IntPtr.Zero)
                {
                    FolderStruct folderStruct = (FolderStruct)Marshal.PtrToStructure(ptr, typeof(FolderStruct));
                    folder = new Folder(folderStruct, device);
                }
            } finally {
                DestroyFolder(root);
            }
            return(folder);
        }
Ejemplo n.º 30
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;
        }
Ejemplo n.º 31
0
        public override void Dispose()
        {
            if (disposed)
                return;

            disposed = true;
            base.Dispose ();

            if (mtp_device != null) {
                lock (mtp_device) {
                    mtp_device.Dispose ();
                }
            }

            mtp_device = null;
        }
Ejemplo n.º 32
0
 internal Album(MtpDevice device, AlbumStruct album) : base(device, album.tracks, album.no_tracks)
 {
     this.album = album;
 }
Ejemplo n.º 33
0
 internal Playlist (MtpDevice device, PlaylistStruct playlist) : base (device, playlist.tracks, playlist.no_tracks)
 {
     this.playlist = playlist;
 }
Ejemplo n.º 34
0
 public Playlist(MtpDevice device, string name) : base(device)
 {
     this.playlist = new PlaylistStruct();
     Name          = name;
     Count         = 0;
 }
Ejemplo n.º 35
0
 public Track(string filename, ulong filesize, MtpDevice device)
     : this(new TrackStruct (), device)
 {
     this.trackStruct.filename = filename;
     this.trackStruct.filesize = filesize;
     this.trackStruct.filetype = DetectFileType (this);
 }
Ejemplo n.º 36
0
 protected override bool ReleaseHandle()
 {
     MtpDevice.ReleaseDevice(handle);
     return(true);
 }
Ejemplo n.º 37
0
 public AbstractTrackList(MtpDevice device, string name)
 {
     this.device = device;
     track_ids   = new List <uint> ();
 }
Ejemplo n.º 38
0
 public void Remove()
 {
     MtpDevice.LIBMTP_Delete_Object(Device.Handle, AlbumId);
 }
Ejemplo n.º 39
0
        public override void Dispose ()
        {
            if (disposed)
                return;

            disposed = true;
            base.Dispose ();

            if (mtp_device != null) {
                lock (mtp_device) {
                    mtp_device.Dispose ();
                }
            }

            ServiceManager.SourceManager.RemoveSource (this);
            mtp_device = null;
        }
Ejemplo n.º 40
0
 public void Remove()
 {
     MtpDevice.DeleteObject(device.Handle, FolderId);
 }
Ejemplo n.º 41
0
        internal static Folder Find(MtpDevice device, uint folderId)
        {
            if (device == null) {
                throw new ArgumentNullException ("device");
            }

            Folder folder = null;
            IntPtr root = GetFolderList (device.Handle);
            try {
                IntPtr ptr = Find (root, folderId);
                if (ptr != IntPtr.Zero) {
                    FolderStruct folderStruct = (FolderStruct)Marshal.PtrToStructure (ptr, typeof (FolderStruct));
                    folder = new Folder (folderStruct, device);
                }
            } finally {
                DestroyFolder (root);
            }
            return folder;
        }
Ejemplo n.º 42
0
 internal Track(TrackStruct track, MtpDevice device)
 {
     this.device      = device;
     this.trackStruct = track;
 }
Ejemplo n.º 43
0
 internal Track(TrackStruct track, MtpDevice device)
 {
     this.device = device;
     this.trackStruct = track;
 }
Ejemplo n.º 44
0
 public Track(string filename, ulong filesize, MtpDevice device) : this(new TrackStruct(), device)
 {
     this.trackStruct.filename = filename;
     this.trackStruct.filesize = filesize;
     this.trackStruct.filetype = DetectFileType(this);
 }
Ejemplo n.º 45
0
 internal Folder(FolderStruct folder, MtpDevice device)
     : this(folder.folder_id, folder.parent_id, folder.name, device)
 {
 }
Ejemplo n.º 46
0
 internal Album (MtpDevice device, AlbumStruct album) : base (device, album.tracks, album.no_tracks)
 {
     this.album = album;
 }
Ejemplo n.º 47
0
 internal Playlist(MtpDevice device, PlaylistStruct playlist) : base(device, playlist.tracks, playlist.no_tracks)
 {
     this.playlist = playlist;
 }
 public AbstractTrackList (MtpDevice device, string name)
 {
     this.device = device;
     track_ids = new List<int> ();
 }
Ejemplo n.º 49
0
 public void Remove()
 {
     MtpDevice.LIBMTP_Delete_Object(Device.Handle, playlist.playlist_id);
 }
Ejemplo n.º 50
0
 internal static List<Folder> GetRootFolders (MtpDevice device)
 {
     List<Folder> folders = new List<Folder>();
     IntPtr root = GetFolderList (device.Handle);
     try {
         for (IntPtr ptr = root; ptr != IntPtr.Zero;) {
             FolderStruct folder = (FolderStruct)Marshal.PtrToStructure(ptr, typeof(FolderStruct));
             folders.Add(new Folder (folder, device));
             ptr = folder.sibling;
         }
     } finally {
         // Recursively destroy the folder tree
         LIBMTP_destroy_folder_t (root);
     }
     return folders;
 }
Ejemplo n.º 51
0
 public static Album GetById (MtpDevice device, uint id)
 {
     IntPtr ptr = Album.LIBMTP_Get_Album (device.Handle, id);
     if (ptr == IntPtr.Zero) {
         return null;
     } else {
         // Destroy the struct after we use it to prevent accessing freed memory
         // in the 'tracks' variable
         AlbumStruct album = (AlbumStruct) Marshal.PtrToStructure(ptr, typeof (AlbumStruct));
         var ret = new Album (device, album);
         LIBMTP_destroy_album_t (ptr);
         return ret;
     }
 }
Ejemplo n.º 52
0
        internal Folder (FolderStruct folder, MtpDevice device)
                    : this (folder.folder_id, folder.parent_id, folder.name, device)
        {

        }
Ejemplo n.º 53
0
 public Album (MtpDevice device, string name, string artist, string genre, string composer) : base (device, name)
 {
     Name = name;
     Artist = artist;
     Genre = genre;
     Composer = composer;
     Count = 0;
     TracksPtr = IntPtr.Zero;
 }
Ejemplo n.º 54
0
        public override void DeviceInitialize (IDevice device)
        {
            base.DeviceInitialize (device);

            var portInfo = device.ResolveUsbPortInfo ();
            if (portInfo == null || portInfo.DeviceNumber == 0) {
                throw new InvalidDeviceException ();
            }

            //int busnum = portInfo.BusNumber;
            int devnum = portInfo.DeviceNumber;

            List<RawMtpDevice> devices = null;
            try {
                devices = MtpDevice.Detect ();
            } catch (TypeInitializationException e) {
                Log.Exception (e);
                Log.Error (
                    Catalog.GetString ("Error Initializing MTP Device Support"),
                    Catalog.GetString ("There was an error initializing MTP device support."), true
                );
                throw new InvalidDeviceException ();
            } catch (Exception e) {
                Log.Exception (e);
                //ShowGeneralExceptionDialog (e);
                throw new InvalidDeviceException ();
            }

            IVolume volume = device as IVolume;
            foreach (var v in devices) {
                // Using the HAL hardware backend, HAL says the busnum is 2, but libmtp says it's 0, so disabling that check
                //if (v.BusNumber == busnum && v.DeviceNumber == devnum) {
                if (v.DeviceNumber == devnum) {
                    // If gvfs-gphoto has it mounted, unmount it
                    if (volume != null && volume.IsMounted) {
                        volume.Unmount ();
                    }

                    for (int i = 5; i > 0 && mtp_device == null; i--) {
                        try {
                            mtp_device = MtpDevice.Connect (v);
                        } catch (Exception) {}

                        if (mtp_device == null) {
                            Log.DebugFormat ("Failed to connect to mtp device. Trying {0} more times...", i - 1);
                            Thread.Sleep (2000);
                        }
                    }
                }
            }

            if (mtp_device == null) {
                throw new InvalidDeviceException ();
            }

            // libmtp sometimes returns '?????'. I assume this is if the device does
            // not supply a friendly name. In this case show the model name.
            if (string.IsNullOrEmpty (mtp_device.Name) || mtp_device.Name == "?????")
                Name = mtp_device.ModelName;
            else
                Name = mtp_device.Name;

            Initialize ();

            List<string> mimetypes = new List<string> ();
            foreach (FileType format in mtp_device.GetFileTypes ()) {
                if (format == FileType.JPEG) {
                    supports_jpegs = true;
                } else {
                    string mimetype = MtpDevice.GetMimeTypeFor (format);
                    if (mimetype != null) {
                        mimetypes.Add (mimetype);
                    }
                }
            }
            AcceptableMimeTypes = mimetypes.ToArray ();

            AddDapProperty (Catalog.GetString ("Serial number"), mtp_device.SerialNumber);
            AddDapProperty (Catalog.GetString ("Version"), mtp_device.Version);
            try {
                AddDapProperty (Catalog.GetString ("Battery level"), String.Format ("{0:0%}", mtp_device.BatteryLevel/100.0));
            } catch (Exception e) {
                Log.Exception ("Unable to get battery level from MTP device", e);
            }
        }
Ejemplo n.º 55
0
 public static Album GetById (MtpDevice device, uint id)
 {
     IntPtr ptr = Album.LIBMTP_Get_Album (device.Handle, id);
     if (ptr == IntPtr.Zero) {
         return null;
     } else {
         AlbumStruct album = (AlbumStruct) Marshal.PtrToStructure(ptr, typeof (AlbumStruct));
         LIBMTP_destroy_album_t (ptr);
         return new Album (device, album);
     }
 }