Beispiel #1
0
        public void DelMediasFromPath(MyWindowsMediaPlayer.Model.Path path)
        {
            Media  selectedMediaTmp = this.SelectedMedia;
            string selectedTypeTmp  = this.SelectedType;

            for (int i = 0; i < this.Musics.Count; i++)
            {
                if (this.Musics[i].Path != null && path.Id == this.Musics[i].Path.Id)
                {
                    this.SelectedMedia = this.Musics[i];
                    this.SelectedType  = "Music";
                    this.DelFromLibrary(null);
                    i = -1;
                }
            }
            for (int i = 0; i < this.Videos.Count; i++)
            {
                if (this.Videos[i].Path != null && path.Id == this.Videos[i].Path.Id)
                {
                    this.SelectedMedia = this.Videos[i];
                    this.SelectedType  = "Video";
                    this.DelFromLibrary(null);
                    i = -1;
                }
            }
            for (int i = 0; i < this.Pictures.Count; i++)
            {
                if (this.Pictures[i].Path != null && path.Id == this.Pictures[i].Path.Id)
                {
                    this.SelectedMedia = this.Pictures[i];
                    this.SelectedType  = "Picture";
                    this.DelFromLibrary(null);
                    i = -1;
                }
            }

            this.SelectedMedia = selectedMediaTmp;
            this.SelectedType  = selectedTypeTmp;
        }
Beispiel #2
0
        public void AddMediasFromPath(MyWindowsMediaPlayer.Model.Path path)
        {
            Stack <string> dirs = new Stack <string>();

            if (System.IO.Directory.Exists(path.PathSource.LocalPath))
            {
                dirs.Push(path.PathSource.LocalPath);

                while (dirs.Count > 0)
                {
                    string   currentDir = dirs.Pop();
                    string[] subDirs;
                    string[] files = null;

                    try
                    {
                        subDirs = Directory.GetDirectories(currentDir);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        continue;
                    }
                    catch (DirectoryNotFoundException)
                    {
                        continue;
                    }

                    try
                    {
                        files = Directory.GetFiles(currentDir);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        continue;
                    }
                    catch (DirectoryNotFoundException)
                    {
                        continue;
                    }

                    foreach (string file in files)
                    {
                        try
                        {
                            System.IO.FileInfo fi  = new System.IO.FileInfo(file);
                            string             ext = System.IO.Path.GetExtension(fi.FullName);

                            if (ext == ".wav" || ext == ".mp3")
                            {
                                int          idMaxMusic = (this.Musics.Count > 0) ? this.Musics.OrderByDescending(item => item.Id).First().Id + 1 : 1;
                                Music        music      = new Music(idMaxMusic, new Uri(fi.FullName), path);
                                List <Music> exist      = (from item in this.Musics where item.Source.AbsolutePath == music.Source.AbsolutePath select item).ToList();
                                if (exist.Count == 0)
                                {
                                    this.Musics.Add(music);
                                    if (this.EventMediaAdded != null)
                                    {
                                        this.EventMediaAdded(music, new EventArgs());
                                    }
                                }
                            }
                            else if (ext == ".avi" || ext == ".mpg" || ext == ".mpeg" || ext == ".wmv" || ext == ".mov" || ext == ".mp4")
                            {
                                int          idMaxVideo = (this.Videos.Count > 0) ? this.Videos.OrderByDescending(item => item.Id).First().Id + 1 : 1;
                                Video        video      = new Video(idMaxVideo, new Uri(fi.FullName), path);
                                List <Video> exist      = (from item in this.Videos where item.Source.AbsolutePath == video.Source.AbsolutePath select item).ToList();
                                if (exist.Count == 0)
                                {
                                    this.Videos.Add(video);
                                    if (this.EventMediaAdded != null)
                                    {
                                        this.EventMediaAdded(video, new EventArgs());
                                    }
                                }
                            }
                            else if (ext == ".gif" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bpm" || ext == ".tif")
                            {
                                int            idMaxPicture = (this.Pictures.Count > 0) ? this.Pictures.OrderByDescending(item => item.Id).First().Id + 1 : 1;
                                Picture        picture      = new Picture(idMaxPicture, new Uri(fi.FullName), path);
                                List <Picture> exist        = (from item in this.Pictures where item.Source.AbsolutePath == picture.Source.AbsolutePath select item).ToList();
                                if (exist.Count == 0)
                                {
                                    this.Pictures.Add(picture);
                                    if (this.EventMediaAdded != null)
                                    {
                                        this.EventMediaAdded(picture, new EventArgs());
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            continue;
                        }
                    }

                    foreach (string str in subDirs)
                    {
                        dirs.Push(str);
                    }
                }
            }
        }