From 764009ebffa4dfee14f31feca26daffbcf358726 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Sun, 9 Aug 2020 03:54:57 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B8=85=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Netch/Controllers/Mode/NFController.cs | 41 --------------------------
Netch/Forms/MainForm.cs | 6 ++--
Netch/Global.cs | 5 ++--
Netch/Netch.cs | 20 +++++--------
Netch/Utils/Logging.cs | 2 +-
5 files changed, 13 insertions(+), 61 deletions(-)
diff --git a/Netch/Controllers/Mode/NFController.cs b/Netch/Controllers/Mode/NFController.cs
index 697e9711..0f6103e9 100644
--- a/Netch/Controllers/Mode/NFController.cs
+++ b/Netch/Controllers/Mode/NFController.cs
@@ -214,35 +214,6 @@ namespace Netch.Controllers
return true;
}
- // private new void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
- // {
- // if (!Write(e.Data)) return;
- // if (State == State.Starting)
- // {
- // if (Instance.HasExited)
- // State = State.Stopped;
- // else if (e.Data.Contains("Started"))
- // State = State.Started;
- // else if (e.Data.Contains("Failed") || e.Data.Contains("Unable")) State = State.Stopped;
- // }
- // else if (State == State.Started)
- // {
- // if (e.Data.StartsWith("[APP][Bandwidth]"))
- // {
- // var splited = e.Data.Replace("[APP][Bandwidth]", "").Trim().Split(',');
- // if (splited.Length == 2)
- // {
- // var uploadSplited = splited[0].Split(':');
- // var downloadSplited = splited[1].Split(':');
- //
- // if (uploadSplited.Length == 2 && downloadSplited.Length == 2)
- // if (long.TryParse(uploadSplited[1], out var upload) && long.TryParse(downloadSplited[1], out var download))
- // Task.Run(() => OnBandwidthUpdated(upload, download));
- // }
- // }
- // }
- // }
-
public override void Stop()
{
Task.Run(() =>
@@ -253,17 +224,5 @@ namespace Netch.Controllers
});
StopInstance();
}
-
- ///
- /// 流量变动事件
- ///
- public event BandwidthUpdateHandler OnBandwidthUpdated;
-
- ///
- /// 流量变动处理器
- ///
- /// 上传
- /// 下载
- public delegate void BandwidthUpdateHandler(long upload, long download);
}
}
\ No newline at end of file
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index 978e911f..1f67f572 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -237,8 +237,7 @@ namespace Netch.Forms
Visible = true;
ShowInTaskbar = true; // 显示在系统任务栏
- WindowState = FormWindowState.Normal; // 还原窗体
- NotifyIcon.Visible = true; // 托盘图标隐藏
+ WindowState = FormWindowState.Normal; // 还原窗体
return;
}
@@ -455,8 +454,7 @@ namespace Netch.Forms
{
Visible = true;
ShowInTaskbar = true; //显示在系统任务栏
- WindowState = FormWindowState.Normal; //还原窗体
- NotifyIcon.Visible = true; //托盘图标隐藏
+ WindowState = FormWindowState.Normal; //还原窗体
}
Activate();
diff --git a/Netch/Global.cs b/Netch/Global.cs
index feaf4336..92dafa35 100644
--- a/Netch/Global.cs
+++ b/Netch/Global.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
+using System.Windows.Forms;
namespace Netch
{
@@ -12,8 +13,8 @@ namespace Netch
/// 换行
///
public const string EOF = "\r\n";
-
- public static readonly string NetchDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd();
+
+ public static readonly string NetchDir = Application.StartupPath;
///
/// 主窗体的静态实例
diff --git a/Netch/Netch.cs b/Netch/Netch.cs
index db7f4546..e99b7395 100644
--- a/Netch/Netch.cs
+++ b/Netch/Netch.cs
@@ -21,7 +21,7 @@ namespace Netch
using (var mutex = new Mutex(false, "Global\\Netch"))
{
// 设置当前目录
- Directory.SetCurrentDirectory(Application.StartupPath);
+ Directory.SetCurrentDirectory(Global.NetchDir);
// 清理上一次的日志文件,防止淤积占用磁盘空间
if (Directory.Exists("logging"))
@@ -40,7 +40,7 @@ namespace Netch
}
// 预创建目录
- var directories = new[] { "mode", "data", "i18n", "logging" };
+ var directories = new[] {"mode", "data", "i18n", "logging"};
foreach (var item in directories)
{
// 检查是否已经存在
@@ -57,11 +57,11 @@ namespace Netch
// 加载语言
i18N.Load(Global.Settings.Language);
- // 记录当前系统语言
- Logging.Info($"当前语言:{Global.Settings.Language}");
- Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}");
- Logging.Info($"主程序创建日期: {File.GetCreationTime(Global.NetchDir + "\\Netch.exe"):yyyy-M-d HH:mm}");
- Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}");
+ Task.Run(() =>
+ {
+ Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}");
+ Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}");
+ });
// 检查是否已经运行
if (!mutex.WaitOne(0, false))
@@ -88,12 +88,6 @@ namespace Netch
{
Logging.Error(e.Exception.ToString());
Utils.Utils.Open(Logging.LogFile);
- /*if (!e.Exception.ToString().Contains("ComboBox"))
- {
- MessageBox.Show(e.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }*/
-
- //Application.Exit();
}
}
}
\ No newline at end of file
diff --git a/Netch/Utils/Logging.cs b/Netch/Utils/Logging.cs
index 9d4dbc29..a527a945 100644
--- a/Netch/Utils/Logging.cs
+++ b/Netch/Utils/Logging.cs
@@ -4,7 +4,7 @@ using Netch.Models;
namespace Netch.Utils
{
- public static partial class Logging
+ public static class Logging
{
public const string LogFile = "logging\\application.log";