1- using MahApps . Metro ;
2- using MahApps . Metro . Controls ;
3- using MahApps . Metro . Controls . Dialogs ;
4- using Spedit . Interop ;
5- using Spedit . Utils ;
6- using System ;
1+ using System ;
72using System . Collections . Generic ;
8- using System . ComponentModel ;
3+ using System . Diagnostics ;
94using System . Globalization ;
105using System . IO ;
11- using System . Linq ;
126using System . Text ;
137using System . Windows ;
148using System . Windows . Controls ;
15- using System . Windows . Documents ;
9+ using System . Windows . Forms ;
1610using System . Windows . Input ;
17- using System . Windows . Media ;
1811using System . Xml ;
19- using Microsoft . CSharp ;
20- using Microsoft . Win32 ;
12+ using MahApps . Metro ;
13+ using MahApps . Metro . Controls . Dialogs ;
14+ using Spedit . Interop ;
15+ using Spedit . Utils ;
16+ using OpenFileDialog = Microsoft . Win32 . OpenFileDialog ;
17+ using TextBox = System . Windows . Controls . TextBox ;
2118
2219namespace Spedit . UI . Windows
2320{
2421 /// <summary>
2522 /// Interaction logic for AboutWindow.xaml
2623 /// </summary>
27- public partial class ConfigWindow : MetroWindow
24+ public partial class ConfigWindow
2825 {
29- private bool NeedsSMDefInvalidation = false ;
30- private bool AllowChange = false ;
26+ private bool NeedsSMDefInvalidation ;
27+ private bool AllowChange ;
3128
3229 public ConfigWindow ( )
3330 {
3431 InitializeComponent ( ) ;
3532 Language_Translate ( ) ;
3633 if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
3734 { ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) , ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ; }
38- for ( int i = 0 ; i < Program . Configs . Length ; ++ i )
35+ foreach ( var config in Program . Configs )
3936 {
40- ConfigListBox . Items . Add ( new ListBoxItem ( ) { Content = Program . Configs [ i ] . Name } ) ;
37+ ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
4138 }
4239 ConfigListBox . SelectedIndex = Program . SelectedConfig ;
4340 }
@@ -82,11 +79,10 @@ private void LoadConfigToUI(int index)
8279
8380 private void NewButton_Clicked ( object sender , RoutedEventArgs e )
8481 {
85- Config c = new Config ( ) { Name = "New Config" , Standard = false , OptimizeLevel = 2 , VerboseLevel = 1 } ;
86- List < Config > configList = new List < Config > ( Program . Configs ) ;
87- configList . Add ( c ) ;
82+ Config c = new Config { Name = "New Config" , Standard = false , OptimizeLevel = 2 , VerboseLevel = 1 } ;
83+ List < Config > configList = new List < Config > ( Program . Configs ) { c } ;
8884 Program . Configs = configList . ToArray ( ) ;
89- ConfigListBox . Items . Add ( new ListBoxItem ( ) { Content = Program . Translations . GetLanguage ( "NewConfig" ) } ) ;
85+ ConfigListBox . Items . Add ( new ListBoxItem { Content = Program . Translations . GetLanguage ( "NewConfig" ) } ) ;
9086 }
9187
9288 private void DeleteButton_Clicked ( object sender , RoutedEventArgs e )
@@ -95,7 +91,7 @@ private void DeleteButton_Clicked(object sender, RoutedEventArgs e)
9591 Config c = Program . Configs [ index ] ;
9692 if ( c . Standard )
9793 {
98- this . ShowMessageAsync ( Program . Translations . GetLanguage ( "CannotDelConf" ) , Program . Translations . GetLanguage ( "YCannotDelConf" ) , MessageDialogStyle . Affirmative , this . MetroDialogOptions ) ;
94+ this . ShowMessageAsync ( Program . Translations . GetLanguage ( "CannotDelConf" ) , Program . Translations . GetLanguage ( "YCannotDelConf" ) , MessageDialogStyle . Affirmative , MetroDialogOptions ) ;
9995 return ;
10096 }
10197 List < Config > configList = new List < Config > ( Program . Configs ) ;
@@ -176,12 +172,16 @@ private void C_VerboseLevel_ValueChanged(object sender, RoutedPropertyChangedEve
176172 private void C_AutoCopy_Changed ( object sender , RoutedEventArgs e )
177173 {
178174 if ( ! AllowChange ) { return ; }
175+
176+ Debug . Assert ( C_AutoCopy . IsChecked != null , "C_AutoCopy.IsChecked != null" ) ;
179177 Program . Configs [ ConfigListBox . SelectedIndex ] . AutoCopy = C_AutoCopy . IsChecked . Value ;
180178 }
181179
182180 private void C_DeleteAfterCopy_Changed ( object sender , RoutedEventArgs e )
183181 {
184182 if ( ! AllowChange ) { return ; }
183+
184+ Debug . Assert ( C_DeleteAfterCopy . IsChecked != null , "C_DeleteAfterCopy.IsChecked != null" ) ;
185185 Program . Configs [ ConfigListBox . SelectedIndex ] . DeleteAfterCopy = C_DeleteAfterCopy . IsChecked . Value ;
186186 }
187187
@@ -227,8 +227,8 @@ private void C_RConIP_TextChanged(object sender, RoutedEventArgs e)
227227 private void C_RConPort_TextChanged ( object sender , RoutedEventArgs e )
228228 {
229229 if ( ! AllowChange ) { return ; }
230- ushort newPort ;
231- if ( ! ushort . TryParse ( C_RConPort . Text , NumberStyles . Any , CultureInfo . InvariantCulture , out newPort ) )
230+
231+ if ( ! ushort . TryParse ( C_RConPort . Text , NumberStyles . Any , CultureInfo . InvariantCulture , out var newPort ) )
232232 {
233233 newPort = 27015 ;
234234 C_RConPort . Text = "27015" ;
@@ -252,21 +252,20 @@ private void MetroWindow_Closed(object sender, EventArgs e)
252252 {
253253 if ( NeedsSMDefInvalidation )
254254 {
255- for ( int i = 0 ; i < Program . Configs . Length ; ++ i )
255+ foreach ( var config in Program . Configs )
256256 {
257- Program . Configs [ i ] . InvalidateSMDef ( ) ;
257+ config . InvalidateSMDef ( ) ;
258258 }
259259 }
260260 Program . MainWindow . FillConfigMenu ( ) ;
261261 Program . MainWindow . ChangeConfig ( Program . SelectedConfig ) ;
262262 StringBuilder outString = new StringBuilder ( ) ;
263- XmlWriterSettings settings = new XmlWriterSettings ( ) { Indent = true , IndentChars = "\t " , NewLineOnAttributes = false , OmitXmlDeclaration = true } ;
263+ XmlWriterSettings settings = new XmlWriterSettings { Indent = true , IndentChars = "\t " , NewLineOnAttributes = false , OmitXmlDeclaration = true } ;
264264 using ( XmlWriter writer = XmlWriter . Create ( outString , settings ) )
265265 {
266266 writer . WriteStartElement ( "Configurations" ) ;
267- for ( int i = 0 ; i < Program . Configs . Length ; ++ i )
267+ foreach ( var c in Program . Configs )
268268 {
269- Config c = Program . Configs [ i ] ;
270269 writer . WriteStartElement ( "Config" ) ;
271270 writer . WriteAttributeString ( "Name" , c . Name ) ;
272271 StringBuilder SMDirOut = new StringBuilder ( ) ;
@@ -349,32 +348,29 @@ public ICommand TextBoxButtonFolderCmd
349348 set { }
350349 get
351350 {
352- if ( this . textBoxButtonFolderCmd == null )
351+ if ( textBoxButtonFolderCmd == null )
353352 {
354- var cmd = new SimpleCommand ( ) ;
355- cmd . CanExecutePredicate = o =>
353+ var cmd = new SimpleCommand
356354 {
357- return true ;
358- } ;
359- cmd . ExecuteAction = o =>
360- {
361- if ( o is TextBox )
355+ CanExecutePredicate = o => true ,
356+ ExecuteAction = o =>
362357 {
363- var dialog = new System . Windows . Forms . FolderBrowserDialog ( ) ;
364- var result = dialog . ShowDialog ( ) ;
365- if ( result == System . Windows . Forms . DialogResult . OK )
358+ if ( o is TextBox box )
366359 {
367- ( ( TextBox ) o ) . Text = dialog . SelectedPath ;
360+ var dialog = new FolderBrowserDialog ( ) ;
361+ var result = dialog . ShowDialog ( ) ;
362+ if ( result == System . Windows . Forms . DialogResult . OK )
363+ {
364+ box . Text = dialog . SelectedPath ;
365+ }
368366 }
369367 }
370368 } ;
371- this . textBoxButtonFolderCmd = cmd ;
369+ textBoxButtonFolderCmd = cmd ;
372370 return cmd ;
373371 }
374- else
375- {
376- return textBoxButtonFolderCmd ;
377- }
372+
373+ return textBoxButtonFolderCmd ;
378374 }
379375 }
380376
@@ -385,40 +381,42 @@ public ICommand TextBoxButtonFileCmd
385381 set { }
386382 get
387383 {
388- if ( this . textBoxButtonFileCmd == null )
384+ if ( textBoxButtonFileCmd == null )
389385 {
390- var cmd = new SimpleCommand ( ) ;
391- cmd . CanExecutePredicate = o =>
392- {
393- return true ;
394- } ;
395- cmd . ExecuteAction = o =>
386+ var cmd = new SimpleCommand
396387 {
397- if ( o is TextBox )
388+ CanExecutePredicate = o => true ,
389+ ExecuteAction = o =>
398390 {
399- var dialog = new OpenFileDialog ( ) ;
400- dialog . Filter = "Executables *.exe|*.exe|All Files *.*|*.*" ;
401- dialog . Multiselect = false ;
402- dialog . CheckFileExists = true ; dialog . CheckPathExists = true ;
403- dialog . Title = Program . Translations . GetLanguage ( "SelectExe" ) ;
404- var result = dialog . ShowDialog ( ) ;
405- if ( result . Value )
391+ if ( o is TextBox box )
406392 {
407- FileInfo fInfo = new FileInfo ( dialog . FileName ) ;
408- if ( fInfo . Exists )
393+ var dialog = new OpenFileDialog
409394 {
410- ( ( TextBox ) o ) . Text = fInfo . FullName ;
395+ Filter = "Executables *.exe|*.exe|All Files *.*|*.*" ,
396+ Multiselect = false ,
397+ CheckFileExists = true ,
398+ CheckPathExists = true ,
399+ Title = Program . Translations . GetLanguage ( "SelectExe" )
400+ } ;
401+ var result = dialog . ShowDialog ( ) ;
402+
403+ Debug . Assert ( result != null , nameof ( result ) + " != null" ) ;
404+ if ( result . Value )
405+ {
406+ FileInfo fInfo = new FileInfo ( dialog . FileName ) ;
407+ if ( fInfo . Exists )
408+ {
409+ box . Text = fInfo . FullName ;
410+ }
411411 }
412412 }
413413 }
414414 } ;
415- this . textBoxButtonFileCmd = cmd ;
415+ textBoxButtonFileCmd = cmd ;
416416 return cmd ;
417417 }
418- else
419- {
420- return textBoxButtonFileCmd ;
421- }
418+
419+ return textBoxButtonFileCmd ;
422420 }
423421 }
424422
@@ -435,16 +433,13 @@ public bool CanExecute(object parameter)
435433
436434 public event EventHandler CanExecuteChanged
437435 {
438- add { CommandManager . RequerySuggested += value ; }
439- remove { CommandManager . RequerySuggested -= value ; }
436+ add => CommandManager . RequerySuggested += value ;
437+ remove => CommandManager . RequerySuggested -= value ;
440438 }
441439
442440 public void Execute ( object parameter )
443441 {
444- if ( ExecuteAction != null )
445- {
446- ExecuteAction ( parameter ) ;
447- }
442+ ExecuteAction ? . Invoke ( parameter ) ;
448443 }
449444 }
450445
0 commit comments