@@ -35,6 +35,7 @@ public async void StartTaskAsync()
35
35
SumConfig ( ) ;
36
36
bool settingLegal = CheckConfig ( ) ;
37
37
38
+ //debug
38
39
//Run on background thread
39
40
await Task . Run ( ( ) =>
40
41
{
@@ -86,7 +87,8 @@ await Task.Run(() =>
86
87
appPath : config . AppPath ,
87
88
appArgs : sumAppArgs ,
88
89
windowStyle : config . WindowStyle ,
89
- priority : config . Priority ) ;
90
+ priority : config . Priority ,
91
+ simulateCmd : config . SimulateCmd ) ;
90
92
} ) ;
91
93
config . CompletedFileNum ++ ;
92
94
Dispatcher . Invoke ( ( ) =>
@@ -101,25 +103,24 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
101
103
//去前后引号
102
104
inputFile = new Regex ( "(^\" )|(\" $)" ) . Replace ( inputFile , "" ) ;
103
105
argsTemplet = new Regex ( "(^\" )|(\" $)" ) . Replace ( argsTemplet , "" ) ;
104
- userArgs = new Regex ( "(^\" )|(\" $)" ) . Replace ( userArgs , "" ) ;
105
106
outputSuffix = new Regex ( "(^\" )|(\" $)" ) . Replace ( outputSuffix , "" ) ;
106
107
outputExtension = new Regex ( "(^\" )|(\" $)" ) . Replace ( outputExtension , "" ) ;
107
108
outputFloder = new Regex ( "(^\" )|(\" $)" ) . Replace ( outputFloder , "" ) ;
108
-
109
- string arguments = argsTemplet ;
109
+
110
+ string args = argsTemplet ;
110
111
111
112
//替换 {UserParameters}
112
113
{
113
114
//替换模板中的标记
114
- arguments = new Regex ( @"\{UserParameters\}" ) . Replace ( arguments , userArgs ) ;
115
+ args = new Regex ( @"\{UserParameters\}" ) . Replace ( args , userArgs ) ;
115
116
}
116
117
117
118
//替换 {InputFile}
118
119
{
119
120
//加前后引号
120
121
string inputFile2 = "\" " + inputFile + "\" " ;
121
122
//替换模板中的标记
122
- arguments = new Regex ( @"\{InputFile\}" ) . Replace ( arguments , inputFile2 ) ;
123
+ args = new Regex ( @"\{InputFile\}" ) . Replace ( args , inputFile2 ) ;
123
124
}
124
125
125
126
//替换 {OutputFile}
@@ -166,17 +167,31 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
166
167
//加前后引号
167
168
outputFile = "\" " + outputFile + "\" " ;
168
169
//替换模板中的标记
169
- arguments = new Regex ( @"\{OutputFile\}" ) . Replace ( arguments , outputFile ) ;
170
+ args = new Regex ( @"\{OutputFile\}" ) . Replace ( args , outputFile ) ;
170
171
}
171
172
172
- return arguments ;
173
+ return args ;
173
174
}
174
175
175
- private void NewProcess ( string appPath , string appArgs , uint windowStyle , uint priority )
176
+ private void NewProcess ( string appPath , string appArgs , uint windowStyle , uint priority , bool simulateCmd )
176
177
{
177
178
var process = new Process ( ) ;
178
- process . StartInfo . FileName = appPath ;
179
- process . StartInfo . Arguments = appArgs ;
179
+ if ( simulateCmd == false )
180
+ {
181
+ process . StartInfo . FileName = appPath ;
182
+ process . StartInfo . Arguments = appArgs ;
183
+ }
184
+ else
185
+ {
186
+ process . StartInfo . FileName = "cmd.exe" ;
187
+ process . StartInfo . Arguments = "/c" + " " + appPath + " " + appArgs ; //这边不能给appPath加引号
188
+ }
189
+
190
+ Debug . WriteLine ( process . StartInfo . Arguments ) ;
191
+ //int id = process.Id;
192
+ //Process.GetProcessById(999999).Kill();
193
+ //Process.GetCurrentProcess().Kill();
194
+
180
195
switch ( windowStyle )
181
196
{
182
197
case 1 :
@@ -191,11 +206,16 @@ private void NewProcess(string appPath, string appArgs, uint windowStyle, uint p
191
206
case 4 :
192
207
process . StartInfo . WindowStyle = ProcessWindowStyle . Maximized ;
193
208
break ;
194
- default :
195
- break ;
196
209
}
197
210
198
- process . Start ( ) ;
211
+ try
212
+ {
213
+ process . Start ( ) ;
214
+ }
215
+ catch ( System . ComponentModel . Win32Exception e )
216
+ {
217
+ Debug . WriteLine ( e . ToString ( ) ) ;
218
+ }
199
219
200
220
process . PriorityBoostEnabled = false ;
201
221
switch ( priority )
@@ -241,6 +261,15 @@ private void SumConfig()
241
261
config . Priority = Convert . ToUInt32 ( Priority . SelectedValue ) ;
242
262
config . ThreadNumber = Convert . ToUInt32 ( ThreadNumber . SelectedValue ) ;
243
263
config . WindowStyle = Convert . ToUInt32 ( CUIWindowStyle . SelectedValue ) ;
264
+ switch ( Convert . ToUInt32 ( SimulateCmd . SelectedValue ) )
265
+ {
266
+ case 1 :
267
+ config . SimulateCmd = false ;
268
+ break ;
269
+ case 2 :
270
+ config . SimulateCmd = true ;
271
+ break ;
272
+ }
244
273
} ) ;
245
274
}
246
275
}
@@ -321,7 +350,7 @@ private void SetProgress(double multiple = -2)
321
350
TaskbarManager . Instance . SetProgressValue ( 100 , 100 , this ) ;
322
351
TaskbarManager . Instance . SetProgressState ( TaskbarProgressBarState . Error , this ) ;
323
352
}
324
- else if ( multiple >= 0 && multiple <= 1 ) //修改
353
+ else if ( multiple >= 0 && multiple <= 1 ) //一般修改
325
354
{
326
355
int percent = Convert . ToInt32 ( Math . Round ( multiple * 100 ) ) ;
327
356
SetTitleSuffix ( percent + "%" ) ;
@@ -340,7 +369,7 @@ private void SetTitleSuffix(string suffix = "")
340
369
}
341
370
else
342
371
{
343
- Title = DefaultTitle + " [ " + suffix + "]" ;
372
+ Title = DefaultTitle + " " + suffix ;
344
373
}
345
374
}
346
375
@@ -365,31 +394,31 @@ await Task.Run(() =>
365
394
if ( usedMem >= 1099511627776 ) //占用内存>=1TB
366
395
{
367
396
memUnit = "TB" ;
368
- usedMem = usedMem / 1099511627776 ; //1024^4(4次方)
397
+ usedMem /= 1099511627776 ; //1024^4(4次方)
369
398
usedMem = Math . Round ( usedMem , 3 ) ;
370
399
}
371
400
else if ( usedMem >= 107374182400 ) //>=100GB
372
401
{
373
402
memUnit = "GB" ;
374
- usedMem = usedMem / 1073741824 ; //^3
403
+ usedMem /= 1073741824 ; //^3
375
404
usedMem = Math . Round ( usedMem , 1 ) ;
376
405
}
377
406
else if ( usedMem >= 10737418240 ) //>=10GB
378
407
{
379
408
memUnit = "GB" ;
380
- usedMem = usedMem / 1073741824 ; //^3
409
+ usedMem /= 1073741824 ; //^3
381
410
usedMem = Math . Round ( usedMem , 2 ) ;
382
411
}
383
412
else if ( usedMem >= 1073741824 ) //>=1GB
384
413
{
385
414
memUnit = "GB" ;
386
- usedMem = usedMem / 1073741824 ; //^3
415
+ usedMem /= 1073741824 ; //^3
387
416
usedMem = Math . Round ( usedMem , 3 ) ;
388
417
}
389
418
else if ( usedMem >= 104857600 ) //>=100MB
390
419
{
391
420
memUnit = "MB" ;
392
- usedMem = usedMem / 1048576 ; //^2
421
+ usedMem /= 1048576 ; //^2
393
422
usedMem = Math . Round ( usedMem , 1 ) ;
394
423
}
395
424
@@ -415,13 +444,7 @@ private bool CheckConfig()
415
444
}
416
445
else if ( AppPath . Text == "" )
417
446
{
418
- string content = QueryLangDict ( "MessageBox_Content_CheckConfig_CommandApplicationIsUnspecified" ) ;
419
- MessageBox . Show ( content , title ) ;
420
- return false ;
421
- }
422
- else if ( ArgsTemplet . Text == "" )
423
- {
424
- string content = QueryLangDict ( "MessageBox_Content_CheckConfig_ArgumentsTempletIsUnspecified" ) ;
447
+ string content = QueryLangDict ( "MessageBox_Content_CheckConfig_CommandAppIsUnspecified" ) ;
425
448
MessageBox . Show ( content , title ) ;
426
449
return false ;
427
450
}
@@ -440,6 +463,12 @@ private bool CheckConfig()
440
463
return false ;
441
464
}
442
465
}
466
+ else if ( AppPath . Text . IndexOf ( ' ' ) != - 1 && Convert . ToInt32 ( SimulateCmd . SelectedValue ) == 2 )
467
+ {
468
+ string content = QueryLangDict ( "MessageBox_Content_CheckConfig_SimulateCmdConfigIsIllegal" ) ;
469
+ MessageBox . Show ( content , title ) ;
470
+ return false ;
471
+ }
443
472
return true ;
444
473
}
445
474
@@ -495,7 +524,7 @@ private void FilesList_Drop(object sender, DragEventArgs e)
495
524
}
496
525
}
497
526
498
- private void SwitchApplicationPath ( object sender , RoutedEventArgs e )
527
+ private void SwitchAppPath ( object sender , RoutedEventArgs e )
499
528
{
500
529
var openFileDialog = new Microsoft . Win32 . OpenFileDialog ( )
501
530
{
@@ -508,18 +537,44 @@ private void SwitchApplicationPath(object sender, RoutedEventArgs e)
508
537
}
509
538
}
510
539
511
- private void ApplicationPath_PreviewDragOver ( object sender , DragEventArgs e )
540
+ private void AppPath_PreviewDragOver ( object sender , DragEventArgs e )
512
541
{
513
542
e . Effects = DragDropEffects . Copy ;
514
543
e . Handled = true ;
515
544
}
516
545
517
- private void ApplicationPath_PreviewDrop ( object sender , DragEventArgs e )
546
+ private void AppPath_PreviewDrop ( object sender , DragEventArgs e )
518
547
{
519
548
string [ ] dropFiles = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
520
549
AppPath . Text = dropFiles [ 0 ] ;
521
550
}
522
-
551
+
552
+ private void InsertArgsTempletTag ( string tagContent )
553
+ {
554
+ string text = ArgsTemplet . Text ;
555
+ string insertContent = "{" + tagContent + "}" ;
556
+ int selectionStart = ArgsTemplet . SelectionStart ;
557
+ text = text . Insert ( selectionStart , insertContent ) ;
558
+ ArgsTemplet . Text = text ;
559
+ ArgsTemplet . SelectionStart = selectionStart + insertContent . Length ;
560
+ ArgsTemplet . Focus ( ) ;
561
+ }
562
+
563
+ private void InsertArgsTempletMark_UserParameters ( object sender , RoutedEventArgs e )
564
+ {
565
+ InsertArgsTempletTag ( "UserParameters" ) ;
566
+ }
567
+
568
+ private void InsertArgsTempletMark_InputFile ( object sender , RoutedEventArgs e )
569
+ {
570
+ InsertArgsTempletTag ( "InputFile" ) ;
571
+ }
572
+
573
+ private void InsertArgsTempletMark_OutputFile ( object sender , RoutedEventArgs e )
574
+ {
575
+ InsertArgsTempletTag ( "OutputFile" ) ;
576
+ }
577
+
523
578
private void ShowArgsTempletHelp ( object sender , RoutedEventArgs e )
524
579
{
525
580
string title = QueryLangDict ( "MessageBox_Title_Hint" ) ;
@@ -656,13 +711,14 @@ private void ImputIniConfig(IniManager ini)
656
711
}
657
712
ThreadNumber . SelectedValue = threadNumber ;
658
713
CUIWindowStyle . SelectedValue = ini . Read ( "Process" , "WindowStyle" ) ;
714
+ SimulateCmd . SelectedValue = ini . Read ( "Process" , "SimulateCmd" ) ;
659
715
string culture = ini . Read ( "Language" , "Culture" ) ;
660
716
if ( culture != "" )
661
717
{
662
718
Thread . CurrentThread . CurrentCulture = new CultureInfo ( culture ) ;
663
719
}
664
720
}
665
- catch ( Exception e )
721
+ catch ( Exception e )
666
722
{
667
723
string title = QueryLangDict ( "MessageBox_Title_Error" ) ;
668
724
string content = QueryLangDict ( "MessageBox_Content_Configfile_FormatMistake" ) ;
@@ -696,6 +752,7 @@ private void SaveIniConfig(IniManager ini)
696
752
ini . Write ( "Process" , "Priority" , Priority . SelectedValue ) ;
697
753
ini . Write ( "Process" , "ThreadNumber" , ThreadNumber . SelectedValue ) ;
698
754
ini . Write ( "Process" , "WindowStyle" , CUIWindowStyle . SelectedValue ) ;
755
+ ini . Write ( "Process" , "SimulateCmd" , SimulateCmd . SelectedValue ) ;
699
756
}
700
757
else
701
758
{
@@ -723,6 +780,8 @@ public class Config
723
780
public int FilesSum = 0 ;
724
781
public int CompletedFileNum = 0 ;
725
782
783
+ public LinkedList < int > runningProcessesID = new LinkedList < int > ( ) ;
784
+
726
785
public string AppPath ;
727
786
public string ArgsTemplet ;
728
787
public string UserArgs ;
@@ -733,5 +792,6 @@ public class Config
733
792
public uint Priority ;
734
793
public uint ThreadNumber ;
735
794
public uint WindowStyle ;
795
+ public bool SimulateCmd ;
736
796
}
737
797
}
0 commit comments