Skip to content

Commit 2464af7

Browse files
authored
Feature: Validate if folder exists for the export (#1760)
* Feature: Validate if folder exists for the export * Docs: Add #1760
1 parent d15f63f commit 2464af7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Globalization;
2+
using System.IO;
3+
using System.Windows.Controls;
4+
using NETworkManager.Localization.Resources;
5+
6+
namespace NETworkManager.Validators
7+
{
8+
/// <summary>
9+
/// Check if the folder in the full path exists on the system (like "C:\Temp" from "C:\Temp\export.json").
10+
/// </summary>
11+
public class FolderInPathExistsValidator : ValidationRule
12+
{
13+
/// <summary>
14+
/// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
15+
/// </summary>
16+
/// <param name="value">File path like "C:\Temp\Test.txt"".</param>
17+
/// <param name="cultureInfo">Culture to use for validation.</param>
18+
/// <returns>True if the folder exists.</returns>
19+
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
20+
{
21+
string path = Path.GetDirectoryName((string)value);
22+
23+
if (Directory.Exists(path))
24+
return ValidationResult.ValidResult;
25+
else
26+
return new ValidationResult(false, Strings.FolderDoesNotExist);
27+
}
28+
}
29+
}

Source/NETworkManager/Views/ExportDialog.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Binding.ValidationRules>
6262
<validators:EmptyValidator ValidatesOnTargetUpdated="True" />
6363
<validators:FilePathValidator ValidatesOnTargetUpdated="True" />
64+
<validators:FolderInPathExistsValidator ValidatesOnTargetUpdated="True" />
6465
</Binding.ValidationRules>
6566
</Binding>
6667
</TextBox.Text>

docs/Changelog/next-release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ New Feature
2727
- Performance of DNS resolutions improved [#1733](https://github.com/BornToBeRoot/NETworkManager/pull/1733){:target="\_blank"}
2828
- Detect new DNS servers if they have been changed e.g. by a new network connection (LAN, WLAN) or VPN connection [#1733](https://github.com/BornToBeRoot/NETworkManager/pull/1733){:target="\_blank"}
2929
- Error messages for failed DNS resolution improved [#1733](https://github.com/BornToBeRoot/NETworkManager/pull/1733){:target="\_blank"}
30+
- Check if folder exists in export dialog [#1760](https://github.com/BornToBeRoot/NETworkManager/pull/1760){:target="\_blank"}
3031

3132
## Bugfixes
3233

0 commit comments

Comments
 (0)