@@ -15,7 +15,7 @@ namespace DesktopClient
15
15
public partial class Main : Form
16
16
{
17
17
// Selected directory from folder browse dialog
18
- private string _rootDirctory ;
18
+ private string _rootDirectory ;
19
19
20
20
// Contains list of movie/tv-show to be downloaded
21
21
private IList < MediaInfo > _mediaFiles ;
@@ -98,22 +98,16 @@ private void ButtonBrowse_Click(object sender, EventArgs e)
98
98
99
99
if ( fbd . ShowDialog ( ) == DialogResult . OK )
100
100
{
101
- _rootDirctory = fbd . SelectedPath ;
102
- textBox1 . Text = _rootDirctory ;
103
- LoadMedias ( ) ;
101
+ textBoxPath . Text = fbd . SelectedPath ;
104
102
// get all movie files and store them in a list for later access...
105
103
}
106
104
}
107
105
}
108
106
109
- private void LoadMedias ( )
107
+ private int LoadMedias ( )
110
108
{
111
- if ( ! Directory . Exists ( _rootDirctory ) )
112
- {
113
- return ;
114
- }
115
109
_mediaFiles . Clear ( ) ;
116
- foreach ( string file in Directory . GetFiles ( _rootDirctory ) )
110
+ foreach ( string file in Directory . GetFiles ( _rootDirectory ) )
117
111
{
118
112
if ( IgnoreExtensions . Contains ( Path . GetExtension ( file ) ) )
119
113
{
@@ -122,10 +116,12 @@ private void LoadMedias()
122
116
var mf = new MediaInfo ( file ) ;
123
117
_mediaFiles . Add ( mf ) ;
124
118
}
119
+ return _mediaFiles . Count ;
125
120
}
126
121
127
122
private async void ButtonDownload_Click ( object sender , EventArgs e )
128
123
{
124
+
129
125
// validation fails
130
126
if ( ! IsValid ( ) )
131
127
{
@@ -177,47 +173,37 @@ private async void ButtonDownload_Click(object sender, EventArgs e)
177
173
178
174
private bool IsValid ( )
179
175
{
180
- if ( string . IsNullOrEmpty ( _rootDirctory ) )
176
+ _rootDirectory = textBoxPath . Text . Trim ( ) ;
177
+ if ( ! Path . IsPathRooted ( _rootDirectory ) )
181
178
{
182
- MessageBox . Show ( "No directory selected " ) ;
179
+ MessageBox . Show ( "Invalid path! " ) ;
183
180
return false ;
184
181
}
185
-
186
- if ( ! Directory . Exists ( _rootDirctory ) )
182
+ if ( ! Directory . Exists ( _rootDirectory ) )
187
183
{
188
184
MessageBox . Show ( "Selected directory doesn't exits!" ) ;
189
185
return false ;
190
186
}
191
-
192
- if ( _mediaFiles . Count == 0 )
187
+ // get media file content from selected path from textbox
188
+ if ( LoadMedias ( ) == 0 )
193
189
{
194
190
MessageBox . Show ( "Media files not loaded!" ) ;
195
191
return false ;
196
192
}
197
-
198
193
return true ;
199
194
}
200
195
201
196
private void textBox1_DragEnter ( object sender , DragEventArgs e )
202
197
{
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 ;
211
199
}
212
200
213
201
private void textBox1_DragDrop ( object sender , DragEventArgs e )
214
202
{
215
203
string [ ] directory = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
216
204
if ( directory . Length > 0 )
217
205
{
218
- _rootDirctory = directory . First ( ) ;
219
- textBox1 . Text = _rootDirctory ;
220
- LoadMedias ( ) ;
206
+ textBoxPath . Text = directory . First ( ) ;
221
207
}
222
208
}
223
209
}
0 commit comments