From c2f763a29ca952d24bfb0501dac9db505e32dd0f Mon Sep 17 00:00:00 2001 From: NotImplementedLife Date: Wed, 16 Aug 2023 19:57:47 +0300 Subject: [PATCH] tried auto update --- MainForm.Designer.cs | 10 ++++++---- MainForm.cs | 4 ++++ Utils/Updates.cs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 Utils/Updates.cs diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index e5ee0b7..db4a300 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -857,14 +857,14 @@ this.SortByIdToolStripMenuItem, this.NoSortToolStripMenuItem}); this.musicOrderToolStripMenuItem.Name = "musicOrderToolStripMenuItem"; - this.musicOrderToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.musicOrderToolStripMenuItem.Size = new System.Drawing.Size(137, 22); this.musicOrderToolStripMenuItem.Text = "Music order"; // // SortByGenreToolStripMenuItem // this.SortByGenreToolStripMenuItem.CheckOnClick = true; this.SortByGenreToolStripMenuItem.Name = "SortByGenreToolStripMenuItem"; - this.SortByGenreToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SortByGenreToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.SortByGenreToolStripMenuItem.Text = "Sort by genre"; this.SortByGenreToolStripMenuItem.Click += new System.EventHandler(this.MusicOrderSortToolStripMenuItem_Click); // @@ -872,7 +872,7 @@ // this.SortByIdToolStripMenuItem.CheckOnClick = true; this.SortByIdToolStripMenuItem.Name = "SortByIdToolStripMenuItem"; - this.SortByIdToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.SortByIdToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.SortByIdToolStripMenuItem.Text = "Sort by Id"; this.SortByIdToolStripMenuItem.Click += new System.EventHandler(this.MusicOrderSortToolStripMenuItem_Click); // @@ -880,7 +880,7 @@ // this.NoSortToolStripMenuItem.CheckOnClick = true; this.NoSortToolStripMenuItem.Name = "NoSortToolStripMenuItem"; - this.NoSortToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.NoSortToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.NoSortToolStripMenuItem.Text = "No sort"; this.NoSortToolStripMenuItem.Click += new System.EventHandler(this.MusicOrderSortToolStripMenuItem_Click); // @@ -889,6 +889,8 @@ this.checkForUpdatesToolStripMenuItem.Name = "checkForUpdatesToolStripMenuItem"; this.checkForUpdatesToolStripMenuItem.Size = new System.Drawing.Size(115, 20); this.checkForUpdatesToolStripMenuItem.Text = "Check for updates"; + this.checkForUpdatesToolStripMenuItem.Visible = false; + this.checkForUpdatesToolStripMenuItem.Click += new System.EventHandler(this.checkForUpdatesToolStripMenuItem_Click); // // RemoveSongButton // diff --git a/MainForm.cs b/MainForm.cs index 6748d2d..c0c6061 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -396,6 +396,10 @@ namespace TaikoSoundEditor } } + private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e) => ExceptionGuard.Run(async () => + { + //var rel = await Updates.GetLatestTja2Fumen(); + }); } } \ No newline at end of file diff --git a/Utils/Updates.cs b/Utils/Updates.cs new file mode 100644 index 0000000..122a1aa --- /dev/null +++ b/Utils/Updates.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace TaikoSoundEditor.Utils +{ + public static class Updates + { + public static async Task GetGithubLatestRelease(string owner, string repo) + { + var url = $"https://api.github.com/repos/{owner}/{repo}/releases/latest"; + using HttpClient client = new HttpClient(); + string json = await client.GetStringAsync(url); + + var t = Task.Run(() => MessageBox.Show(json)); + t.Wait(); + + return Json.Deserialize(json); + } + + public static async Task GetLatestTja2Fumen() + { + return await GetGithubLatestRelease("vivaria", "tja2fumen"); + } + + + public class GithubRelease + { + [JsonPropertyName("url")] public string Url { get; set; } + [JsonPropertyName("tag_name")] public string TagName { get; set; } + [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("prerelease")] public bool Prerelease { get; set; } + [JsonPropertyName("assets")] public GithubAsset[] Assets { get; set; } + + } + + public class GithubAsset + { + [JsonPropertyName("name")] public string Name { get; set; } + [JsonPropertyName("browser_download_url")] public string DownloadUrl { get; set; } + } + } +}