From 7b4d13c16ff8c176e8bfeba3a98b49fd0bbbb6e6 Mon Sep 17 00:00:00 2001 From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com> Date: Wed, 18 Jun 2025 15:40:07 +0800 Subject: [PATCH] =?UTF-8?q?update:=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/AutoUpdateHelper.cs | 93 +++++++++++++++--- .../net472/InkCanvasForClass.g.resources | Bin 5178682 -> 5178682 bytes 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Ink Canvas/Helpers/AutoUpdateHelper.cs b/Ink Canvas/Helpers/AutoUpdateHelper.cs index dd3059c7..2133efc5 100644 --- a/Ink Canvas/Helpers/AutoUpdateHelper.cs +++ b/Ink Canvas/Helpers/AutoUpdateHelper.cs @@ -8,6 +8,7 @@ using System.Windows; using System.Collections.ObjectModel; using System.Linq; using System.Windows.Controls; +using System.IO.Compression; namespace Ink_Canvas.Helpers { @@ -19,7 +20,7 @@ namespace Ink_Canvas.Helpers { string localVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); string remoteAddress = proxy; - remoteAddress += "https://github.com/CJKmkp/ICC-CE/blob/main/AutomaticUpdateVersionControl.txt"; + remoteAddress += "https://github.com/awesome-iwb/icc-ce/blob/main/AutomaticUpdateVersionControl.txt"; string remoteVersion = await GetRemoteVersion(remoteAddress); if (remoteVersion != null) @@ -85,10 +86,11 @@ namespace Ink_Canvas.Helpers return true; } - string downloadUrl = $"{proxy}https://github.com/ChangSakura/Ink-Canvas/releases/download/v{version}/Ink.Canvas.Annotation.V{version}.Setup.exe"; + string downloadUrl = $"{proxy}https://github.com/awesome-iwb/icc-ce/releases/download/{version}/InkCanvasForClass.CE.{version}.zip"; SaveDownloadStatus(false); - await DownloadFile(downloadUrl, $"{updatesFolderPath}\\Ink.Canvas.Annotation.V{version}.Setup.exe"); + string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip"); + await DownloadFile(downloadUrl, zipFilePath); SaveDownloadStatus(true); LogHelper.WriteLogToFile("AutoUpdate | Setup file successfully downloaded."); @@ -96,7 +98,7 @@ namespace Ink_Canvas.Helpers } catch (Exception ex) { - LogHelper.WriteLogToFile($"AutoUpdate | Error downloading and installing update: {ex.Message}", LogHelper.LogType.Error); + LogHelper.WriteLogToFile($"AutoUpdate | Error downloading update: {ex.Message}", LogHelper.LogType.Error); SaveDownloadStatus(false); return false; @@ -155,21 +157,43 @@ namespace Ink_Canvas.Helpers { try { - string setupFilePath = Path.Combine(updatesFolderPath, $"Ink.Canvas.Annotation.V{version}.Setup.exe"); + string zipFilePath = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip"); - if (!File.Exists(setupFilePath)) + if (!File.Exists(zipFilePath)) { - LogHelper.WriteLogToFile($"AutoUpdate | Setup file not found: {setupFilePath}", LogHelper.LogType.Error); + LogHelper.WriteLogToFile($"AutoUpdate | ZIP file not found: {zipFilePath}", LogHelper.LogType.Error); return; } - string InstallCommand = $"\"{setupFilePath}\" /SILENT"; - if (isInSilence) InstallCommand += " /VERYSILENT"; - ExecuteCommandLine(InstallCommand); - Application.Current.Dispatcher.Invoke(() => + // 创建临时解压目录 + string extractPath = Path.Combine(updatesFolderPath, $"Extract_{version}"); + if (Directory.Exists(extractPath)) { - Application.Current.Shutdown(); - }); + Directory.Delete(extractPath, true); + } + Directory.CreateDirectory(extractPath); + + // 解压ZIP文件 + LogHelper.WriteLogToFile($"AutoUpdate | Extracting ZIP file to: {extractPath}"); + ZipFile.ExtractToDirectory(zipFilePath, extractPath); + + // 获取当前应用程序路径 + string currentAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + LogHelper.WriteLogToFile($"AutoUpdate | Current application directory: {currentAppDir}"); + + // 复制解压的文件到应用程序目录 + LogHelper.WriteLogToFile($"AutoUpdate | Copying files to application directory"); + CopyDirectory(extractPath, currentAppDir); + + // 清理临时文件 + if (Directory.Exists(extractPath)) + { + Directory.Delete(extractPath, true); + } + + // 重启应用程序 + LogHelper.WriteLogToFile($"AutoUpdate | Update completed, restarting application"); + RestartApplication(); } catch (Exception ex) { @@ -177,6 +201,49 @@ namespace Ink_Canvas.Helpers } } + private static void CopyDirectory(string sourceDir, string destinationDir) + { + // 创建目标目录(如果不存在) + Directory.CreateDirectory(destinationDir); + + // 复制所有文件 + foreach (string filePath in Directory.GetFiles(sourceDir)) + { + string fileName = Path.GetFileName(filePath); + string destPath = Path.Combine(destinationDir, fileName); + try + { + // 如果目标文件存在,先删除 + if (File.Exists(destPath)) + { + File.Delete(destPath); + } + File.Copy(filePath, destPath); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"AutoUpdate | Error copying file {fileName}: {ex.Message}", LogHelper.LogType.Error); + } + } + + // 递归复制所有子目录 + foreach (string subDirPath in Directory.GetDirectories(sourceDir)) + { + string subDirName = Path.GetFileName(subDirPath); + string destSubDir = Path.Combine(destinationDir, subDirName); + CopyDirectory(subDirPath, destSubDir); + } + } + + private static void RestartApplication() + { + string appPath = Assembly.GetExecutingAssembly().Location; + Process.Start(appPath); + Application.Current.Dispatcher.Invoke(() => + { + Application.Current.Shutdown(); + }); + } private static void ExecuteCommandLine(string command) { diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources index 977fc01171f075340462a0fb8bd14ecab48a1632..d8812017ff81516474557b2ebe1dda906a3ab646 100644 GIT binary patch delta 514 zcmZwEyG{Z@6vpv@uDdFVqIkm_I9_qr1r+ay&Vu);EbJ_J3`+}>O{|Ea@*Rj4lMosk zUqNdh!OqTqV$5a}i(hfhH#s>u)AHNV7Mi9sa!%1H)L%XE;>x#bP}W^(+zJ0)_z^_W zfle6cf(Z-V=s_=H=tDo^7{DMB7{V};7{MsUFpdeNFo`KlV+ONGBZD~z%wqwISi&+^ zki{x&I9P*=9P%h&9UCZO6IxlRI66oBD~%b+4Cf*Yc!qXVKNi{pkOFo^r5gvMC#7?u!kij92ki{`_$fE!oMVz37Q=H)(7r4Zg)Sc`5j(Ww4 z^wmT*r6xn(J&0Samn7GJ4)&(MUsUAxtN3yMOU-Ic_+_yz?2y{a^7BKyN7Tf|UlI3o E0fJGfYybcN