[英]Electron-builder (NSIS): do not ask about deleting data on reinstall (cannot distinguish reinstall and uninstall)
我使用 Electron-builder(版本 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
所以我們用一個變量來區分app什么時候重裝,什么時候卸載。 在我們更新 electron-builder(以前的版本 22.11.7)和 electron(以前的版本是 13.1.6)之前,它一直在工作。 現在的問題是變量在重新安裝時不存儲值“install”,並且對話框總是出現,在重新安裝時也是如此。 任何幫助都會很棒。
該問題已通過文檔中提到的標志isUpdated
解決。 ( https://www.electron.build/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
很簡單。 前段時間我嘗試使用它,但由於某種原因它無法正常工作。 不行,我們不需要使用變量!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.