电子构建器(NSIS):不要询问有关删除重新安装的数据(无法区分重新安装和卸载)

发布于 2025-01-23 03:23:09 字数 1182 浏览 2 评论 0原文

我使用电子构建器(版本22.14.13)为我们的应用程序(Windows)创建安装程序。

我需要创建自定义安装程序,因此,当用户卸载应用程序时,对话框如果要删除应用程序数据,则会出现对话框。

问题在于,如果用户重新安装应用程序(在现有一个上安装)时,不应询问他,并且应保存应用程序数据。基于有类似问题的人的答案(#5633 #4141 )我来了下一个解决方案。我使用以下脚本定制宏:

!macro customInit
  #If app is installed over previous version we shouldn't ask whether to delete app data or not
  StrCpy $1 "install"
!macroend

!macro customUnInit
  SetSilent normal
!macroend

!macro customUnInstall
  ${if} $1 == "install"
    Goto done
  ${EndIf}

  MessageBox MB_YESNO "Delete application data?" \
    /SD IDNO IDNO Skipped IDYES Accepted

  Accepted:
    !ifdef APP_PRODUCT_FILENAME
      RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
    !endif
    Goto done
  Skipped:
    Goto done
  done:
!macroend

因此,我们使用一个变量来区分应用程序何时重新安装以及何时被卸载。它一直在工作,直到我们更新电子构建器(以前的版本22.11.7)和电子(以前的版本为13.1.6)。 现在的问题是,变量不会在重新安装上存储“安装”,并且对话框也总是在重新安装上出现。任何帮助都会很棒。

I use Electron-builder (of version 22.14.13) to create installer for our app (Windows).

I needed to create custom installer, so when user uninstalls the app the dialog appears if he wants to remove app data either or not.

The problem was that in case when user reinstalls app (installing over existing one) he shouldn't be asked about that and app data should be saved. Based on answers of people with similar issues (#5633, #4141) I've come to the next solution. I customized macros with following script:

!macro customInit
  #If app is installed over previous version we shouldn't ask whether to delete app data or not
  StrCpy $1 "install"
!macroend

!macro customUnInit
  SetSilent normal
!macroend

!macro customUnInstall
  ${if} $1 == "install"
    Goto done
  ${EndIf}

  MessageBox MB_YESNO "Delete application data?" \
    /SD IDNO IDNO Skipped IDYES Accepted

  Accepted:
    !ifdef APP_PRODUCT_FILENAME
      RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
    !endif
    Goto done
  Skipped:
    Goto done
  done:
!macroend

So we use a variable to distinguish when app is reinstalled and when it's uninstalled. It was working until we updated electron-builder (previous version 22.11.7) and electron (previous version was 13.1.6).
The problem now is that variable doesn't store value "install" on reinstall and the dialog always appears, on reinstall too. Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2025-01-30 03:23:09

使用文档中提到的标志的标志解决了该问题。 ( https://wwwwwww.electron.build/configuration/configuration/nsis.html

更新的脚本看起来像这样:

!macro customUnInstall
  # when App is updated we want to preserve user data by default
  ${if} ${isUpdated}
    Goto done
  ${endIf}


  MessageBox MB_YESNO "Delete application data?" \
    /SD IDNO IDNO Skipped IDYES Accepted

  Accepted:
    !ifdef APP_PRODUCT_FILENAME
      RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
    !endif
    Goto done
  Skipped:
    Goto done
  done:
!macroend

很简单。我尝试使用它前一段时间,这是由于某种原因无法正常工作。它不起作用,我们不需要使用变量!

The problem was solved with a flag isUpdated which is mentioned in documentation. (https://www.electron.build/configuration/nsis.html)

So updated script looks like this:

!macro customUnInstall
  # when App is updated we want to preserve user data by default
  ${if} ${isUpdated}
    Goto done
  ${endIf}


  MessageBox MB_YESNO "Delete application data?" \
    /SD IDNO IDNO Skipped IDYES Accepted

  Accepted:
    !ifdef APP_PRODUCT_FILENAME
      RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
    !endif
    Goto done
  Skipped:
    Goto done
  done:
!macroend

So simple. I tried to use it some time ago and by some reason it wasn't working. Not it works and we don't need to use variable!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文