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

Commit 6f95b2e

Browse files
committed
0.9.5.7
Bug Fix * When you press stop buttom, sometime app will try to kill system process(pid:0). * Task progress bar's size out of bounds.
1 parent 5fa0b8f commit 6f95b2e

File tree

6 files changed

+73
-78
lines changed

6 files changed

+73
-78
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,4 @@ Usage: cwebp [-preset <...>] [options] in_file [-o out_file]
5757

5858
* 可在程序所在目录下新建一个名为`Portable`的文件(无拓展名),让程序把ini配置文件放在所在目录,达到便携化效果。
5959

60-
***所有CPU都已占满**时,`Process.Start();`需要很长时间,因此可能难以达到所指定的线程数。
61-
62-
### Bugs
63-
64-
* Combo Box只有“收起”时才能看到Pressed效果。
60+
***所有CPU都已占满**时,`Process.Start();`需要很长时间,因此可能难以达到所指定的线程数。

UniversalGUI/MainIcon.ico

-7.11 KB
Binary file not shown.

UniversalGUI/MainWindow.xaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
mc:Ignorable="d"
1010
Title="{DynamicResource Window_MainWindow_Title}" Height="425" Width="700" MinWidth="550" MinHeight="425" Closing="MainWindow_WindowClosing" Loaded="MainWindow_Loaded">
1111

12-
<Grid>
13-
<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}"/>
14-
<ProgressBar x:Name="TaskProgressBar" HorizontalAlignment="Right" Height="5" Margin="0, 0, 20, 20" VerticalAlignment="Bottom" Width="100" BorderBrush="#0000" Foreground="DimGray" Visibility="Hidden"/>
12+
<Grid Margin="15">
13+
<Button x:Name="StartTaskButton" Content="{DynamicResource Button_StartTask_Content_Start}" HorizontalAlignment="Right" Height="50" Margin="0" VerticalAlignment="Bottom" Width="100" FontSize="16" Click="StartTaskAsync" Style="{DynamicResource FlatButton}"/>
14+
<ProgressBar x:Name="TaskProgressBar" HorizontalAlignment="Right" Height="4" Margin="0,0,1,1" VerticalAlignment="Bottom" Width="98" BorderBrush="#0000" Foreground="DimGray" Visibility="Hidden" Background="#0000"/>
1515
<Grid x:Name="TaskSettings">
16-
<GroupBox Header="{DynamicResource GroupBox_ImputFiles_Header}" Margin="20, 20, 260, 240">
16+
<GroupBox Header="{DynamicResource GroupBox_ImputFiles_Header}" Margin="0,0,240,220">
1717
<Grid>
1818
<ListBox x:Name="FilesList" Margin="5" AllowDrop="True" Drop="FilesList_Drop" SelectionMode="Extended" DragOver="FilesList_DragOver"/>
1919
<Grid Panel.ZIndex="1" Opacity="0.75">
@@ -23,7 +23,7 @@
2323
</Grid>
2424
</Grid>
2525
</GroupBox>
26-
<GroupBox Header="{DynamicResource GroupBox_Command_Header}" Margin="20, 0, 260, 20" Height="210" VerticalAlignment="Bottom">
26+
<GroupBox Header="{DynamicResource GroupBox_Command_Header}" Margin="0,0,240,0" Height="210" VerticalAlignment="Bottom">
2727
<Grid>
2828
<TextBlock Height="20" Margin="5, 5, 5, 0" Text="{DynamicResource TextBlock_AppPath_Text}" VerticalAlignment="Top"/>
2929
<TextBox x:Name="AppPath" Height="20" Margin="5, 25, 24, 0" VerticalAlignment="Top" Text="" PreviewDragOver="AppPath_PreviewDragOver" PreviewDrop="AppPath_PreviewDrop"/>
@@ -47,7 +47,7 @@
4747
</Menu>
4848
</Grid>
4949
</GroupBox>
50-
<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,0,0,220" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
5151
<Grid>
5252
<TextBlock Height="20" Margin="5, 5, 110, 0" Text="{DynamicResource TextBlock_OutputExtension_Text}" VerticalAlignment="Top" TextAlignment="Right"/>
5353
<TextBox x:Name="OutputExtension" Height="20" Margin="0, 5, 5, 0" Text="" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100" GotFocus="OutputExtension_GotFocus" PreviewMouseDown="OutputExtension_PreviewMouseDown"/>
@@ -62,7 +62,7 @@
6262
<TextBlock Height="20" Margin="5, 80, 5, 0" TextWrapping="Wrap" Text="{DynamicResource TextBlock_OutputConfigTips_Text}" VerticalAlignment="Top" TextAlignment="Right" Foreground="#FF707070" FontSize="10"/>
6363
</Grid>
6464
</GroupBox>
65-
<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,0,60" VerticalAlignment="Bottom" Height="150" Width="230" HorizontalAlignment="Right" Grid.ColumnSpan="2">
6666
<Grid>
6767
<TextBlock Height="20" Margin="5, 5, 110, 0" Text="{DynamicResource TextBlock_Priority_Text}" VerticalAlignment="Top" TextAlignment="Right"/>
6868
<ComboBox x:Name="Priority" SelectedValuePath="Tag" Margin="0, 5, 5, 0" VerticalAlignment="Top" Height="20" Style="{DynamicResource FlatComboBox}" HorizontalAlignment="Right" Width="100">
@@ -104,7 +104,7 @@
104104
</ComboBox>
105105
</Grid>
106106
</GroupBox>
107-
<GroupBox x:Name="Monitor" Header="{DynamicResource GroupBox_Monitor_Header}" Height="60" Margin="0, 0, 130, 20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120">
107+
<GroupBox Header="{DynamicResource GroupBox_Monitor_Header}" Height="60" Margin="0,0,110,0" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120">
108108
<Grid>
109109
<TextBlock HorizontalAlignment="Left" Height="15" Margin="2, 5, 0, 0" Text="{DynamicResource TextBlock_MonitorForCPU_Text}" VerticalAlignment="Top" Width="30" FontSize="10" TextAlignment="Right"/>
110110
<TextBlock x:Name="MonitorForCPU" Height="15" Margin="34, 5, 2, 0" Text="--%" VerticalAlignment="Top" FontSize="10"/>

