SEBWIN-849: Implemented index suffix for already existing files when downloading.

This commit is contained in:
Damian Büchel 2024-05-22 15:25:52 +02:00
parent 639700abd8
commit 3b099688f7
2 changed files with 26 additions and 1 deletions

View file

@ -138,6 +138,11 @@ namespace SafeExamBrowser.Browser.Handlers
filePath = Path.Combine(KnownFolders.Downloads.ExpandedPath, downloadItem.SuggestedFileName);
}
if (File.Exists(filePath))
{
filePath = AppendIndexSuffixTo(filePath);
}
if (showDialog)
{
logger.Debug($"Allowing user to select custom download location, with '{filePath}' as suggestion.");
@ -155,6 +160,26 @@ namespace SafeExamBrowser.Browser.Handlers
}
}
private string AppendIndexSuffixTo(string filePath)
{
var directory = Path.GetDirectoryName(filePath);
var extension = Path.GetExtension(filePath);
var name = Path.GetFileNameWithoutExtension(filePath);
var path = default(string);
for (var suffix = 1; suffix < int.MaxValue; suffix++)
{
path = Path.Combine(directory, $"{name}({suffix}){extension}");
if (!File.Exists(path))
{
break;
}
}
return path;
}
private void RequestConfigurationFileDownload(DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
var args = new DownloadEventArgs { Url = downloadItem.Url };

View file

@ -334,7 +334,7 @@ namespace SafeExamBrowser.SystemComponents.Network
Changed?.Invoke();
}
private void LogNetworkChanges(ConnectionStatus previousStatus, WirelessNetwork currentNetwork)
private void LogNetworkChanges(ConnectionStatus previousStatus, WirelessNetwork currentNetwork = default)
{
if (previousStatus != ConnectionStatus.Connected && Status == ConnectionStatus.Connected)
{