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

Commit c74c607

Browse files
committed
0.9.4.0
What's new: * Stop task halfway. Bug Fix: * If there are too many files, some files may be missing.
1 parent f179fd0 commit c74c607

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

UniversalGUI/MainWindow.xaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<Grid>
1313
<Button x:Name="StartTaskButton" Content="{DynamicResource Button_StartTask_Content_Start}" HorizontalAlignment="Right" Height="50" Margin="0, 0, 20, 20" VerticalAlignment="Bottom" Width="100" FontSize="16" Click="StartTaskAsync" Style="{DynamicResource FlatButton}"/>
1414
<ProgressBar x:Name="TaskProgressBar" HorizontalAlignment="Right" Height="5" Margin="0, 0, 20, 20" VerticalAlignment="Bottom" Width="100" BorderBrush="#0000" Foreground="DimGray" Visibility="Hidden"/>
15-
<GroupBox Header="{DynamicResource GroupBox_ImputFiles_Header}" Margin="20, 20, 260, 240">
15+
<Grid x:Name="TaskSettings">
16+
<GroupBox Header="{DynamicResource GroupBox_ImputFiles_Header}" Margin="20, 20, 260, 240">
1617
<Grid>
1718
<ListBox x:Name="FilesList" Margin="5" AllowDrop="True" Drop="FilesList_Drop" SelectionMode="Extended" DragOver="FilesList_DragOver"/>
1819
<Grid Panel.ZIndex="1" Opacity="0.75">
@@ -22,7 +23,7 @@
2223
</Grid>
2324
</Grid>
2425
</GroupBox>
25-
<GroupBox Header="{DynamicResource GroupBox_Command_Header}" Margin="20, 0, 260, 20" Height="210" VerticalAlignment="Bottom">
26+
<GroupBox Header="{DynamicResource GroupBox_Command_Header}" Margin="20, 0, 260, 20" Height="210" VerticalAlignment="Bottom">
2627
<Grid>
2728
<TextBlock Height="20" Margin="5, 5, 5, 0" Text="{DynamicResource TextBlock_AppPath_Text}" VerticalAlignment="Top"/>
2829
<TextBox x:Name="AppPath" Height="20" Margin="5, 25, 24, 0" VerticalAlignment="Top" Text="" PreviewDragOver="AppPath_PreviewDragOver" PreviewDrop="AppPath_PreviewDrop"/>
@@ -46,7 +47,7 @@
4647
</Menu>
4748
</Grid>
4849
</GroupBox>
49-
<GroupBox Header="{DynamicResource GroupBox_Output_Header}" Margin="0, 20, 20, 240" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
50+
<GroupBox Header="{DynamicResource GroupBox_Output_Header}" Margin="0, 20, 20, 240" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
5051
<Grid>
5152
<TextBlock Height="20" Margin="5, 5, 110, 0" Text="{DynamicResource TextBlock_OutputExtension_Text}" VerticalAlignment="Top" TextAlignment="Right"/>
5253
<TextBox x:Name="OutputExtension" Height="20" Margin="0, 5, 5, 0" Text="" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100" GotFocus="OutputExtension_GotFocus" PreviewMouseDown="OutputExtension_PreviewMouseDown"/>
@@ -61,7 +62,7 @@
6162
<TextBlock Height="20" Margin="5, 80, 5, 0" TextWrapping="Wrap" Text="{DynamicResource TextBlock_OutputConfigTips_Text}" VerticalAlignment="Top" TextAlignment="Right" Foreground="#FF707070" FontSize="10"/>
6263
</Grid>
6364
</GroupBox>
64-
<GroupBox Header="{DynamicResource GroupBox_Process_Header}" Margin="0, 0, 20, 90" VerticalAlignment="Bottom" Height="140" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
65+
<GroupBox Header="{DynamicResource GroupBox_Process_Header}" Margin="0, 0, 20, 90" VerticalAlignment="Bottom" Height="140" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
6566
<Grid>
6667
<TextBlock Height="20" Margin="5, 5, 110, 0" Text="{DynamicResource TextBlock_Priority_Text}" VerticalAlignment="Top" TextAlignment="Right"/>
6768
<ComboBox x:Name="Priority" SelectedValuePath="Tag" Margin="0, 5, 5, 0" VerticalAlignment="Top" Height="20" Style="{DynamicResource FlatComboBox}" HorizontalAlignment="Right" Width="100">
@@ -103,7 +104,7 @@
103104
</ComboBox>
104105
</Grid>
105106
</GroupBox>
106-
<GroupBox x:Name="Monitor" Header="{DynamicResource GroupBox_Monitor_Header}" Height="60" Margin="0, 0, 130, 20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120">
107+
<GroupBox x:Name="Monitor" Header="{DynamicResource GroupBox_Monitor_Header}" Height="60" Margin="0, 0, 130, 20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120">
107108
<Grid>
108109
<TextBlock HorizontalAlignment="Left" Height="15" Margin="2, 5, 0, 0" Text="{DynamicResource TextBlock_MonitorForCPU_Text}" VerticalAlignment="Top" Width="30" FontSize="10" TextAlignment="Right"/>
109110
<TextBlock x:Name="MonitorForCPU" Height="15" Margin="34, 5, 2, 0" Text="--%" VerticalAlignment="Top" FontSize="10"/>
@@ -112,5 +113,6 @@
112113
<TextBlock x:Name="MonitorForRAM" Height="15" Margin="34, 20, 2, 0" Text="----KB (--%)" VerticalAlignment="Top" FontSize="10"/>
113114
</Grid>
114115
</GroupBox>
116+
</Grid>
115117
</Grid>
116118
</Window>

