@@ -54,7 +54,7 @@ public HomeViewModel(ISnackbarMessageQueue snackbarMessageQueue)
54
54
_openFolder = new DelegateCommand ( OnOpenFolder , CanOpenFolder ) ;
55
55
_startDownload = new DelegateCommand ( OnStartDownload , CanStartDownload ) ;
56
56
_listFormats = new DelegateCommand ( OnListFormats , CanStartDownload ) ;
57
- _abortDl = new DelegateCommand ( OnAbortDl , ( object commandParameter ) => _freezeButton ) ;
57
+ _abortDl = new DelegateCommand ( OnAbortDl , ( object ? commandParameter ) => _freezeButton ) ;
58
58
59
59
ContainerList = new ObservableCollection < string > ( )
60
60
{
@@ -232,8 +232,14 @@ private void DlProcess_Exited(object? sender, EventArgs e)
232
232
Application . Current . Dispatcher . Invoke ( UpdateButtons ) ;
233
233
}
234
234
235
- private void OnBrowseFolder ( object commandParameter )
235
+ private void OnBrowseFolder ( object ? commandParameter )
236
236
{
237
+ if ( commandParameter == null )
238
+ throw new ArgumentNullException ( nameof ( commandParameter ) ) ;
239
+
240
+ if ( commandParameter is not string parameter )
241
+ throw new ArgumentException ( "Command parameter is not a string." , nameof ( commandParameter ) ) ;
242
+
237
243
Microsoft . Win32 . OpenFileDialog folderDialog = new Microsoft . Win32 . OpenFileDialog
238
244
{
239
245
FileName = "Folder Selection." ,
@@ -242,19 +248,19 @@ private void OnBrowseFolder(object commandParameter)
242
248
CheckPathExists = true
243
249
} ;
244
250
245
- if ( ( string ) commandParameter == "DownloadPath" )
251
+ if ( parameter == "DownloadPath" )
246
252
folderDialog . InitialDirectory = DownloadPath ;
247
253
248
254
bool ? result = folderDialog . ShowDialog ( ) ;
249
255
250
256
if ( result == true )
251
257
{
252
- if ( ( string ) commandParameter == "DownloadPath" )
258
+ if ( parameter == "DownloadPath" )
253
259
DownloadPath = Path . GetDirectoryName ( folderDialog . FileName ) ?? "" ;
254
260
}
255
261
}
256
262
257
- private void OnOpenFolder ( object commandParameter )
263
+ private void OnOpenFolder ( object ? commandParameter )
258
264
{
259
265
try
260
266
{
@@ -266,7 +272,7 @@ private void OnOpenFolder(object commandParameter)
266
272
}
267
273
}
268
274
269
- private void OnStartDownload ( object commandParameter )
275
+ private void OnStartDownload ( object ? commandParameter )
270
276
{
271
277
FreezeButton = true ;
272
278
DownloadButtonProgressIndeterminate = true ;
@@ -344,7 +350,7 @@ private void OnStartDownload(object commandParameter)
344
350
}
345
351
}
346
352
347
- private void OnListFormats ( object commandParameter )
353
+ private void OnListFormats ( object ? commandParameter )
348
354
{
349
355
FreezeButton = true ;
350
356
FormatsButtonProgressIndeterminate = true ;
@@ -379,7 +385,7 @@ private void OnListFormats(object commandParameter)
379
385
}
380
386
}
381
387
382
- private void OnAbortDl ( object commandParameter )
388
+ private void OnAbortDl ( object ? commandParameter )
383
389
{
384
390
try
385
391
{
@@ -401,12 +407,12 @@ private void OnAbortDl(object commandParameter)
401
407
}
402
408
}
403
409
404
- private bool CanOpenFolder ( object commandParameter )
410
+ private bool CanOpenFolder ( object ? commandParameter )
405
411
{
406
412
return ! String . IsNullOrEmpty ( _downloadPath ) && Directory . Exists ( _downloadPath ) ;
407
413
}
408
414
409
- private bool CanStartDownload ( object commandParameter )
415
+ private bool CanStartDownload ( object ? commandParameter )
410
416
{
411
417
return ! String . IsNullOrEmpty ( _link ) && ! String . IsNullOrEmpty ( _container ) && ! String . IsNullOrEmpty ( _format ) && ! String . IsNullOrEmpty ( _settings . DlPath ) && ! _freezeButton ;
412
418
}
@@ -446,7 +452,7 @@ private void UpdateDl()
446
452
}
447
453
}
448
454
449
- private void DlOutputHandler ( object sendingProcess , DataReceivedEventArgs outLine )
455
+ private void DlOutputHandler ( object ? sendingProcess , DataReceivedEventArgs outLine )
450
456
{
451
457
if ( ! string . IsNullOrEmpty ( outLine . Data ) )
452
458
{
@@ -511,7 +517,7 @@ public string Container
511
517
EnableFormatSelection = true ;
512
518
else
513
519
{
514
- this . RaiseAndSetIfChanged ( ref _format , "Auto" , " Format" ) ;
520
+ this . RaiseAndSetIfChanged ( ref _format , "Auto" , nameof ( Format ) ) ;
515
521
_settings . Format = _format ;
516
522
EnableFormatSelection = false ;
517
523
}
0 commit comments