Skip to content

Commit b232a4b

Browse files
committed
[desktop-client] - fix path issues
1 parent 8f5555d commit b232a4b

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed

DesktopClient/Main.Designer.cs

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DesktopClient/Main.cs

+14-28
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace DesktopClient
1515
public partial class Main : Form
1616
{
1717
// Selected directory from folder browse dialog
18-
private string _rootDirctory;
18+
private string _rootDirectory;
1919

2020
// Contains list of movie/tv-show to be downloaded
2121
private IList<MediaInfo> _mediaFiles;
@@ -98,22 +98,16 @@ private void ButtonBrowse_Click(object sender, EventArgs e)
9898

9999
if (fbd.ShowDialog() == DialogResult.OK)
100100
{
101-
_rootDirctory = fbd.SelectedPath;
102-
textBox1.Text = _rootDirctory;
103-
LoadMedias();
101+
textBoxPath.Text = fbd.SelectedPath;
104102
// get all movie files and store them in a list for later access...
105103
}
106104
}
107105
}
108106

109-
private void LoadMedias()
107+
private int LoadMedias()
110108
{
111-
if (!Directory.Exists(_rootDirctory))
112-
{
113-
return;
114-
}
115109
_mediaFiles.Clear();
116-
foreach (string file in Directory.GetFiles(_rootDirctory))
110+
foreach (string file in Directory.GetFiles(_rootDirectory))
117111
{
118112
if (IgnoreExtensions.Contains(Path.GetExtension(file)))
119113
{
@@ -122,10 +116,12 @@ private void LoadMedias()
122116
var mf = new MediaInfo(file);
123117
_mediaFiles.Add(mf);
124118
}
119+
return _mediaFiles.Count;
125120
}
126121

127122
private async void ButtonDownload_Click(object sender, EventArgs e)
128123
{
124+
129125
// validation fails
130126
if (!IsValid())
131127
{
@@ -177,47 +173,37 @@ private async void ButtonDownload_Click(object sender, EventArgs e)
177173

178174
private bool IsValid()
179175
{
180-
if (string.IsNullOrEmpty(_rootDirctory))
176+
_rootDirectory = textBoxPath.Text.Trim();
177+
if (!Path.IsPathRooted(_rootDirectory))
181178
{
182-
MessageBox.Show("No directory selected");
179+
MessageBox.Show("Invalid path!");
183180
return false;
184181
}
185-
186-
if (!Directory.Exists(_rootDirctory))
182+
if (!Directory.Exists(_rootDirectory))
187183
{
188184
MessageBox.Show("Selected directory doesn't exits!");
189185
return false;
190186
}
191-
192-
if (_mediaFiles.Count == 0)
187+
// get media file content from selected path from textbox
188+
if (LoadMedias() == 0)
193189
{
194190
MessageBox.Show("Media files not loaded!");
195191
return false;
196192
}
197-
198193
return true;
199194
}
200195

201196
private void textBox1_DragEnter(object sender, DragEventArgs e)
202197
{
203-
if (e.Data.GetDataPresent(DataFormats.FileDrop))
204-
{
205-
e.Effect = DragDropEffects.Copy;
206-
}
207-
else
208-
{
209-
e.Effect = DragDropEffects.None;
210-
}
198+
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
211199
}
212200

213201
private void textBox1_DragDrop(object sender, DragEventArgs e)
214202
{
215203
string[] directory = (string[])e.Data.GetData(DataFormats.FileDrop);
216204
if (directory.Length > 0)
217205
{
218-
_rootDirctory = directory.First();
219-
textBox1.Text = _rootDirctory;
220-
LoadMedias();
206+
textBoxPath.Text = directory.First();
221207
}
222208
}
223209
}

0 commit comments

Comments
 (0)