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

Commit f179fd0

Browse files
committed
0.9.2.0
What's new? * Using menu to insert marks into args templet. * Simulate cmd function, enhance sometime compatibility. * Other changes. Bug Fix * Some bug fix.
1 parent 56c9506 commit f179fd0

25 files changed

+190
-1175
lines changed

UniversalGUI/IniManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class IniManager
2121
/// <returns></returns>
2222
[DllImport("kernel32")]
2323
private static extern int GetPrivateProfileString(
24-
string section,
25-
string key,
26-
string value,
27-
StringBuilder cache,
28-
int cacheSize,
24+
string section,
25+
string key,
26+
string value,
27+
StringBuilder cache,
28+
int cacheSize,
2929
string path);
3030

3131
/// <summary>
@@ -38,9 +38,9 @@ private static extern int GetPrivateProfileString(
3838
/// <returns>0:error 1:success</returns>
3939
[DllImport("kernel32")]
4040
private static extern long WritePrivateProfileString(
41-
string section,
42-
string key,
43-
string value,
41+
string section,
42+
string key,
43+
string value,
4444
string path);
4545
#endregion
4646

UniversalGUI/LoadResourceDll.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
5757
/// <summary>
5858
/// 注册资源中的dll
5959
/// </summary>
60-
/// <param name="pattern">*表示连续的未知字符,_表示单个未知字符,如*.dll</param>
60+
/// <param name="pattern">*表示连续的未知字符, _表示单个未知字符, 如*.dll</param>
6161
public static void RegistDLL(string pattern = "*.dll")
6262
{
6363
System.IO.Directory.GetFiles("", "");
@@ -70,14 +70,14 @@ public static void RegistDLL(string pattern = "*.dll")
7070
}
7171
//程序集加入已处理集合
7272
Assemblies.Add(ass.FullName, null);
73-
//绑定程序集加载失败事件(这里我测试了,就算重复绑也是没关系的)
73+
//绑定程序集加载失败事件(这里我测试了, 就算重复绑也是没关系的)
7474
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
7575
//获取所有资源文件文件名
7676
var res = ass.GetManifestResourceNames();
7777
var regex = new Regex("^" + pattern.Replace(".", "\\.").Replace("*", ".*").Replace("_", ".") + "$", RegexOptions.IgnoreCase);
7878
foreach (var r in res)
7979
{
80-
//如果是dll,则加载
80+
//如果是dll, 则加载
8181
if (regex.IsMatch(r))
8282
{
8383
try

UniversalGUI/MainWindow.xaml

Lines changed: 55 additions & 39 deletions
Large diffs are not rendered by default.

UniversalGUI/MainWindow.xaml.cs

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public async void StartTaskAsync()
3535
SumConfig();
3636
bool settingLegal = CheckConfig();
3737

38+
//debug
3839
//Run on background thread
3940
await Task.Run(() =>
4041
{
@@ -86,7 +87,8 @@ await Task.Run(() =>
8687
appPath: config.AppPath,
8788
appArgs: sumAppArgs,
8889
windowStyle: config.WindowStyle,
89-
priority: config.Priority);
90+
priority: config.Priority,
91+
simulateCmd: config.SimulateCmd);
9092
});
9193
config.CompletedFileNum++;
9294
Dispatcher.Invoke(() =>
@@ -101,25 +103,24 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
101103
//去前后引号
102104
inputFile = new Regex("(^\")|(\"$)").Replace(inputFile, "");
103105
argsTemplet = new Regex("(^\")|(\"$)").Replace(argsTemplet, "");
104-
userArgs = new Regex("(^\")|(\"$)").Replace(userArgs, "");
105106
outputSuffix = new Regex("(^\")|(\"$)").Replace(outputSuffix, "");
106107
outputExtension = new Regex("(^\")|(\"$)").Replace(outputExtension, "");
107108
outputFloder = new Regex("(^\")|(\"$)").Replace(outputFloder, "");
108-
109-
string arguments = argsTemplet;
109+
110+
string args = argsTemplet;
110111

111112
//替换 {UserParameters}
112113
{
113114
//替换模板中的标记
114-
arguments = new Regex(@"\{UserParameters\}").Replace(arguments, userArgs);
115+
args = new Regex(@"\{UserParameters\}").Replace(args, userArgs);
115116
}
116117

117118
//替换 {InputFile}
118119
{
119120
//加前后引号
120121
string inputFile2 = "\"" + inputFile + "\"";
121122
//替换模板中的标记
122-
arguments = new Regex(@"\{InputFile\}").Replace(arguments, inputFile2);
123+
args = new Regex(@"\{InputFile\}").Replace(args, inputFile2);
123124
}
124125

125126
//替换 {OutputFile}
@@ -166,17 +167,31 @@ private string SumAppArgs(string argsTemplet, string inputFile, string userArgs,
166167
//加前后引号
167168
outputFile = "\"" + outputFile + "\"";
168169
//替换模板中的标记
169-
arguments = new Regex(@"\{OutputFile\}").Replace(arguments, outputFile);
170+
args = new Regex(@"\{OutputFile\}").Replace(args, outputFile);
170171
}
171172

172-
return arguments;
173+
return args;
173174
}
174175

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)
176177
{
177178
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+
180195
switch (windowStyle)
181196
{
182197
case 1:
@@ -191,11 +206,16 @@ private void NewProcess(string appPath, string appArgs, uint windowStyle, uint p
191206
case 4:
192207
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
193208
break;
194-
default:
195-
break;
196209
}
197210

198-
process.Start();
211+
try
212+
{
213+
process.Start();
214+
}
215+
catch (System.ComponentModel.Win32Exception e)
216+
{
217+
Debug.WriteLine(e.ToString());
218+
}
199219

200220
process.PriorityBoostEnabled = false;
201221
switch (priority)
@@ -241,6 +261,15 @@ private void SumConfig()
241261
config.Priority = Convert.ToUInt32(Priority.SelectedValue);
242262
config.ThreadNumber = Convert.ToUInt32(ThreadNumber.SelectedValue);
243263
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+
}
244273
});
245274
}
246275
}
@@ -321,7 +350,7 @@ private void SetProgress(double multiple = -2)
321350
TaskbarManager.Instance.SetProgressValue(100, 100, this);
322351
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Error, this);
323352
}
324-
else if (multiple >= 0 && multiple <= 1) //修改
353+
else if (multiple >= 0 && multiple <= 1) //一般修改
325354
{
326355
int percent = Convert.ToInt32(Math.Round(multiple * 100));
327356
SetTitleSuffix(percent + "%");
@@ -340,7 +369,7 @@ private void SetTitleSuffix(string suffix = "")
340369
}
341370
else
342371
{
343-
Title = DefaultTitle + " [" + suffix + "]";
372+
Title = DefaultTitle + " " + suffix;
344373
}
345374
}
346375

