diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 1d2be8c9..f4ea1294 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -54,6 +54,12 @@ namespace Shadowsocks.Controller public string Path; } + public class UpdatedEventArgs : EventArgs + { + public string OldVersion; + public string NewVersion; + } + public class TrafficPerSecond { public long inboundCounter; @@ -80,6 +86,9 @@ namespace Shadowsocks.Controller public event ErrorEventHandler Errored; + // Invoked when controller.Start(); + public event EventHandler ProgramUpdated; + public ShadowsocksController() { _config = Configuration.Load(); @@ -88,10 +97,25 @@ namespace Shadowsocks.Controller _pluginsByServer = new ConcurrentDictionary(); StartReleasingMemory(); StartTrafficStatistics(61); + + ProgramUpdated += (o, e) => + { + logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}"); + }; } public void Start(bool regHotkeys = true) { + if (_config.updated && regHotkeys) + { + _config.updated = false; + ProgramUpdated.Invoke(this, new UpdatedEventArgs() + { + OldVersion = _config.version, + NewVersion = UpdateChecker.Version, + }); + Configuration.Save(_config); + } Reload(); if (regHotkeys) { diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 200cd20c..9eb50a09 100644 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -45,9 +45,14 @@ namespace Shadowsocks.Model NLogConfig nLogConfig; private static readonly string CONFIG_FILE = "gui-config.json"; + + [JsonIgnore] + public bool updated = false; + [JsonIgnore] public string localHost => GetLocalHost(); - private string GetLocalHost() { + private string GetLocalHost() + { return isIPv6Enabled ? "[::1]" : "127.0.0.1"; } public Server GetCurrentServer() @@ -86,6 +91,10 @@ namespace Shadowsocks.Model string configContent = File.ReadAllText(CONFIG_FILE); Configuration config = JsonConvert.DeserializeObject(configContent); config.isDefault = false; + if (UpdateChecker.Asset.CompareVersion(UpdateChecker.Version, config.version ?? "0") > 0) + { + config.updated = true; + } if (config.configs == null) config.configs = new List(); @@ -101,7 +110,8 @@ namespace Shadowsocks.Model config.proxy = new ProxyConfig(); if (config.hotkey == null) config.hotkey = new HotkeyConfig(); - if (!System.Net.Sockets.Socket.OSSupportsIPv6) { + if (!System.Net.Sockets.Socket.OSSupportsIPv6) + { config.isIPv6Enabled = false; // disable IPv6 if os not support } //TODO if remote host(server) do not support IPv6 (or DNS resolve AAAA TYPE record) disable IPv6? diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 906ea685..e24ab322 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -30,7 +30,7 @@ namespace Shadowsocks Model.NLogConfig.TouchAndApplyNLogConfig(); // .NET Framework 4.7.2 on Win7 compatibility - System.Net.ServicePointManager.SecurityProtocol |= + System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; // store args for further use @@ -83,6 +83,7 @@ namespace Shadowsocks return; } Directory.SetCurrentDirectory(Application.StartupPath); + #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); @@ -91,6 +92,7 @@ namespace Shadowsocks #endif MainController = new ShadowsocksController(); MenuController = new MenuViewController(MainController); + HotKeys.Init(MainController); MainController.Start(); Application.Run(); diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 271f67ba..ddcf21f4 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -374,7 +374,7 @@ namespace Shadowsocks.View { string argument = @"/select, " + e.Path; - System.Diagnostics.Process.Start("explorer.exe", argument); + Process.Start("explorer.exe", argument); } void ShowBalloonTip(string title, string content, ToolTipIcon icon, int timeout) @@ -417,10 +417,10 @@ namespace Shadowsocks.View if (updateChecker.NewVersionFound) { updateChecker.NewVersionFound = false; /* Reset the flag */ - if (System.IO.File.Exists(updateChecker.LatestVersionLocalName)) + if (File.Exists(updateChecker.LatestVersionLocalName)) { string argument = "/select, \"" + updateChecker.LatestVersionLocalName + "\""; - System.Diagnostics.Process.Start("explorer.exe", argument); + Process.Start("explorer.exe", argument); } } } @@ -567,7 +567,12 @@ namespace Shadowsocks.View if (_isFirstRun) { CheckUpdateForFirstRun(); - ShowFirstTimeBalloon(); + ShowBalloonTip( + I18N.GetString("Shadowsocks is here"), + I18N.GetString("You can turn on/off Shadowsocks in the context menu"), + ToolTipIcon.Info, + 0 + ); _isFirstRun = false; } } @@ -606,14 +611,6 @@ namespace Shadowsocks.View updateChecker.CheckUpdate(config, 3000); } - private void ShowFirstTimeBalloon() - { - _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks is here"); - _notifyIcon.BalloonTipText = I18N.GetString("You can turn on/off Shadowsocks in the context menu"); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(0); - } - private void AboutItem_Click(object sender, EventArgs e) { Process.Start("https://github.com/shadowsocks/shadowsocks-windows");