Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed May 15, 2019
2 parents c721d73 + 2725d7f commit a0d9df3
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 96 deletions.
1 change: 1 addition & 0 deletions shadowsocks-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void Main(string[] args)
#endif
#if !_CONSOLE
_viewController = new MenuViewController(_controller);
SystemEvents.SessionEnding += _viewController.Quit_Click;
#endif

_controller.Start();
Expand Down
101 changes: 47 additions & 54 deletions shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,26 @@ private static void SetNotifyIconText(NotifyIcon ni, string text)

private void UpdateTrayIcon()
{
int dpi = 96;
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
int dpi;
using (var graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpi = (int)graphics.DpiX;
}
Configuration config = controller.GetCurrentConfiguration();
bool enabled = config.sysProxyMode != (int)ProxyMode.NoModify && config.sysProxyMode != (int)ProxyMode.Direct;
bool global = config.sysProxyMode == (int)ProxyMode.Global;
bool random = config.random;
var config = controller.GetCurrentConfiguration();
var enabled = config.sysProxyMode != (int)ProxyMode.NoModify && config.sysProxyMode != (int)ProxyMode.Direct;
var global = config.sysProxyMode == (int)ProxyMode.Global;
var random = config.random;

try
{
Bitmap icon = new Bitmap("icon.png");
Icon newIcon = Icon.FromHandle(icon.GetHicon());
var icon = new Bitmap("icon.png");
var newIcon = Icon.FromHandle(icon.GetHicon());
icon.Dispose();
_notifyIcon.Icon = newIcon;
}
catch
{
Bitmap icon = null;
Bitmap icon;
if (dpi < 97)
{
// dpi = 96;
Expand Down Expand Up @@ -193,12 +193,12 @@ private void UpdateTrayIcon()
mul_r = 0.4;
}

Bitmap iconCopy = new Bitmap(icon);
for (int x = 0; x < iconCopy.Width; x++)
var iconCopy = new Bitmap(icon);
for (var x = 0; x < iconCopy.Width; ++x)
{
for (int y = 0; y < iconCopy.Height; y++)
for (var y = 0; y < iconCopy.Height; ++y)
{
Color color = icon.GetPixel(x, y);
var color = icon.GetPixel(x, y);
iconCopy.SetPixel(x, y,

Color.FromArgb((byte)(color.A * mul_a),
Expand All @@ -207,56 +207,47 @@ private void UpdateTrayIcon()
((byte)(color.B * mul_b))));
}
}
Icon newIcon = Icon.FromHandle(iconCopy.GetHicon());
var newIcon = Icon.FromHandle(iconCopy.GetHicon());
icon.Dispose();
iconCopy.Dispose();

_notifyIcon.Icon = newIcon;
}

string strServer = null;
var line3 = string.Empty;
var line4 = string.Empty;
if (random)
{
switch (config.balanceAlgorithm)
strServer = $@"{I18N.GetString("Load balance")}{I18N.GetString(": ")}{I18N.GetString(config.balanceAlgorithm)}";
if (config.randomInGroup)
{
case "OneByOne":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("OneByOne")}";
break;
case "Random":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("Random")}";
break;
case "FastDownloadSpeed":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("FastDownloadSpeed")}";
break;
case "LowLatency":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("LowLatency")}";
break;
case "LowException":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("LowException")}";
break;
case "SelectedFirst":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("SelectedFirst")}";
break;
case "Timer":
strServer = $@"{I18N.GetString("Balance")}{I18N.GetString(": ")}{I18N.GetString("Timer")}";
break;
line3 = $@"{I18N.GetString("Balance in group")}{Environment.NewLine}";
}

if (config.autoBan)
{
line4 = $@"{I18N.GetString("AutoBan")}{Environment.NewLine}";
}
}
else
{
var groupName = config.configs[config.index].group;
var serverName = config.configs[config.index].remarks;
if (string.IsNullOrWhiteSpace(groupName))
{
strServer = string.IsNullOrWhiteSpace(serverName) ? null : serverName;
}
else if (string.IsNullOrWhiteSpace(serverName))
{
strServer = $@"{groupName}";
}
else
if (config.index >= 0 && config.index < config.configs.Count)
{
strServer = $@"{groupName}{I18N.GetString(": ")}{serverName}";
var groupName = config.configs[config.index].group;
var serverName = config.configs[config.index].remarks;
if (string.IsNullOrWhiteSpace(groupName))
{
strServer = string.IsNullOrWhiteSpace(serverName) ? null : serverName;
}
else if (string.IsNullOrWhiteSpace(serverName))
{
strServer = $@"{groupName}";
}
else
{
strServer = $@"{groupName}{I18N.GetString(": ")}{serverName}";
}
}
}

