@@ -26,159 +26,6 @@ namespace Shadowsocks.Controller | |||
public const string Version = "4.1.9.2"; | |||
private class CheckUpdateTimer : System.Timers.Timer | |||
{ | |||
public Configuration config; | |||
public CheckUpdateTimer(int p) : base(p) | |||
{ | |||
} | |||
} | |||
public void CheckUpdate(Configuration config, int delay) | |||
{ | |||
CheckUpdateTimer timer = new CheckUpdateTimer(delay); | |||
timer.AutoReset = false; | |||
timer.Elapsed += Timer_Elapsed; | |||
timer.config = config; | |||
timer.Enabled = true; | |||
} | |||
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) | |||
{ | |||
CheckUpdateTimer timer = (CheckUpdateTimer)sender; | |||
Configuration config = timer.config; | |||
timer.Elapsed -= Timer_Elapsed; | |||
timer.Enabled = false; | |||
timer.Dispose(); | |||
CheckUpdate(config); | |||
} | |||
public void CheckUpdate(Configuration config) | |||
{ | |||
this.config = config; | |||
try | |||
{ | |||
Logging.Debug("Checking updates..."); | |||
WebClient http = CreateWebClient(); | |||
http.DownloadStringCompleted += http_DownloadStringCompleted; | |||
http.DownloadStringAsync(new Uri(UpdateURL)); | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logging.LogUsefulException(ex); | |||
} | |||
} | |||
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) | |||
{ | |||
try | |||
{ | |||
string response = e.Result; | |||
JArray result = JArray.Parse(response); | |||
List<Asset> asserts = new List<Asset>(); | |||
if (result != null) | |||
{ | |||
foreach (JObject release in result) | |||
{ | |||
var isPreRelease = (bool)release["prerelease"]; | |||
if (isPreRelease && !config.checkPreRelease) | |||
{ | |||
continue; | |||
} | |||
foreach (JObject asset in (JArray)release["assets"]) | |||
{ | |||
Asset ass = Asset.ParseAsset(asset); | |||
if (ass != null) | |||
{ | |||
ass.prerelease = isPreRelease; | |||
if (ass.IsNewVersion(Version, config.checkPreRelease)) | |||
{ | |||
asserts.Add(ass); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
if (asserts.Count != 0) | |||
{ | |||
SortByVersions(asserts); | |||
Asset asset = asserts[asserts.Count - 1]; | |||
NewVersionFound = true; | |||
LatestVersionURL = asset.browser_download_url; | |||
LatestVersionNumber = asset.version; | |||
LatestVersionName = asset.name; | |||
LatestVersionSuffix = asset.suffix == null ? "" : $"-{asset.suffix}"; | |||
startDownload(); | |||
} | |||
else | |||
{ | |||
Logging.Debug("No update is available"); | |||
if (CheckUpdateCompleted != null) | |||
{ | |||
CheckUpdateCompleted(this, new EventArgs()); | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logging.LogUsefulException(ex); | |||
} | |||
} | |||
private void startDownload() | |||
{ | |||
try | |||
{ | |||
LatestVersionLocalName = Utils.GetTempPath(LatestVersionName); | |||
WebClient http = CreateWebClient(); | |||
http.DownloadFileCompleted += Http_DownloadFileCompleted; | |||
http.DownloadFileAsync(new Uri(LatestVersionURL), LatestVersionLocalName); | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logging.LogUsefulException(ex); | |||
} | |||
} | |||
private void Http_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) | |||
{ | |||
try | |||
{ | |||
if (e.Error != null) | |||
{ | |||
Logging.LogUsefulException(e.Error); | |||
return; | |||
} | |||
Logging.Debug($"New version {LatestVersionNumber}{LatestVersionSuffix} found: {LatestVersionLocalName}"); | |||
if (CheckUpdateCompleted != null) | |||
{ | |||
CheckUpdateCompleted(this, new EventArgs()); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
Logging.LogUsefulException(ex); | |||
} | |||
} | |||
private WebClient CreateWebClient() | |||
{ | |||
WebClient http = new WebClient(); | |||
http.Headers.Add("User-Agent", UserAgent); | |||
http.Proxy = new WebProxy(config.localHost, config.localPort); | |||
return http; | |||
} | |||
private void SortByVersions(List<Asset> asserts) | |||
{ | |||
asserts.Sort(); | |||
} | |||
public class Asset : IComparable<Asset> | |||
{ | |||
public bool prerelease; | |||
@@ -28,7 +28,6 @@ namespace Shadowsocks.View | |||
private Icon icon, icon_in, icon_out, icon_both, previousIcon; | |||
private bool _isFirstRun; | |||
private bool _isStartupChecking; | |||
private string _urlToOpen; | |||
private ContextMenu contextMenu1; | |||
@@ -96,9 +95,6 @@ namespace Shadowsocks.View | |||
_notifyIcon.BalloonTipClosed += _notifyIcon_BalloonTipClosed; | |||
controller.TrafficChanged += controller_TrafficChanged; | |||
this.updateChecker = new UpdateChecker(); | |||
updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted; | |||
LoadCurrentConfiguration(); | |||
Configuration config = controller.GetConfigurationCopy(); | |||
@@ -108,11 +104,6 @@ namespace Shadowsocks.View | |||
_isFirstRun = true; | |||
ShowConfigForm(); | |||
} | |||
else if (config.autoCheckUpdate) | |||
{ | |||
_isStartupChecking = true; | |||
updateChecker.CheckUpdate(config, 3000); | |||
} | |||
} | |||
private void controller_TrafficChanged(object sender, EventArgs e) | |||
@@ -320,13 +311,6 @@ namespace Shadowsocks.View | |||
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), | |||
this.VerboseLoggingToggleItem = CreateMenuItem( "Verbose Logging", new EventHandler(this.VerboseLoggingToggleItem_Click) ), | |||
this.ShowPluginOutputToggleItem = CreateMenuItem("Show Plugin Output", new EventHandler(this.ShowPluginOutputToggleItem_Click)), | |||
//this.WriteI18NFileItem = CreateMenuItem("Write translation template",new EventHandler(WriteI18NFileItem_Click)), | |||
CreateMenuGroup("Updates...", new MenuItem[] { | |||
CreateMenuItem("Check for Updates...", new EventHandler(this.checkUpdatesItem_Click)), | |||
new MenuItem("-"), | |||
this.autoCheckUpdatesToggleItem = CreateMenuItem("Check for Updates at Startup", new EventHandler(this.autoCheckUpdatesToggleItem_Click)), | |||
this.checkPreReleaseToggleItem = CreateMenuItem("Check Pre-release Version", new EventHandler(this.checkPreReleaseToggleItem_Click)), | |||
}), | |||
CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)), | |||
}), | |||
new MenuItem("-"), | |||
@@ -397,19 +381,6 @@ namespace Shadowsocks.View | |||
ShowBalloonTip(I18N.GetString("Shadowsocks"), result, ToolTipIcon.Info, 1000); | |||
} | |||
void updateChecker_CheckUpdateCompleted(object sender, EventArgs e) | |||
{ | |||
if (updateChecker.NewVersionFound) | |||
{ | |||
ShowBalloonTip(I18N.GetString("Shadowsocks {0} Update Found", updateChecker.LatestVersionNumber + updateChecker.LatestVersionSuffix), I18N.GetString("Click here to update"), ToolTipIcon.Info, 5000); | |||
} | |||
else if (!_isStartupChecking) | |||
{ | |||
ShowBalloonTip(I18N.GetString("Shadowsocks"), I18N.GetString("No update is available"), ToolTipIcon.Info, 5000); | |||
} | |||
_isStartupChecking = false; | |||
} | |||
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) | |||
{ | |||
if (updateChecker.NewVersionFound) | |||
@@ -564,7 +535,6 @@ namespace Shadowsocks.View | |||
Utils.ReleaseMemory(true); | |||
if (_isFirstRun) | |||
{ | |||
CheckUpdateForFirstRun(); | |||
ShowFirstTimeBalloon(); | |||
_isFirstRun = false; | |||
} | |||
@@ -596,14 +566,6 @@ namespace Shadowsocks.View | |||
Application.Exit(); | |||
} | |||
private void CheckUpdateForFirstRun() | |||
{ | |||
Configuration config = controller.GetConfigurationCopy(); | |||
if (config.isDefault) return; | |||
_isStartupChecking = true; | |||
updateChecker.CheckUpdate(config, 3000); | |||
} | |||
private void ShowFirstTimeBalloon() | |||
{ | |||
_notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks is here"); | |||
@@ -936,11 +898,6 @@ namespace Shadowsocks.View | |||
UpdateUpdateMenu(); | |||
} | |||
private void checkUpdatesItem_Click(object sender, EventArgs e) | |||
{ | |||
updateChecker.CheckUpdate(controller.GetConfigurationCopy()); | |||
} | |||
private void proxyItem_Click(object sender, EventArgs e) | |||
{ | |||
ShowProxyForm(); | |||