forked from Planshit/Tai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9c9892
commit 527b5c6
Showing
20 changed files
with
1,069 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="Updater.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:Updater" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace Updater | ||
{ | ||
/// <summary> | ||
/// App.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
private System.Threading.Mutex mutex; | ||
|
||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
base.OnStartup(e); | ||
// 阻止多开和用户主动启动 | ||
if (e.Args.Length == 0 || IsRuned()) | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
Activated += (s, e2) => | ||
{ | ||
var mainWindow = App.Current.MainWindow; | ||
if (mainWindow.DataContext != null) | ||
{ | ||
var mainModel = mainWindow.DataContext as MainModel; | ||
if (string.IsNullOrEmpty(mainModel.Version)) | ||
{ | ||
mainModel.Version = e.Args[0]; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
#region 获取当前程序是否已运行 | ||
/// <summary> | ||
/// 获取当前程序是否已运行 | ||
/// </summary> | ||
private bool IsRuned() | ||
{ | ||
bool ret; | ||
mutex = new System.Threading.Mutex(true, System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name, out ret); | ||
if (!ret) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Updater | ||
{ | ||
|
||
public class GithubRelease | ||
{ | ||
public class VersionInfo | ||
{ | ||
/// <summary> | ||
/// 版本标题 | ||
/// </summary> | ||
public string Title { get; set; } | ||
/// <summary> | ||
/// 版本号 | ||
/// </summary> | ||
public string Version { get; set; } | ||
/// <summary> | ||
/// 是否是预览版本 | ||
/// </summary> | ||
public bool IsPre { get; set; } | ||
/// <summary> | ||
/// 下载路径 | ||
/// </summary> | ||
public string DownloadUrl { get; set; } | ||
/// <summary> | ||
/// 版本更新内容网页链接 | ||
/// </summary> | ||
public string HtmlUrl { get; set; } | ||
} | ||
public class GithubModel | ||
{ | ||
public string tag_name { get; set; } | ||
public string html_url { get; set; } | ||
public string name { get; set; } | ||
public bool prerelease { get; set; } | ||
|
||
public List<GithubAssetsModel> assets { get; set; } | ||
} | ||
public class GithubAssetsModel | ||
{ | ||
public string browser_download_url { get; set; } | ||
} | ||
private string githubUrl; | ||
private string nowVersion; | ||
public VersionInfo Info { get; set; } | ||
|
||
//public event UpdaterEventHandler RequestCompleteEvent; | ||
//public event UpdaterEventHandler RequestErrorEvent; | ||
//public delegate void UpdaterEventHandler(object sender, object value); | ||
public GithubRelease(string githubUrl, string nowVersion) | ||
{ | ||
this.githubUrl = githubUrl; | ||
this.nowVersion = nowVersion; | ||
Info = new VersionInfo(); | ||
} | ||
public bool IsCanUpdate() | ||
{ | ||
return !(nowVersion == Info.Version); | ||
} | ||
public async Task<VersionInfo> GetRequest() | ||
{ | ||
var result = await Task.Run(() => | ||
{ | ||
HttpWebResponse httpWebRespones = null; | ||
try | ||
{ | ||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; | ||
HttpWebRequest httpWebRequest = WebRequest.Create(githubUrl) as HttpWebRequest; | ||
httpWebRequest.Timeout = 60 * 1000; | ||
httpWebRequest.ReadWriteTimeout = 60000; | ||
httpWebRequest.AllowAutoRedirect = true; | ||
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"; | ||
httpWebRespones = (HttpWebResponse)httpWebRequest.GetResponse(); | ||
|
||
|
||
using (Stream stream = httpWebRespones.GetResponseStream()) | ||
{ | ||
List<byte> lst = new List<byte>(); | ||
int nRead = 0; | ||
while ((nRead = stream.ReadByte()) != -1) lst.Add((byte)nRead); | ||
byte[] bodyBytes = lst.ToArray(); | ||
|
||
string body = Encoding.UTF8.GetString(bodyBytes, 0, bodyBytes.Length); | ||
|
||
var data = JsonConvert.DeserializeObject<GithubModel>(body); | ||
Info.IsPre = data.prerelease; | ||
Info.Title = data.name; | ||
Info.Version = data.tag_name; | ||
Info.DownloadUrl = data.assets[0].browser_download_url; | ||
Info.HtmlUrl = data.html_url; | ||
return Info; | ||
} | ||
|
||
} | ||
catch (Exception ec) | ||
{ | ||
return null; | ||
} | ||
|
||
}); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Updater | ||
{ | ||
public class MainModel : UINotifyPropertyChanged | ||
{ | ||
private double ProcessValue_; | ||
public double ProcessValue { get { return ProcessValue_; } set { ProcessValue_ = value; OnPropertyChanged(); } } | ||
private string Version_; | ||
public string Version { get { return Version_; } set { Version_ = value; OnPropertyChanged(); } } | ||
|
||
} | ||
} |
Oops, something went wrong.