Skip to content

Commit 26f66d4

Browse files
committed
Fixed issue with checking recent network files making VidCoder start slow.
1 parent 61696bf commit 26f66d4

File tree

1 file changed

+65
-10
lines changed

1 file changed

+65
-10
lines changed

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,23 +3683,78 @@ private void RefreshRangePreview()
36833683
this.RaisePropertyChanged(nameof(this.RangePreviewLengthText));
36843684
}
36853685

3686-
private void RefreshRecentSourceOptions()
3686+
private async void RefreshRecentSourceOptions()
36873687
{
3688-
this.recentSourceOptions.Clear();
3688+
try
3689+
{
3690+
var entries = await Task.Run(() =>
3691+
{
3692+
var list = new List<(string Path, bool IsFile)>();
3693+
3694+
List<string> sourceHistory;
3695+
try
3696+
{
3697+
sourceHistory = SourceHistory.GetHistory() ?? new List<string>();
3698+
}
3699+
catch
3700+
{
3701+
// If getting history fails, return empty list.
3702+
return list;
3703+
}
3704+
3705+
foreach (string path in sourceHistory)
3706+
{
3707+
try
3708+
{
3709+
if (File.Exists(path))
3710+
{
3711+
list.Add((path, true));
3712+
}
3713+
else if (Directory.Exists(path))
3714+
{
3715+
list.Add((path, false));
3716+
}
3717+
}
3718+
catch
3719+
{
3720+
// Ignore individual path errors.
3721+
}
3722+
}
3723+
3724+
return list;
3725+
});
3726+
3727+
// Update UI on UI thread without re-checking file system.
3728+
DispatchUtilities.BeginInvoke(() =>
3729+
{
3730+
this.recentSourceOptions.Clear();
3731+
3732+
foreach (var entry in entries)
3733+
{
3734+
if (entry.IsFile)
3735+
{
3736+
this.recentSourceOptions.Add(new SourceOptionViewModel(new SourceOption { Type = SourceType.File }, entry.Path));
3737+
}
3738+
else
3739+
{
3740+
this.recentSourceOptions.Add(new SourceOptionViewModel(new SourceOption { Type = SourceType.DiscVideoFolder }, entry.Path));
3741+
}
3742+
}
36893743

3690-
List<string> sourceHistory = SourceHistory.GetHistory();
3691-
foreach (string recentSourcePath in sourceHistory)
3744+
this.RaisePropertyChanged(nameof(this.RecentSourcesVisible));
3745+
});
3746+
}
3747+
catch (Exception ex)
36923748
{
3693-
if (File.Exists(recentSourcePath))
3749+
// Ensure async void exceptions are observed and logged.
3750+
try
36943751
{
3695-
this.recentSourceOptions.Add(new SourceOptionViewModel(new SourceOption { Type = SourceType.File }, recentSourcePath));
3752+
this.logger.LogError("RefreshRecentSourceOptions failed: " + ex.ToString());
36963753
}
3697-
else if (Directory.Exists(recentSourcePath))
3754+
catch
36983755
{
3699-
this.recentSourceOptions.Add(new SourceOptionViewModel(new SourceOption { Type = SourceType.DiscVideoFolder }, recentSourcePath));
3756+
// Swallow if logger fails.
37003757
}
37013758
}
3702-
3703-
this.RaisePropertyChanged(nameof(this.RecentSourcesVisible));
37043759
}
37053760
}

0 commit comments

Comments
 (0)