diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml index 4efd3a3..30e512e 100644 --- a/ProxySU/MainWindow.xaml +++ b/ProxySU/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProxySU" mc:Ignorable="d" - Title="ProxySU - v2.0.2" Height="625" Width="530"> + Title="ProxySU - v2.0.3" Height="625" Width="530"> @@ -38,12 +38,16 @@ - - - - - + + + + + + + + + diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index 451d2b9..79ca0ad 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -22,6 +22,7 @@ using Newtonsoft.Json.Serialization; using System.Drawing; using QRCoder; using System.Net; +using System.ComponentModel; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Runtime; @@ -108,15 +109,164 @@ namespace ProxySU //TextBoxNaiveUser3in1.Text = RandomUserName(); //TextBoxNaivePassword3in1.Text= RandomUUID(); - + + Thread thread = new Thread(() => TestLatestVersionProxySU(TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU)); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); } - #region 端口数字防错代码,密钥选择代码 + #region 端口数字防错代码,密钥选择代码 检测新版本代码 + //检测ProxySU新版本 + private void TestLatestVersionProxySU(TextBlock TextBlockLastVersionProxySU,TextBlock TextBlockNewVersionReminder,Button ButtonUpgradeProxySU) + { + string strJson = GetLatestJson(@"https://api.github.com/repos/proxysu/windows/releases/latest"); + if (String.IsNullOrEmpty(strJson) == false) + { + JObject lastVerJsonObj = JObject.Parse(strJson); + string lastVersion = (string)lastVerJsonObj["tag_name"];//得到远程版本信息 + + Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + string cerversion = "v" + version.ToString().Substring(0, 5); //获取本地版本信息 + + //版本信息不相同,则认为新版本发布,显示出新版本信息及更新提醒,下载按钮 + if (String.Equals(lastVersion, cerversion) == false) + { + TextBlockLastVersionProxySU.Dispatcher.BeginInvoke(updateNewVersionProxySUAction, TextBlockLastVersionProxySU, TextBlockNewVersionReminder, ButtonUpgradeProxySU, lastVersion); + } + else + { + + } + } + else + { + //MessageBox.Show("获取Json失败"); + } + } + + //下载最新版ProxySU + private void ButtonUpgradeProxySU_Click(object sender, RoutedEventArgs e) + { + TextBlockNewVersionReminder.Visibility = Visibility.Hidden; + TextBlockNewVersionDown.Visibility = Visibility.Visible; + //TextBlockNewVersionReminder.Text = Application.Current.FindResource("TextBlockNewVersionDown").ToString(); + try + { + string strJson = GetLatestJson(@"https://api.github.com/repos/proxysu/windows/releases/latest"); + if (String.IsNullOrEmpty(strJson) == false) + { + JObject lastVerJsonObj = JObject.Parse(strJson); + string latestVerDownUrl = (string)lastVerJsonObj["assets"][0]["browser_download_url"]; + + Uri latestVerDownUri = new Uri(latestVerDownUrl); + string latestNewVerFileName = (string)lastVerJsonObj["assets"][0]["name"]; + + WebClient webClientNewVer = new WebClient(); + webClientNewVer.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); + //webClientNewVer.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); + webClientNewVer.DownloadFileAsync(latestVerDownUri, latestNewVerFileName); + //webClientNewVer.DownloadFile(latestVerDownUrl, latestNewVerFileName); + } + } + catch (Exception ex1) + { + // MessageBox.Show(ex1.ToString()); + + return; + } + } + //文件下载完处理方法 + private void Completed(object sender, AsyncCompletedEventArgs e) + { + if (e.Cancelled == true) + { + MessageBox.Show(e.Error.ToString()); + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDownProxyFail").ToString()); + //label1.Text = "Download cancelled!"; + } + else + { + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDownProxySuccess").ToString()); + } + } + + //获取LatestJson + private string GetLatestJson(string theLatestUrl) + { + try + { + //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768 | SecurityProtocolType.Tls; + ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; + // ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00 | 0x30); + //string url = "https://api.github.com/repos/proxysu/windows/releases/latest"; + Uri uri = new Uri(theLatestUrl); + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); + req.Accept = @"application/json"; + req.UserAgent = @"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"; + HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); + Stream stream = resp.GetResponseStream(); + StreamReader sr = new StreamReader(stream); + string strJson = sr.ReadToEnd(); + return strJson; + } + catch (Exception ex1) + { + return null; + } + } + + //更新新版本提醒显示 + Action updateNewVersionProxySUAction = new Action(UpdateNewVersionProxySU); + private static void UpdateNewVersionProxySU(TextBlock TextBlockLastVersionProxySU, TextBlock TextBlockNewVersionReminder, Button ButtonUpgradeProxySU, string theLatestVersion) + { + TextBlockLastVersionProxySU.Text = theLatestVersion; + TextBlockLastVersionProxySU.Visibility = Visibility.Visible; + TextBlockNewVersionReminder.Visibility = Visibility.Visible; + ButtonUpgradeProxySU.Visibility = Visibility.Visible; + } + + + //更新状态条显示 + Action updateAction = new Action(UpdateTextBlock); + private static void UpdateTextBlock(TextBlock textBlockName, ProgressBar progressBar, string currentStatus) + { + textBlockName.Text = currentStatus; + + if (currentStatus.Contains("成功") == true || currentStatus.ToLower().Contains("success") == true) + { + progressBar.IsIndeterminate = false; + progressBar.Value = 100; + } + else if (currentStatus.Contains("失败") == true || currentStatus.Contains("取消") == true || currentStatus.Contains("退出") == true || currentStatus.ToLower().Contains("fail") == true || currentStatus.ToLower().Contains("cancel") == true || currentStatus.ToLower().Contains("exit") == true) + { + progressBar.IsIndeterminate = false; + progressBar.Value = 0; + } + else + { + progressBar.IsIndeterminate = true; + //progressBar.Value = 0; + } + + + } + + //更新监视窗内的显示 + Action updateMonitorAction = new Action(UpdateTextBox); + private static void UpdateTextBox(TextBox textBoxName, string currentResult) + { + textBoxName.Text = textBoxName.Text + currentResult + Environment.NewLine; + textBoxName.ScrollToEnd(); + } + + //退出主程序 private void Button_canel_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } // private static readonly Regex _regex = new Regex("[^0-9]+"); + + //检测数字输入 private void TextBoxPort_PreviewTextInput(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("[^0-9]+"); @@ -6729,39 +6879,6 @@ namespace ProxySU } } - //更新UI显示内容 - Action updateAction = new Action(UpdateTextBlock); - private static void UpdateTextBlock(TextBlock textBlockName, ProgressBar progressBar, string currentStatus) - { - textBlockName.Text = currentStatus; - - if (currentStatus.Contains("成功") == true || currentStatus.ToLower().Contains("success") == true) - { - progressBar.IsIndeterminate = false; - progressBar.Value = 100; - } - else if (currentStatus.Contains("失败") == true || currentStatus.Contains("取消") == true || currentStatus.Contains("退出") == true || currentStatus.ToLower().Contains("fail") == true || currentStatus.ToLower().Contains("cancel") == true || currentStatus.ToLower().Contains("exit") == true) - { - progressBar.IsIndeterminate = false; - progressBar.Value = 0; - } - else - { - progressBar.IsIndeterminate = true; - //progressBar.Value = 0; - } - - - } - - //更新监视窗内的显示内容 - Action updateMonitorAction = new Action(UpdateTextBox); - private static void UpdateTextBox(TextBox textBoxName, string currentResult) - { - textBoxName.Text = textBoxName.Text + currentResult + Environment.NewLine; - textBoxName.ScrollToEnd(); - } - //检测系统内核是否符合安装要求 private static bool DetectKernelVersion(string kernelVer) { @@ -7133,8 +7250,7 @@ namespace ProxySU } } - - #endregion + #endregion // #region 三合一安装过程 diff --git a/ProxySU/Properties/AssemblyInfo.cs b/ProxySU/Properties/AssemblyInfo.cs index 4738786..1d41a49 100644 --- a/ProxySU/Properties/AssemblyInfo.cs +++ b/ProxySU/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.0.0")] -[assembly: AssemblyFileVersion("0.0.0.0")] +[assembly: AssemblyVersion("2.0.3.0")] +[assembly: AssemblyFileVersion("2.0.3.0")] diff --git a/ProxySU/Translations/ProxySU.en-US.xaml b/ProxySU/Translations/ProxySU.en-US.xaml index 91fe0c6..7a657db 100644 --- a/ProxySU/Translations/ProxySU.en-US.xaml +++ b/ProxySU/Translations/ProxySU.en-US.xaml @@ -3,6 +3,11 @@ xmlns:local="clr-namespace:ProxySU.Translations" xmlns:sys="clr-namespace:System;assembly=mscorlib"> + The new version has been released! + Downloading...Wait Prompt... + The download of the latest version failed, please try again later! + Download the latest version successfully, the file has been saved in the same directory of the current ProxySU.exe + Update 界面語言: Deployment Resources diff --git a/ProxySU/Translations/ProxySU.zh-CN.xaml b/ProxySU/Translations/ProxySU.zh-CN.xaml index 8defebb..5f47548 100644 --- a/ProxySU/Translations/ProxySU.zh-CN.xaml +++ b/ProxySU/Translations/ProxySU.zh-CN.xaml @@ -3,6 +3,11 @@ xmlns:local="clr-namespace:ProxySU.Translations" xmlns:sys="clr-namespace:System;assembly=mscorlib"> + 最新版本已发布了,快去更新一下吧! + 正在下载最新版,请等待完成提示.... + 最新版下载失败,请稍后重试! + 下载最新版成功,文件已存入当前ProxySU.exe同一目录 + 下载更新 Languages: 应用布署 资源工具 diff --git a/ProxySU/Translations/ProxySU.zh-TW.xaml b/ProxySU/Translations/ProxySU.zh-TW.xaml index 570d3b7..6f44171 100644 --- a/ProxySU/Translations/ProxySU.zh-TW.xaml +++ b/ProxySU/Translations/ProxySU.zh-TW.xaml @@ -3,6 +3,11 @@ xmlns:local="clr-namespace:ProxySU.Translations" xmlns:sys="clr-namespace:System;assembly=mscorlib"> + 最新版本已發布了,快去更新一下吧! + 正在下載最新版,請等待完成提示.... + 最新版下載失敗,請稍後重試! + 下載最新版成功,文件已存入當前ProxySU.exe同一目錄 + 下載更新 Languages: 應用佈署 資源工具 diff --git a/ProxySU/bin/Beta/Beta.zip b/ProxySU/bin/Beta/Beta.zip index 8e003f1..99213d9 100644 Binary files a/ProxySU/bin/Beta/Beta.zip and b/ProxySU/bin/Beta/Beta.zip differ