Change In-App-Update system

This commit is contained in:
miku-666
2024-06-25 20:23:32 +02:00
parent 07d319b7f4
commit ff93889776
7 changed files with 70 additions and 62 deletions

View File

@@ -45,7 +45,7 @@ jobs:
run: "msbuild PCK_Studio.sln -p:Configuration=Release"
- name: Package binary
run: Compress-Archive -Path ${{ github.workspace }}\PCK-Studio\bin\Release\ -Destination ${{ env.RELEASE_NAME }}.zip
run: Compress-Archive -Path "${{ github.workspace }}\PCK-Studio\bin\Release\*" -Destination ${{ env.RELEASE_NAME }}.zip
- name: Release
uses: softprops/action-gh-release@v2

View File

@@ -47,7 +47,7 @@ namespace PCKStudio_Updater
{
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 @@ namespace PCKStudio_Updater
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 @@ namespace PCKStudio_Updater
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 @@ namespace PCKStudio_Updater
Debug.WriteLine("Download Complete", category: nameof(GithubUpdateDownloader));
EmptyDirectory(directory);
UnpackZip(zipFilePath);
File.Delete(zipFilePath);
downloadDirectory = directory;
}
}

View File

@@ -2480,12 +2480,7 @@ namespace PckStudio
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Program.Updater.IsUpdateAvailable(Application.ProductVersion))
{
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");
Program.UpdateToLatest();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)

View File

@@ -679,6 +679,9 @@
<PackageReference Include="AnimatedGif">
<Version>1.0.5</Version>
</PackageReference>
<PackageReference Include="Autoupdater.NET.Official">
<Version>1.9.1</Version>
</PackageReference>
<PackageReference Include="Costura.Fody">
<Version>5.8.0-alpha0098</Version>
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -716,10 +719,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCK-Studio-Updater\PCK-Studio-Updater.csproj">
<Project>{5B223556-15B9-41DA-AA0B-5E7F45E743BF}</Project>
<Name>PCK-Studio-Updater</Name>
</ProjectReference>
<ProjectReference Include="..\Vendor\OMI-Lib\OMI Filetypes Library\OMI Filetype Library.csproj">
<Project>{693AEBC1-293D-4DF0-BCAE-26A1099FE7BB}</Project>
<Name>OMI Filetype Library</Name>

View File

@@ -6,8 +6,9 @@ using System.Windows.Forms;
using PckStudio.Internal.Misc;
using PckStudio.Internal;
using PckStudio.Properties;
using PCKStudio_Updater;
using PckStudio.Internal.App;
using AutoUpdaterDotNET;
using Newtonsoft.Json;
namespace PckStudio
@@ -15,22 +16,13 @@ namespace PckStudio
static class Program
{
internal static readonly Uri ProjectUrl = new Uri("https://github.com/PhoenixARC/-PCK-Studio");
internal static readonly Uri RawProjectUrl = new Uri("https://raw.githubusercontent.com/PhoenixARC/-PCK-Studio");
internal static readonly string BaseAPIUrl = "http://api.pckstudio.xyz/api/pck";
internal static readonly string BackUpAPIUrl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/";
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; }
/// <summary>
@@ -39,9 +31,23 @@ namespace PckStudio
[STAThread]
static void Main(string[] args)
{
AutoUpdater.SetOwner(MainInstance);
//AutoUpdater.ClearAppDirectory = true;
#if DEBUG
AutoUpdater.ReportErrors = true;
#endif
AutoUpdater.DownloadPath = Application.StartupPath;
AutoUpdater.ExecutablePath = "./PCK-Studio.exe";
AutoUpdater.TopMost = true;
string jsonPath = Path.Combine(Environment.CurrentDirectory, "updates.json");
AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);
AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent;
AutoUpdater.Icon = Resources.ProjectLogo.ToBitmap();
if (Settings.Default.AutoUpdate)
{
UpdateToLatest("Click Ok to continue.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, DialogResult.OK);
UpdateToLatest();
}
ApplicationScope.Initialize();
@@ -51,24 +57,48 @@ namespace PckStudio
if (args.Length > 0 && File.Exists(args[0]) && args[0].EndsWith(".pck"))
MainInstance.InitPckFromFile(args[0]);
Application.ApplicationExit += (sender, e) => { RPC.Deinitialize(); };
MainInstance.FocusMe();
Application.Run(MainInstance);
}
[Conditional("NDEBUG")]
internal static void UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult)
internal static void UpdateToLatest()
{
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
string url = $"{RawProjectUrl}/main/Version.json";
AutoUpdater.Start(url);
#endif
}
class UpdateInfo
{
[JsonProperty("version")]
public string Version { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("changelog")]
public string Changelog { get; set; }
[JsonProperty("mandatory")]
public bool Mandatory { get; set; }
}
private static void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args)
{
UpdateInfo json = JsonConvert.DeserializeObject<UpdateInfo>(args.RemoteData);
args.UpdateInfo = new UpdateInfoEventArgs
{
CurrentVersion = json.Version,
DownloadURL = json.Url,
ChangelogURL = json.Changelog,
Mandatory = new Mandatory()
{
Value = json.Mandatory,
}
};
}
}
}

View File

@@ -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

6
Version.json Normal file
View File

@@ -0,0 +1,6 @@
{
"version": "7.0.0.0",
"url": "https://github.com/PhoenixARC/-PCK-Studio/releases/download/v7.0.0.0/PCK-Studio.zip",
"changelog": "https://raw.githubusercontent.com/PhoenixARC/-PCK-Studio/main/CHANGELOG.md",
"mandatory": false
}