mirror of https://github.com/2dust/v2rayN
parent
dcd050eee1
commit
54bebd9a6b
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Handler;
|
||||
using v2rayN.HttpProxyHandler;
|
||||
using v2rayN.Mode;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace v2rayN.Forms
|
||||
{
|
||||
|
@ -17,7 +17,6 @@ namespace v2rayN.Forms
|
|||
private V2rayUpdateHandle v2rayUpdateHandle;
|
||||
private V2rayUpdateHandle v2rayUpdateHandle2;
|
||||
private List<int> lvSelecteds = new List<int>();
|
||||
|
||||
private StatisticsHandler statistics = null;
|
||||
|
||||
#region Window 事件
|
||||
|
@ -44,70 +43,60 @@ namespace v2rayN.Forms
|
|||
v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent;
|
||||
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;
|
||||
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++)
|
||||
try
|
||||
{
|
||||
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)
|
||||
up /= (ulong)(config.statisticsFreshRate / 1000f);
|
||||
down /= (ulong)(config.statisticsFreshRate / 1000f);
|
||||
toolSslServerSpeed.Text = string.Format(
|
||||
"{0}/s↑ | {1}/s↓",
|
||||
Utils.HumanFy(up),
|
||||
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;
|
||||
string unit;
|
||||
Utils.ToHumanReadable(amount, out result, out unit);
|
||||
return $"{string.Format("{0:f2}", result)}{unit}";
|
||||
};
|
||||
totalUp_ = human_fy(statistics[index].totalUp);
|
||||
totalDown_ = human_fy(statistics[index].totalDown);
|
||||
todayUp_ = human_fy(statistics[index].todayUp);
|
||||
todayDown_ = human_fy(statistics[index].todayDown);
|
||||
totalUp_ = Utils.HumanFy(statistics[index].totalUp);
|
||||
totalDown_ = Utils.HumanFy(statistics[index].totalDown);
|
||||
todayUp_ = Utils.HumanFy(statistics[index].todayUp);
|
||||
todayDown_ = Utils.HumanFy(statistics[index].todayDown);
|
||||
}
|
||||
|
||||
datas.Add(new string[] { totalUp_, totalDown_, todayUp_, todayDown_ });
|
||||
}
|
||||
|
||||
datas.Add(new string[] { totalUp_, totalDown_, todayUp_, todayDown_ });
|
||||
}
|
||||
|
||||
lvServers.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
lvServers.SuspendLayout();
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
lvServers.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
var indexStart = 9;
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][0];
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][1];
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][2];
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][3];
|
||||
}
|
||||
lvServers.ResumeLayout();
|
||||
});
|
||||
lvServers.SuspendLayout();
|
||||
for (int i = 0; i < datas.Count; i++)
|
||||
{
|
||||
var indexStart = 9;
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][0];
|
||||
lvServers.Items[i].SubItems[indexStart++].Text = datas[i][1];
|
||||
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)
|
||||
|
@ -179,8 +168,7 @@ namespace v2rayN.Forms
|
|||
Utils.SaveLog("Windows shutdown UnsetProxy");
|
||||
//CloseV2ray();
|
||||
ConfigHandler.ToJsonFile(config);
|
||||
|
||||
statistics?.saveToFile();
|
||||
statistics?.saveToFile();
|
||||
ProxySetting.UnsetProxy();
|
||||
m.Result = (IntPtr)1;
|
||||
break;
|
||||
|
@ -262,17 +250,10 @@ namespace v2rayN.Forms
|
|||
var index = statistics.Statistic.FindIndex(item_ => item_.address == item.address);
|
||||
if (index != -1)
|
||||
{
|
||||
Func<ulong, string> human_fy = (amount) =>
|
||||
{
|
||||
double result;
|
||||
string unit;
|
||||
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);
|
||||
totalUp = Utils.HumanFy(statistics.Statistic[index].totalUp);
|
||||
totalDown = Utils.HumanFy(statistics.Statistic[index].totalDown);
|
||||
todayUp = Utils.HumanFy(statistics.Statistic[index].todayUp);
|
||||
todayDown = Utils.HumanFy(statistics.Statistic[index].todayDown);
|
||||
}
|
||||
|
||||
lvItem = new ListViewItem(new string[]
|
||||
|
@ -509,23 +490,10 @@ namespace v2rayN.Forms
|
|||
menuSelectAll_Click(null, null);
|
||||
break;
|
||||
case Keys.T:
|
||||
// Speed test selected servers
|
||||
if (!config.sysAgentEnabled || config.listenerType != 1)
|
||||
{
|
||||
UI.Show(UIRes.I18N("NeedHttpGlobalProxy"));
|
||||
return;
|
||||
}
|
||||
|
||||
UI.Show(UIRes.I18N("SpeedServerTips"));
|
||||
|
||||
GetLvSelectedIndex();
|
||||
ServerSpeedTest();
|
||||
menuSpeedServer_Click(null, null);
|
||||
break;
|
||||
case Keys.P:
|
||||
// Ping selected servers
|
||||
GetLvSelectedIndex();
|
||||
ClearTestResult();
|
||||
bgwPing.RunWorkerAsync();
|
||||
menuPingServer_Click(null, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1090,7 +1058,7 @@ namespace v2rayN.Forms
|
|||
private void SetTestResult(int k, string 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()
|
||||
{
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
using v2rayN.Handler;
|
||||
|
||||
|
@ -336,15 +333,15 @@ namespace v2rayN.Forms
|
|||
|
||||
config.statisticsFreshRate = (int)cbFreshrate.SelectedValue;
|
||||
|
||||
if(lastEnableStatistics != config.enableStatistics)
|
||||
{
|
||||
/// https://stackoverflow.com/questions/779405/how-do-i-restart-my-c-sharp-winform-application
|
||||
// Shut down the current app instance.
|
||||
Application.Exit();
|
||||
//if(lastEnableStatistics != config.enableStatistics)
|
||||
//{
|
||||
// /// https://stackoverflow.com/questions/779405/how-do-i-restart-my-c-sharp-winform-application
|
||||
// // Shut down the current app instance.
|
||||
// Application.Exit();
|
||||
|
||||
// Restart the app passing "/restart [processId]" as cmd line args
|
||||
Process.Start(Application.ExecutablePath, "/restart " + Process.GetCurrentProcess().Id);
|
||||
}
|
||||
// // Restart the app passing "/restart [processId]" as cmd line args
|
||||
// Process.Start(Application.ExecutablePath, "/restart " + Process.GetCurrentProcess().Id);
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,9 +149,9 @@ namespace v2rayN
|
|||
public const uint InboundAPIPort = 10805;
|
||||
public enum StatisticsFreshRate
|
||||
{
|
||||
quick = 500,
|
||||
medium = 1000,
|
||||
slow = 2000
|
||||
quick = 1000,
|
||||
medium = 2000,
|
||||
slow = 3000
|
||||
}
|
||||
public const string StatisticLogDirectory = "Statistics";
|
||||
public const string StatisticLogOverall = "overall.txt";
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Threading;
|
||||
using v2rayN.Mode;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
|
|
|
@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
|
|||
// 方法是按如下所示使用“*”:
|
||||
//[assembly: AssemblyVersion("1.0.*")]
|
||||
//[assembly: AssemblyVersion("1.0.0")]
|
||||
[assembly: AssemblyFileVersion("2.36")]
|
||||
[assembly: AssemblyFileVersion("2.37")]
|
||||
|
|
|
@ -273,19 +273,19 @@ namespace v2rayN
|
|||
{
|
||||
var factor = 1024u;
|
||||
var KBs = amount / factor;
|
||||
if(KBs > 0)
|
||||
if (KBs > 0)
|
||||
{
|
||||
// multi KB
|
||||
var MBs = KBs / factor;
|
||||
if(MBs > 0)
|
||||
if (MBs > 0)
|
||||
{
|
||||
// multi MB
|
||||
var GBs = MBs / factor;
|
||||
if(GBs > 0)
|
||||
if (GBs > 0)
|
||||
{
|
||||
// multi GB
|
||||
var TBs = GBs / factor;
|
||||
if(TBs > 0)
|
||||
if (TBs > 0)
|
||||
{
|
||||
// 你是魔鬼吗? 用这么多流量
|
||||
result = TBs + GBs % factor / (factor + 0.0);
|
||||
|
@ -303,7 +303,7 @@ namespace v2rayN
|
|||
result = KBs + amount % factor / (factor + 0.0);
|
||||
unit = "KB";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = amount;
|
||||
|
@ -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)
|
||||
{
|
||||
var list = new List<Mode.VmessItem>();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<StartAction>Project</StartAction>
|
||||
<StartArguments>/restart 1001</StartArguments>
|
||||
<StartArguments>
|
||||
</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue