Browse Source

ListViewItem引用列名称,增加代码可靠性

pull/572/head
YFdyh000 5 years ago
parent
commit
a6664fbc01
  1. 71
      v2rayN/v2rayN/Forms/MainForm.cs

71
v2rayN/v2rayN/Forms/MainForm.cs

@ -193,8 +193,12 @@ namespace v2rayN.Forms
VmessItem item = config.vmess[k]; VmessItem item = config.vmess[k];
ListViewItem lvItem = null; void _addSubItem(ListViewItem i, string name, string text)
if (statistics != null && statistics.Enable) {
i.SubItems.Add(new ListViewItem.ListViewSubItem() { Name = name, Text = text });
}
bool stats = statistics != null && statistics.Enable;
if (stats)
{ {
ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId()); ServerStatItem sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId());
if (sItem != null) if (sItem != null)
@ -204,43 +208,27 @@ namespace v2rayN.Forms
todayUp = Utils.HumanFy(sItem.todayUp); todayUp = Utils.HumanFy(sItem.todayUp);
todayDown = Utils.HumanFy(sItem.todayDown); todayDown = Utils.HumanFy(sItem.todayDown);
} }
lvItem = new ListViewItem(new string[]
{
def,
((EConfigType)item.configType).ToString(),
item.remarks,
item.address,
item.port.ToString(),
//item.id,
//item.alterId.ToString(),
item.security,
item.network,
item.getSubRemarks(config),
item.testResult,
todayDown,
todayUp,
totalDown,
totalUp
});
} }
else ListViewItem lvItem = new ListViewItem();
_addSubItem(lvItem, "enabled", def);
_addSubItem(lvItem, "type", ((EConfigType)item.configType).ToString());
_addSubItem(lvItem, "remarks", item.remarks);
_addSubItem(lvItem, "address", item.address);
_addSubItem(lvItem, "port", item.port.ToString());
//_addSubItem(lvItem, "id", item.id);
//_addSubItem(lvItem, "alterId", item.alterId.ToString());
_addSubItem(lvItem, "security", item.security);
_addSubItem(lvItem, "network", item.network);
_addSubItem(lvItem, "SubRemarks", item.getSubRemarks(config));
_addSubItem(lvItem, "testResult", item.testResult);
if (stats)
{ {
lvItem = new ListViewItem(new string[] _addSubItem(lvItem, "todayDown", todayDown);
{ _addSubItem(lvItem, "todayUp", todayUp);
def, _addSubItem(lvItem, "totalDown", totalDown);
((EConfigType)item.configType).ToString(), _addSubItem(lvItem, "totalUp", totalUp);
item.remarks,
item.address,
item.port.ToString(),
//item.id,
//item.alterId.ToString(),
item.security,
item.network,
item.getSubRemarks(config),
item.testResult
});
} }
if (k % 2 == 1) // 隔行着色 if (k % 2 == 1) // 隔行着色
{ {
lvItem.BackColor = Color.WhiteSmoke; lvItem.BackColor = Color.WhiteSmoke;
@ -1021,7 +1009,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[8].Text = txt; lvServers.Items[k].SubItems["testResult"].Text = txt;
} }
private void ClearTestResult() private void ClearTestResult()
{ {
@ -1060,11 +1048,10 @@ namespace v2rayN.Forms
{ {
lvServers.SuspendLayout(); lvServers.SuspendLayout();
int indexStart = 9; lvServers.Items[i].SubItems["todayDown"].Text = Utils.HumanFy(statistics[index].todayDown);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayDown); lvServers.Items[i].SubItems["todayUp"].Text = Utils.HumanFy(statistics[index].todayUp);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayUp); lvServers.Items[i].SubItems["totalDown"].Text = Utils.HumanFy(statistics[index].totalDown);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalDown); lvServers.Items[i].SubItems["totalUp"].Text = Utils.HumanFy(statistics[index].totalUp);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalUp);
lvServers.ResumeLayout(); lvServers.ResumeLayout();
}); });

Loading…
Cancel
Save