33using System . Diagnostics ;
44using System . Globalization ;
55using System . IO ;
6+ using System . Linq ;
67using System . Text ;
78using System . Windows ;
89using 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