@@ -365,31 +394,31 @@ await Task.Run(() =>
365394
if (usedMem >= 1099511627776) //占用内存>=1TB
366395
{
367396
memUnit = "TB";
368-
usedMem = usedMem / 1099511627776; //1024^4(4次方)
397+
usedMem /= 1099511627776; //1024^4(4次方)
369398
usedMem = Math.Round(usedMem, 3);
370399
}
371400
else if (usedMem >= 107374182400) //>=100GB
372401
{
373402
memUnit = "GB";
374-
usedMem = usedMem / 1073741824; //^3
403+
usedMem /= 1073741824; //^3
375404
usedMem = Math.Round(usedMem, 1);
376405
}
377406
else if (usedMem >= 10737418240) //>=10GB
378407
{
379408
memUnit = "GB";
380-
usedMem = usedMem / 1073741824; //^3
409+
usedMem /= 1073741824; //^3
381410
usedMem = Math.Round(usedMem, 2);
382411
}
383412
else if (usedMem >= 1073741824) //>=1GB
384413
{
385414
memUnit = "GB";
386-
usedMem = usedMem / 1073741824; //^3
415+
usedMem /= 1073741824; //^3
387416
usedMem = Math.Round(usedMem, 3);
388417
}
389418
else if (usedMem >= 104857600) //>=100MB
390419
{
391420
memUnit = "MB";
392-
usedMem = usedMem / 1048576;//^2
421+
usedMem /= 1048576;//^2
393422
usedMem = Math.Round(usedMem, 1);
394423
}
395424

@@ -415,13 +444,7 @@ private bool CheckConfig()
415444
}
416445
else if (AppPath.Text == "")
417446
{
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");
425448
MessageBox.Show(content, title);
426449
return false;
427450
}
@@ -440,6 +463,12 @@ private bool CheckConfig()
440463
return false;
441464
}
442465
}
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+
}
443472
return true;
444473
}
445474

