@@ -72,28 +72,21 @@ private async void StartTaskButton_Click(object sender, RoutedEventArgs e)
72
72
if ( UiData . TaskRunning )
73
73
{
74
74
StopTask ( ) ;
75
- return ;
76
75
}
77
- StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Stop" ) ;
78
- UiData . TaskRunning = true ;
79
- SetProgress ( 0 ) ;
80
- taskFiles = new TaskFiles ( FilesList . Items ) ;
81
- bool settingLegal = CheckConfig ( ) ;
82
- await Task . Run ( StartTask ) ;
83
- if ( settingLegal == true )
84
- {
76
+ else if ( CheckConfig ( ) )
77
+ {
78
+ UiData . TaskRunning = true ;
79
+ SetProgress ( 0 ) ;
80
+ StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Stop" ) ;
81
+ taskFiles = new TaskFiles ( FilesList . Items ) ;
82
+ await Task . Run ( StartTask ) ;
85
83
StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Finished" ) ;
86
- SetProgress ( 1 ) ;
87
- }
88
- else
89
- {
90
- StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Error" ) ;
91
- SetProgress ( - 1 ) ;
84
+ SetProgress ( 1 ) ;
85
+ await Task . Delay ( 3000 ) ;
86
+ UiData . TaskRunning = false ;
87
+ SetProgress ( ) ;
88
+ StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Start" ) ;
92
89
}
93
- await Task . Delay ( 3000 ) ; //Show result to user
94
- StartTaskButton . Content = QueryLangDict ( "Button_StartTask_Start" ) ;
95
- UiData . TaskRunning = false ;
96
- SetProgress ( ) ;
97
90
}
98
91
99
92
private void SetProgress ( double multiple = - 2 )
@@ -116,15 +109,6 @@ private void SetProgress(double multiple = -2)
116
109
TaskbarManager . SetProgressValue ( 0 , 100 ) ;
117
110
TaskbarManager . SetProgressState ( TaskbarProgressBarState . NoProgress ) ;
118
111
}
119
- else if ( multiple == - 1 ) // Error warning
120
- {
121
- string suffix = QueryLangDict ( "Window_MainWindow_Title_Suffix_Error" ) ;
122
- SetTitleSuffix ( suffix ) ;
123
- TaskProgressBar . Foreground = new SolidColorBrush ( Color . FromRgb ( 221 , 0 , 0 ) ) ;
124
- TaskProgressBar . Value = 100 ;
125
- TaskbarManager . SetProgressValue ( 100 , 100 ) ;
126
- TaskbarManager . SetProgressState ( TaskbarProgressBarState . Error ) ;
127
- }
128
112
else
129
113
{
130
114
throw new ArgumentException ( ) ;
@@ -220,7 +204,7 @@ private bool CheckConfig()
220
204
return false ;
221
205
}
222
206
}
223
- else if ( CustomThreadCountItem . IsSelected == true && ( ( int ) CustomThreadCountItem . Tag == 0 || CustomThreadCountTextBox . Text == "" ) )
207
+ else if ( UiData . ThreadCount == 0 || CustomThreadCountTextBox . Text == "" )
224
208
{
225
209
MessageBox . Show (
226
210
QueryLangDict ( "Message_ThreadNumberIsIllegal" ) ,
@@ -368,6 +352,7 @@ private void CustomThreadCountTextBox_LostFocus(object sender, RoutedEventArgs e
368
352
private void CustomThreadCountTextBox_TextChanged ( object senderObj , TextChangedEventArgs e )
369
353
{
370
354
var sender = ( TextBox ) senderObj ;
355
+ CustomThreadCountItem . Tag = sender . Text ;
371
356
try
372
357
{
373
358
Convert . ToUInt16 ( sender . Text ) ;
@@ -404,57 +389,53 @@ private string GetIniConfigFile()
404
389
405
390
private void ImputIniConfig ( IniManager ini )
406
391
{
407
- if ( File . Exists ( ini . IniFilePath ) && File . ReadAllBytes ( ini . IniFilePath ) . Length ! = 0 )
392
+ if ( ! File . Exists ( ini . IniFilePath ) || File . ReadAllBytes ( ini . IniFilePath ) . Length = = 0 )
408
393
{
409
- if ( ini . Read ( "Versions" , "ConfigFile" ) == IniConfigFileVersion )
410
- {
411
- try
412
- {
413
- string windowWidth = ini . Read ( "Window" , "Width" ) ;
414
- this . Width = Convert . ToDouble ( windowWidth ) ;
415
- string windowHeight = ini . Read ( "Window" , "Height" ) ;
416
- this . Height = Convert . ToDouble ( windowHeight ) ;
417
-
418
- UiData . AppPath = ini . Read ( "Command" , "AppPath" ) ;
419
- UiData . ArgsTemplet = ini . Read ( "Command" , "ArgsTemplet" ) ;
420
- UiData . UserArgs = ini . Read ( "Command" , "UserArgs" ) ;
421
- UiData . OutputExtension = ini . Read ( "Output" , "Extension" ) ;
422
- UiData . OutputSuffix = ini . Read ( "Output" , "Suffix" ) ;
423
- UiData . OutputFloder = ini . Read ( "Output" , "Floder" ) ;
424
- UiData . Priority = Convert . ToInt32 ( ini . Read ( "Process" , "Priority" ) ) ;
425
- int threadCount = Convert . ToInt32 ( ini . Read ( "Process" , "ThreadCount" ) ) ;
426
- if ( threadCount > 8 )
427
- {
428
- //Bug !!!
429
- CustomThreadCountTextBox . Text = threadCount . ToString ( ) ;
430
- //CustomThreadCountItem.Tag = threadCount;
431
- //CustomThreadCountItem.IsSelected = true;
432
- }
433
- UiData . ThreadCount = threadCount ;
434
- UiData . WindowStyle = Convert . ToInt32 ( ini . Read ( "Process" , "WindowStyle" ) ) ;
435
- UiData . SimulateCmd = Convert . ToInt32 ( ini . Read ( "Process" , "SimulateCmd" ) ) ;
436
-
437
- string culture = ini . Read ( "Language" , "Culture" ) ;
438
- if ( culture != "" )
439
- {
440
- Thread . CurrentThread . CurrentCulture = new CultureInfo ( culture ) ;
441
- }
442
- }
443
- catch ( Exception e )
444
- {
445
- MessageBox . Show (
446
- QueryLangDict ( "Message_ConfigfileFormatMistake" ) + "\n \n " + e . TargetSite + "\n \n " + e . Message ,
447
- QueryLangDict ( "Message_Title_Error" )
448
- ) ;
449
- }
450
- }
451
- else
452
- {
453
- MessageBox . Show (
454
- QueryLangDict ( "Message_UseBuildInConfigfile" ) ,
455
- QueryLangDict ( "Message_Title_Hint" )
456
- ) ;
457
- }
394
+ return ;
395
+ }
396
+ else if ( ini . Read ( "Versions" , "ConfigFile" ) != IniConfigFileVersion )
397
+ {
398
+ MessageBox . Show (
399
+ QueryLangDict ( "Message_UseBuildInConfigfile" ) ,
400
+ QueryLangDict ( "Message_Title_Hint" )
401
+ ) ;
402
+ return ;
403
+ }
404
+ else
405
+ {
406
+ try
407
+ {
408
+ this . Width = Convert . ToDouble ( ini . Read ( "Window" , "Width" ) ) ;
409
+ this . Height = Convert . ToDouble ( ini . Read ( "Window" , "Height" ) ) ;
410
+ UiData . AppPath = ini . Read ( "Command" , "AppPath" ) ;
411
+ UiData . ArgsTemplet = ini . Read ( "Command" , "ArgsTemplet" ) ;
412
+ UiData . UserArgs = ini . Read ( "Command" , "UserArgs" ) ;
413
+ UiData . OutputExtension = ini . Read ( "Output" , "Extension" ) ;
414
+ UiData . OutputSuffix = ini . Read ( "Output" , "Suffix" ) ;
415
+ UiData . OutputFloder = ini . Read ( "Output" , "Floder" ) ;
416
+ UiData . Priority = Convert . ToInt32 ( ini . Read ( "Process" , "Priority" ) ) ;
417
+ int threadCount = Convert . ToInt32 ( ini . Read ( "Process" , "ThreadCount" ) ) ;
418
+ if ( threadCount > 8 )
419
+ {
420
+ CustomThreadCountTextBox . Text = threadCount . ToString ( ) ;
421
+ }
422
+ UiData . ThreadCount = threadCount ;
423
+ UiData . WindowStyle = Convert . ToInt32 ( ini . Read ( "Process" , "WindowStyle" ) ) ;
424
+ UiData . SimulateCmd = Convert . ToInt32 ( ini . Read ( "Process" , "SimulateCmd" ) ) ;
425
+
426
+ string culture = ini . Read ( "Language" , "Culture" ) ;
427
+ if ( culture != "" )
428
+ {
429
+ Thread . CurrentThread . CurrentCulture = new CultureInfo ( culture ) ;
430
+ }
431
+ }
432
+ catch ( Exception e )
433
+ {
434
+ MessageBox . Show (
435
+ QueryLangDict ( "Message_ConfigfileFormatMistake" ) + "\n \n " + e . TargetSite + "\n \n " + e . Message ,
436
+ QueryLangDict ( "Message_Title_Error" )
437
+ ) ;
438
+ }
458
439
}
459
440
}
460
441
@@ -474,10 +455,21 @@ private void SaveIniConfig(IniManager ini)
474
455
) ;
475
456
return ;
476
457
}
477
- }
478
-
479
- if ( ini . Read ( "Versions" , "ConfigFile" ) == IniConfigFileVersion || File . ReadAllBytes ( ini . IniFilePath ) . Length == 0 )
480
- {
458
+ }
459
+ else if ( ini . Read ( "Versions" , "ConfigFile" ) != IniConfigFileVersion || File . ReadAllBytes ( ini . IniFilePath ) . Length == 0 )
460
+ {
461
+ var result = MessageBox . Show (
462
+ QueryLangDict ( "Message_CreatNewConfigfile" ) ,
463
+ QueryLangDict ( "Message_Title_Hint" ) ,
464
+ MessageBoxButton . YesNo
465
+ ) ;
466
+ if ( result == MessageBoxResult . Yes )
467
+ {
468
+ ini . CreatFile ( ) ;
469
+ }
470
+ }
471
+ else
472
+ {
481
473
ini . Write ( "Versions" , "ConfigFile" , IniConfigFileVersion ) ;
482
474
ini . Write ( "Window" , "Width" , this . Width ) ;
483
475
ini . Write ( "Window" , "Height" , this . Height ) ;
@@ -492,19 +484,6 @@ private void SaveIniConfig(IniManager ini)
492
484
ini . Write ( "Process" , "WindowStyle" , UiData . WindowStyle ) ;
493
485
ini . Write ( "Process" , "SimulateCmd" , UiData . SimulateCmd ) ;
494
486
}
495
- else
496
- {
497
- var result = MessageBox . Show (
498
- QueryLangDict ( "Message_CreatNewConfigfile" ) ,
499
- QueryLangDict ( "Message_Title_Hint" ) ,
500
- MessageBoxButton . YesNo
501
- ) ;
502
- if ( result == MessageBoxResult . Yes )
503
- {
504
- ini . CreatFile ( ) ;
505
- SaveIniConfig ( ini ) ;
506
- }
507
- }
508
487
}
509
488
}
510
489
@@ -590,12 +569,6 @@ public int SimulateCmd
590
569
set { _simulateCmd = value ; NotifyValueChanged ( "SimulateCmd" ) ; }
591
570
}
592
571
593
- public bool ConfigVariable
594
- {
595
- get => ! TaskRunning ;
596
- set => NotifyValueChanged ( "ConfigVariable" ) ; // Throw set value
597
- }
598
-
599
572
private bool _taskRunning = false ;
600
573
public bool TaskRunning
601
574
{
@@ -606,20 +579,26 @@ public bool TaskRunning
606
579
ConfigVariable = ! value ;
607
580
NotifyValueChanged ( "TaskRunning" ) ;
608
581
}
582
+ }
583
+
584
+ public bool ConfigVariable
585
+ {
586
+ get => ! TaskRunning ;
587
+ set => NotifyValueChanged ( "ConfigVariable" ) ; // Throw set value
609
588
}
610
589
611
590
private string _cpuUsage = "--%" ;
612
591
public string CpuUsage
613
592
{
614
593
get => _cpuUsage ;
615
594
set { _cpuUsage = value ; NotifyValueChanged ( "CpuUsage" ) ; }
616
- }
617
-
595
+ }
596
+
618
597
private string _ramUsage = "--GB (--%)" ;
619
598
public string RamUsage
620
599
{
621
600
get => _ramUsage ;
622
601
set { _ramUsage = value ; NotifyValueChanged ( "RamUsage" ) ; }
623
- }
624
- }
602
+ }
603
+ }
625
604
}
0 commit comments