diff --git a/MyScreenSaver/Forms/ShowScreenSaverForm.cs b/MyScreenSaver/Forms/ShowScreenSaverForm.cs index 1f9498a..870f96b 100644 --- a/MyScreenSaver/Forms/ShowScreenSaverForm.cs +++ b/MyScreenSaver/Forms/ShowScreenSaverForm.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.IO; using System.Linq; using System.Windows.Forms; namespace MyScreenSaver @@ -12,6 +13,10 @@ public partial class ShowScreenSaverForm : Form { private List picturefiles = new List(); private List musicfiles = new List(); + + private static List picture_extensions = new List(); + private static List music_extensions = new List(); + private bool pause = false; private int i = 0; private int z = 0; @@ -77,8 +82,6 @@ private void ErrorMusic(string error) private void GetSettings() { this.Text = Localization.ImageSlideshow; - List picture_extensions = new List(); - List music_extensions = new List(); lblTime.Visible = Properties.Settings.Default.ShowTime; try @@ -90,16 +93,10 @@ private void GetSettings() foreach (var item in Properties.Settings.Default.PictureDir) { - var dosyalar = picture_extensions.SelectMany(ext => new System.IO.DirectoryInfo(item).GetFiles(ext, System.IO.SearchOption.AllDirectories)); - foreach (var item2 in dosyalar) - { - //if (!item2.FullName.Contains("Sys")) - //{ - picturefiles.Add(item2.FullName); - //} - } - z = dosyalar.Count(); + picturefiles.AddRange(SearchForPictureFiles(item)); } + + z = picturefiles.Count(); listBoxImageList.DataSource = picturefiles; } catch (Exception ex) @@ -146,32 +143,32 @@ private void GetSettings() foreach (var item in Properties.Settings.Default.MusicDir) { - var dosyalar = music_extensions.SelectMany(ext => new System.IO.DirectoryInfo(item).GetFiles(ext, System.IO.SearchOption.AllDirectories)); - foreach (var item2 in dosyalar) + musicfiles.AddRange(SearchForMusicFiles(item)); + music_z = musicfiles.Count(); + + if (!Properties.Settings.Default.MusicAppWMP) { - musicfiles.Add(item2.FullName); - music_z = dosyalar.Count(); + string fi = "file:///"; - if (!Properties.Settings.Default.MusicAppWMP) + try { - string fi = "file:///"; - - try + foreach (var it in musicfiles) { - axVLCPlugin.playlist.add(fi + item2.FullName); + axVLCPlugin.playlist.add(fi + it); axVLCPlugin.playlist.play(); } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - continue; - } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + continue; } } } + listBoxMusicList.DataSource = musicfiles; - if(Properties.Settings.Default.MusicAppWMP) + if (Properties.Settings.Default.MusicAppWMP) { if (music_z != 0) { @@ -208,6 +205,74 @@ private void GetSettings() } } + static List SearchForPictureFiles(string directory) + { + var pictureFiles = new List(); + + try + { + foreach (string ext in picture_extensions) + { + foreach (string filePath in Directory.GetFiles(directory, ext)) + { + pictureFiles.Add(filePath); + } + } + + foreach (string subDirectory in Directory.GetDirectories(directory)) + { + try + { + pictureFiles.AddRange(SearchForPictureFiles(subDirectory)); + } + catch (UnauthorizedAccessException ex) + { + // MessageBox.Show(ex.Message); + } + } + } + catch (UnauthorizedAccessException ex) + { + // MessageBox.Show(ex.Message); + } + + return pictureFiles; + } + + static List SearchForMusicFiles(string directory) + { + var musicFiles = new List(); + + try + { + foreach (string ext in music_extensions) + { + foreach (string filePath in Directory.GetFiles(directory, ext)) + { + musicFiles.Add(filePath); + } + } + + foreach (string subDirectory in Directory.GetDirectories(directory)) + { + try + { + musicFiles.AddRange(SearchForMusicFiles(subDirectory)); + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + } + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + + return musicFiles; + } + private void PreviousPicture() { try @@ -324,7 +389,9 @@ private void ShowOptionsForm() } listBoxImageList.DataSource = listBoxMusicList.DataSource = null; picturefiles.Clear(); + picture_extensions.Clear(); musicfiles.Clear(); + music_extensions.Clear(); i = 0; z = 0; music_i = 0; diff --git a/MyScreenSaver/Forms/VideoPlayerVLCForm.cs b/MyScreenSaver/Forms/VideoPlayerVLCForm.cs index f8d3201..8974493 100644 --- a/MyScreenSaver/Forms/VideoPlayerVLCForm.cs +++ b/MyScreenSaver/Forms/VideoPlayerVLCForm.cs @@ -1,7 +1,7 @@ using MyScreenSaver.Languages; using System; using System.Collections.Generic; -using System.Linq; +using System.IO; using System.Windows.Forms; namespace MyScreenSaver @@ -9,7 +9,7 @@ namespace MyScreenSaver public partial class VideoPlayerVLCForm : Form { private List videofiles = new List(); - private List video_extensions = new List(); + private static List video_extensions = new List(); private bool playing; public VideoPlayerVLCForm() { @@ -39,23 +39,21 @@ private void GetSettings() { try { - var dosyalar = video_extensions.SelectMany(ext => new System.IO.DirectoryInfo(item).GetFiles(ext, System.IO.SearchOption.AllDirectories)); + videofiles.AddRange(SearchForVideoFiles(item)); - - foreach (var item2 in dosyalar) + try { - try - { - axVLCPlugin.playlist.add(fi + item2.FullName); - videofiles.Add(item2.FullName); - } - catch (Exception) + foreach (var item2 in videofiles) { - - continue; + axVLCPlugin.playlist.add(fi + item2); } } + catch (Exception) + { + continue; + } } + catch (Exception ex) { MessageBox.Show(ex.Message); @@ -72,6 +70,40 @@ private void GetSettings() } } + static List SearchForVideoFiles(string directory) + { + var videoFiles = new List(); + + try + { + foreach (string ext in video_extensions) + { + foreach (string filePath in Directory.GetFiles(directory, ext)) + { + videoFiles.Add(filePath); + } + } + + foreach (string subDirectory in Directory.GetDirectories(directory)) + { + try + { + videoFiles.AddRange(SearchForVideoFiles(subDirectory)); + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + } + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + + return videoFiles; + } + private void ShowOptionsForm() { OptionsForm options = new OptionsForm(); diff --git a/MyScreenSaver/Forms/VideoPlayerWMPForm.cs b/MyScreenSaver/Forms/VideoPlayerWMPForm.cs index effe0ce..8abedff 100644 --- a/MyScreenSaver/Forms/VideoPlayerWMPForm.cs +++ b/MyScreenSaver/Forms/VideoPlayerWMPForm.cs @@ -2,7 +2,7 @@ using MyScreenSaver.Models.WMP; using System; using System.Collections.Generic; -using System.Linq; +using System.IO; using System.Windows.Forms; namespace MyScreenSaver @@ -10,7 +10,8 @@ namespace MyScreenSaver public partial class VideoPlayerWMPForm : Form { private List videofiles = new List(); - private List video_extensions = new List(); + private static List video_extensions = new List(); + private int i; private bool playing; private int msplayerstatus; @@ -27,8 +28,6 @@ private void GetSettings() this.Text = Localization.VideoSlideshow; listBoxVideoList.Location = new System.Drawing.Point(1600, 0); listBoxVideoList.Enabled = false; - //axVLCPlugin.Toolbar = false; - //axVLCPlugin.CtlVisible = false; axWindowsMediaPlayer.Ctlenabled = true; listBoxVideoList.Visible = false; @@ -39,28 +38,13 @@ private void GetSettings() video_extensions.Add(item); } - //string fi = "file:///"; foreach (var item in Properties.Settings.Default.VideoDir) { - var dosyalar = video_extensions.SelectMany(ext => new System.IO.DirectoryInfo(item).GetFiles(ext, System.IO.SearchOption.AllDirectories)); - foreach (var item2 in dosyalar) - { - //try - //{ - - //} - //catch (Exception) - //{ - - // throw; - //} - videofiles.Add(item2.FullName); - } + videofiles.AddRange(SearchForVideoFiles(item)); } listBoxVideoList.DataSource = videofiles; axWindowsMediaPlayer.URL = videofiles[0]; - //PlayVideo(); } catch (Exception ex) { @@ -87,6 +71,40 @@ private void ShowOptionsForm() } } + static List SearchForVideoFiles(string directory) + { + var videoFiles = new List(); + + try + { + foreach (string ext in video_extensions) + { + foreach (string filePath in Directory.GetFiles(directory, ext)) + { + videoFiles.Add(filePath); + } + } + + foreach (string subDirectory in Directory.GetDirectories(directory)) + { + try + { + videoFiles.AddRange(SearchForVideoFiles(subDirectory)); + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + } + } + catch (UnauthorizedAccessException) + { + // MessageBox.Show(ex.Message); + } + + return videoFiles; + } + private void ShowVideoList() { if (listBoxVideoList.Enabled == false)