Browse Source

Merge pull request #2778 from studentmain/check-updated

Check program is updated
tags/4.1.9.3
Student Main GitHub 5 years ago
parent
commit
1faa8dea9f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 15 deletions
  1. +24
    -0
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +12
    -2
      shadowsocks-csharp/Model/Configuration.cs
  3. +3
    -1
      shadowsocks-csharp/Program.cs
  4. +9
    -12
      shadowsocks-csharp/View/MenuViewController.cs

+ 24
- 0
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -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<UpdatedEventArgs> ProgramUpdated;
public ShadowsocksController()
{
_config = Configuration.Load();
@@ -88,10 +97,25 @@ namespace Shadowsocks.Controller
_pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>();
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)
{


+ 12
- 2
shadowsocks-csharp/Model/Configuration.cs View File

@@ -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<Configuration>(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<Server>();
@@ -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?


+ 3
- 1
shadowsocks-csharp/Program.cs View File

@@ -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();


+ 9
- 12
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -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");


Loading…
Cancel
Save