diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs
index 23514364..a74c5b99 100644
--- a/Netch/Controllers/MainController.cs
+++ b/Netch/Controllers/MainController.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
+using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -133,7 +134,15 @@ namespace Netch.Controllers
}
Global.MainForm.StatusText(i18N.Translate("Starting ", pEncryptedProxyController.Name));
- result = await Task.Run(() => pEncryptedProxyController.Start(server, mode));
+ try
+ {
+ result = await Task.Run(() => pEncryptedProxyController.Start(server, mode));
+ }
+ catch (Exception e)
+ {
+ Logging.Error("加密代理启动失败未处理异常: " + e);
+ result = false;
+ }
}
if (result)
@@ -162,7 +171,18 @@ namespace Netch.Controllers
if (pModeController != null)
{
Global.MainForm.StatusText(i18N.Translate("Starting ", pModeController.Name));
- result = await Task.Run(() => pModeController.Start(server, mode));
+ try
+ {
+ result = await Task.Run(() => pModeController.Start(server, mode));
+ }
+ catch (Exception e)
+ {
+ if (e is DllNotFoundException || e is FileNotFoundException)
+ MessageBoxX.Show(e.Message + "\n\n" + i18N.Translate("Missing File or runtime components"), owner: Global.MainForm);
+ else
+ Logging.Error("模式启动失败未处理异常" + e);
+ result = false;
+ }
}
if (result)
diff --git a/Netch/Forms/MainForm.Control.cs b/Netch/Forms/MainForm.Control.cs
index 5acbfac2..de10d2d4 100644
--- a/Netch/Forms/MainForm.Control.cs
+++ b/Netch/Forms/MainForm.Control.cs
@@ -40,22 +40,8 @@ namespace Netch.Forms
var server = ServerComboBox.SelectedItem as Models.Server;
var mode = ModeComboBox.SelectedItem as Models.Mode;
- var result = false;
- try
- {
- // TODO 完善控制器异常处理
- result = await _mainController.Start(server, mode);
- }
- catch (Exception e)
- {
- if (e is DllNotFoundException || e is FileNotFoundException)
- MessageBoxX.Show(e.Message + "\n\n" + i18N.Translate("Missing File or runtime components"), owner: this);
- Netch.Application_OnException(null, new ThreadExceptionEventArgs(e));
- }
-
-
- if (result)
+ if (await _mainController.Start(server, mode))
{
State = State.Started;
_ = Task.Run(() => { Bandwidth.NetTraffic(server, mode, ref _mainController); });
diff --git a/Netch/Forms/Mode/Process.cs b/Netch/Forms/Mode/Process.cs
index c3d8ef13..0664c53e 100644
--- a/Netch/Forms/Mode/Process.cs
+++ b/Netch/Forms/Mode/Process.cs
@@ -11,15 +11,16 @@ namespace Netch.Forms.Mode
{
//用于判断当前窗口是否为编辑模式
private bool EditMode;
+
//被编辑模式坐标
private Models.Mode EditMode_Old;
+
///
- /// 编辑模式
- ///
- /// 模式
+ /// 编辑模式
+ ///
+ /// 模式
public Process(Models.Mode mode)
{
-
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
@@ -38,8 +39,8 @@ namespace Netch.Forms.Mode
FilenameTextBox.Text = mode.FileName;
RemarkTextBox.Text = mode.Remark;
-
}
+
public Process()
{
InitializeComponent();
@@ -51,10 +52,10 @@ namespace Netch.Forms.Mode
}
///
- /// 扫描目录
- ///
- /// 路径
- public void ScanDirectory(string DirName)
+ /// 扫描目录
+ ///
+ /// 路径
+ public void ScanDirectory(string DirName)
{
try
{
@@ -75,16 +76,24 @@ namespace Netch.Forms.Mode
while (DirStack.Count > 0)
{
var DirInfo = new DirectoryInfo(DirStack.Pop());
- foreach (var DirChildInfo in DirInfo.GetDirectories())
+ try
{
- DirStack.Push(DirChildInfo.FullName);
- }
- foreach (var FileChildInfo in DirInfo.GetFiles())
- {
- if (FileChildInfo.Name.EndsWith(".exe") && !RuleListBox.Items.Contains(FileChildInfo.Name))
+ foreach (var DirChildInfo in DirInfo.GetDirectories())
{
- RuleListBox.Items.Add(FileChildInfo.Name);
+ DirStack.Push(DirChildInfo.FullName);
}
+
+ foreach (var FileChildInfo in DirInfo.GetFiles())
+ {
+ if (FileChildInfo.Name.EndsWith(".exe") && !RuleListBox.Items.Contains(FileChildInfo.Name))
+ {
+ RuleListBox.Items.Add(FileChildInfo.Name);
+ }
+ }
+ }
+ catch (Exception)
+ {
+ // ignored
}
}
}
@@ -136,10 +145,11 @@ namespace Netch.Forms.Mode
strip.Items.Add(i18N.Translate("Delete"));
if (e.Button == MouseButtons.Right)
{
- strip.Show(RuleListBox, e.Location);//鼠标右键按下弹出菜单
+ strip.Show(RuleListBox, e.Location); //鼠标右键按下弹出菜单
strip.MouseClick += deleteRule_Click;
}
}
+
void deleteRule_Click(object sender, EventArgs e)
{
if (RuleListBox.SelectedIndex != -1)
@@ -249,7 +259,7 @@ namespace Netch.Forms.Mode
else
{
Global.Settings.ModeFileNameType = 2;
- FilenameTextBox.Text = ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
+ FilenameTextBox.Text = ((long) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
}
Configuration.Save();
@@ -261,6 +271,7 @@ namespace Netch.Forms.Mode
MessageBoxX.Show(i18N.Translate("Please enter a mode filename"));
return;
}
+
var ModeFilename = Path.Combine("mode", FilenameTextBox.Text);
// 如果文件已存在,返回
@@ -332,4 +343,4 @@ namespace Netch.Forms.Mode
}
}
}
-}
+}
\ No newline at end of file