Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI 为主的琐碎优化 #453

Merged
merged 19 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions v2rayN/v2rayN/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 77 additions & 54 deletions v2rayN/v2rayN/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ private void InitServersView()

if (statistics != null && statistics.Enable)
{
lvServers.Columns.Add(UIRes.I18N("LvTotalUploadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTotalDownloadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTodayUploadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTodayDownloadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTodayUploadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTotalDownloadDataAmount"), 70, HorizontalAlignment.Left);
lvServers.Columns.Add(UIRes.I18N("LvTotalUploadDataAmount"), 70, HorizontalAlignment.Left);
}
}

Expand Down Expand Up @@ -198,13 +198,13 @@ private void RefreshServersView()
ListViewItem lvItem = null;
if (statistics != null && statistics.Enable)
{
var index = statistics.Statistic.FindIndex(item_ => item_.itemId == item.getItemId());
if (index != -1)
var sItem = statistics.Statistic.Find(item_ => item_.itemId == item.getItemId());
if (sItem != null)
{
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);
totalUp = Utils.HumanFy(sItem.totalUp);
totalDown = Utils.HumanFy(sItem.totalDown);
todayUp = Utils.HumanFy(sItem.todayUp);
todayDown = Utils.HumanFy(sItem.todayDown);
}

lvItem = new ListViewItem(new string[]
Expand All @@ -220,10 +220,10 @@ private void RefreshServersView()
item.network,
item.getSubRemarks(config),
item.testResult,
totalUp,
totalDown,
todayDown,
todayUp,
todayDown
totalDown,
totalUp
});
}
else
Expand All @@ -241,10 +241,6 @@ private void RefreshServersView()
item.network,
item.getSubRemarks(config),
item.testResult
//totalUp,
//totalDown,
//todayUp,
//todayDown,
});
}

Expand Down Expand Up @@ -324,7 +320,7 @@ private void DisplayToolStatus()
{
toolSslSocksPort.Text =
toolSslHttpPort.Text =
toolSslPacPort.Text = "NONE";
toolSslPacPort.Text = "OFF";

toolSslSocksPort.Text = $"{Global.Loopback}:{config.inbound[0].localPort}";

Expand Down Expand Up @@ -468,7 +464,7 @@ private void lvServers_DoubleClick(object sender, EventArgs e)
}
}

private void lvServers_KeyDown(object sender, KeyEventArgs e)
private void lvServers_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control)
{
Expand All @@ -477,6 +473,18 @@ private void lvServers_KeyDown(object sender, KeyEventArgs e)
case Keys.A:
menuSelectAll_Click(null, null);
break;
case Keys.C:
menuExport2ShareUrl_Click(null, null);
break;
case Keys.V:
menuAddServers_Click(null, null);
break;
case Keys.U:
menuMoveTop_Click(null, null);
break;
case Keys.D:
menuMoveBottom_Click(null, null);
break;
case Keys.P:
menuPingServer_Click(null, null);
break;
Expand All @@ -491,20 +499,23 @@ private void lvServers_KeyDown(object sender, KeyEventArgs e)
break;
}
}
switch (e.KeyCode)
else
{
case Keys.Enter:
menuSetDefaultServer_Click(null, null);
break;
case Keys.Delete:
menuRemoveServer_Click(null, null);
break;
case Keys.U:
menuMoveUp_Click(null, null);
break;
case Keys.D:
menuMoveDown_Click(null, null);
break;
switch (e.KeyCode)
{
case Keys.Enter:
menuSetDefaultServer_Click(null, null);
break;
case Keys.Delete:
menuRemoveServer_Click(null, null);
break;
case Keys.U:
menuMoveUp_Click(null, null);
break;
case Keys.D:
menuMoveDown_Click(null, null);
break;
}
}
}

Expand Down Expand Up @@ -546,13 +557,16 @@ private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
{
List<Mode.VmessItem> servers = null;
Utils.DedupServerList(config.vmess, out servers);
int oldCount = config.vmess.Count;
int newCount = servers.Count;
if (servers != null)
{
config.vmess = servers;
}
//刷新
RefreshServers();
LoadV2ray();
UI.Show(string.Format(UIRes.I18N("RemoveDuplicateServerResult"), oldCount, newCount));
}

private void menuCopyServer_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -638,9 +652,9 @@ private void menuExport2ShareUrl_Click(object sender, EventArgs e)
GetLvSelectedIndex();

