mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-08-02 15:12:13 +00:00
Program - Move Update related initialization into Updater class
This commit is contained in:
24
PCK-Studio/Internal/Json/UpdateInformation.cs
Normal file
24
PCK-Studio/Internal/Json/UpdateInformation.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace PckStudio.Internal.Json
|
||||||
|
{
|
||||||
|
internal class UpdateInformation
|
||||||
|
{
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
62
PCK-Studio/Internal/Updater.cs
Normal file
62
PCK-Studio/Internal/Updater.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using AutoUpdaterDotNET;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PckStudio.Internal.Json;
|
||||||
|
using PckStudio.Properties;
|
||||||
|
|
||||||
|
namespace PckStudio.Internal
|
||||||
|
{
|
||||||
|
internal static class Updater
|
||||||
|
{
|
||||||
|
private static Uri _appCast;
|
||||||
|
|
||||||
|
internal static void Initialize(Uri appCast)
|
||||||
|
{
|
||||||
|
_appCast = appCast;
|
||||||
|
//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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void SetOwner(Form owner) => AutoUpdater.SetOwner(owner);
|
||||||
|
|
||||||
|
internal static void UpdateToLatest()
|
||||||
|
{
|
||||||
|
#if NDEBUG
|
||||||
|
string url = $"{_appCast}/main/Version.json";
|
||||||
|
AutoUpdater.Start(url);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args)
|
||||||
|
{
|
||||||
|
UpdateInformation json = JsonConvert.DeserializeObject<UpdateInformation>(args.RemoteData);
|
||||||
|
args.UpdateInfo = new UpdateInfoEventArgs
|
||||||
|
{
|
||||||
|
CurrentVersion = json.Version,
|
||||||
|
DownloadURL = json.Url,
|
||||||
|
ChangelogURL = json.Changelog,
|
||||||
|
Mandatory = new Mandatory()
|
||||||
|
{
|
||||||
|
Value = json.Mandatory,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2251,7 +2251,7 @@ namespace PckStudio
|
|||||||
|
|
||||||
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
|
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Program.UpdateToLatest();
|
Updater.UpdateToLatest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -157,6 +157,7 @@
|
|||||||
<Compile Include="Extensions\PckAssetExtensions.cs" />
|
<Compile Include="Extensions\PckAssetExtensions.cs" />
|
||||||
<Compile Include="Extensions\TreeNodeExtensions.cs" />
|
<Compile Include="Extensions\TreeNodeExtensions.cs" />
|
||||||
<Compile Include="Internal\Deserializer\ImageDeserializer.cs" />
|
<Compile Include="Internal\Deserializer\ImageDeserializer.cs" />
|
||||||
|
<Compile Include="Internal\Json\UpdateInformation.cs" />
|
||||||
<Compile Include="Internal\Serializer\AnimationSerializer.cs" />
|
<Compile Include="Internal\Serializer\AnimationSerializer.cs" />
|
||||||
<Compile Include="Internal\Deserializer\AnimationDeserializer.cs" />
|
<Compile Include="Internal\Deserializer\AnimationDeserializer.cs" />
|
||||||
<Compile Include="Interfaces\IPckAssetDeserializer.cs" />
|
<Compile Include="Interfaces\IPckAssetDeserializer.cs" />
|
||||||
@@ -169,6 +170,7 @@
|
|||||||
<Compile Include="Internal\Serializer\ImageSerializer.cs" />
|
<Compile Include="Internal\Serializer\ImageSerializer.cs" />
|
||||||
<Compile Include="Internal\SkinAnimFlag.cs" />
|
<Compile Include="Internal\SkinAnimFlag.cs" />
|
||||||
<Compile Include="Internal\SkinAnimMask.cs" />
|
<Compile Include="Internal\SkinAnimMask.cs" />
|
||||||
|
<Compile Include="Internal\Updater.cs" />
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
|||||||
@@ -31,74 +31,18 @@ namespace PckStudio
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
AutoUpdater.SetOwner(MainInstance);
|
Updater.Initialize(RawProjectUrl);
|
||||||
//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();
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationScope.Initialize();
|
ApplicationScope.Initialize();
|
||||||
Trace.TraceInformation("Startup");
|
Trace.TraceInformation("Startup");
|
||||||
RPC.Initialize();
|
RPC.Initialize();
|
||||||
MainInstance = new MainForm();
|
MainInstance = new MainForm();
|
||||||
|
Updater.SetOwner(MainInstance);
|
||||||
if (args.Length > 0 && File.Exists(args[0]) && args[0].EndsWith(".pck"))
|
if (args.Length > 0 && File.Exists(args[0]) && args[0].EndsWith(".pck"))
|
||||||
MainInstance.InitPckFromFile(args[0]);
|
MainInstance.InitPckFromFile(args[0]);
|
||||||
Application.ApplicationExit += (sender, e) => { RPC.Deinitialize(); };
|
Application.ApplicationExit += (sender, e) => { RPC.Deinitialize(); };
|
||||||
MainInstance.FocusMe();
|
MainInstance.FocusMe();
|
||||||
Application.Run(MainInstance);
|
Application.Run(MainInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static void UpdateToLatest()
|
|
||||||
{
|
|
||||||
#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,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user