Expand All @@ -266,13 +257,15 @@ private void UpdateTrayIcon()
? global ? I18N.GetString("Global") : I18N.GetString("PAC")
: I18N.GetString("Disable system proxy"))
+ Environment.NewLine;
var line2 = string.IsNullOrWhiteSpace(strServer) ? null : strServer + Environment.NewLine;
var line3 = string.Format(I18N.GetString("Running: Port {0}"), config.localPort); // this feedback is very important because they need to know Shadowsocks is running
var line2 = string.IsNullOrWhiteSpace(strServer) ? null : $@"{strServer}{Environment.NewLine}";
var line5 = string.Format(I18N.GetString("Running: Port {0}"), config.localPort); // this feedback is very important because they need to know Shadowsocks is running

var text = $@"{line1}{line2}{line3}";
if (text.Length > 127 && line1.Length + line3.Length + Environment.NewLine.Length < 128)
var text = $@"{line1}{line2}{line3}{line4}{line5}";
var suffix = $@"...{Environment.NewLine}";
var l = line1.Length + line3.Length + line4.Length + line5.Length + suffix.Length;
if (text.Length > 127 && l < 128)
{
text = $@"{line1}{strServer?.Substring(0, 127 - line1.Length - line3.Length - Environment.NewLine.Length)}{Environment.NewLine}{line3}";
text = $@"{line1}{strServer?.Substring(0, 127 - l)}{suffix}{line3}{line4}{line5}";
}
SetNotifyIconText(_notifyIcon, text);
}
Expand Down Expand Up @@ -1019,7 +1012,7 @@ private void Setting_Click(object sender, EventArgs e)
ShowSettingForm();
}

private void Quit_Click(object sender, EventArgs e)
public void Quit_Click(object sender, EventArgs e)
{
controller.Stop();
if (configForm != null)
Expand Down
20 changes: 15 additions & 5 deletions shadowsocks-csharp/View/ServerLogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public ServerLogForm(ShadowsocksController controller)
continue;
width += ServerDataGrid.Columns[i].Width;
}
this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1;
if (ExistDoubleBufferListViewVerticalScrollBar)
width += SystemInformation.VerticalScrollBarWidth;
this.Width = width + (this.Width - this.ClientSize.Width) + 1;
ServerDataGrid.AutoResizeColumnHeadersHeight();
}
private MenuItem CreateMenuGroup(string text, MenuItem[] items)
Expand All @@ -134,7 +136,7 @@ private void UpdateTitle()
{
this.Text = title_perfix + I18N.GetString("ServerLog") + "("
+ (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
+ "(" + Model.Server.GetForwardServerRef().GetConnections().Count.ToString()+ ")"
+ "(" + Model.Server.GetForwardServerRef().GetConnections().Count.ToString() + ")"
+ " " + I18N.GetString("Version") + UpdateChecker.FullVersion
+ ")";
}
Expand Down Expand Up @@ -681,7 +683,9 @@ private void autosizeColumns()
continue;
width += ServerDataGrid.Columns[i].Width;
}
this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1;
if (ExistDoubleBufferListViewVerticalScrollBar)
width += SystemInformation.VerticalScrollBarWidth;
this.Width = width + (this.Width - this.ClientSize.Width) + 1;
ServerDataGrid.AutoResizeColumnHeadersHeight();
}

Expand Down Expand Up @@ -1139,7 +1143,9 @@ private void ServerLogForm_ResizeEnd(object sender, EventArgs e)
continue;
width += ServerDataGrid.Columns[i].Width;
}
width += SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1;
if (ExistDoubleBufferListViewVerticalScrollBar)
width += SystemInformation.VerticalScrollBarWidth;
width += (this.Width - this.ClientSize.Width) + 1;
ServerDataGrid.Columns[2].Width += this.Width - width;
}

Expand All @@ -1152,8 +1158,12 @@ private void ServerDataGrid_ColumnWidthChanged(object sender, DataGridViewColumn
continue;
width += ServerDataGrid.Columns[i].Width;
}
this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1;
ServerDataGrid.AutoResizeColumnHeadersHeight();
if (ExistDoubleBufferListViewVerticalScrollBar)
width += SystemInformation.VerticalScrollBarWidth;
this.Width = width + (this.Width - this.ClientSize.Width) + 1;
}

private bool ExistDoubleBufferListViewVerticalScrollBar => ServerDataGrid.ColumnHeadersHeight + (controller.GetCurrentConfiguration().configs.Count * ServerDataGrid.RowTemplate.Height) >= ServerDataGrid.Height;
}
}
Loading

0 comments on commit a0d9df3

Please sign in to comment.