From 0b6992d80fd188fe3b8b816f15a49619867eaf8f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 22 Aug 2022 17:12:11 -0500 Subject: reorder share scan state handling --- src/slskd/Application.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index f9cb95d2..5a56e110 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -927,23 +927,15 @@ namespace slskd if (!previous.Scanning && current.Scanning) { + // the scan is starting SharesRefreshStarted = DateTime.UtcNow; State.SetValue(s => s with { Shares = current }); Log.Information("Scanning shares"); } - - var lastProgress = Math.Round(previous.ScanProgress * 100); - var currentProgress = Math.Round(current.ScanProgress * 100); - - if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 10 == 0) - { - State.SetValue(s => s with { Shares = current }); - Log.Information("Scanned {Percent}% of shared directories. Found {Files} files so far.", currentProgress, current.Files); - } - - if (previous.Scanning && !current.Scanning) + else if (previous.Scanning && !current.Scanning) { + // the scan is finishing State.SetValue(s => s with { Shares = current }); if (current.Faulted) @@ -967,6 +959,18 @@ namespace slskd } } } + else + { + // the scan is neither starting nor finishing; progress update + var lastProgress = Math.Round(previous.ScanProgress * 100); + var currentProgress = Math.Round(current.ScanProgress * 100); + + if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 10d == 0) + { + State.SetValue(s => s with { Shares = current }); + Log.Information("Scanned {Percent}% () of shared directories. Found {Files} files so far.", currentProgress, current.Files); + } + } } private void State_OnChange((State Previous, State Current) state) -- cgit v1.2.3