pull/43/head 2.37
2dust 2019-08-27 09:02:20 +08:00
parent dcd050eee1
commit 54bebd9a6b
7 changed files with 85 additions and 114 deletions

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.HttpProxyHandler; using v2rayN.HttpProxyHandler;
using v2rayN.Mode; using v2rayN.Mode;
using System.Collections.Generic;
using System.IO;
namespace v2rayN.Forms namespace v2rayN.Forms
{ {
@ -17,7 +17,6 @@ namespace v2rayN.Forms
private V2rayUpdateHandle v2rayUpdateHandle; private V2rayUpdateHandle v2rayUpdateHandle;
private V2rayUpdateHandle v2rayUpdateHandle2; private V2rayUpdateHandle v2rayUpdateHandle2;
private List<int> lvSelecteds = new List<int>(); private List<int> lvSelecteds = new List<int>();
private StatisticsHandler statistics = null; private StatisticsHandler statistics = null;
#region Window 事件 #region Window 事件
@ -44,70 +43,60 @@ namespace v2rayN.Forms
v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent;
if (config.enableStatistics) if (config.enableStatistics)
{ {
statistics = new StatisticsHandler(config, UpdateHandler); statistics = new StatisticsHandler(config, UpdateStatisticsHandler);
} }
} }
private void UpdateHandler(ulong totalUp, ulong totalDown, ulong up, ulong down, List<Mode.ServerStatistics> statistics) private void UpdateStatisticsHandler(ulong totalUp, ulong totalDown, ulong up, ulong down, List<Mode.ServerStatistics> statistics)
{ {
double up_amount = 0.0, down_amount; try
string up_unit = "", down_unit;
up /= (ulong)(config.statisticsFreshRate / 1000f);
down /= (ulong)(config.statisticsFreshRate / 1000f);
Utils.ToHumanReadable(up, out up_amount, out up_unit);
Utils.ToHumanReadable(down, out down_amount, out down_unit);
up_unit += "/s";
down_unit += "/s";
toolSslServerSpeed.Text = string.Format(
"{0:f2} {1}↑ | {2:f2} {3}↓",
up_amount,
up_unit,
down_amount,
down_unit
);
List<string[]> datas = new List<string[]>();
for (int i = 0; i < config.vmess.Count; i++)
{ {
string totalUp_ = string.Empty, up /= (ulong)(config.statisticsFreshRate / 1000f);
totalDown_ = string.Empty, down /= (ulong)(config.statisticsFreshRate / 1000f);
todayUp_ = string.Empty, toolSslServerSpeed.Text = string.Format(
todayDown_ = string.Empty; "{0}/s↑ | {1}/s↓",
var index = statistics.FindIndex(item_ => (config.vmess[i].address == item_.address && config.vmess[i].port == item_.port && config.vmess[i].path == item_.path)); Utils.HumanFy(up),
if (index != -1) Utils.HumanFy(down)
);
List<string[]> datas = new List<string[]>();
for (int i = 0; i < config.vmess.Count; i++)
{ {
Func<ulong, string> human_fy = (amount) => string totalUp_ = string.Empty,
totalDown_ = string.Empty,
todayUp_ = string.Empty,
todayDown_ = string.Empty;
var index = statistics.FindIndex(item_ => (config.vmess[i].address == item_.address && config.vmess[i].port == item_.port && config.vmess[i].path == item_.path));
if (index != -1)
{ {
double result; totalUp_ = Utils.HumanFy(statistics[index].totalUp);
string unit; totalDown_ = Utils.HumanFy(statistics[index].totalDown);
Utils.ToHumanReadable(amount, out result, out unit); todayUp_ = Utils.HumanFy(statistics[index].todayUp);
return $"{string.Format("{0:f2}", result)}{unit}"; todayDown_ = Utils.HumanFy(statistics[index].todayDown);
}; }
totalUp_ = human_fy(statistics[index].totalUp);
totalDown_ = human_fy(statistics[index].totalDown); datas.Add(new string[] { totalUp_, totalDown_, todayUp_, todayDown_ });
todayUp_ = human_fy(statistics[index].todayUp);
todayDown_ = human_fy(statistics[index].todayDown);
} }
datas.Add(new string[] { totalUp_, totalDown_, todayUp_, todayDown_ }); lvServers.Invoke((MethodInvoker)delegate
}
lvServers.Invoke((MethodInvoker)delegate
{
lvServers.SuspendLayout();
for (int i = 0; i < datas.Count; i++)
{ {
var indexStart = 9; lvServers.SuspendLayout();
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][0]; for (int i = 0; i < datas.Count; i++)
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][1]; {
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][2]; var indexStart = 9;
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][3]; lvServers.Items[i].SubItems[indexStart++].Text = datas[i][0];
} lvServers.Items[i].SubItems[indexStart++].Text = datas[i][1];
lvServers.ResumeLayout(); lvServers.Items[i].SubItems[indexStart++].Text = datas[i][2];
}); lvServers.Items[i].SubItems[indexStart++].Text = datas[i][3];
}
lvServers.ResumeLayout();
});
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
} }
private void MainForm_VisibleChanged(object sender, EventArgs e) private void MainForm_VisibleChanged(object sender, EventArgs e)
@ -179,8 +168,7 @@ namespace v2rayN.Forms
Utils.SaveLog("Windows shutdown UnsetProxy"); Utils.SaveLog("Windows shutdown UnsetProxy");
//CloseV2ray(); //CloseV2ray();
ConfigHandler.ToJsonFile(config); ConfigHandler.ToJsonFile(config);
statistics?.saveToFile();
statistics?.saveToFile();
ProxySetting.UnsetProxy(); ProxySetting.UnsetProxy();
m.Result = (IntPtr)1; m.Result = (IntPtr)1;
break; break;
@ -262,17 +250,10 @@ namespace v2rayN.Forms
var index = statistics.Statistic.FindIndex(item_ => item_.address == item.address); var index = statistics.Statistic.FindIndex(item_ => item_.address == item.address);
if (index != -1) if (index != -1)
{ {
Func<ulong, string> human_fy = (amount) => totalUp = Utils.HumanFy(statistics.Statistic[index].totalUp);
{ totalDown = Utils.HumanFy(statistics.Statistic[index].totalDown);
double result; todayUp = Utils.HumanFy(statistics.Statistic[index].todayUp);
string unit; todayDown = Utils.HumanFy(statistics.Statistic[index].todayDown);
Utils.ToHumanReadable(amount, out result, out unit);
return $"{string.Format("{0:f2}", result)}{unit}";
};
totalUp = human_fy(statistics.Statistic[index].totalUp);
totalDown = human_fy(statistics.Statistic[index].totalDown);
todayUp = human_fy(statistics.Statistic[index].todayUp);
todayDown = human_fy(statistics.Statistic[index].todayDown);
} }
lvItem = new ListViewItem(new string[] lvItem = new ListViewItem(new string[]
@ -509,23 +490,10 @@ namespace v2rayN.Forms
menuSelectAll_Click(null, null); menuSelectAll_Click(null, null);
break; break;
case Keys.T: case Keys.T:
// Speed test selected servers menuSpeedServer_Click(null, null);
if (!config.sysAgentEnabled || config.listenerType != 1)
{
UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
return;
}
UI.Show(UIRes.I18N("SpeedServerTips"));
GetLvSelectedIndex();
ServerSpeedTest();
break; break;
case Keys.P: case Keys.P:
// Ping selected servers menuPingServer_Click(null, null);
GetLvSelectedIndex();
ClearTestResult();
bgwPing.RunWorkerAsync();
break; break;
} }
} }
@ -1090,7 +1058,7 @@ namespace v2rayN.Forms
private void SetTestResult(int k, string txt) private void SetTestResult(int k, string txt)
{ {
config.vmess[k].testResult = txt; config.vmess[k].testResult = txt;
lvServers.Items[k].SubItems[lvServers.Items[k].SubItems.Count - 1].Text = txt; lvServers.Items[k].SubItems[8].Text = txt;
} }
private void ClearTestResult() private void ClearTestResult()
{ {

View File

@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms; using System.Windows.Forms;
using v2rayN.Handler; using v2rayN.Handler;
@ -336,15 +333,15 @@ namespace v2rayN.Forms
config.statisticsFreshRate = (int)cbFreshrate.SelectedValue; config.statisticsFreshRate = (int)cbFreshrate.SelectedValue;
if(lastEnableStatistics != config.enableStatistics) //if(lastEnableStatistics != config.enableStatistics)
{ //{
/// https://stackoverflow.com/questions/779405/how-do-i-restart-my-c-sharp-winform-application // /// https://stackoverflow.com/questions/779405/how-do-i-restart-my-c-sharp-winform-application
// Shut down the current app instance. // // Shut down the current app instance.
Application.Exit(); // Application.Exit();
// Restart the app passing "/restart [processId]" as cmd line args // // Restart the app passing "/restart [processId]" as cmd line args
Process.Start(Application.ExecutablePath, "/restart " + Process.GetCurrentProcess().Id); // Process.Start(Application.ExecutablePath, "/restart " + Process.GetCurrentProcess().Id);
} //}
return 0; return 0;
} }