UniversalGUI/MainWindow.xaml.cs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -85,78 +85,80 @@ public void StopTask()
8585
{
8686
try
8787
{
88-
Process.GetProcessById(processIdArr[i]).Kill();
89-
processIdArr[i] = 0;
88+
if(processIdArr[i] != -1)
89+
{
90+
Process.GetProcessById(processIdArr[i]).Kill();
91+
}
92+
processIdArr[i] = -1;
9093
}
9194
catch (System.ArgumentException e)
9295
{
93-
Debug.WriteLine("Maybe the process [" + processIdArr[i] + "] isn't running. Exception message: {0}", e.Message);
96+
Debug.WriteLine("Maybe the process [" + processIdArr[i] + "] isn't running. Exception message: " + e.Message);
9497
}
9598
catch (System.ComponentModel.Win32Exception e)
9699
{
97-
MessageBox.Show("Can't kill the process [" + processIdArr[i] + "] . You can try again. Exception message: {0}", e.Message);
100+
MessageBox.Show("Can't kill the process [" + processIdArr[i] + "] . You can try again. Exception message: " + e.Message);
98101
}
99102
}
100103
});
101104
}
102105

103-
public async Task NewThreadAsync(int processNumber)
106+
public async Task NewThreadAsync(int processIDIndex)
104107
{
105108
while (true)
106109
{
107-
string inputFile = Dispatcher.Invoke(() =>
110+
string inputFileName = Dispatcher.Invoke(() =>
108111
{
109112
if (config.FilesList.Count > 0)
110113
{
111-
string firstFile = config.FilesList.First.Value;
114+
string firstFileName = config.FilesList.First.Value;
112115
config.FilesList.RemoveFirst();
113-
return firstFile;
116+
return firstFileName;
114117
}
115118
else
116119
{
117120
return null;
118121
}
119122
});
120123

121-
if (inputFile == null)
124+
if (inputFileName == null)
122125
{
123-
break;
126+
return;
124127
}
125-
else
126-
{
127-
string appArgs = SumAppArgs(
128-
argsTemplet: config.ArgsTemplet,
129-
inputFile: inputFile,
130-
userArgs: config.UserArgs,
131-
outputSuffix: config.OutputSuffix,
132-
outputExtension: config.OutputExtension,
133-
outputFloder: config.OutputFloder);
134-
135-
await Task.Run(() =>
136-
{
137-
NewProcess(
138-
appPath: config.AppPath,
139-
appArgs: appArgs,
140-
windowStyle: config.WindowStyle,
141-
priority: config.Priority,
142-
simulateCmd: config.SimulateCmd,
143-
processIndex: processNumber);
144-
});
145128

146-
config.CompletedFileNum++;
129+
string appArgs = SumAppArgs(
130+
argsTemplet: config.ArgsTemplet,
131+
inputFileName: inputFileName,
132+
userArgs: config.UserArgs,
133+
outputSuffix: config.OutputSuffix,
134+
outputExtension: config.OutputExtension,
135+
outputFloder: config.OutputFloder);
147136

148-
Dispatcher.Invoke(() =>
149-
{
150-
SetProgress((double)config.CompletedFileNum / config.FilesSum);
151-
});
152-
}
137+
138+
Process process = NewProcess(
139+
appPath: config.AppPath,
140+
appArgs: appArgs,
141+
windowStyle: config.WindowStyle,
142+
priority: config.Priority,
143+
simulateCmd: config.SimulateCmd);
144+
145+
processIdArr[processIDIndex] = process.Id;
146+
147+
await Task.Run(() => process.WaitForExit());
148+
149+
config.CompletedFileNumber++;
150+
151+
Dispatcher.Invoke(() =>
152+
{
153+
SetProgress((double)config.CompletedFileNumber / config.FilesSum);
154+
});
153155
}
154156
}
155157

156-
private string SumAppArgs(string argsTemplet, string inputFile, string userArgs, string outputSuffix, string outputExtension, string outputFloder)
158+
private string SumAppArgs(string argsTemplet, string inputFileName, string userArgs, string outputSuffix, string outputExtension, string outputFloder)
157159
{
158160
//去前后引号
159-
inputFile = new Regex("(^\")|(\"$)").Replace(inputFile, "");
161+
inputFileName = new Regex("(^\")|(\"$)").Replace(inputFileName, "");
160162
argsTemplet = new Regex("(^\")|(\"$)").Replace(argsTemplet, "");
161163
outputSuffix = new Regex("(^\")|(\"$)").Replace(outputSuffix, "");
162164
outputExtension = new Regex("(^\")|(\"$)").Replace(outputExtension, "");
@@ -173,7 +175,7 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
173175
//替换 {InputFile}
174176
{
175177
//加前后引号
176-
string inputFile2 = "\"" + inputFile + "\"";
178+
string inputFile2 = "\"" + inputFileName + "\"";
177179
//替换模板中的标记
178180
args = new Regex(@"\{InputFile\}").Replace(args, inputFile2);
179181
}
@@ -182,7 +184,7 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
182184
{
183185
string outputFile;
184186
//获得主文件名
185-
string mainName = new Regex(@"\..[^.]+?$").Replace(inputFile, "");
187+
string mainName = new Regex(@"\..[^.]+?$").Replace(inputFileName, "");
186188

187189
//后缀
188190
if (outputSuffix != "")
@@ -200,7 +202,7 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
200202
else
201203
{
202204
//原拓展名
203-
var sourceExtension = new Regex(@"\..[^.]+?$").Match(inputFile);
205+
var sourceExtension = new Regex(@"\..[^.]+?$").Match(inputFileName);
204206
extension = Convert.ToString(sourceExtension);
205207
}
206208
//去除拓展名前的点
@@ -228,7 +230,7 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
228230
return args;
229231
}
230232

231-
private void NewProcess(string appPath, string appArgs, uint windowStyle, uint priority, bool simulateCmd, int processIndex)
233+
private Process NewProcess(string appPath, string appArgs, uint windowStyle, uint priority, bool simulateCmd)
232234
{
233235
var process = new Process();
234236
if (simulateCmd == false)
@@ -261,12 +263,11 @@ private void NewProcess(string appPath, string appArgs, uint windowStyle, uint p
261263
try
262264
{
263265
process.Start();
264-
processIdArr[processIndex] = process.Id;
265266
}
266267
catch (System.ComponentModel.Win32Exception e)
267268
{
268269
Debug.WriteLine("The process can not be started. Exception message: {0}", e.Message);
269-
return;
270+
return null;
270271
}
271272

272273
process.PriorityBoostEnabled = false;
@@ -291,7 +292,8 @@ private void NewProcess(string appPath, string appArgs, uint windowStyle, uint p
291292
process.PriorityClass = ProcessPriorityClass.RealTime;
292293
break;
293294
}
294-
process.WaitForExit();
295+
296+
return process;
295297
}
296298

297299
private void SumConfig()
@@ -326,7 +328,7 @@ private void SumConfig()
326328
}
327329
}
328330

329-
//Start and Exit
331+
//On Start and Exit
330332
public partial class MainWindow : Window
331333
{
332334
public MainWindow()
@@ -443,33 +445,32 @@ await Task.Run(() =>
443445
cpuUseRatio = Math.Round(cpuPerformanceCounter.NextValue());
444446
usedMem = (double)computerInfo.TotalPhysicalMemory - computerInfo.AvailablePhysicalMemory;
445447
memUseRatio = Math.Round((double)usedMem / computerInfo.TotalPhysicalMemory * 100);
446-
447448
//按需切换占用内存大小的显示单位及精度
448-
if (usedMem >= 1099511627776) //占用内存>=1TB
449+
if (usedMem >= 1099511627776) //1TB
449450
{
450451
memUnit = "TB";
451-
usedMem /= 1099511627776; //1024^4(4次方)
452+
usedMem /= 1099511627776; //1024^4
452453
usedMem = Math.Round(usedMem, 3);
453454
}
454-
else if (usedMem >= 107374182400) //>=100GB
455+
else if (usedMem >= 107374182400) //100GB
455456
{
456457
memUnit = "GB";
457458
usedMem /= 1073741824; //^3
458459
usedMem = Math.Round(usedMem, 1);
459460
}
460-
else if (usedMem >= 10737418240) //>=10GB
461+
else if (usedMem >= 10737418240) //10GB
461462
{
462463
memUnit = "GB";
463464
usedMem /= 1073741824; //^3
464465
usedMem = Math.Round(usedMem, 2);
465466
}
466-
else if (usedMem >= 1073741824) //>=1GB
467+
else if (usedMem >= 1073741824) //1GB
467468
{
468469
memUnit = "GB";
469470
usedMem /= 1073741824; //^3
470471
usedMem = Math.Round(usedMem, 3);
471472
}
472-
else if (usedMem >= 104857600) //>=100MB
473+
else if (usedMem >= 104857600) //100MB
473474
{
474475
memUnit = "MB";
475476
usedMem /= 1048576;//^2
@@ -842,7 +843,7 @@ public class Config
842843
{
843844
public LinkedList<string> FilesList = new LinkedList<string>();
844845
public int FilesSum = 0;
845-
public int CompletedFileNum = 0;
846+
public int CompletedFileNumber = 0;
846847

847848
public string AppPath;
848849
public string ArgsTemplet;

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.5.4")]
55-
[assembly: AssemblyFileVersion("0.9.5.4")]
54+
[assembly: AssemblyVersion("0.9.5.7")]
55+
[assembly: AssemblyFileVersion("0.9.5.7")]

UniversalGUI/Resources/Theme/Flat.xaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@
6161

6262
<!--FlatComboBox-->
6363
<SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#999"/>
64-
<SolidColorBrush x:Key="ComboBox.Static.Background" Color="White"/>
64+
<SolidColorBrush x:Key="ComboBox.Static.Background" Color="#fff"/>
6565
<SolidColorBrush x:Key="ComboBox.Static.Border" Color="#999"/>
6666
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#666"/>
67-
<SolidColorBrush x:Key="ComboBox.Pressed.Background" Color="#CCC"/>
68-
<SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#666"/>
69-
<SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#EEE"/>
70-
<SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#EEE"/>
67+
<SolidColorBrush x:Key="ComboBox.Checked.Border" Color="#666"/>
68+
<SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#eee"/>
69+
<SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#eee"/>
7170
<SolidColorBrush x:Key="ComboBox.Disabled.Foreground" Color="#838383"/>
72-
<SolidColorBrush x:Key="TextBox.Static.Background" Color="White"/>
71+
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#fff"/>
7372
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
7473
<Setter Property="OverridesDefaultStyle" Value="true"/>
7574
<Setter Property="IsTabStop" Value="false"/>
@@ -93,11 +92,10 @@
9392
</MultiDataTrigger>
9493
<MultiDataTrigger>
9594
<MultiDataTrigger.Conditions>
96-
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
95+
<Condition Binding="{Binding IsChecked, RelativeSource={RelativeSource Self}}" Value="true"/>
9796
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
9897
</MultiDataTrigger.Conditions>
99-
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
100-
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
98+
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Checked.Border}"/>
10199
</MultiDataTrigger>
102100
<MultiDataTrigger>
103101
<MultiDataTrigger.Conditions>

0 commit comments

Comments
 (0)