[ColorPicker]Fix format name duplicates (#22565)

* ColorPicker fix format name duplicates

* ColorPicker: extend settings-loading with security code which skips color formats with empty name or duplicate names

* Spell checker fix, typo, sorry
This commit is contained in:
Laszlo Nemeth 2022-12-09 17:30:06 +01:00 committed by GitHub
parent 7d53b9a5b5
commit e5d001e434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -234,13 +234,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
{
// skip entries with empty name or duplicated name, it should never occur
string storedName = storedColorFormat.Key;
if (storedName == string.Empty || ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(storedName.ToUpperInvariant(), StringComparison.Ordinal)) > 0)
{
continue;
}
string format = storedColorFormat.Value.Value;
if (format == string.Empty)
{
format = ColorFormatHelper.GetDefaultFormat(storedColorFormat.Key);
format = ColorFormatHelper.GetDefaultFormat(storedName);
}
ColorFormatModel customColorFormat = new ColorFormatModel(storedColorFormat.Key, format, storedColorFormat.Value.Key);
ColorFormatModel customColorFormat = new ColorFormatModel(storedName, format, storedColorFormat.Value.Key);
customColorFormat.PropertyChanged += ColorFormat_PropertyChanged;
ColorFormats.Add(customColorFormat);
}
@ -400,7 +407,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
else
{
colorFormatModel.IsValid = ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(colorFormatModel.Name.ToUpperInvariant(), StringComparison.Ordinal)) < 2;
colorFormatModel.IsValid = ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(colorFormatModel.Name.ToUpperInvariant(), StringComparison.Ordinal))
< (colorFormatModel.IsNew ? 1 : 2);
}
}