Skip to content

Commit

Permalink
Access to the path is denied (fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
firatlogoglu committed Aug 18, 2023
1 parent bd4e033 commit 376fe0d
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 59 deletions.
119 changes: 93 additions & 26 deletions MyScreenSaver/Forms/ShowScreenSaverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,6 +13,10 @@ public partial class ShowScreenSaverForm : Form
{
private List<string> picturefiles = new List<string>();
private List<string> musicfiles = new List<string>();

private static List<string> picture_extensions = new List<string>();
private static List<string> music_extensions = new List<string>();

private bool pause = false;
private int i = 0;
private int z = 0;
Expand Down Expand Up @@ -77,8 +82,6 @@ private void ErrorMusic(string error)
private void GetSettings()
{
this.Text = Localization.ImageSlideshow;
List<string> picture_extensions = new List<string>();
List<string> music_extensions = new List<string>();
lblTime.Visible = Properties.Settings.Default.ShowTime;

try
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -208,6 +205,74 @@ private void GetSettings()
}
}

static List<string> SearchForPictureFiles(string directory)
{
var pictureFiles = new List<string>();

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<string> SearchForMusicFiles(string directory)
{
var musicFiles = new List<string>();

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
Expand Down Expand Up @@ -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;
Expand Down
58 changes: 45 additions & 13 deletions MyScreenSaver/Forms/VideoPlayerVLCForm.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using MyScreenSaver.Languages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;

namespace MyScreenSaver
{
public partial class VideoPlayerVLCForm : Form
{
private List<string> videofiles = new List<string>();
private List<string> video_extensions = new List<string>();
private static List<string> video_extensions = new List<string>();
private bool playing;
public VideoPlayerVLCForm()
{
Expand Down Expand Up @@ -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);
Expand All @@ -72,6 +70,40 @@ private void GetSettings()
}
}

static List<string> SearchForVideoFiles(string directory)
{
var videoFiles = new List<string>();

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();
Expand Down
58 changes: 38 additions & 20 deletions MyScreenSaver/Forms/VideoPlayerWMPForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
using MyScreenSaver.Models.WMP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;

namespace MyScreenSaver
{
public partial class VideoPlayerWMPForm : Form
{
private List<string> videofiles = new List<string>();
private List<string> video_extensions = new List<string>();
private static List<string> video_extensions = new List<string>();

private int i;
private bool playing;
private int msplayerstatus;
Expand All @@ -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;

Expand All @@ -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)
{
Expand All @@ -87,6 +71,40 @@ private void ShowOptionsForm()
}
}

static List<string> SearchForVideoFiles(string directory)
{
var videoFiles = new List<string>();

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)
Expand Down

0 comments on commit 376fe0d

Please sign in to comment.