diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs
index 5be51b7..967c4fe 100644
--- a/Bloxstrap/Resources/Strings.Designer.cs
+++ b/Bloxstrap/Resources/Strings.Designer.cs
@@ -1843,7 +1843,16 @@ namespace Bloxstrap.Resources {
}
///
- /// Looks up a localized string similar to The name of this flag is not valid as names can only contain letters, numbers, and underscores.
+ /// Looks up a localized string similar to The entry for '{0}' is not valid as the value must be a boolean (either 'True' or 'False').
+ ///
+ public static string Menu_FastFlagEditor_InvalidBoolValue {
+ get {
+ return ResourceManager.GetString("Menu.FastFlagEditor.InvalidBoolValue", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The entry for '{0}' is not valid as the name can only contain letters, numbers, and underscores.
///
public static string Menu_FastFlagEditor_InvalidCharacter {
get {
@@ -1864,7 +1873,16 @@ namespace Bloxstrap.Resources {
}
///
- /// Looks up a localized string similar to The name of this flag is not valid as names must start with FFlag, DFInt, etc.
+ /// Looks up a localized string similar to The entry for '{0}' is not valid as the value must be a number.
+ ///
+ public static string Menu_FastFlagEditor_InvalidNumberValue {
+ get {
+ return ResourceManager.GetString("Menu.FastFlagEditor.InvalidNumberValue", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to The entry for '{0}' is not valid as the name must start with FFlag, DFInt, etc.
///
public static string Menu_FastFlagEditor_InvalidPrefix {
get {
diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx
index b930fba..552d5cb 100644
--- a/Bloxstrap/Resources/Strings.resx
+++ b/Bloxstrap/Resources/Strings.resx
@@ -673,7 +673,7 @@ There are {0} conflicting flag definitions:
Export JSON
- The name of this flag is not valid as names can only contain letters, numbers, and underscores
+ The entry for '{0}' is not valid as the name can only contain letters, numbers, and underscores
The JSON you've entered does not appear to be valid. Please double check it and try again.
@@ -682,7 +682,7 @@ More information:
{0}
- The name of this flag is not valid as names must start with FFlag, DFInt, etc
+ The entry for '{0}' is not valid as the name must start with FFlag, DFInt, etc
Copied to clipboard.
@@ -1072,4 +1072,11 @@ Selecting 'No' will ignore this warning and continue installation.
JSON files
+
+ The entry for '{0}' is not valid as the value must be a boolean (either 'True' or 'False')
+ Do not translate 'True' and 'False', those must stay in English
+
+
+ The entry for '{0}' is not valid as the value must be a number
+
\ 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 9cf3b24..54d4c96 100644
--- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
+++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs
@@ -6,6 +6,8 @@ using System.Collections.ObjectModel;
using Wpf.Ui.Mvvm.Contracts;
using Bloxstrap.UI.Elements.Dialogs;
+using Newtonsoft.Json.Linq;
+using System.Xml.Linq;
namespace Bloxstrap.UI.Elements.Menu.Pages
{
@@ -96,27 +98,19 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
return;
if (dialog.Tabs.SelectedIndex == 0)
- AddEntry(dialog.FlagNameTextBox.Text, dialog.FlagValueTextBox.Text);
+ AddSingle(dialog.FlagNameTextBox.Text, dialog.FlagValueTextBox.Text);
else if (dialog.Tabs.SelectedIndex == 1)
ImportJSON(dialog.JsonTextBox.Text);
}
- private void AddEntry(string name, string value)
+ private void AddSingle(string name, string value)
{
FastFlag? entry;
if (App.FastFlags.GetValue(name) is null)
{
- if (!_validPrefixes.Where(x => name.StartsWith(x)).Any())
+ if (!ValidateFlagEntry(name, value))
{
- Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPrefix, MessageBoxImage.Error);
- ShowAddDialog();
- return;
- }
-
- if (!name.All(x => char.IsLetterOrDigit(x) || x == '_'))
- {
- Frontend.ShowMessageBox(Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidCharacter, MessageBoxImage.Error);
ShowAddDialog();
return;
}
@@ -240,12 +234,38 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
if (App.FastFlags.Prop.ContainsKey(pair.Key) && !overwriteConflicting)
continue;
+ if (!ValidateFlagEntry(pair.Key, (string)pair.Value))
+ continue;
+
App.FastFlags.SetValue(pair.Key, pair.Value);
}
ClearSearch();
}
+ private bool ValidateFlagEntry(string name, string value)
+ {
+ string lowerValue = value.ToLowerInvariant();
+ string errorMessage = "";
+
+ if (!_validPrefixes.Where(x => name.StartsWith(x)).Any())
+ errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidPrefix;
+ else if (!name.All(x => char.IsLetterOrDigit(x) || x == '_'))
+ errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidCharacter;
+ else if (name[..6].Contains("FFlag") && lowerValue != "true" && lowerValue != "false")
+ errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidBoolValue;
+ else if (name[..5].Contains("FInt") && !Int32.TryParse(value, out _))
+ errorMessage = Bloxstrap.Resources.Strings.Menu_FastFlagEditor_InvalidNumberValue;
+
+ if (!String.IsNullOrEmpty(errorMessage))
+ {
+ Frontend.ShowMessageBox(String.Format(errorMessage, name), MessageBoxImage.Error);
+ return false;
+ }
+
+ return true;
+ }
+
// refresh list on page load to synchronize with preset page
private void Page_Loaded(object sender, RoutedEventArgs e) => ReloadList();
@@ -253,30 +273,17 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
{
int index = e.Row.GetIndex();
FastFlag entry = _fastFlagList[index];
+
+ var textbox = e.EditingElement as TextBox;
+
+ if (textbox is null)
+ return;
switch (e.Column.Header)
{
- /* case "Enabled":
- bool enabled = (bool)((CheckBox)e.EditingElement).IsChecked!;
-
- if (enabled)
- {
- App.FastFlags.SetValue(entry.Name, entry.Value);
- App.FastFlags.SetValue($"Disable{entry.Name}", null);
- }
- else
- {
- App.FastFlags.SetValue(entry.Name, null);
- App.FastFlags.SetValue($"Disable{entry.Name}", entry.Value);
- }
-
- break; */
-
case "Name":
- var textbox = e.EditingElement as TextBox;
-
string oldName = entry.Name;
- string newName = textbox!.Text;
+ string newName = textbox.Text;
if (newName == oldName)
return;
@@ -300,7 +307,15 @@ namespace Bloxstrap.UI.Elements.Menu.Pages
break;
case "Value":
- string newValue = ((TextBox)e.EditingElement).Text;
+ string oldValue = entry.Value;
+ string newValue = textbox.Text;
+
+ if (!ValidateFlagEntry(entry.Name, newValue))
+ {
+ e.Cancel = true;
+ textbox.Text = oldValue;
+ return;
+ }
App.FastFlags.SetValue(entry.Name, newValue);