Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 19a2114

Browse files
committed
added check for duplicated and empty config names
1 parent 7b6a510 commit 19a2114

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

Interop/TranslationProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ private void FillToEnglishDefaults()
314314
language.Add("JavaDownErrorTitle", "Java download error");
315315
language.Add("JavaDownErrorMessage", "SPCode could not download Java by itself. Would you like to download it manually?");
316316
language.Add("JavaOpenedBrowser", "Java download link opened in browser");
317+
language.Add("ErrorSavingConfigs", "Could not save the current configs state");
318+
language.Add("DuplicateConfigNames", "You cannot have 2 configs or more with the same name.");
319+
language.Add("EmptyConfigNames", "You cannot have configs with an empty name.");
317320
}
318321
}
319322
}

UI/Windows/ConfigWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
Width="1085" Height="625" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" GlowBrush="{DynamicResource AccentColorBrush}"
7-
Title="Configurations" ShowTitleBar="False" Closed="MetroWindow_Closed">
7+
Title="Configurations" ShowTitleBar="False" Closing="MetroWindow_Closing">
88
<controls:MetroWindow.Resources>
99
<ResourceDictionary>
1010
<ResourceDictionary.MergedDictionaries>

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Globalization;
55
using System.IO;
6+
using System.Linq;
67
using System.Text;
78
using System.Windows;
89
using System.Windows.Controls;
@@ -461,8 +462,9 @@ private void C_RConCmds_TextChanged(object sender, RoutedEventArgs e)
461462
Program.Configs[ConfigListBox.SelectedIndex].RConCommands = C_RConCmds.Text;
462463
}
463464

464-
private void MetroWindow_Closed(object sender, EventArgs e)
465+
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
465466
{
467+
// TODO: find out what is this for
466468
if (NeedsSMDefInvalidation)
467469
{
468470
foreach (var config in Program.Configs)
@@ -471,6 +473,40 @@ private void MetroWindow_Closed(object sender, EventArgs e)
471473
}
472474
}
473475

476+
// Fill a list with all configs from the ListBox
477+
478+
var configsList = new List<string>();
479+
480+
for (int i = 0; i < ConfigListBox.Items.Count; i++)
481+
{
482+
configsList.Add(((ListBoxItem)ConfigListBox.Items[i]).Content.ToString());
483+
}
484+
485+
// Check for empty named configs and disallow saving configs
486+
487+
foreach (var cfg in configsList)
488+
{
489+
if (cfg == string.Empty)
490+
{
491+
e.Cancel = true;
492+
this.ShowMessageAsync(Program.Translations.GetLanguage("ErrorSavingConfigs"),
493+
Program.Translations.GetLanguage("EmptyConfigNames"), MessageDialogStyle.Affirmative,
494+
MetroDialogOptions);
495+
return;
496+
}
497+
}
498+
499+
// Check for duplicate names in the config list and disallow saving configs
500+
501+
if (configsList.Count != configsList.Distinct().Count())
502+
{
503+
e.Cancel = true;
504+
this.ShowMessageAsync(Program.Translations.GetLanguage("ErrorSavingConfigs"),
505+
Program.Translations.GetLanguage("DuplicateConfigNames"), MessageDialogStyle.Affirmative,
506+
MetroDialogOptions);
507+
return;
508+
}
509+
474510
Program.MainWindow.FillConfigMenu();
475511
Program.MainWindow.ChangeConfig(Program.SelectedConfig);
476512
var outString = new StringBuilder();

0 commit comments

Comments
 (0)