mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
扫描文件夹异常处理,主控制器异常处理改进
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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); });
|
||||
|
||||
@@ -11,15 +11,16 @@ namespace Netch.Forms.Mode
|
||||
{
|
||||
//用于判断当前窗口是否为编辑模式
|
||||
private bool EditMode;
|
||||
|
||||
//被编辑模式坐标
|
||||
private Models.Mode EditMode_Old;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑模式
|
||||
/// </summary>
|
||||
/// <param name="mode">模式</param>
|
||||
/// 编辑模式
|
||||
/// </summary>
|
||||
/// <param name="mode">模式</param>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫描目录
|
||||
/// </summary>
|
||||
/// <param name="DirName">路径</param>
|
||||
public void ScanDirectory(string DirName)
|
||||
/// 扫描目录
|
||||
/// </summary>
|
||||
/// <param name="DirName">路径</param>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user