Skip to content

Commit

Permalink
Merge branch 'develop' into PR-82
Browse files Browse the repository at this point in the history
# Conflicts:
#	shadowsocks-csharp/Model/Configuration.cs
#	shadowsocks-csharp/View/SettingsForm.cs
  • Loading branch information
Akkariiin committed Apr 19, 2019
2 parents 4e849dd + 5ccd1ec commit 1d0f398
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 64 deletions.
2 changes: 2 additions & 0 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class Configuration

public bool autoBan;
public bool checkSwitchAutoCloseAll;
public bool logEnable;
public bool sameHostForSameTarget;

public int keepVisitTime;
Expand Down Expand Up @@ -438,6 +439,7 @@ public void CopyFrom(Configuration config)
authPass = config.authPass;
autoBan = config.autoBan;
checkSwitchAutoCloseAll = config.checkSwitchAutoCloseAll;
logEnable = config.logEnable;
sameHostForSameTarget = config.sameHostForSameTarget;
keepVisitTime = config.keepVisitTime;
isHideTips = config.isHideTips;
Expand Down
12 changes: 9 additions & 3 deletions shadowsocks-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ static void Main(string[] args)
if (try_times > 0)
Logging.save_to_file = false;
#endif

_controller = new ShadowsocksController();
HostMap.Instance().LoadHostFile();

// Logging
Configuration cfg = _controller.GetConfiguration();
Logging.save_to_file = cfg.logEnable;

//#if !DEBUG
Logging.OpenLogFile();
//#endif
_controller = new ShadowsocksController();
HostMap.Instance().LoadHostFile();

#if _DOTNET_4_0
// Enable Modern TLS when .NET 4.5+ installed.
Expand All @@ -91,7 +97,7 @@ static void Main(string[] args)
_viewController = new MenuViewController(_controller);
#endif

_controller.Start();
_controller.Start();

#if !_CONSOLE
//Util.Utils.ReleaseMemory();
Expand Down
126 changes: 65 additions & 61 deletions shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
using Shadowsocks.Model;
using Shadowsocks.Properties;
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using ZXing;
using ZXing.Common;
using ZXing.QrCode;
using System.Threading;
using System.Text.RegularExpressions;

