diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index e291473b..dbf19944 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -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); } } diff --git a/app/Gpu/AmdGpuControl.cs b/app/Gpu/AmdGpuControl.cs index 6352b3d4..745674d9 100644 --- a/app/Gpu/AmdGpuControl.cs +++ b/app/Gpu/AmdGpuControl.cs @@ -11,7 +11,7 @@ public class AmdGpuControl : IGpuControl { public bool IsNvidia => false; - + public string FullName => _internalDiscreteAdapter!.AdapterName; public AmdGpuControl() { if (!Adl2.Load()) return; diff --git a/app/Gpu/IGpuControl.cs b/app/Gpu/IGpuControl.cs index cd7d6639..0fd640ca 100644 --- a/app/Gpu/IGpuControl.cs +++ b/app/Gpu/IGpuControl.cs @@ -3,6 +3,7 @@ public interface IGpuControl : IDisposable { bool IsNvidia { get; } bool IsValid { get; } + public string FullName { get; } int? GetCurrentTemperature(); int? GetGpuUse(); } diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 0c5e68cb..99d2edd8 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -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 diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index 53202484..612cde2f 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -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 // diff --git a/app/Settings.cs b/app/Settings.cs index 1b0a0653..4a31beca 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -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 @@ -293,11 +297,16 @@ namespace GHelper var url = config.GetProperty("assets")[0].GetProperty("browser_download_url").ToString(); var gitVersion = new Version(tag); - var appVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString()); + 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) {