StringBuilder sb = new StringBuilder();
for (int k = 0; k < lvSelecteds.Count; k++)
foreach (int v in lvSelecteds)
{
string url = ConfigHandler.GetVmessQRCode(config, lvSelecteds[k]);
string url = ConfigHandler.GetVmessQRCode(config, v);
if (Utils.IsNullOrEmpty(url))
{
continue;
Expand All @@ -660,9 +674,9 @@ private void menuExport2SubContent_Click(object sender, EventArgs e)
GetLvSelectedIndex();

StringBuilder sb = new StringBuilder();
for (int k = 0; k < lvSelecteds.Count; k++)
foreach (int v in lvSelecteds)
{
string url = ConfigHandler.GetVmessQRCode(config, lvSelecteds[k]);
string url = ConfigHandler.GetVmessQRCode(config, v);
if (Utils.IsNullOrEmpty(url))
{
continue;
Expand Down Expand Up @@ -809,9 +823,10 @@ private void menuAddSocksServer_Click(object sender, EventArgs e)
private void menuAddServers_Click(object sender, EventArgs e)
{
string clipboardData = Utils.GetClipboardData();
if (AddBatchServers(clipboardData) == 0)
int result = AddBatchServers(clipboardData);
if (result > 0)
{
UI.Show(UIRes.I18N("SuccessfullyImportedServerViaClipboard"));
UI.Show(string.Format(UIRes.I18N("SuccessfullyImportedServerViaClipboard"), result));
}
}

Expand All @@ -823,16 +838,19 @@ private void menuScanScreen_Click(object sender, EventArgs e)

private int AddBatchServers(string clipboardData, string subid = "")
{
if (ConfigHandler.AddBatchServers(ref config, clipboardData, subid) != 0)
int counter;
int _Add()
{
return ConfigHandler.AddBatchServers(ref config, clipboardData, subid);
}
counter = _Add();
if (counter < 1)
{
clipboardData = Utils.Base64Decode(clipboardData);
if (ConfigHandler.AddBatchServers(ref config, clipboardData, subid) != 0)
{
return -1;
}
counter = _Add();
}
RefreshServers();
return 0;
return counter;
}

#endregion
Expand Down Expand Up @@ -970,9 +988,9 @@ private void SetTestResult(int k, string txt)
}
private void ClearTestResult()
{
for (int k = 0; k < lvSelecteds.Count; k++)
foreach (int s in lvSelecteds)
{
SetTestResult(lvSelecteds[k], "");
SetTestResult(s, "");
}
}
private void UpdateSpeedtestHandler(int index, string msg)
Expand Down Expand Up @@ -1006,10 +1024,10 @@ private void UpdateStatisticsHandler(ulong up, ulong down, List<ServerStatItem>
lvServers.SuspendLayout();

var indexStart = 9;
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalUp);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalDown);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayUp);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayDown);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].todayUp);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalDown);
lvServers.Items[i].SubItems[indexStart++].Text = Utils.HumanFy(statistics[index].totalUp);

lvServers.ResumeLayout();
});
Expand Down Expand Up @@ -1056,7 +1074,7 @@ private void MoveServer(EMove eMove)
}
if (ConfigHandler.MoveServer(ref config, index, eMove) == 0)
{
//刷新
//TODO: reload is not good.
RefreshServers();
LoadV2ray();
}
Expand Down Expand Up @@ -1199,7 +1217,7 @@ private void tsbCheckUpdateN_Click(object sender, EventArgs e)
}

AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
downloadHandle.AbsoluteV2rayN(config);
downloadHandle.CheckUpdateAsync("v2rayN");
}

private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1272,7 +1290,7 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
}

AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
downloadHandle.AbsoluteV2rayCore(config);
downloadHandle.CheckUpdateAsync("Core");
}

private void tsbCheckUpdatePACList_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1356,7 +1374,7 @@ private void bgwScan_ProgressChanged(object sender, System.ComponentModel.Progre
}
else
{
if (AddBatchServers(result) == 0)
if (AddBatchServers(result) > 0)
{
UI.Show(UIRes.I18N("SuccessfullyImportedServerViaScan"));
}
Expand Down Expand Up @@ -1416,7 +1434,7 @@ private void tsbSubUpdate_Click(object sender, EventArgs e)
ConfigHandler.RemoveServerViaSubid(ref config, id);
AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}");
RefreshServers();
if (AddBatchServers(result, id) == 0)
if (AddBatchServers(result, id) > 0)
{
}
else
Expand Down Expand Up @@ -1456,10 +1474,15 @@ private void tsbLanguageZhHans_Click(object sender, EventArgs e)
private void SetCurrentLanguage(string value)
{
Utils.RegWriteValue(Global.MyRegPath, Global.MyRegKeyLanguage, value);
Application.Restart();
}

#endregion

#endregion

private void tsbV2rayWebsite_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(Global.v2rayWebsiteUrl);
}
}
}
Loading