Browse Source

fix(bundler/nsis): calculate accurate app size, closes #7056 (#7057)

Amr Bashir 2 years ago
parent
commit
1b8001b8b8

+ 5 - 0
.changes/nsis-accurate-app-size.md

@@ -0,0 +1,5 @@
+---
+'tauri-bundler': 'patch:bug'
+---
+
+Fix incorrect estimated app size for NSIS bundler when installed to a non-empty directory.

+ 11 - 3
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -500,23 +500,31 @@ SectionEnd
   app_check_done:
   app_check_done:
 !macroend
 !macroend
 
 
+Var AppSize
 Section Install
 Section Install
   SetOutPath $INSTDIR
   SetOutPath $INSTDIR
+  StrCpy $AppSize 0
 
 
   !insertmacro CheckIfAppIsRunning
   !insertmacro CheckIfAppIsRunning
 
 
   ; Copy main executable
   ; Copy main executable
   File "${MAINBINARYSRCPATH}"
   File "${MAINBINARYSRCPATH}"
+  ${GetSize} "$INSTDIR" "/M=${MAINBINARYNAME}.exe /S=0B" $0 $1 $2
+  IntOp $AppSize $AppSize + $0
 
 
   ; Copy resources
   ; Copy resources
   {{#each resources}}
   {{#each resources}}
     CreateDirectory "$INSTDIR\\{{this.[0]}}"
     CreateDirectory "$INSTDIR\\{{this.[0]}}"
     File /a "/oname={{this.[1]}}" "{{@key}}"
     File /a "/oname={{this.[1]}}" "{{@key}}"
+    ${GetSize} "$INSTDIR" "/M={{this.[1]}} /S=0B" $0 $1 $2
+    IntOp $AppSize $AppSize + $0
   {{/each}}
   {{/each}}
 
 
   ; Copy external binaries
   ; Copy external binaries
   {{#each binaries}}
   {{#each binaries}}
     File /a "/oname={{this}}" "{{@key}}"
     File /a "/oname={{this}}" "{{@key}}"
+    ${GetSize} "$INSTDIR" "/M={{this}} /S=0B" $0 $1 $2
+    IntOp $AppSize $AppSize + $0
   {{/each}}
   {{/each}}
 
 
   ; Create uninstaller
   ; Create uninstaller
@@ -540,9 +548,9 @@ Section Install
   WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
   WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1"
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1"
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1"
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1"
-  ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
-  IntFmt $0 "0x%08X" $0
-  WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$0"
+  IntOp $AppSize $AppSize / 1000
+  IntFmt $AppSize "0x%08X" $AppSize
+  WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$AppSize"
 
 
   ; Create start menu shortcut (GUI)
   ; Create start menu shortcut (GUI)
   !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
   !insertmacro MUI_STARTMENU_WRITE_BEGIN Application