Check program is updatedtags/4.1.9.3
@@ -54,6 +54,12 @@ namespace Shadowsocks.Controller | |||||
public string Path; | public string Path; | ||||
} | } | ||||
public class UpdatedEventArgs : EventArgs | |||||
{ | |||||
public string OldVersion; | |||||
public string NewVersion; | |||||
} | |||||
public class TrafficPerSecond | public class TrafficPerSecond | ||||
{ | { | ||||
public long inboundCounter; | public long inboundCounter; | ||||
@@ -80,6 +86,9 @@ namespace Shadowsocks.Controller | |||||
public event ErrorEventHandler Errored; | public event ErrorEventHandler Errored; | ||||
// Invoked when controller.Start(); | |||||
public event EventHandler<UpdatedEventArgs> ProgramUpdated; | |||||
public ShadowsocksController() | public ShadowsocksController() | ||||
{ | { | ||||
_config = Configuration.Load(); | _config = Configuration.Load(); | ||||
@@ -88,10 +97,25 @@ namespace Shadowsocks.Controller | |||||
_pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>(); | _pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>(); | ||||
StartReleasingMemory(); | StartReleasingMemory(); | ||||
StartTrafficStatistics(61); | StartTrafficStatistics(61); | ||||
ProgramUpdated += (o, e) => | |||||
{ | |||||
logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}"); | |||||
}; | |||||
} | } | ||||
public void Start(bool regHotkeys = true) | 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(); | Reload(); | ||||
if (regHotkeys) | if (regHotkeys) | ||||
{ | { | ||||
@@ -45,9 +45,14 @@ namespace Shadowsocks.Model | |||||
NLogConfig nLogConfig; | NLogConfig nLogConfig; | ||||
private static readonly string CONFIG_FILE = "gui-config.json"; | private static readonly string CONFIG_FILE = "gui-config.json"; | ||||
[JsonIgnore] | |||||
public bool updated = false; | |||||
[JsonIgnore] | [JsonIgnore] | ||||
public string localHost => GetLocalHost(); | public string localHost => GetLocalHost(); | ||||
private string GetLocalHost() { | |||||
private string GetLocalHost() | |||||
{ | |||||
return isIPv6Enabled ? "[::1]" : "127.0.0.1"; | return isIPv6Enabled ? "[::1]" : "127.0.0.1"; | ||||
} | } | ||||
public Server GetCurrentServer() | public Server GetCurrentServer() | ||||
@@ -86,6 +91,10 @@ namespace Shadowsocks.Model | |||||
string configContent = File.ReadAllText(CONFIG_FILE); | string configContent = File.ReadAllText(CONFIG_FILE); | ||||
Configuration config = JsonConvert.DeserializeObject<Configuration>(configContent); | Configuration config = JsonConvert.DeserializeObject<Configuration>(configContent); | ||||
config.isDefault = false; | config.isDefault = false; | ||||
if (UpdateChecker.Asset.CompareVersion(UpdateChecker.Version, config.version ?? "0") > 0) | |||||
{ | |||||
config.updated = true; | |||||
} | |||||
if (config.configs == null) | if (config.configs == null) | ||||
config.configs = new List<Server>(); | config.configs = new List<Server>(); | ||||
@@ -101,7 +110,8 @@ namespace Shadowsocks.Model | |||||
config.proxy = new ProxyConfig(); | config.proxy = new ProxyConfig(); | ||||
if (config.hotkey == null) | if (config.hotkey == null) | ||||
config.hotkey = new HotkeyConfig(); | 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 | 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? | //TODO if remote host(server) do not support IPv6 (or DNS resolve AAAA TYPE record) disable IPv6? | ||||
@@ -30,7 +30,7 @@ namespace Shadowsocks | |||||
Model.NLogConfig.TouchAndApplyNLogConfig(); | Model.NLogConfig.TouchAndApplyNLogConfig(); | ||||
// .NET Framework 4.7.2 on Win7 compatibility | // .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; | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; | ||||
// store args for further use | // store args for further use | ||||
@@ -83,6 +83,7 @@ namespace Shadowsocks | |||||
return; | return; | ||||
} | } | ||||
Directory.SetCurrentDirectory(Application.StartupPath); | Directory.SetCurrentDirectory(Application.StartupPath); | ||||
#if DEBUG | #if DEBUG | ||||
// truncate privoxy log file while debugging | // truncate privoxy log file while debugging | ||||
string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); | string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); | ||||
@@ -91,6 +92,7 @@ namespace Shadowsocks | |||||
#endif | #endif | ||||
MainController = new ShadowsocksController(); | MainController = new ShadowsocksController(); | ||||
MenuController = new MenuViewController(MainController); | MenuController = new MenuViewController(MainController); | ||||
HotKeys.Init(MainController); | HotKeys.Init(MainController); | ||||
MainController.Start(); | MainController.Start(); | ||||
Application.Run(); | Application.Run(); | ||||
@@ -374,7 +374,7 @@ namespace Shadowsocks.View | |||||
{ | { | ||||
string argument = @"/select, " + e.Path; | 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) | void ShowBalloonTip(string title, string content, ToolTipIcon icon, int timeout) | ||||
@@ -417,10 +417,10 @@ namespace Shadowsocks.View | |||||
if (updateChecker.NewVersionFound) | if (updateChecker.NewVersionFound) | ||||
{ | { | ||||
updateChecker.NewVersionFound = false; /* Reset the flag */ | updateChecker.NewVersionFound = false; /* Reset the flag */ | ||||
if (System.IO.File.Exists(updateChecker.LatestVersionLocalName)) | |||||
if (File.Exists(updateChecker.LatestVersionLocalName)) | |||||
{ | { | ||||
string argument = "/select, \"" + 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) | if (_isFirstRun) | ||||
{ | { | ||||
CheckUpdateForFirstRun(); | 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; | _isFirstRun = false; | ||||
} | } | ||||
} | } | ||||
@@ -606,14 +611,6 @@ namespace Shadowsocks.View | |||||
updateChecker.CheckUpdate(config, 3000); | 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) | private void AboutItem_Click(object sender, EventArgs e) | ||||
{ | { | ||||
Process.Start("https://github.com/shadowsocks/shadowsocks-windows"); | Process.Start("https://github.com/shadowsocks/shadowsocks-windows"); | ||||