Browse Source

Download new version automatically

use proxy to check new version && download
pull/122/head
kookxiang 10 years ago
parent
commit
7d8eb540e6
2 changed files with 29 additions and 2 deletions
  1. +27
    -0
      shadowsocks-csharp/Controller/UpdateChecker.cs
  2. +2
    -2
      shadowsocks-csharp/View/MenuViewController.cs

+ 27
- 0
shadowsocks-csharp/Controller/UpdateChecker.cs View File

@@ -1,10 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
namespace Shadowsocks.Controller
@@ -21,12 +24,31 @@ namespace Shadowsocks.Controller
public void CheckUpdate()
{
// Waiting for proxy start
Thread.Sleep(5000);
// TODO test failures
WebClient http = new WebClient();
http.Proxy = new WebProxy("127.0.0.1", 8123);
http.DownloadStringCompleted += http_DownloadStringCompleted;
http.DownloadStringAsync(new Uri(UpdateURL));
}
public void CheckUpdateDelayed()
{
Thread updateCheckerThread = new Thread(new ThreadStart(this.CheckUpdate));
updateCheckerThread.IsBackground = true;
updateCheckerThread.Start();
}
public void DownloadNewVersion()
{
WebClient webClient = new WebClient();
webClient.Proxy = new WebProxy("127.0.0.1", 8123);
webClient.DownloadFileAsync(new Uri(LatestVersionURL), Path.GetTempPath() + "shadowsocks.zip");
webClient.DownloadFileCompleted += newVersionDownloadCompleted;
}
public static int CompareVersion(string l, string r)
{
var ls = l.Split('.');
@@ -107,6 +129,11 @@ namespace Shadowsocks.Controller
return CompareVersion(version, currentVersion) > 0;
}
private void newVersionDownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
System.Diagnostics.Process.Start(Path.GetTempPath() + "shadowsocks.zip");
}
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try


+ 2
- 2
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -57,7 +57,7 @@ namespace Shadowsocks.View
LoadCurrentConfiguration();
updateChecker.CheckUpdate();
updateChecker.CheckUpdateDelayed();
if (controller.GetConfiguration().isDefault)
{
@@ -188,7 +188,7 @@ namespace Shadowsocks.View
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(updateChecker.LatestVersionURL);
updateChecker.DownloadNewVersion();
}


Loading…
Cancel
Save