mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Added auto-update checker
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
using Starlight.Communication;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
using System.Globalization;
|
||||
using System.Management;
|
||||
using System.Text;
|
||||
@@ -343,11 +344,17 @@ namespace Starlight.AnimeMatrix
|
||||
public void PresentClock()
|
||||
{
|
||||
int second = DateTime.Now.Second;
|
||||
string time;
|
||||
|
||||
if (CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains("H"))
|
||||
PresentTextDiagonal(DateTime.Now.ToString(" H" + ((second % 2 == 0) ? ":" : " ") + "mm"));
|
||||
time = DateTime.Now.ToString("H" + ((second % 2 == 0) ? ":" : " ") + "mm");
|
||||
else
|
||||
PresentTextDiagonal(DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt"));
|
||||
time = DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt");
|
||||
|
||||
if (_model == AnimeType.GA401)
|
||||
PresentText(time);
|
||||
else
|
||||
PresentTextDiagonal(time);
|
||||
}
|
||||
|
||||
public void PresentText(string text1, string text2 = "")
|
||||
@@ -359,14 +366,14 @@ namespace Starlight.AnimeMatrix
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
|
||||
using (Font font = new Font("Arial", 24F, GraphicsUnit.Pixel))
|
||||
using (Font font = new Font("Consolas", 24F, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(text1, font);
|
||||
g.DrawString(text1, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 3, -3);
|
||||
g.DrawString(text1, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 3, -4);
|
||||
}
|
||||
|
||||
if (text2.Length > 0)
|
||||
using (Font font = new Font("Arial", 18F, GraphicsUnit.Pixel))
|
||||
using (Font font = new Font("Consolas", 18F, GraphicsUnit.Pixel))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(text2, font);
|
||||
g.DrawString(text2, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 1, 25);
|
||||
@@ -437,6 +444,24 @@ namespace Starlight.AnimeMatrix
|
||||
|
||||
Clear();
|
||||
|
||||
|
||||
InstalledFontCollection installedFontCollection = new InstalledFontCollection();
|
||||
|
||||
|
||||
string familyName;
|
||||
string familyList = "";
|
||||
FontFamily[] fontFamilies;
|
||||
// Get the array of FontFamily objects.
|
||||
fontFamilies = installedFontCollection.Families;
|
||||
|
||||
int count = fontFamilies.Length;
|
||||
for (int j = 0; j < count; ++j)
|
||||
{
|
||||
familyName = fontFamilies[j].Name;
|
||||
familyList = familyList + familyName;
|
||||
familyList = familyList + ", ";
|
||||
}
|
||||
|
||||
int maxX = (int)Math.Sqrt(MaxRows * MaxRows + MaxColumns * MaxColumns);
|
||||
|
||||
using (Bitmap bmp = new Bitmap(maxX, MaxRows))
|
||||
@@ -446,10 +471,10 @@ namespace Starlight.AnimeMatrix
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
|
||||
using (Font font = new Font("Calibri", 13F, GraphicsUnit.Pixel))
|
||||
using (Font font = new Font("Consolas", 13F, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(text, font);
|
||||
g.DrawString(text, font, Brushes.White, 4, 0);
|
||||
g.DrawString(text, font, Brushes.White, 4, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public class AmdGpuControl : IGpuControl {
|
||||
|
||||
public bool IsNvidia => false;
|
||||
|
||||
|
||||
public string FullName => _internalDiscreteAdapter!.AdapterName;
|
||||
public AmdGpuControl() {
|
||||
if (!Adl2.Load())
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
public interface IGpuControl : IDisposable {
|
||||
bool IsNvidia { get; }
|
||||
bool IsValid { get; }
|
||||
public string FullName { get; }
|
||||
int? GetCurrentTemperature();
|
||||
int? GetGpuUse();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public static class HardwareControl
|
||||
try
|
||||
{
|
||||
int? gpuUse = GpuControl?.GetGpuUse();
|
||||
Logger.WriteLine("GPU usage: " + GpuControl?.FullName + " " + gpuUse + "%");
|
||||
if (gpuUse is not null) return (int)gpuUse;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -113,16 +114,12 @@ public static class HardwareControl
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsUsedGPU(int threshold = 20)
|
||||
public static bool IsUsedGPU(int threshold = 10)
|
||||
{
|
||||
int use = GetGpuUse();
|
||||
Logger.WriteLine("GPU usage: " + use);
|
||||
if (use > threshold)
|
||||
if (GetGpuUse() > threshold)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
use = GetGpuUse();
|
||||
Logger.WriteLine("GPU usage: " + use);
|
||||
return (use > threshold);
|
||||
return (GetGpuUse() > threshold);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -136,7 +133,7 @@ public static class HardwareControl
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void RecreateGpuControlWithDelay(int delay = 3)
|
||||
public static void RecreateGpuControlWithDelay(int delay = 5)
|
||||
{
|
||||
// Re-enabling the discrete GPU takes a bit of time,
|
||||
// so a simple workaround is to refresh again after that happens
|
||||
|
||||
9
app/Settings.Designer.cs
generated
9
app/Settings.Designer.cs
generated
@@ -267,24 +267,25 @@ namespace GHelper
|
||||
labelModel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
labelModel.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelModel.ForeColor = SystemColors.ControlDark;
|
||||
labelModel.Location = new Point(291, 119);
|
||||
labelModel.Location = new Point(380, 119);
|
||||
labelModel.Margin = new Padding(8, 0, 8, 0);
|
||||
labelModel.Name = "labelModel";
|
||||
labelModel.Size = new Size(492, 32);
|
||||
labelModel.Size = new Size(400, 32);
|
||||
labelModel.TabIndex = 38;
|
||||
labelModel.TextAlign = ContentAlignment.TopRight;
|
||||
//
|
||||
// labelVersion
|
||||
//
|
||||
labelVersion.AutoSize = true;
|
||||
labelVersion.AutoSize = false;
|
||||
labelVersion.Font = new Font("Segoe UI", 9F, FontStyle.Underline, GraphicsUnit.Point);
|
||||
labelVersion.ForeColor = SystemColors.ControlDark;
|
||||
labelVersion.Location = new Point(25, 119);
|
||||
labelVersion.Margin = new Padding(8, 0, 8, 0);
|
||||
labelVersion.Name = "labelVersion";
|
||||
labelVersion.Size = new Size(44, 32);
|
||||
labelVersion.Size = new Size(300, 32);
|
||||
labelVersion.TabIndex = 37;
|
||||
labelVersion.Text = "v.0";
|
||||
labelVersion.Cursor = Cursors.Hand;
|
||||
//
|
||||
// labelBattery
|
||||
//
|
||||
|
||||
@@ -3,9 +3,13 @@ using GHelper.Gpu;
|
||||
using Starlight.AnimeMatrix;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Tools;
|
||||
|
||||
namespace GHelper
|
||||
@@ -294,10 +298,15 @@ namespace GHelper
|
||||
|
||||
var gitVersion = new Version(tag);
|
||||
var appVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
//appVersion = new Version("0.50.0.0");
|
||||
|
||||
if (gitVersion.CompareTo(appVersion) > 0)
|
||||
int newer = gitVersion.CompareTo(appVersion);
|
||||
|
||||
if (newer > 0)
|
||||
{
|
||||
SetVersionLabel(Properties.Strings.DownloadUpdate + ": " + tag, url);
|
||||
DialogResult dialogResult = MessageBox.Show(Properties.Strings.DownloadUpdate + ": G-Helper " + tag + "?", "Update", MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.Yes) AutoUpdate(url);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -314,6 +323,59 @@ namespace GHelper
|
||||
|
||||
}
|
||||
|
||||
void SetVersionLabel(string label, string url = null)
|
||||
{
|
||||
BeginInvoke(delegate
|
||||
{
|
||||
labelVersion.Text = label;
|
||||
if (url is not null)
|
||||
{
|
||||
this.versionUrl = url;
|
||||
labelVersion.ForeColor = Color.Red;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async void AutoUpdate(string requestUri)
|
||||
{
|
||||
|
||||
Uri uri = new Uri(requestUri);
|
||||
string filename = Path.GetFileName(uri.LocalPath);
|
||||
string exeLocation = Application.ExecutablePath;
|
||||
string exeDir = Path.GetDirectoryName(exeLocation);
|
||||
string zipLocation = exeDir + "\\" + filename;
|
||||
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.DownloadFile(uri, zipLocation);
|
||||
}
|
||||
|
||||
var cmd = new Process();
|
||||
cmd.StartInfo.UseShellExecute = false;
|
||||
cmd.StartInfo.CreateNoWindow = true;
|
||||
cmd.StartInfo.FileName = "powershell";
|
||||
cmd.StartInfo.Arguments = $"Start-Sleep -Seconds 1; Expand-Archive {zipLocation} -DestinationPath {exeDir} -Force; {exeLocation}";
|
||||
cmd.Start();
|
||||
|
||||
Debug.WriteLine(requestUri);
|
||||
Debug.WriteLine(zipLocation);
|
||||
|
||||
Application.Exit();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void LabelVersion_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (versionUrl.Contains(".zip"))
|
||||
AutoUpdate(versionUrl);
|
||||
else
|
||||
Process.Start(new ProcessStartInfo(versionUrl) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
private static void TrayIcon_MouseMove(object? sender, MouseEventArgs e)
|
||||
{
|
||||
Program.settingsForm.RefreshSensors();
|
||||
@@ -419,22 +481,8 @@ namespace GHelper
|
||||
}
|
||||
|
||||
|
||||
void SetVersionLabel(string label, string url = null)
|
||||
{
|
||||
labelVersion.Text = label;
|
||||
if (url is not null)
|
||||
{
|
||||
this.versionUrl = url;
|
||||
labelVersion.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LabelVersion_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(versionUrl) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
|
||||
private void CheckStartup_CheckedChanged(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user