From e8f34eaa0f4c43b0e9f430e8d0463caa00a13b07 Mon Sep 17 00:00:00 2001 From: srthMD Date: Sat, 13 Jul 2024 17:05:12 +0300 Subject: [PATCH 1/2] support for _placefilter and _datacenterfilter --- Bloxstrap/Resources/Strings.resx | 3 ++ .../Menu/Pages/FastFlagEditorPage.xaml.cs | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index b5eadc2..c749c3d 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1021,4 +1021,7 @@ Selecting 'No' will ignore this warning and continue installation. System default + + The entry for '{0}' is not valid as the place filter is not formatted correctly. + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs index d7d5cf0..4542ca2 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs @@ -22,9 +22,15 @@ namespace Bloxstrap.UI.Elements.Menu.Pages private readonly ObservableCollection _fastFlagList = new(); private readonly List _validPrefixes = new() { - "FFlag", "DFFlag", "SFFlag", "FInt", "DFInt", "FString", "DFString", "FLog", "DFlog" + "FFlag", "DFFlag", "SFFlag", "FInt", "DFInt", "FString", "DFString", "FLog", "DFLog" }; + // values must match the entire string to avoid cases where half the string + // matches but the filter would still be invalid + private readonly Regex _boolFilterPattern = new("(?:true|false)(;[\\d]{1,})+$"); + private readonly Regex _intFilterPattern = new("([\\d]{1,})?(;[\\d]{1,})+$"); + private readonly Regex _stringFilterPattern = new("^[^;]*(;[\\d]{1,})+$"); + private bool _showPresets = false; private string _searchFilter = ""; @@ -253,17 +259,22 @@ namespace Bloxstrap.UI.Elements.Menu.Pages string lowerValue = value.ToLowerInvariant(); string errorMessage = ""; - if (!_validPrefixes.Where(x => name.StartsWith(x)).Any()) + if (!_validPrefixes.Any(name.StartsWith)) errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPrefix; else if (!name.All(x => char.IsLetterOrDigit(x) || x == '_')) errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidCharacter; + + // sorry + if (name.EndsWith("_PlaceFilter") || name.EndsWith("_DataCenterFilter")) + errorMessage = !Validate_Filter(name, value) ? Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPlaceFilter : ""; else if ((name.StartsWith("FInt") || name.StartsWith("DFInt")) && !Int32.TryParse(value, out _)) errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidNumberValue; else if ((name.StartsWith("FFlag") || name.StartsWith("DFFlag")) && lowerValue != "true" && lowerValue != "false") errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidBoolValue; + if (!String.IsNullOrEmpty(errorMessage)) - { + { Frontend.ShowMessageBox(String.Format(errorMessage, name), MessageBoxImage.Error); return false; } @@ -271,6 +282,18 @@ namespace Bloxstrap.UI.Elements.Menu.Pages return true; } + private bool Validate_Filter(string name, string value) + { + if(name.StartsWith("FFlag") || name.StartsWith("DFFlag")) + return _boolFilterPattern.IsMatch(value); + if (name.StartsWith("FInt") || name.StartsWith("DFInt")) + return _intFilterPattern.IsMatch(value); + if (name.StartsWith("FString") || name.StartsWith("DFString") || name.StartsWith("FLog") || name.StartsWith("DFLog")) + return _stringFilterPattern.IsMatch(value); + + return false; + } + // refresh list on page load to synchronize with preset page private void Page_Loaded(object sender, RoutedEventArgs e) => ReloadList(); From c4f1aab1a699e20de5828b1610003839410ffbab Mon Sep 17 00:00:00 2001 From: srth Date: Sat, 13 Jul 2024 14:53:04 +0000 Subject: [PATCH 2/2] remove comment i forgot why it was here --- Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs index 4542ca2..d8f4e08 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs @@ -264,7 +264,6 @@ namespace Bloxstrap.UI.Elements.Menu.Pages else if (!name.All(x => char.IsLetterOrDigit(x) || x == '_')) errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidCharacter; - // sorry if (name.EndsWith("_PlaceFilter") || name.EndsWith("_DataCenterFilter")) errorMessage = !Validate_Filter(name, value) ? Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPlaceFilter : ""; else if ((name.StartsWith("FInt") || name.StartsWith("DFInt")) && !Int32.TryParse(value, out _))