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; }
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; }
internal Folder(uint folderId, uint parentId, string name, MtpDevice device) { this.device = device; this.folderId = folderId; this.parentId = parentId; this.name = name; }
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; }
public Playlist(MtpDevice device, string name) : base(device, name) { this.playlist = new PlaylistStruct(); TracksPtr = IntPtr.Zero; Name = name; Count = 0; }
internal Folder (uint folderId, uint parentId, string name, MtpDevice device) { this.device = device; this.folderId = folderId; this.parentId = parentId; this.name = name; }
public Playlist (MtpDevice device, string name) : base (device, name) { this.playlist = new PlaylistStruct (); TracksPtr = IntPtr.Zero; Name = name; Count = 0; }
public Playlist(MtpDevice device, string name) : base(device) { this.playlist = new PlaylistStruct (); Name = name; Count = 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; }
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; }
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)); } }
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; }
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)); } } }
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> (); } }
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; }
protected AbstractTrackList(MtpDevice device) { if (device == null) { throw new ArgumentNullException("device"); } this.device = device; if (track_ids == null) { track_ids = new List <uint> (); } }
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; }
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); } }
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); }
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; }
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> (); } }
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); }
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); }
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); } }
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)); }
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); }
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; }
public override void Dispose() { if (disposed) return; disposed = true; base.Dispose (); if (mtp_device != null) { lock (mtp_device) { mtp_device.Dispose (); } } mtp_device = null; }
internal Album(MtpDevice device, AlbumStruct album) : base(device, album.tracks, album.no_tracks) { this.album = album; }
internal Playlist (MtpDevice device, PlaylistStruct playlist) : base (device, playlist.tracks, playlist.no_tracks) { this.playlist = playlist; }
public Playlist(MtpDevice device, string name) : base(device) { this.playlist = new PlaylistStruct(); Name = name; Count = 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); }
protected override bool ReleaseHandle() { MtpDevice.ReleaseDevice(handle); return(true); }
public AbstractTrackList(MtpDevice device, string name) { this.device = device; track_ids = new List <uint> (); }
public void Remove() { MtpDevice.LIBMTP_Delete_Object(Device.Handle, AlbumId); }
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; }
public void Remove() { MtpDevice.DeleteObject(device.Handle, FolderId); }
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; }
internal Track(TrackStruct track, MtpDevice device) { this.device = device; this.trackStruct = track; }
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); }
internal Folder(FolderStruct folder, MtpDevice device) : this(folder.folder_id, folder.parent_id, folder.name, device) { }
internal Album (MtpDevice device, AlbumStruct album) : base (device, album.tracks, album.no_tracks) { this.album = album; }
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> (); }
public void Remove() { MtpDevice.LIBMTP_Delete_Object(Device.Handle, playlist.playlist_id); }
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; }
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; } }
internal Folder (FolderStruct folder, MtpDevice device) : this (folder.folder_id, folder.parent_id, folder.name, device) { }
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; }
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); } }
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); } }