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 ;
7
2
using System . Collections . Generic ;
8
- using System . ComponentModel ;
3
+ using System . Diagnostics ;
9
4
using System . Globalization ;
10
5
using System . IO ;
11
- using System . Linq ;
12
6
using System . Text ;
13
7
using System . Windows ;
14
8
using System . Windows . Controls ;
15
- using System . Windows . Documents ;
9
+ using System . Windows . Forms ;
16
10
using System . Windows . Input ;
17
- using System . Windows . Media ;
18
11
using 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 ;
21
18
22
19
namespace Spedit . UI . Windows
23
20
{
24
21
/// <summary>
25
22
/// Interaction logic for AboutWindow.xaml
26
23
/// </summary>
27
- public partial class ConfigWindow : MetroWindow
24
+ public partial class ConfigWindow
28
25
{
29
- private bool NeedsSMDefInvalidation = false ;
30
- private bool AllowChange = false ;
26
+ private bool NeedsSMDefInvalidation ;
27
+ private bool AllowChange ;
31
28
32
29
public ConfigWindow ( )
33
30
{
34
31
InitializeComponent ( ) ;
35
32
Language_Translate ( ) ;
36
33
if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
37
34
{ 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 )
39
36
{
40
- ConfigListBox . Items . Add ( new ListBoxItem ( ) { Content = Program . Configs [ i ] . Name } ) ;
37
+ ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
41
38
}
42
39
ConfigListBox . SelectedIndex = Program . SelectedConfig ;
43
40
}
@@ -82,11 +79,10 @@ private void LoadConfigToUI(int index)
82
79
83
80
private void NewButton_Clicked ( object sender , RoutedEventArgs e )
84
81
{
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 } ;
88
84
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" ) } ) ;
90
86
}
91
87
92
88
private void DeleteButton_Clicked ( object sender , RoutedEventArgs e )
@@ -95,7 +91,7 @@ private void DeleteButton_Clicked(object sender, RoutedEventArgs e)
95
91
Config c = Program . Configs [ index ] ;
96
92
if ( c . Standard )
97
93
{
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 ) ;
99
95
return ;
100
96
}
101
97
List < Config > configList = new List < Config > ( Program . Configs ) ;
@@ -176,12 +172,16 @@ private void C_VerboseLevel_ValueChanged(object sender, RoutedPropertyChangedEve
176
172
private void C_AutoCopy_Changed ( object sender , RoutedEventArgs e )
177
173
{
178
174
if ( ! AllowChange ) { return ; }
175
+
176
+ Debug . Assert ( C_AutoCopy . IsChecked != null , "C_AutoCopy.IsChecked != null" ) ;
179
177
Program . Configs [ ConfigListBox . SelectedIndex ] . AutoCopy = C_AutoCopy . IsChecked . Value ;
180
178
}
181
179
182
180
private void C_DeleteAfterCopy_Changed ( object sender , RoutedEventArgs e )
183
181
{
184
182
if ( ! AllowChange ) { return ; }
183
+
184
+ Debug . Assert ( C_DeleteAfterCopy . IsChecked != null , "C_DeleteAfterCopy.IsChecked != null" ) ;
185
185
Program . Configs [ ConfigListBox . SelectedIndex ] . DeleteAfterCopy = C_DeleteAfterCopy . IsChecked . Value ;
186
186
}
187
187
@@ -227,8 +227,8 @@ private void C_RConIP_TextChanged(object sender, RoutedEventArgs e)
227
227
private void C_RConPort_TextChanged ( object sender , RoutedEventArgs e )
228
228
{
229
229
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 ) )
232
232
{
233
233
newPort = 27015 ;
234
234
C_RConPort . Text = "27015" ;
@@ -252,21 +252,20 @@ private void MetroWindow_Closed(object sender, EventArgs e)
252
252
{
253
253
if ( NeedsSMDefInvalidation )
254
254
{
255
- for ( int i = 0 ; i < Program . Configs . Length ; ++ i )
255
+ foreach ( var config in Program . Configs )
256
256
{
257
- Program . Configs [ i ] . InvalidateSMDef ( ) ;
257
+ config . InvalidateSMDef ( ) ;
258
258
}
259
259
}
260
260
Program . MainWindow . FillConfigMenu ( ) ;
261
261
Program . MainWindow . ChangeConfig ( Program . SelectedConfig ) ;
262
262
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 } ;
264
264
using ( XmlWriter writer = XmlWriter . Create ( outString , settings ) )
265
265
{
266
266
writer . WriteStartElement ( "Configurations" ) ;
267
- for ( int i = 0 ; i < Program . Configs . Length ; ++ i )
267
+ foreach ( var c in Program . Configs )
268
268
{
269
- Config c = Program . Configs [ i ] ;
270
269
writer . WriteStartElement ( "Config" ) ;
271
270
writer . WriteAttributeString ( "Name" , c . Name ) ;
272
271
StringBuilder SMDirOut = new StringBuilder ( ) ;
@@ -349,32 +348,29 @@ public ICommand TextBoxButtonFolderCmd
349
348
set { }
350
349
get
351
350
{
352
- if ( this . textBoxButtonFolderCmd == null )
351
+ if ( textBoxButtonFolderCmd == null )
353
352
{
354
- var cmd = new SimpleCommand ( ) ;
355
- cmd . CanExecutePredicate = o =>
353
+ var cmd = new SimpleCommand
356
354
{
357
- return true ;
358
- } ;
359
- cmd . ExecuteAction = o =>
360
- {
361
- if ( o is TextBox )
355
+ CanExecutePredicate = o => true ,
356
+ ExecuteAction = o =>
362
357
{
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 )
366
359
{
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
+ }
368
366
}
369
367
}
370
368
} ;
371
- this . textBoxButtonFolderCmd = cmd ;
369
+ textBoxButtonFolderCmd = cmd ;
372
370
return cmd ;
373
371
}
374
- else
375
- {
376
- return textBoxButtonFolderCmd ;
377
- }
372
+
373
+ return textBoxButtonFolderCmd ;
378
374
}
379
375
}
380
376
@@ -385,40 +381,42 @@ public ICommand TextBoxButtonFileCmd
385
381
set { }
386
382
get
387
383
{
388
- if ( this . textBoxButtonFileCmd == null )
384
+ if ( textBoxButtonFileCmd == null )
389
385
{
390
- var cmd = new SimpleCommand ( ) ;
391
- cmd . CanExecutePredicate = o =>
392
- {
393
- return true ;
394
- } ;
395
- cmd . ExecuteAction = o =>
386
+ var cmd = new SimpleCommand
396
387
{
397
- if ( o is TextBox )
388
+ CanExecutePredicate = o => true ,
389
+ ExecuteAction = o =>
398
390
{
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 )
406
392
{
407
- FileInfo fInfo = new FileInfo ( dialog . FileName ) ;
408
- if ( fInfo . Exists )
393
+ var dialog = new OpenFileDialog
409
394
{
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
+ }
411
411
}
412
412
}
413
413
}
414
414
} ;
415
- this . textBoxButtonFileCmd = cmd ;
415
+ textBoxButtonFileCmd = cmd ;
416
416
return cmd ;
417
417
}
418
- else
419
- {
420
- return textBoxButtonFileCmd ;
421
- }
418
+
419
+ return textBoxButtonFileCmd ;
422
420
}
423
421
}
424
422
@@ -435,16 +433,13 @@ public bool CanExecute(object parameter)
435
433
436
434
public event EventHandler CanExecuteChanged
437
435
{
438
- add { CommandManager . RequerySuggested += value ; }
439
- remove { CommandManager . RequerySuggested -= value ; }
436
+ add => CommandManager . RequerySuggested += value ;
437
+ remove => CommandManager . RequerySuggested -= value ;
440
438
}
441
439
442
440
public void Execute ( object parameter )
443
441
{
444
- if ( ExecuteAction != null )
445
- {
446
- ExecuteAction ( parameter ) ;
447
- }
442
+ ExecuteAction ? . Invoke ( parameter ) ;
448
443
}
449
444
}
450
445
0 commit comments