Skip to content

Commit

Permalink
checking new version when running
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyRabbit committed Aug 30, 2017
1 parent 24196d4 commit 119a00a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
1 change: 1 addition & 0 deletions AntiRecall/AntiRecall.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="network\CheckUpdate.cs" />
<Compile Include="network\DataRecive.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
Expand Down
5 changes: 4 additions & 1 deletion AntiRecall/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
using System.IO;
using System.Diagnostics;
using AntiRecall.deploy;

using AntiRecall.network;
using System.Threading;

namespace AntiRecall
{
Expand Down Expand Up @@ -91,6 +92,8 @@ public MainWindow()
InitializeComponent();
ShortCut.init_shortcut("AntiRecall");
ShortCut.init_xml();
CheckUpdate.init_checkUpdate();

if (ShortCut.CheckXml())
{
QQPath.Text = ShortCut.QueryXml("QQPath");
Expand Down
4 changes: 3 additions & 1 deletion AntiRecall/deploy/ShortCut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ShortCut
{
public static string currentDirectory { set; get; }

public static string myVersion { set; get; }

public static SortedDictionary<string, string> antiRElement;

public static void init_xml()
Expand Down Expand Up @@ -82,7 +84,7 @@ public static void init_shortcut(string filename)
{
if (currentDirectory == null)
currentDirectory = System.IO.Directory.GetCurrentDirectory();

myVersion = "1.1.0";

if (!CheckShortCut(filename))
{
Expand Down
117 changes: 117 additions & 0 deletions AntiRecall/network/CheckUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Windows;
using AntiRecall.deploy;
using System.Net;
using System.Threading;
using System.ComponentModel;
using System.Windows.Forms;

namespace AntiRecall.network
{
class CheckUpdate
{
private static string newVersion;
private static string url;
private static WebClient client;

public static void init_checkUpdate()
{
Thread thread = new Thread(() => StartUpdate());
thread.Start();
}

private static void StartUpdate()
{
if (CheckNewVersion())
{
if (ShowUpdate())
{
if (DownloadNewVersion())
{
MessageBoxResult result = System.Windows.MessageBox.Show(@"下载成功,请手动解压覆盖源文件", @"大吉大利,今晚吃鸡", MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
{
System.Diagnostics.Process.Start(ShortCut.currentDirectory + @"\\tmp");
}
}
else
{
MessageBoxResult result = System.Windows.MessageBox.Show(@"下载失败,请手动更新。", @"错误", MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
System.Diagnostics.Process.Start("https://github.com/FlyRabbit/AntiRecall/releases");
}
}
}
}



private static bool CheckNewVersion()
{
XmlDocument doc = new XmlDocument();
doc.Load("https://etenal.me/wp-content/uploads/AntiRecall/newversion.xml");
newVersion = doc.DocumentElement.GetAttribute("Version");
url = doc.DocumentElement.GetAttribute("Url");
return (!newVersion.Equals(ShortCut.myVersion));
}

private static bool ShowUpdate()
{
MessageBoxResult result = System.Windows.MessageBox.Show(@"检测到新版本,是否下载更新?", @"检查更新", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
return true;
else
return false;
}

private static bool DownloadNewVersion()
{
if (!System.IO.Directory.Exists(ShortCut.currentDirectory + @"\\tmp"))
System.IO.Directory.CreateDirectory(ShortCut.currentDirectory + @"\\tmp");

try
{
/*
Thread thread = new Thread(() => {
client = new WebClient();
client.DownloadFileCompleted += DownloadCompleted;
client.DownloadFileAsync(new Uri(url), @".\\tmp\\AntiRecall.zip");
});
thread.Start();
*/
client = new WebClient();
client.DownloadFile(url, ".\\tmp\\AntiRecall.zip");
return true;
}
catch (Exception)
{
return false;
}
}

private static void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
long size = new System.IO.FileInfo(@".\\tmp\\AntiRecall.zip").Length;
if (size != 0)
{
MessageBoxResult result = System.Windows.MessageBox.Show(@"下载成功,请手动解压覆盖源文件", @"大吉大利,今晚吃鸡", MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
{
System.Diagnostics.Process.Start(ShortCut.currentDirectory + @"\\tmp");
}
}
else
{
MessageBoxResult result = System.Windows.MessageBox.Show(@"下载失败,请手动更新。", @"错误", MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
System.Diagnostics.Process.Start("https://github.com/FlyRabbit/AntiRecall/releases");
}
}

}
}

0 comments on commit 119a00a

Please sign in to comment.