installer.nsh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. !include WinVer.nsh
  2. Caption "${PRODUCT_NAME} ${VERSION}"
  3. !macro preInit
  4. ${IfNot} ${AtLeastWin10}
  5. MessageBox MB_ICONEXCLAMATION "非常抱歉,思源笔记无法在 Windows 10 以下的系统上进行安装$\n$\n\
  6. Sorry, SiYuan cannot be installed on systems below Windows 10$\n"
  7. Quit
  8. ${EndIf}
  9. nsExec::Exec 'TASKKILL /F /IM "SiYuan.exe"'
  10. nsExec::Exec 'TASKKILL /F /IM "SiYuan-Kernel.exe"'
  11. !macroend
  12. !macro customUnInit
  13. ${un.FindIt} "$INSTDIR" "data" $R0
  14. ${If} -1 != $R0
  15. MessageBox MB_ICONSTOP "检测到安装路径下包含了工作空间数据 $R0,请将工作空间文件夹移到其他位置后再试。$\n$\n\
  16. The workspace data $R0 was detected in the installation path, please move the workspace folder to another location and try again.$\n"
  17. Quit
  18. ${EndIf}
  19. !macroend
  20. !macro customUnInstall
  21. ${IfNot} ${isUpdated}
  22. MessageBox MB_YESNO "是否需要彻底删除全局配置($PROFILE\.config\siyuan\)?$\n$\n\
  23. Do you want to delete the global configuration ($PROFILE\.config\siyuan\)?$\n" \
  24. /SD IDYES IDYES AcceptedRMConf IDNO SkippedRMConf
  25. AcceptedRMConf:
  26. RMDir /r "$PROFILE\.config\siyuan\"
  27. SkippedRMConf:
  28. ${EndIf}
  29. ${IfNot} ${isUpdated}
  30. MessageBox MB_YESNO "是否需要彻底删除默认工作空间($PROFILE\SiYuan\)?$\n$\n\
  31. Do you want to completely delete the default workspace ($PROFILE\SiYuan\)?$\n" \
  32. /SD IDNO IDYES AcceptedRMWorkspace IDNO SkippedRMWrokspace
  33. AcceptedRMWorkspace:
  34. RMDir /r "$PROFILE\SiYuan\"
  35. RMDir /r "$PROFILE\Desktop\conf\"
  36. RMDir /r "$PROFILE\Desktop\data\"
  37. RMDir /r "$PROFILE\Desktop\temp\"
  38. SkippedRMWrokspace:
  39. ${EndIf}
  40. !macroend
  41. # https://nsis.sourceforge.io/FindIt:_Simple_search_for_file_/_directory
  42. !macro un.FindIt In For Result
  43. Push "${In}"
  44. Push "${For}"
  45. Call un.FindIt
  46. Pop "${Result}"
  47. !macroend
  48. !define un.FindIt "!insertmacro un.FindIt"
  49. Function un.FindIt
  50. Exch $R0
  51. Exch
  52. Exch $R1
  53. Push $R2
  54. Push $R3
  55. Push $R4
  56. Push $R5
  57. Push $R6
  58. StrCpy $R6 -1
  59. StrCpy $R3 1
  60. Push $R1
  61. nextDir:
  62. Pop $R1
  63. IntOp $R3 $R3 - 1
  64. ClearErrors
  65. FindFirst $R5 $R2 "$R1\*.*"
  66. nextFile:
  67. StrCmp $R2 "." gotoNextFile
  68. StrCmp $R2 ".." gotoNextFile
  69. StrCmp $R2 $R0 0 isDir
  70. StrCpy $R6 "$R1\$R2"
  71. loop:
  72. StrCmp $R3 0 done
  73. Pop $R1
  74. IntOp $R3 $R3 - 1
  75. Goto loop
  76. isDir:
  77. IfFileExists "$R1\$R2\*.*" 0 gotoNextFile
  78. IntOp $R3 $R3 + 1
  79. Push "$R1\$R2"
  80. gotoNextFile:
  81. FindNext $R5 $R2
  82. IfErrors 0 nextFile
  83. done:
  84. FindClose $R5
  85. StrCmp $R3 0 0 nextDir
  86. StrCpy $R0 $R6
  87. Pop $R6
  88. Pop $R5
  89. Pop $R4
  90. Pop $R3
  91. Pop $R2
  92. Pop $R1
  93. Exch $R0
  94. FunctionEnd