@@ -495,7 +524,7 @@ private void FilesList_Drop(object sender, DragEventArgs e)
495524
}
496525
}
497526

498-
private void SwitchApplicationPath(object sender, RoutedEventArgs e)
527+
private void SwitchAppPath(object sender, RoutedEventArgs e)
499528
{
500529
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
501530
{
@@ -508,18 +537,44 @@ private void SwitchApplicationPath(object sender, RoutedEventArgs e)
508537
}
509538
}
510539

511-
private void ApplicationPath_PreviewDragOver(object sender, DragEventArgs e)
540+
private void AppPath_PreviewDragOver(object sender, DragEventArgs e)
512541
{
513542
e.Effects = DragDropEffects.Copy;
514543
e.Handled = true;
515544
}
516545

517-
private void ApplicationPath_PreviewDrop(object sender, DragEventArgs e)
546+
private void AppPath_PreviewDrop(object sender, DragEventArgs e)
518547
{
519548
string[] dropFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
520549
AppPath.Text = dropFiles[0];
521550
}
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+
523578
private void ShowArgsTempletHelp(object sender, RoutedEventArgs e)
524579
{
525580
string title = QueryLangDict("MessageBox_Title_Hint");
@@ -656,13 +711,14 @@ private void ImputIniConfig(IniManager ini)
656711
}
657712
ThreadNumber.SelectedValue = threadNumber;
658713
CUIWindowStyle.SelectedValue = ini.Read("Process", "WindowStyle");
714+
SimulateCmd.SelectedValue = ini.Read("Process", "SimulateCmd");
659715
string culture = ini.Read("Language", "Culture");
660716
if (culture != "")
661717
{
662718
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
663719
}
664720
}
665-
catch(Exception e)
721+
catch (Exception e)
666722
{
667723
string title = QueryLangDict("MessageBox_Title_Error");
668724
string content = QueryLangDict("MessageBox_Content_Configfile_FormatMistake");
@@ -696,6 +752,7 @@ private void SaveIniConfig(IniManager ini)
696752
ini.Write("Process", "Priority", Priority.SelectedValue);
697753
ini.Write("Process", "ThreadNumber", ThreadNumber.SelectedValue);
698754
ini.Write("Process", "WindowStyle", CUIWindowStyle.SelectedValue);
755+
ini.Write("Process", "SimulateCmd", SimulateCmd.SelectedValue);
699756
}
700757
else
701758
{
@@ -723,6 +780,8 @@ public class Config
723780
public int FilesSum = 0;
724781
public int CompletedFileNum = 0;
725782

783+
public LinkedList<int> runningProcessesID = new LinkedList<int>();
784+
726785
public string AppPath;
727786
public string ArgsTemplet;
728787
public string UserArgs;
@@ -733,5 +792,6 @@ public class Config
733792
public uint Priority;
734793
public uint ThreadNumber;
735794
public uint WindowStyle;
795+
public bool SimulateCmd;
736796
}
737797
}

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.8.2.9")]
55-
[assembly: AssemblyFileVersion("0.8.2.9")]
54+
[assembly: AssemblyVersion("0.9.2.0")]
55+
[assembly: AssemblyFileVersion("0.9.2.0")]

0 commit comments

Comments
 (0)