UniversalGUI/MainWindow.xaml.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ public partial class MainWindow : Window
2525

2626
public async void StartTaskAsync()
2727
{
28+
//Stop task
29+
if(TaskProgressBar.Visibility == Visibility.Visible)
30+
{
31+
StopTask();
32+
return;
33+
}
34+
2835
//Change UI
29-
this.IsEnabled = false;
30-
StartTaskButton.IsEnabled = false;
31-
StartTaskButton.Content = QueryLangDict("Button_StartTask_Content_Running");
36+
TaskSettings.IsEnabled = false;
37+
StartTaskButton.Content = QueryLangDict("Button_StartTask_Content_Stop");
3238
SetProgress(0);
3339

3440
//Collect config on UI
3541
SumConfig();
3642
bool settingLegal = CheckConfig();
37-
38-
//debug
43+
3944
//Run on background thread
4045
await Task.Run(() =>
4146
{
@@ -51,7 +56,7 @@ await Task.Run(() =>
5156
});
5257

5358
//Change UI
54-
this.IsEnabled = true;
59+
TaskSettings.IsEnabled = true;
5560
if (settingLegal == true)
5661
{
5762
StartTaskButton.Content = QueryLangDict("Button_StartTask_Content_Finished");
@@ -63,34 +68,47 @@ await Task.Run(() =>
6368
SetProgress(-1);
6469
}
6570
await Task.Delay(3000); //Show result to user
66-
StartTaskButton.IsEnabled = true;
6771
StartTaskButton.Content = QueryLangDict("Button_StartTask_Content_Start");
6872
TaskProgressBar.Visibility = Visibility.Hidden;
6973
SetProgress(); //擦屁股
7074
}
7175

76+
public void StopTask()
77+
{
78+
config = new Config();
79+
}
80+
7281
public async Task NewThreadAsync()
7382
{
7483
while (config.FilesList.Count > 0)
7584
{
76-
string sumAppArgs = SumAppArgs(
85+
string inputFile = Dispatcher.Invoke(() =>
86+
{
87+
string firstFile = config.FilesList.First.Value;
88+
config.FilesList.RemoveFirst();
89+
return firstFile;
90+
});
91+
92+
string appArgs = SumAppArgs(
7793
argsTemplet: config.ArgsTemplet,
78-
inputFile: config.FilesList.First.Value, //链表中第一个文件
94+
inputFile: inputFile,
7995
userArgs: config.UserArgs,
8096
outputSuffix: config.OutputSuffix,
8197
outputExtension: config.OutputExtension,
8298
outputFloder: config.OutputFloder);
83-
config.FilesList.RemoveFirst(); //弹出链表中第一个文件
99+
84100
await Task.Run(() =>
85101
{
86102
NewProcess(
87103
appPath: config.AppPath,
88-
appArgs: sumAppArgs,
104+
appArgs: appArgs,
89105
windowStyle: config.WindowStyle,
90106
priority: config.Priority,
91107
simulateCmd: config.SimulateCmd);
92108
});
109+
93110
config.CompletedFileNum++;
111+
94112
Dispatcher.Invoke(() =>
95113
{
96114
SetProgress((double)config.CompletedFileNum / config.FilesSum);
@@ -215,6 +233,12 @@ private void NewProcess(string appPath, string appArgs, uint windowStyle, uint p
215233
catch (System.ComponentModel.Win32Exception e)
216234
{
217235
Debug.WriteLine(e.ToString());
236+
return;
237+
}
238+
catch (System.InvalidOperationException e)
239+
{
240+
Debug.WriteLine(e.ToString());
241+
return;
218242
}
219243

220244
process.PriorityBoostEnabled = false;
@@ -369,7 +393,7 @@ private void SetTitleSuffix(string suffix = "")
369393
}
370394
else
371395
{
372-
Title = DefaultTitle + " " + suffix;
396+
Title = DefaultTitle + " [" + suffix + "] ";
373397
}
374398
}
375399

UniversalGUI/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
5252
// 方法是按如下所示使用“*”: :
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("0.9.2.0")]
55-
[assembly: AssemblyFileVersion("0.9.2.0")]
54+
[assembly: AssemblyVersion("0.9.4.0")]
55+
[assembly: AssemblyFileVersion("0.9.4.0")]

0 commit comments

Comments
 (0)