/// <summary>Update the enabled state of UI elements</summary> private void UpdateUI(object sender = null, EventArgs args = null) { m_btn_range_to_start.Enabled = m_radio_range.Checked; m_btn_range_to_end.Enabled = m_radio_range.Checked; m_tb_range_min.Enabled = m_radio_range.Checked; m_tb_range_max.Enabled = m_radio_range.Checked; var status = string.Empty; for (;;) { if (!Path_.IsValidFilepath(OutputFilepath, false)) { status = "Invalid export file path"; break; } if (ByteRange.Count <= 0) { status = "Invalid export data range"; break; } break; } m_lbl_status.Text = status; m_lbl_status.ForeColor = Color.DarkRed; m_btn_ok.Enabled = !status.HasValue(); }
public object?Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string path)) { return(value); } if (!Path_.IsValidFilepath(path, false)) { return(value); } return(Path_.FileName(path)); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (!(value is string path)) { return(new ValidationResult(false, $"Value '{value}' is not a string")); } if (!Path_.IsValidFilepath(path, true)) { return(new ValidationResult(false, $"Path '{path}' is not a valid or is a relative path")); } return(ValidationResult.ValidResult); }
/// <summary>Set up the Control</summary> private void SetupUI() { // Path combo m_cb_path.ValueType = typeof(string); m_cb_path.ValidateText = t => Path_.IsValidFilepath(t, false); m_cb_path.ValueCommitted += (s, a) => { Path = (string)m_cb_path.Value; }; // Browse for a path m_btn_browse.Click += (s, a) => { BrowsePath(); }; }
public void TestPathValidation() { Assert.True(Path_.IsValidDirectory(@"A:\dir1\..\.\dir2", true)); Assert.True(Path_.IsValidDirectory(@"A:\dir1\..\.\dir2", false)); Assert.True(Path_.IsValidDirectory(@".\dir1\..\.\dir2", false)); Assert.True(Path_.IsValidDirectory(@"A:\dir1\..\.\dir2\", true)); Assert.True(Path_.IsValidDirectory(@"A:\dir1\..\.\dir2\", false)); Assert.True(Path_.IsValidDirectory(@".\dir1\..\.\dir2\", false)); Assert.False(Path_.IsValidDirectory(@".\dir1?\..\.\", false)); Assert.True(Path_.IsValidFilepath(@"A:\dir1\..\.\dir2\file.txt", true)); Assert.True(Path_.IsValidFilepath(@"A:\dir1\..\.\dir2\file", false)); Assert.True(Path_.IsValidFilepath(@".\dir1\..\.\dir2\file", false)); Assert.False(Path_.IsValidFilepath(@".\dir1\", false)); Assert.False(Path_.IsValidFilepath(@".\dir1\file*.txt", false)); Assert.False(Path_.IsValidFilepath(@"A:\dump\file.tx##:t", false)); Assert.False(Path_.IsValidFilepath(@"A:\dump\fi:.txt", false)); Assert.False(Path_.IsValidFilepath(@"A:\dump\f*.txt", false)); Assert.False(Path_.IsValidFilepath(@"A:\dump\f?.txt", false)); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (!(value is string s) || !Path_.IsValidFilepath(s, true)) { return(new ValidationResult(false, "Filepath is not a valid")); }