View File

@ -149,9 +149,9 @@ namespace v2rayN
public const uint InboundAPIPort = 10805; public const uint InboundAPIPort = 10805;
public enum StatisticsFreshRate public enum StatisticsFreshRate
{ {
quick = 500, quick = 1000,
medium = 1000, medium = 2000,
slow = 2000 slow = 3000
} }
public const string StatisticLogDirectory = "Statistics"; public const string StatisticLogDirectory = "Statistics";
public const string StatisticLogOverall = "overall.txt"; public const string StatisticLogOverall = "overall.txt";

View File

@ -1,13 +1,10 @@
using System; using System;
using System.Threading;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Diagnostics;
using System.IO;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading;
using System.Diagnostics;
using v2rayN.Mode; using v2rayN.Mode;
namespace v2rayN.Handler namespace v2rayN.Handler

View File

@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")] //[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("2.36")] [assembly: AssemblyFileVersion("2.37")]

View File

@ -273,19 +273,19 @@ namespace v2rayN
{ {
var factor = 1024u; var factor = 1024u;
var KBs = amount / factor; var KBs = amount / factor;
if(KBs > 0) if (KBs > 0)
{ {
// multi KB // multi KB
var MBs = KBs / factor; var MBs = KBs / factor;
if(MBs > 0) if (MBs > 0)
{ {
// multi MB // multi MB
var GBs = MBs / factor; var GBs = MBs / factor;
if(GBs > 0) if (GBs > 0)
{ {
// multi GB // multi GB
var TBs = GBs / factor; var TBs = GBs / factor;
if(TBs > 0) if (TBs > 0)
{ {
// 你是魔鬼吗? 用这么多流量 // 你是魔鬼吗? 用这么多流量
result = TBs + GBs % factor / (factor + 0.0); result = TBs + GBs % factor / (factor + 0.0);
@ -311,12 +311,20 @@ namespace v2rayN
} }
} }
public static string HumanFy(ulong amount)
{
double result;
string unit;
ToHumanReadable(amount, out result, out unit);
return $"{string.Format("{0:f2}", result)}{unit}";
}
public static void DedupServerList(List<Mode.VmessItem> source, out List<Mode.VmessItem> result) public static void DedupServerList(List<Mode.VmessItem> source, out List<Mode.VmessItem> result)
{ {
var list = new List<Mode.VmessItem>(); var list = new List<Mode.VmessItem>();
foreach (var item in source) foreach (var item in source)
{ {
if(!list.Exists(i => item.address == i.address && item.port == i.port && item.path == i.path)) if (!list.Exists(i => item.address == i.address && item.port == i.port && item.path == i.path))
{ {
list.Add(item); list.Add(item);
} }

View File

@ -16,6 +16,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Project</StartAction> <StartAction>Project</StartAction>
<StartArguments>/restart 1001</StartArguments> <StartArguments>
</StartArguments>
</PropertyGroup> </PropertyGroup>
</Project> </Project>