SEBWIN-849: Implemented index suffix for already existing files when downloading.
This commit is contained in:
parent
639700abd8
commit
3b099688f7
2 changed files with 26 additions and 1 deletions
|
@ -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 };
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue