1
0
Fork 0
mirror of https://github.com/proxysu/ProxySU.git synced 2025-04-04 06:13:37 +03:00

添加新版本提示

This commit is contained in:
ProxySU 2020-09-05 20:26:00 +08:00
parent 1421ef51e0
commit 577ca29156
7 changed files with 180 additions and 45 deletions

View file

@ -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">
<!--以下样式参考自https://yq.aliyun.com/articles/331878
https://docs.microsoft.com/en-us/dotnet/desktop-wpf/fundamentals/styles-templates-overview-->
<Window.Resources>
@ -38,12 +38,16 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
<ColumnDefinition Width="1.6*"></ColumnDefinition>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
<ColumnDefinition Width="0.6*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TextBlockLastVersionProxySU" Foreground="Red" Grid.Column="0" Margin="3" Visibility="Hidden" HorizontalAlignment="Right" ></TextBlock>
<TextBlock x:Name="TextBlockNewVersionReminder" Text="{DynamicResource TextBlockNewVersionReminder}" Grid.Column="1" Grid.ColumnSpan="1" Margin="3" Visibility="Hidden"></TextBlock>
<TextBlock x:Name="TextBlockNewVersionDown" Text="{DynamicResource TextBlockNewVersionDown}" Grid.Column="1" Grid.ColumnSpan="1" Margin="3" Visibility="Hidden"></TextBlock>
<Button x:Name="ButtonUpgradeProxySU" Content="{DynamicResource ButtonUpgradeProxySU}" Grid.Column="2" Margin="3" Visibility="Hidden" Click="ButtonUpgradeProxySU_Click"></Button>
<TextBlock Grid.Column="3" Text="{DynamicResource MainWindowsLanguage}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5"></TextBlock>
<ComboBox x:Name="ComboBoxLanguage" Grid.Column="4" Height="25" Width="80" SelectionChanged="ComboBoxLanguage_SelectionChanged"></ComboBox>
</Grid>

View file

@ -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<TextBlock, TextBlock, Button, string> updateNewVersionProxySUAction = new Action<TextBlock, TextBlock, Button, string>(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<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(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<TextBox, string> updateMonitorAction = new Action<TextBox, string>(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<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(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<TextBox, string> updateMonitorAction = new Action<TextBox, string>(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 三合一安装过程

View file

@ -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")]

View file

@ -3,6 +3,11 @@
xmlns:local="clr-namespace:ProxySU.Translations"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<!-- Main program interface -->
<sys:String x:Key="TextBlockNewVersionReminder">The new version has been released!</sys:String>
<sys:String x:Key="TextBlockNewVersionDown">Downloading...Wait Prompt...</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxyFail">The download of the latest version failed, please try again later!</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxySuccess">Download the latest version successfully, the file has been saved in the same directory of the current ProxySU.exe</sys:String>
<sys:String x:Key="ButtonUpgradeProxySU">Update</sys:String>
<sys:String x:Key="MainWindowsLanguage">界面語言:</sys:String>
<sys:String x:Key="TabItemHeaderAppDeployment">Deployment</sys:String>
<sys:String x:Key="TabItemHeaderResourceTools">Resources</sys:String>

View file

@ -3,6 +3,11 @@
xmlns:local="clr-namespace:ProxySU.Translations"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<!-- 主程序界面 -->
<sys:String x:Key="TextBlockNewVersionReminder">最新版本已发布了,快去更新一下吧!</sys:String>
<sys:String x:Key="TextBlockNewVersionDown">正在下载最新版,请等待完成提示....</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxyFail">最新版下载失败,请稍后重试!</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxySuccess">下载最新版成功文件已存入当前ProxySU.exe同一目录</sys:String>
<sys:String x:Key="ButtonUpgradeProxySU">下载更新</sys:String>
<sys:String x:Key="MainWindowsLanguage">Languages:</sys:String>
<sys:String x:Key="TabItemHeaderAppDeployment">应用布署</sys:String>
<sys:String x:Key="TabItemHeaderResourceTools">资源工具</sys:String>

View file

@ -3,6 +3,11 @@
xmlns:local="clr-namespace:ProxySU.Translations"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<!-- 主程序界面 -->
<sys:String x:Key="TextBlockNewVersionReminder">最新版本已發布了,快去更新一下吧!</sys:String>
<sys:String x:Key="TextBlockNewVersionDown">正在下載最新版,請等待完成提示....</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxyFail">最新版下載失敗,請稍後重試!</sys:String>
<sys:String x:Key="MessageBoxShow_ErrorDownProxySuccess">下載最新版成功文件已存入當前ProxySU.exe同一目錄</sys:String>
<sys:String x:Key="ButtonUpgradeProxySU">下載更新</sys:String>
<sys:String x:Key="MainWindowsLanguage">Languages:</sys:String>
<sys:String x:Key="TabItemHeaderAppDeployment">應用佈署</sys:String>
<sys:String x:Key="TabItemHeaderResourceTools">資源工具</sys:String>

Binary file not shown.