Some updater progress. I want to make it automatic at some point.
This commit is contained in:
parent
3665b0547a
commit
4fc2425797
@ -2,9 +2,15 @@
|
|||||||
using Graphing.Parts;
|
using Graphing.Parts;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Graphing.Forms;
|
namespace Graphing.Forms;
|
||||||
@ -72,6 +78,8 @@ public partial class GraphForm : Form
|
|||||||
ZoomLevel = 1;
|
ZoomLevel = 1;
|
||||||
initialWindowPos = Location;
|
initialWindowPos = Location;
|
||||||
initialWindowSize = Size;
|
initialWindowSize = Size;
|
||||||
|
|
||||||
|
RunUpdateChecker();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Int2 GraphSpaceToScreenSpace(Float2 graphPoint)
|
public Int2 GraphSpaceToScreenSpace(Float2 graphPoint)
|
||||||
@ -475,7 +483,7 @@ public partial class GraphForm : Form
|
|||||||
cacheForm.TopMost = true;
|
cacheForm.TopMost = true;
|
||||||
cacheForm.Show();
|
cacheForm.Show();
|
||||||
}
|
}
|
||||||
private void MiscMenuPreload_Click(object sender, EventArgs e)
|
private void MiscMenuPreload_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Float2 min = MinVisibleGraph, max = MaxVisibleGraph;
|
Float2 min = MinVisibleGraph, max = MaxVisibleGraph;
|
||||||
Float2 add = new(max.x - min.x, max.y - min.y);
|
Float2 add = new(max.x - min.x, max.y - min.y);
|
||||||
@ -507,4 +515,52 @@ public partial class GraphForm : Form
|
|||||||
}
|
}
|
||||||
shifter.Show();
|
shifter.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void RunUpdateChecker()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpClient http = new();
|
||||||
|
HttpRequestMessage request = new(HttpMethod.Get, "https://api.github.com/repos/That-One-Nerd/Graphing/releases");
|
||||||
|
request.Headers.Add("User-Agent", "ThatOneNerd.Graphing-Update-Checker");
|
||||||
|
|
||||||
|
HttpResponseMessage result = await http.SendAsync(request);
|
||||||
|
if (!result.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to check for updates.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray arr = JsonSerializer.Deserialize<JsonArray>(await result.Content.ReadAsStreamAsync())!;
|
||||||
|
JsonObject latest = arr[0]!.AsObject();
|
||||||
|
|
||||||
|
Version curVersion = Version.Parse(Assembly.GetAssembly(typeof(GraphForm))!.FullName!.Split(',')[1].Trim()[8..^2]);
|
||||||
|
Version newVersion = Version.Parse(latest["tag_name"]!.GetValue<string>());
|
||||||
|
|
||||||
|
if (newVersion > curVersion)
|
||||||
|
{
|
||||||
|
// Updates are required.
|
||||||
|
DialogResult button = MessageBox.Show(
|
||||||
|
$"A new update is available!\n{curVersion} -> {newVersion}\nWould you like to download the update?",
|
||||||
|
"Graphing Calculator Update", MessageBoxButtons.YesNo);
|
||||||
|
|
||||||
|
if (button == DialogResult.No) return;
|
||||||
|
|
||||||
|
ProcessStartInfo website = new()
|
||||||
|
{
|
||||||
|
FileName = latest["html_url"]!.GetValue<string>(),
|
||||||
|
UseShellExecute = true
|
||||||
|
};
|
||||||
|
Process.Start(website);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Up-to-date.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to check for updates:\n{ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ internal static class Program
|
|||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
|
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
|
||||||
|
|
||||||
GraphForm graph = new("One Of The Graphing Calculators Of All Time");
|
GraphForm graph = new("One Of The Graphing Calculators Of All Time");
|
||||||
|
|
||||||
Equation equA = new(Math.Sin),
|
Equation equA = new(Math.Sin),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user