Added new PCK-Studio Updater (#20)

* Added PCK-Studio-Updater project

* Updated PCK-Studio-Updater to be a standanlone executable and added checkbox for using beta builds in the settings panel

* Rename constant define '_NOT_DEBUG' to 'NDEBUG' and moved it to .csproj file
This commit is contained in:
Miku-666
2023-10-08 15:00:01 +02:00
committed by GitHub
parent 2e8a4316ba
commit 1e94d23281
23 changed files with 1242 additions and 1021 deletions

View File

@@ -1,21 +1,36 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using PckStudio.Classes.Misc;
using PckStudio.Internal;
using PckStudio.Properties;
using PCKStudio_Updater;
namespace PckStudio
{
static class Program
{
public static readonly string ProjectUrl = "https://github.com/PhoenixARC/-PCK-Studio";
public static readonly string BaseAPIUrl = "http://api.pckstudio.xyz/api/pck";
public static readonly string BackUpAPIUrl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/";
public static readonly string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.ProductName);
public static readonly string AppDataCache = Path.Combine(AppData, "cache");
internal static readonly Uri ProjectUrl = new Uri("https://github.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/";
public static MainForm MainInstance { get; private set; }
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>
/// The main entry point for the application.
@@ -23,6 +38,11 @@ namespace PckStudio
[STAThread]
static void Main(string[] args)
{
if (Settings.Default.AutoUpdate)
{
UpdateToLatest("Click Ok to continue.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, DialogResult.OK);
}
ApplicationScope.Initialize();
Trace.TraceInformation("Startup");
RPC.Initialize();
@@ -32,5 +52,21 @@ namespace PckStudio
Application.ApplicationExit += (sender, e) => { RPC.Deinitialize(); };
Application.Run(MainInstance);
}
[Conditional("NDEBUG")]
internal static void UpdateToLatest(string message, MessageBoxButtons buttons, MessageBoxIcon icon, DialogResult dialogResult)
{
bool updateAvailable = Updater.IsUpdateAvailable(Application.ProductVersion);
if (updateAvailable && MessageBox.Show(
"New update available.\n" +
message,
"Update Available",
buttons, icon, MessageBoxDefaultButton.Button1) == dialogResult)
{
Updater.DownloadTo(new DirectoryInfo(Application.StartupPath));
Updater.Launch();
Application.Exit();
}
}
}
}
}