From dbc99c429c93113510db0debf6f60f770837a85a Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Fri, 11 Nov 2022 10:54:30 +0100 Subject: [PATCH] changed the UpdateAPI and set animation easeinout --- WeeXnes/App.xaml.cs | 2 + WeeXnes/Core/ApiResponse.cs | 55 +++++++++++++++------------ WeeXnes/Core/Globals.cs | 4 +- WeeXnes/MVVM/View/SettingView.xaml.cs | 38 ++++++++++-------- WeeXnes/MainWindow.xaml | 14 ++++++- WeeXnes/Misc/UpdateMessage.xaml.cs | 13 ++++--- WeeXnes/WeeXnes.csproj | 2 +- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs index 5e5e464..de93f90 100644 --- a/WeeXnes/App.xaml.cs +++ b/WeeXnes/App.xaml.cs @@ -2,6 +2,8 @@ using System.Windows; using WeeXnes.Core; using System.IO; +using System.Reflection; +using WeeXnes.Misc; using Application = System.Windows.Forms.Application; namespace WeeXnes diff --git a/WeeXnes/Core/ApiResponse.cs b/WeeXnes/Core/ApiResponse.cs index 934d262..78bc131 100644 --- a/WeeXnes/Core/ApiResponse.cs +++ b/WeeXnes/Core/ApiResponse.cs @@ -1,30 +1,37 @@ -namespace WeeXnes.Core -{ - public class ApiResponse - { - public string download_url { get; set; } - public string file_name { get; set; } - public string tag_name { get; set; } - public string name { get; set; } - public string description { get; set; } - public ApiResponse(string _download_url, string _file_name, string _tag_name, string _name, string _description) - { - this.download_url = _download_url; - this.file_name = _file_name; - this.tag_name = _tag_name; - this.name = _name; - this.description = _description; - } +using System.Collections; +using System.Collections.Generic; +namespace WeeXnes.Core +{ + public class GithubApiResponse + { + public string tag_name { get; set; } + public IList assets { get; set; } + + public GithubApiResponse(string tag_name, IList assets) + { + this.tag_name = tag_name; + this.assets = assets; + } public override string ToString() { - string returnval = - "download_url: " + this.download_url + "\n" + - "file_name: " + this.file_name + "\n" + - "tag_name: " + this.tag_name + "\n" + - "name: " + this.name + "\n" + - "description: " + this.description; - return returnval; + return this.tag_name + " with " + this.assets.Count; + } + } + + public class GithubAsset + { + public string browser_download_url { get; set; } + public string name { get; set; } + + public GithubAsset(string browser_download_url, string name) + { + this.browser_download_url = browser_download_url; + this.name = name; + } + public override string ToString() + { + return this.name; } } } \ No newline at end of file diff --git a/WeeXnes/Core/Globals.cs b/WeeXnes/Core/Globals.cs index aa2f9d7..787acb1 100644 --- a/WeeXnes/Core/Globals.cs +++ b/WeeXnes/Core/Globals.cs @@ -16,10 +16,10 @@ namespace WeeXnes.Core public static string encryptionKey = "8zf5#RdyQ]$4x4_"; public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes"); public static string SettingsFileName = "settings.ini"; - public static string version = "3.6.6"; + public static string version = "3.6.7"; public static bool info_isRpcRunning = false; public static bool info_RpcAutoStart; - public static string apiUrl = "http://weexnes.com:5169/"; + public static string apiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; public static UpdateVar settings_alwaysOnTop = new UpdateVar(); public static UpdateVar settings_osxStyleControlls = new UpdateVar(); diff --git a/WeeXnes/MVVM/View/SettingView.xaml.cs b/WeeXnes/MVVM/View/SettingView.xaml.cs index df35d6d..73b068b 100644 --- a/WeeXnes/MVVM/View/SettingView.xaml.cs +++ b/WeeXnes/MVVM/View/SettingView.xaml.cs @@ -282,23 +282,27 @@ namespace WeeXnes.MVVM.View private void CheckForUpdateBtn_OnClick(object sender, RoutedEventArgs e) { - WebClient client = new WebClient(); try { - string downloadString = client.DownloadString(Globals.apiUrl); - ApiResponse GitHub = JsonConvert.DeserializeObject(downloadString); - if (GitHub.tag_name != Globals.version) - { - Misc.UpdateMessage updateMessage = new UpdateMessage( - GitHub, - "Update Found"); - updateMessage.Show(); - } - else - { - Misc.Message msg = new Misc.Message("No Updates found"); - msg.Show(); - } + using(WebClient webClient = new WebClient()) + {; + webClient.Headers.Add("Authorization", "Basic :x-oauth-basic"); + webClient.Headers.Add("User-Agent","lk-github-clien"); + var downloadString = webClient.DownloadString(Globals.apiUrl); + GithubApiResponse ApiResponseData = JsonConvert.DeserializeObject(downloadString); + if (ApiResponseData.tag_name != Globals.version) + { + Misc.UpdateMessage updateMessage = new UpdateMessage( + ApiResponseData, + "Update Found"); + updateMessage.Show(); + } + else + { + Misc.Message msg = new Misc.Message("No Updates found"); + msg.Show(); + } + } } catch (Exception ex) { @@ -306,6 +310,10 @@ namespace WeeXnes.MVVM.View error.Show(); } + WebClient client = new WebClient(); + + + } diff --git a/WeeXnes/MainWindow.xaml b/WeeXnes/MainWindow.xaml index c4e6130..4dd8140 100644 --- a/WeeXnes/MainWindow.xaml +++ b/WeeXnes/MainWindow.xaml @@ -72,7 +72,12 @@ Storyboard.TargetName="NavigationBorder" Storyboard.TargetProperty="(Border.Width)" To="200" Duration="0:0:00.4" AutoReverse="False" - /> + + > + + + + @@ -83,7 +88,12 @@ Storyboard.TargetName="NavigationBorder" Storyboard.TargetProperty="(Border.Width)" To="50" Duration="0:0:00.4" AutoReverse="False" - /> + > + + + + + diff --git a/WeeXnes/Misc/UpdateMessage.xaml.cs b/WeeXnes/Misc/UpdateMessage.xaml.cs index 63d332e..bc14422 100644 --- a/WeeXnes/Misc/UpdateMessage.xaml.cs +++ b/WeeXnes/Misc/UpdateMessage.xaml.cs @@ -11,8 +11,8 @@ namespace WeeXnes.Misc { public partial class UpdateMessage : Window { - public static ApiResponse GitHub; - public UpdateMessage(ApiResponse _GitHub, string _title = "Message") + public static GithubApiResponse GitHub; + public UpdateMessage(GithubApiResponse _GitHub, string _title = "Message") { InitializeComponent(); string content = "Your Version: " + Globals.version + "\n" + @@ -26,13 +26,14 @@ namespace WeeXnes.Misc { checkForFile(); WebClient client = new WebClient(); - client.DownloadFile(GitHub.download_url, GitHub.file_name); + client.DownloadFile(GitHub.assets[0].browser_download_url, GitHub.assets[0].name); + client.Dispose(); } private static void checkForFile() { - if (File.Exists(GitHub.file_name)) + if (File.Exists(GitHub.assets[0].name)) { - File.Delete(GitHub.file_name); + File.Delete(GitHub.assets[0].name); } } private void OkButton_OnClick(object sender, RoutedEventArgs e) @@ -43,7 +44,7 @@ namespace WeeXnes.Misc string path = Application.StartupPath; string fileName = Path.GetFileName(Application.ExecutablePath); string pid = Process.GetCurrentProcess().Id.ToString(); - Process updateProc = Process.Start("Update.exe", "\"" + path + "\"" + " " + "\"" + fileName + "\"" + " " + "\"" + pid + "\"" + " " + "\"" + GitHub.file_name + "\""); + Process updateProc = Process.Start("Update.exe", "\"" + path + "\"" + " " + "\"" + fileName + "\"" + " " + "\"" + pid + "\"" + " " + "\"" + GitHub.assets[0].name + "\""); } catch (Exception ex) { diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index 6786c57..bc71dd0 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - 3.6.6 + 3.6.7 {4B33CEE7-C74D-43B9-B99A-8B273D5195BC} WinExe WeeXnes