From 69ff1f2c39fd6e46f531c72be67273ae9330955e Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:23:32 +0200 Subject: [PATCH] Update update system --- .../API/GithubUpdateDownloader.cs | 8 ++--- PCK-Studio/MainForm.cs | 6 ++-- PCK-Studio/PckStudio.csproj | 7 ++-- PCK-Studio/Program.cs | 32 ++++--------------- PCK_Studio.sln | 20 ------------ Version.json | 6 ++++ 6 files changed, 21 insertions(+), 58 deletions(-) create mode 100644 Version.json diff --git a/PCK-Studio-Updater/API/GithubUpdateDownloader.cs b/PCK-Studio-Updater/API/GithubUpdateDownloader.cs index b89c3897..663da45e 100644 --- a/PCK-Studio-Updater/API/GithubUpdateDownloader.cs +++ b/PCK-Studio-Updater/API/GithubUpdateDownloader.cs @@ -47,7 +47,7 @@ public bool IsUpdateAvailable(Version productVersion) { Debug.WriteLine("Release Product ver.: " + latestReleaseVersion); Debug.WriteLine("Current Product ver.: " + productVersion); - return latestReleaseVersion.CompareTo(productVersion) > 0; + return latestReleaseVersion.CompareTo(productVersion) >= 0; } public bool IsUpdateAvailable(string productVersion) @@ -101,10 +101,9 @@ private void GetLatestRelease(bool prerelease) private void EmptyDirectory(DirectoryInfo directory) { - string appname = Assembly.GetExecutingAssembly().GetName().Name; foreach (FileInfo file in directory.GetFiles()) { - if (Path.GetFileNameWithoutExtension(file.Name) != appname && file.Name != "update.zip") + if (Path.GetFileNameWithoutExtension(file.Name) != _updateParams.TargetExecutableName && file.Name != "update.zip") file.Delete(); } foreach (DirectoryInfo subDirectory in directory.GetDirectories()) @@ -118,7 +117,7 @@ public void DownloadTo(DirectoryInfo directory) if (latestFetchedRelease.Assets?.Count > 0) { var asset = latestFetchedRelease.Assets[0]; - string zipFilePath = Path.Combine(directory.FullName, "update.zip"); + string zipFilePath = Path.Combine(directory.FullName, asset.Name); using(var zipFileStream = File.OpenWrite(zipFilePath)) { DownloadAsset(asset, zipFileStream); @@ -126,7 +125,6 @@ public void DownloadTo(DirectoryInfo directory) Debug.WriteLine("Download Complete", category: nameof(GithubUpdateDownloader)); EmptyDirectory(directory); UnpackZip(zipFilePath); - File.Delete(zipFilePath); downloadDirectory = directory; } } diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index b376b921..a0273f5e 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -2480,12 +2480,10 @@ private void addANIMEntryToolStripMenuItem1_Click(object sender, EventArgs e) private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e) { - if (Program.Updater.IsUpdateAvailable(Application.ProductVersion)) + if (Program.UpdateToLatest("Would you like to download it?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DialogResult.Yes)) { - Program.UpdateToLatest("Would you like to download it?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DialogResult.Yes); - return; + MessageBox.Show(this, "Already up to date.", "No update available"); } - MessageBox.Show(this, "Already up to date.", "No update available"); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 3e9d2105..c82f17d4 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -679,6 +679,9 @@ 1.0.5 + + 1.9.1 + 5.8.0-alpha0098 compile; runtime; build; native; contentfiles; analyzers; buildtransitive @@ -716,10 +719,6 @@ - - {5B223556-15B9-41DA-AA0B-5E7F45E743BF} - PCK-Studio-Updater - {693AEBC1-293D-4DF0-BCAE-26A1099FE7BB} OMI Filetype Library diff --git a/PCK-Studio/Program.cs b/PCK-Studio/Program.cs index 393faaf9..be455fd0 100644 --- a/PCK-Studio/Program.cs +++ b/PCK-Studio/Program.cs @@ -6,7 +6,6 @@ using PckStudio.Internal.Misc; using PckStudio.Internal; using PckStudio.Properties; -using PCKStudio_Updater; using PckStudio.Internal.App; @@ -21,16 +20,6 @@ static class Program internal static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.ProductName); internal static readonly string AppDataCache = Path.Combine(AppData, "cache"); - private static readonly GithubParams UpdateParams = new GithubParams( - Path.GetDirectoryName(ProjectUrl.AbsolutePath).Replace("\\", ""), - Path.GetFileName(ProjectUrl.AbsolutePath), - Application.ProductName, - Settings.Default.UsePrerelease, - new Regex("(\\*|\\d+(\\.\\d+){0,3}(\\.\\*)?)") - ); - internal static readonly IUpdateDownloader Updater = new GithubUpdateDownloader(UpdateParams); - - internal static MainForm MainInstance { get; private set; } /// @@ -54,21 +43,14 @@ static void Main(string[] args) Application.Run(MainInstance); } - [Conditional("NDEBUG")] - internal static void UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult) + internal static bool UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult) { - bool updateAvailable = Updater.IsUpdateAvailable(Application.ProductVersion); - if (updateAvailable && MessageBox.Show( - MainInstance ?? null, - "New update available.\n" + - message, - "Update Available", - buttons, icon, MessageBoxDefaultButton.Button1) == dialogResult) - { - Updater.DownloadTo(new DirectoryInfo(Application.StartupPath)); - Updater.Launch(); - Application.Exit(); - } +#if NDEBUG + AutoUpdaterDotNET.AutoUpdater.Start($"{ProjectUrl}/Version.xml"); + return true; +#else + return false; +#endif } } } \ No newline at end of file diff --git a/PCK_Studio.sln b/PCK_Studio.sln index 772bd2c5..8062268c 100644 --- a/PCK_Studio.sln +++ b/PCK_Studio.sln @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OMI Filetype Library", "Ven EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpMss32", "Vendor\SharpMss32\SharpMss32\SharpMss32.csproj", "{E8D0B671-3AB1-48B6-A767-58DF67BD5D11}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCK-Studio-Updater", "PCK-Studio-Updater\PCK-Studio-Updater.csproj", "{5B223556-15B9-41DA-AA0B-5E7F45E743BF}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Beta|Any CPU = Beta|Any CPU @@ -80,24 +78,6 @@ Global {E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x64.Build.0 = Release|Any CPU {E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x86.ActiveCfg = Release|Any CPU {E8D0B671-3AB1-48B6-A767-58DF67BD5D11}.Release|x86.Build.0 = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|Any CPU.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|Any CPU.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x64.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x64.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x86.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Beta|x86.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x64.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x64.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x86.ActiveCfg = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Debug|x86.Build.0 = Debug|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|Any CPU.Build.0 = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x64.ActiveCfg = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x64.Build.0 = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x86.ActiveCfg = Release|Any CPU - {5B223556-15B9-41DA-AA0B-5E7F45E743BF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Version.json b/Version.json new file mode 100644 index 00000000..b68f411a --- /dev/null +++ b/Version.json @@ -0,0 +1,6 @@ +{ + "version": "7.0.0.0", + "url": "https://github.com/PhoenixARC/-PCK-Studio/releases/tag/v7.0.0.0/PCK-Studio.zip", + "changelog": "https://github.com/PhoenixARC/-PCK-Studio/releases", + "mandatory": false +}