From dace6ad486879ac20c2e49f7ef8ed0b247164875 Mon Sep 17 00:00:00 2001 From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com> Date: Wed, 18 Jun 2025 16:08:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomaticUpdateVersionControl.txt | 2 +- Ink Canvas/Helpers/AutoUpdateHelper.cs | 61 ++++++++++++++++-- Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs | 13 +++- .../net472/InkCanvasForClass.g.resources | Bin 5178682 -> 5178682 bytes 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/AutomaticUpdateVersionControl.txt b/AutomaticUpdateVersionControl.txt index f5d2a585..0cb79294 100644 --- a/AutomaticUpdateVersionControl.txt +++ b/AutomaticUpdateVersionControl.txt @@ -1 +1 @@ -1.6.3 \ No newline at end of file +1.6.3.0 \ No newline at end of file diff --git a/Ink Canvas/Helpers/AutoUpdateHelper.cs b/Ink Canvas/Helpers/AutoUpdateHelper.cs index 2133efc5..25b63b4f 100644 --- a/Ink Canvas/Helpers/AutoUpdateHelper.cs +++ b/Ink Canvas/Helpers/AutoUpdateHelper.cs @@ -19,30 +19,37 @@ namespace Ink_Canvas.Helpers try { string localVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + LogHelper.WriteLogToFile($"AutoUpdate | Local version: {localVersion}"); + string remoteAddress = proxy; remoteAddress += "https://github.com/awesome-iwb/icc-ce/blob/main/AutomaticUpdateVersionControl.txt"; string remoteVersion = await GetRemoteVersion(remoteAddress); if (remoteVersion != null) { + LogHelper.WriteLogToFile($"AutoUpdate | Remote version: {remoteVersion}"); Version local = new Version(localVersion); Version remote = new Version(remoteVersion); if (remote > local) { - LogHelper.WriteLogToFile("AutoUpdate | New version Availble: " + remoteVersion); + LogHelper.WriteLogToFile($"AutoUpdate | New version available: {remoteVersion}"); return remoteVersion; } - else return null; + else + { + LogHelper.WriteLogToFile($"AutoUpdate | Current version is up to date"); + return null; + } } else { - LogHelper.WriteLogToFile("Failed to retrieve remote version.", LogHelper.LogType.Error); + LogHelper.WriteLogToFile("AutoUpdate | Failed to retrieve remote version.", LogHelper.LogType.Error); return null; } } catch (Exception ex) { - Console.WriteLine($"AutoUpdate | Error: {ex.Message}"); + LogHelper.WriteLogToFile($"AutoUpdate | Error in CheckForUpdates: {ex.Message}", LogHelper.LogType.Error); return null; } } @@ -53,15 +60,59 @@ namespace Ink_Canvas.Helpers { try { + // Set a reasonable timeout + client.Timeout = TimeSpan.FromSeconds(15); + + LogHelper.WriteLogToFile($"AutoUpdate | Sending HTTP request to: {fileUrl}"); HttpResponseMessage response = await client.GetAsync(fileUrl); + + LogHelper.WriteLogToFile($"AutoUpdate | HTTP response status: {response.StatusCode}"); response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); + string content = await response.Content.ReadAsStringAsync(); + // Trim any whitespace, newlines, etc. + content = content.Trim(); + + // If the content contains HTML (likely the GitHub view page instead of raw content), + // try to extract the version number + if (content.Contains(" 0) + { + int endPos = content.IndexOf("", startPos); + if (endPos > startPos) + { + string tableContent = content.Substring(startPos, endPos - startPos); + // Look for the version number pattern (like 1.2.3 or 1.2.3.4) + var match = System.Text.RegularExpressions.Regex.Match(tableContent, @"(\d+\.\d+\.\d+(\.\d+)?)"); + if (match.Success) + { + content = match.Groups[1].Value; + LogHelper.WriteLogToFile($"AutoUpdate | Extracted version from HTML: {content}"); + } + else + { + LogHelper.WriteLogToFile($"AutoUpdate | Could not extract version from HTML content"); + return null; + } + } + } + } + + LogHelper.WriteLogToFile($"AutoUpdate | Response content: {content}"); + return content; } catch (HttpRequestException ex) { LogHelper.WriteLogToFile($"AutoUpdate | HTTP request error: {ex.Message}", LogHelper.LogType.Error); } + catch (TaskCanceledException ex) + { + LogHelper.WriteLogToFile($"AutoUpdate | Request timed out: {ex.Message}", LogHelper.LogType.Error); + } catch (Exception ex) { LogHelper.WriteLogToFile($"AutoUpdate | Error: {ex.Message}", LogHelper.LogType.Error); diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs index c974d1a3..0f1f851e 100644 --- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs +++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs @@ -70,8 +70,17 @@ namespace Ink_Canvas { BoundsWidth = Settings.Advanced.FingerModeBoundsWidth; } - if (Settings.Startup.IsAutoUpdate) { - ToggleSwitchIsAutoUpdate.IsOn = true; + // Always show update setting in UI based on stored preference + ToggleSwitchIsAutoUpdate.IsOn = Settings.Startup.IsAutoUpdate; + + // Always check for updates at startup, regardless of the setting + if (isStartup) { + LogHelper.WriteLogToFile("AutoUpdate | Running auto-update check at startup"); + AutoUpdate(); + } + // Call auto-update when setting is changed (not at startup) + else if (Settings.Startup.IsAutoUpdate) { + LogHelper.WriteLogToFile("AutoUpdate | Running auto-update check after settings change"); AutoUpdate(); } diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources index d8812017ff81516474557b2ebe1dda906a3ab646..61cfb4ff1244e1d950ed0729f04954dd3423bd0e 100644 GIT binary patch delta 478 zcmZ9|xlRI66vpv@j0}PfqPXD#cwJ$19QR$B0bFlQKaXK)VKSW|hKhF}THJ)t*!lum z`w%8}{*y_@gyNT+^PO{=)Af7NE;>mkVmIGi@n$(6wV-TTj`k@0C*emB#Q|QW(Yv45TrN48|~yEG96CDNJJqIm}`X^H@M01r)Iefh8WH~92dAm1rA(PQ9~V9xW)}`ai@fT|NIrc&}><4sVl>i y6*~+y_3$FSc-WhYrAGF@501WH<&WMMwi=$yD7Po;xnQC?pHeIIZ7JhdmQsHw-KJsy delta 478 zcmZ9|yG{a85XSLr+)b#rpmKG-48Dgk>2cpGE2#qZ- zptTQSV&^~EWKAf3$;>x1&2+t9xQkBI4i#G;j(E51e%&uymaRPs?@4$egfWC+Xc$2R zIz};uC}J2#90n#Zi3FxFjU;A}!Yt-6k2DsL!6KHBMGnhYfxs%(u#OFEVhed}!^94D zVPOvi6tRy39O4MaI6(