diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs
index cf4406b0..b760d3ea 100755
--- a/shadowsocks-csharp/Util/Util.cs
+++ b/shadowsocks-csharp/Util/Util.cs
@@ -9,6 +9,20 @@ using Shadowsocks.Controller;
namespace Shadowsocks.Util
{
+ public struct BandwidthScaleInfo
+ {
+ public float value;
+ public string unit_name;
+ public long unit;
+
+ public BandwidthScaleInfo(float value, string unit_name, long unit)
+ {
+ this.value = value;
+ this.unit_name = unit_name;
+ this.unit = unit;
+ }
+ }
+
public class Utils
{
private static bool? _portableMode;
@@ -114,7 +128,7 @@ namespace Shadowsocks.Util
public static string FormatBandwidth(long n)
{
var result = GetBandwidthScale(n);
- return $"{result.Item1:0.##}{result.Item2}";
+ return $"{result.value:0.##}{result.unit_name}";
}
public static string FormatBytes(long bytes)
@@ -127,32 +141,32 @@ namespace Shadowsocks.Util
const long E = P * 1024L;
if (bytes >= P * 990)
- return (bytes / (double)E).ToString("F5") + "EB";
+ return (bytes / (double)E).ToString("F5") + "EiB";
if (bytes >= T * 990)
- return (bytes / (double)P).ToString("F5") + "PB";
+ return (bytes / (double)P).ToString("F5") + "PiB";
if (bytes >= G * 990)
- return (bytes / (double)T).ToString("F5") + "TB";
+ return (bytes / (double)T).ToString("F5") + "TiB";
if (bytes >= M * 990)
{
- return (bytes / (double)G).ToString("F4") + "GB";
+ return (bytes / (double)G).ToString("F4") + "GiB";
}
if (bytes >= M * 100)
{
- return (bytes / (double)M).ToString("F1") + "MB";
+ return (bytes / (double)M).ToString("F1") + "MiB";
}
if (bytes >= M * 10)
{
- return (bytes / (double)M).ToString("F2") + "MB";
+ return (bytes / (double)M).ToString("F2") + "MiB";
}
if (bytes >= K * 990)
{
- return (bytes / (double)M).ToString("F3") + "MB";
+ return (bytes / (double)M).ToString("F3") + "MiB";
}
if (bytes > K * 2)
{
- return (bytes / (double)K).ToString("F1") + "KB";
+ return (bytes / (double)K).ToString("F1") + "KiB";
}
- return bytes.ToString();
+ return bytes.ToString() + "B";
}
///
@@ -160,11 +174,9 @@ namespace Shadowsocks.Util
///
/// Raw bandwidth
///
- /// Item1: float, bandwidth with suitable scale (eg. 56)
- /// Item2: string, scale unit name (eg. KiB)
- /// Item3: long, scale unit (eg. 1024)
+ /// The BandwidthScaleInfo struct
///
- public static Tuple GetBandwidthScale(long n)
+ public static BandwidthScaleInfo GetBandwidthScale(long n)
{
long scale = 1;
float f = n;
@@ -193,7 +205,7 @@ namespace Shadowsocks.Util
scale <<= 10;
unit = "TiB";
}
- return new Tuple(f, unit, scale);
+ return new BandwidthScaleInfo(f, unit, scale);
}
public static RegistryKey OpenUserRegKey( string name, bool writable ) {
diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs
index 3684adee..c29ff82d 100644
--- a/shadowsocks-csharp/View/LogForm.cs
+++ b/shadowsocks-csharp/View/LogForm.cs
@@ -14,6 +14,18 @@ using System.Text;
namespace Shadowsocks.View
{
+ struct TrafficInfo
+ {
+ public long inbound;
+ public long outbound;
+
+ public TrafficInfo(long inbound, long outbound)
+ {
+ this.inbound = inbound;
+ this.outbound = outbound;
+ }
+ }
+
public partial class LogForm : Form
{
long lastOffset;
@@ -24,7 +36,7 @@ namespace Shadowsocks.View
#region chart
long lastMaxSpeed;
- public ShadowsocksController.QueueLast> traffic = new ShadowsocksController.QueueLast>();
+ ShadowsocksController.QueueLast traffic = new ShadowsocksController.QueueLast();
#endregion
public LogForm(ShadowsocksController controller, string filename)
@@ -54,7 +66,7 @@ namespace Shadowsocks.View
List outboundPoints = new List();
TextAnnotation inboundAnnotation = new TextAnnotation();
TextAnnotation outboundAnnotation = new TextAnnotation();
- Tuple bandwidthScale;
+ BandwidthScaleInfo bandwidthScale;
const long minScale = 50;
long maxSpeed = 0;
long lastInbound, lastOutbound;
@@ -65,12 +77,12 @@ namespace Shadowsocks.View
return;
foreach (var trafficPerSecond in traffic)
{
- inboundPoints.Add(trafficPerSecond.Item1);
- outboundPoints.Add(trafficPerSecond.Item2);
- maxSpeed = Math.Max(maxSpeed, Math.Max(trafficPerSecond.Item1, trafficPerSecond.Item2));
+ inboundPoints.Add(trafficPerSecond.inbound);
+ outboundPoints.Add(trafficPerSecond.outbound);
+ maxSpeed = Math.Max(maxSpeed, Math.Max(trafficPerSecond.inbound, trafficPerSecond.outbound));
}
- lastInbound = traffic.Last().Item1;
- lastOutbound = traffic.Last().Item2;
+ lastInbound = traffic.Last().inbound;
+ lastOutbound = traffic.Last().outbound;
}
if (maxSpeed > 0)
@@ -87,15 +99,15 @@ namespace Shadowsocks.View
bandwidthScale = Utils.GetBandwidthScale(maxSpeed);
//rescale the original data points, since it is List, .ForEach does not work
- inboundPoints = inboundPoints.Select(p => p / bandwidthScale.Item3).ToList();
- outboundPoints = outboundPoints.Select(p => p / bandwidthScale.Item3).ToList();
+ inboundPoints = inboundPoints.Select(p => p / bandwidthScale.unit).ToList();
+ outboundPoints = outboundPoints.Select(p => p / bandwidthScale.unit).ToList();
if (trafficChart.IsHandleCreated)
{
trafficChart.Series["Inbound"].Points.DataBindY(inboundPoints);
trafficChart.Series["Outbound"].Points.DataBindY(outboundPoints);
- trafficChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:0.##} " + bandwidthScale.Item2;
- trafficChart.ChartAreas[0].AxisY.Maximum = bandwidthScale.Item1;
+ trafficChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:0.##} " + bandwidthScale.unit_name;
+ trafficChart.ChartAreas[0].AxisY.Maximum = bandwidthScale.value;
inboundAnnotation.AnchorDataPoint = trafficChart.Series["Inbound"].Points.Last();
inboundAnnotation.Text = Utils.FormatBandwidth(lastInbound);
outboundAnnotation.AnchorDataPoint = trafficChart.Series["Outbound"].Points.Last();
@@ -110,10 +122,10 @@ namespace Shadowsocks.View
{
lock (this)
{
- traffic = new ShadowsocksController.QueueLast>();
+ traffic = new ShadowsocksController.QueueLast();
foreach (var trafficPerSecond in controller.traffic)
{
- traffic.Enqueue(new Tuple(trafficPerSecond.inboundIncreasement, trafficPerSecond.outboundIncreasement));
+ traffic.Enqueue(new TrafficInfo(trafficPerSecond.inboundIncreasement, trafficPerSecond.outboundIncreasement));
}
}
}