From c4596155703cf22cf5d9cf734157eb509df9ed83 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 20 Mar 2023 20:40:28 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20Windows=20=E7=AB=AF=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=A3=80=E6=B5=8B=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/7717?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/electron-builder.yml | 1 + app/nsis/installer.nsh | 88 +++++++++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/app/electron-builder.yml b/app/electron-builder.yml index a9ad3c970..d4cb514ef 100644 --- a/app/electron-builder.yml +++ b/app/electron-builder.yml @@ -37,6 +37,7 @@ nsis: shortcutName: "SiYuan" license: "../LICENSE" include: "nsis/installer.nsh" + warningsAsErrors: false installerSidebar: "nsis/installerSidebar.bmp" uninstallerSidebar: "nsis/uninstallerSidebar.bmp" diff --git a/app/nsis/installer.nsh b/app/nsis/installer.nsh index edc03a84d..de611687d 100644 --- a/app/nsis/installer.nsh +++ b/app/nsis/installer.nsh @@ -2,19 +2,87 @@ Caption "${PRODUCT_NAME} ${VERSION}" !macro preInit - nsExec::Exec 'TASKKILL /F /IM "SiYuan.exe"' - nsExec::Exec 'TASKKILL /F /IM "SiYuan-Kernel.exe"' -!macroend - -!macro customInstallMode ${IfNot} ${AtLeastWin10} MessageBox MB_ICONEXCLAMATION "即将停止对 Windows 7/8 和 Server 2012 的支持,建议升级到 Windows 10 或者更高版本。$\n$\n\ Support for Windows 7/8 and Server 2012 will be stopped soon, it is recommended to upgrade to Windows 10 or higher version.$\n" ${EndIf} - MessageBox MB_ICONEXCLAMATION|MB_OKCANCEL "进行安装或卸载时会删除安装目录下所有文件,请务必确认工作空间没有放置在安装路径下!是否继续?$\n$\n\ - When installing or uninstalling, all files in the installation directory will be deleted, please make sure that the workspace is not placed in the installation path! Do you want to continue?$\n" IDOK yes IDCANCEL no - no: - Quit - yes: + nsExec::Exec 'TASKKILL /F /IM "SiYuan.exe"' + nsExec::Exec 'TASKKILL /F /IM "SiYuan-Kernel.exe"' !macroend + +!macro customUnInit + ${un.FindIt} "$INSTDIR" "data" $R0 + ${If} -1 != $R0 + MessageBox MB_ICONSTOP "检测到安装路径下包含了工作空间数据 $R0,请将工作空间文件夹移到其他位置后再试。$\n$\n\ + The workspace data $R0 was detected in the installation path, please move the workspace folder to another location and try again.$\n" + Quit + ${EndIf} +!macroend + + +# https://nsis.sourceforge.io/FindIt:_Simple_search_for_file_/_directory +!macro un.FindIt In For Result +Push "${In}" +Push "${For}" + Call un.FindIt +Pop "${Result}" +!macroend +!define un.FindIt "!insertmacro un.FindIt" + +Function un.FindIt +Exch $R0 +Exch +Exch $R1 +Push $R2 +Push $R3 +Push $R4 +Push $R5 +Push $R6 + + StrCpy $R6 -1 + StrCpy $R3 1 + + Push $R1 + + nextDir: + Pop $R1 + IntOp $R3 $R3 - 1 + ClearErrors + FindFirst $R5 $R2 "$R1\*.*" + + nextFile: + StrCmp $R2 "." gotoNextFile + StrCmp $R2 ".." gotoNextFile + + StrCmp $R2 $R0 0 isDir + StrCpy $R6 "$R1\$R2" + loop: + StrCmp $R3 0 done + Pop $R1 + IntOp $R3 $R3 - 1 + Goto loop + + isDir: + + IfFileExists "$R1\$R2\*.*" 0 gotoNextFile + IntOp $R3 $R3 + 1 + Push "$R1\$R2" + + gotoNextFile: + FindNext $R5 $R2 + IfErrors 0 nextFile + + done: + FindClose $R5 + StrCmp $R3 0 0 nextDir + StrCpy $R0 $R6 + +Pop $R6 +Pop $R5 +Pop $R4 +Pop $R3 +Pop $R2 +Pop $R1 +Exch $R0 +FunctionEnd \ No newline at end of file