Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 681eb9b

Browse files
committed
Fix bug
Fix the function about customized thread count. Remove the waiting time after the error is detected.
1 parent 554ab6e commit 681eb9b

File tree

5 files changed

+90
-112
lines changed

5 files changed

+90
-112
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=LF

UniversalGUI/App.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading.Tasks;
77
using System.Windows;
88
using System.Windows.Controls;
9-
using System.Windows.Threading;
109

1110
namespace UniversalGUI
1211
{
@@ -22,7 +21,7 @@ public void StartTask()
2221
{
2322
int threadCount = UiData.ThreadCount;
2423
processIds = new int[threadCount];
25-
Task[] tasks = new Task[threadCount];
24+
var tasks = new Task[threadCount];
2625
for (int i = 0; i < threadCount; i++)
2726
{
2827
tasks[i] = CreateThreadAsync(i);
@@ -266,7 +265,7 @@ public string Current
266265
{
267266
get
268267
{
269-
if (Enumerator.MoveNext()) // Side effect !
268+
if (Enumerator.MoveNext()) // Side effect!
270269
{
271270
CompletedCount++;
272271
return Enumerator.Current;

UniversalGUI/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
<ComboBoxItem Tag="6" Content="6"/>
171171
<ComboBoxItem Tag="7" Content="7"/>
172172
<ComboBoxItem Tag="8" Content="8"/>
173-
<ComboBoxItem x:Name="CustomThreadCountItem" Tag="{Binding CustomThreadCountTextBox.Text}">
173+
<ComboBoxItem x:Name="CustomThreadCountItem">
174174
<TextBox x:Name="CustomThreadCountTextBox" MinWidth="40" Margin="-2,0" Padding="-1" BorderBrush="{x:Null}" LostFocus="CustomThreadCountTextBox_LostFocus" TextChanged="CustomThreadCountTextBox_TextChanged"/>
175175
</ComboBoxItem>
176176
</ComboBox>

UniversalGUI/MainWindow.xaml.cs

Lines changed: 85 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,21 @@ private async void StartTaskButton_Click(object sender, RoutedEventArgs e)
7272
if (UiData.TaskRunning)
7373
{
7474
StopTask();
75-
return;
7675
}
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);
8583
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");
9289
}
93-
await Task.Delay(3000); //Show result to user
94-
StartTaskButton.Content = QueryLangDict("Button_StartTask_Start");
95-
UiData.TaskRunning = false;
96-
SetProgress();
9790
}
9891

9992
private void SetProgress(double multiple = -2)
@@ -116,15 +109,6 @@ private void SetProgress(double multiple = -2)
116109
TaskbarManager.SetProgressValue(0, 100);
117110
TaskbarManager.SetProgressState(TaskbarProgressBarState.NoProgress);
118111
}
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-
}
128112
else
129113
{
130114
throw new ArgumentException();
@@ -220,7 +204,7 @@ private bool CheckConfig()
220204
return false;
221205
}
222206
}
223-
else if (CustomThreadCountItem.IsSelected == true && ((int)CustomThreadCountItem.Tag == 0 || CustomThreadCountTextBox.Text == ""))
207+
else if (UiData.ThreadCount == 0 || CustomThreadCountTextBox.Text == "")
224208
{
225209
MessageBox.Show(
226210
QueryLangDict("Message_ThreadNumberIsIllegal"),
@@ -368,6 +352,7 @@ private void CustomThreadCountTextBox_LostFocus(object sender, RoutedEventArgs e
368352
private void CustomThreadCountTextBox_TextChanged(object senderObj, TextChangedEventArgs e)
369353
{
370354
var sender = (TextBox)senderObj;
355+
CustomThreadCountItem.Tag = sender.Text;
371356
try
372357
{
373358
Convert.ToUInt16(sender.Text);
@@ -404,57 +389,53 @@ private string GetIniConfigFile()
404389

405390
private void ImputIniConfig(IniManager ini)
406391
{
407-
if (File.Exists(ini.IniFilePath) && File.ReadAllBytes(ini.IniFilePath).Length != 0)
392+
if (!File.Exists(ini.IniFilePath) || File.ReadAllBytes(ini.IniFilePath).Length == 0)
408393
{
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+
}
458439
}
459440
}
460441

@@ -474,10 +455,21 @@ private void SaveIniConfig(IniManager ini)
474455
);
475456
return;
476457
}
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+
{
481473
ini.Write("Versions", "ConfigFile", IniConfigFileVersion);
482474
ini.Write("Window", "Width", this.Width);
483475
ini.Write("Window", "Height", this.Height);
@@ -492,19 +484,6 @@ private void SaveIniConfig(IniManager ini)
492484
ini.Write("Process", "WindowStyle", UiData.WindowStyle);
493485
ini.Write("Process", "SimulateCmd", UiData.SimulateCmd);
494486
}
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-
}
508487
}
509488
}
510489

@@ -590,12 +569,6 @@ public int SimulateCmd
590569
set { _simulateCmd = value; NotifyValueChanged("SimulateCmd"); }
591570
}
592571

593-
public bool ConfigVariable
594-
{
595-
get => !TaskRunning;
596-
set => NotifyValueChanged("ConfigVariable"); // Throw set value
597-
}
598-
599572
private bool _taskRunning = false;
600573
public bool TaskRunning
601574
{
@@ -606,20 +579,26 @@ public bool TaskRunning
606579
ConfigVariable = !value;
607580
NotifyValueChanged("TaskRunning");
608581
}
582+
}
583+
584+
public bool ConfigVariable
585+
{
586+
get => !TaskRunning;
587+
set => NotifyValueChanged("ConfigVariable"); // Throw set value
609588
}
610589

611590
private string _cpuUsage = "--%";
612591
public string CpuUsage
613592
{
614593
get => _cpuUsage;
615594
set { _cpuUsage = value; NotifyValueChanged("CpuUsage"); }
616-
}
617-
595+
}
596+
618597
private string _ramUsage = "--GB (--%)";
619598
public string RamUsage
620599
{
621600
get => _ramUsage;
622601
set { _ramUsage = value; NotifyValueChanged("RamUsage"); }
623-
}
624-
}
602+
}
603+
}
625604
}

UniversalGUI/Resources/Theme/Flat.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,6 @@
286286
</ControlTemplate>
287287
</Setter.Value>
288288
</Setter>
289-
</Style>
289+
</Style>
290290

291291
</ResourceDictionary>

0 commit comments

Comments
 (0)