namespace Shadowsocks.View
{
Expand Down Expand Up @@ -73,6 +70,9 @@ public class MenuViewController
private bool configfrom_open = false;
private List<EventParams> eventList = new List<EventParams>();

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern bool DestroyIcon(IntPtr handle);

public MenuViewController(ShadowsocksController controller)
{
this.controller = controller;
Expand Down Expand Up @@ -115,13 +115,13 @@ private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (timerDelayCheckUpdate != null)
{
if (timerDelayCheckUpdate.Interval <= 1000.0 * 30)
{
timerDelayCheckUpdate.Interval = 1000.0 * 60 * 5;
}
else
//if (timerDelayCheckUpdate.Interval <= 1000.0 * 30)
//{
// timerDelayCheckUpdate.Interval = 1000.0 * 60 * 5;
//}
//else
{
timerDelayCheckUpdate.Interval = 1000.0 * 60 * 60 * 2;
timerDelayCheckUpdate.Interval = 1000.0 * 60 * 60 * 6;
}
}
updateChecker.CheckUpdate(controller.GetCurrentConfiguration());
Expand All @@ -140,7 +140,7 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e)

private void UpdateTrayIcon()
{
int dpi;
int dpi = 96;
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpi = (int)graphics.DpiX;
Expand All @@ -150,62 +150,64 @@ private void UpdateTrayIcon()
bool global = config.sysProxyMode == (int)ProxyMode.Global;
bool random = config.random;

try
//try
//{
// Bitmap icon = new Bitmap("icon.png");
// Icon newIcon = Icon.FromHandle(icon.GetHicon());
// _notifyIcon.Icon = newIcon;
// DestroyIcon(newIcon.Handle);
//}
//catch
//{
Bitmap icon = null;
if (dpi < 97)
{
using (Bitmap icon = new Bitmap("icon.png"))
{
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
}
// dpi = 96;
icon = Resources.ss16;
}
catch
else if (dpi < 121)
{
Bitmap icon = null;
if (dpi < 97)
{
// dpi = 96;
icon = Resources.ss16;
}
else if (dpi < 121)
{
// dpi = 120;
icon = Resources.ss20;
}
else
{
icon = Resources.ss24;
}
double mul_a = 1.0, mul_r = 1.0, mul_g = 1.0, mul_b = 1.0;
if (!enabled)
{
mul_g = 0.4;
}
else if (!global)
{
mul_b = 0.4;
mul_g = 0.8;
}
if (!random)
{
mul_r = 0.4;
}
// dpi = 120;
icon = Resources.ss20;
}
else
{
icon = Resources.ss24;
}
double mul_a = 1.0, mul_r = 1.0, mul_g = 1.0, mul_b = 1.0;
if (!enabled)
{
mul_g = 0.4;
}
else if (!global)
{
mul_b = 0.4;
mul_g = 0.8;
}
if (!random)
{
mul_r = 0.4;
}

using (Bitmap iconCopy = new Bitmap(icon))
Bitmap iconCopy = new Bitmap(icon);
{
for (int x = 0; x < iconCopy.Width; x++)
{
for (int x = 0; x < iconCopy.Width; x++)
for (int y = 0; y < iconCopy.Height; y++)
{
for (int y = 0; y < iconCopy.Height; y++)
{
Color color = icon.GetPixel(x, y);
iconCopy.SetPixel(x, y,
Color.FromArgb((byte)(color.A * mul_a),
((byte)(color.R * mul_r)),
((byte)(color.G * mul_g)),
((byte)(color.B * mul_b))));
}
Color color = icon.GetPixel(x, y);
iconCopy.SetPixel(x, y,
Color.FromArgb((byte)(color.A * mul_a),
(byte)(color.R * mul_r),
(byte)(color.G * mul_g),
(byte)(color.B * mul_b)));
}
_notifyIcon.Icon = Icon.FromHandle(iconCopy.GetHicon());
}
Icon newIcon = Icon.FromHandle(iconCopy.GetHicon());
_notifyIcon.Icon = newIcon;
DestroyIcon(newIcon.Handle);
}
//}

// we want to show more details but notify icon title is limited to 63 characters
string text = (enabled ?
Expand Down Expand Up @@ -309,12 +311,14 @@ private void controller_ToggleModeChanged(object sender, EventArgs e)
{
Configuration config = controller.GetCurrentConfiguration();
UpdateSysProxyMode(config);
UpdateTrayIcon();
}

private void controller_ToggleRuleModeChanged(object sender, EventArgs e)
{
Configuration config = controller.GetCurrentConfiguration();
UpdateProxyRule(config);
UpdateTrayIcon();
}

void controller_FileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
Expand Down Expand Up @@ -589,7 +593,7 @@ void updateFreeNodeChecker_NewFreeNodeFound(object sender, EventArgs e)
controller.SaveServersConfig(config);
}
}

if (count > 0)
{
if (updateFreeNodeChecker.noitify)
Expand Down
47 changes: 47 additions & 0 deletions shadowsocks-csharp/View/SettingsForm.Designer.cs

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

3 changes: 3 additions & 0 deletions shadowsocks-csharp/View/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void UpdateTexts()
checkSwitchAutoCloseAll.Text = I18N.GetString(checkSwitchAutoCloseAll.Text);
checkRandom.Text = I18N.GetString(checkRandom.Text);
CheckAutoBan.Text = I18N.GetString("AutoBan");
CheckLogEnable.Text = I18N.GetString("Enable Log");

Socks5ProxyGroup.Text = I18N.GetString(Socks5ProxyGroup.Text);
checkBoxPacProxy.Text = I18N.GetString(checkBoxPacProxy.Text);
Expand Down Expand Up @@ -158,6 +159,7 @@ private int SaveOldSelectedServer()

_modifiedConfiguration.autoBan = CheckAutoBan.Checked;
_modifiedConfiguration.checkSwitchAutoCloseAll = checkSwitchAutoCloseAll.Checked;
_modifiedConfiguration.logEnable = CheckLogEnable.Checked;

return ret;
}
Expand Down Expand Up @@ -205,6 +207,7 @@ private void LoadSelectedServer()

CheckAutoBan.Checked = _modifiedConfiguration.autoBan;
checkSwitchAutoCloseAll.Checked = _modifiedConfiguration.checkSwitchAutoCloseAll;
CheckLogEnable.Checked = _modifiedConfiguration.logEnable;
}

private void LoadCurrentConfiguration()
Expand Down

0 comments on commit 1d0f398

Please sign in to comment.