diff --git a/crates/packager/src/package/nsis/installer.nsi b/crates/packager/src/package/nsis/installer.nsi index a32afd4b..ec26f9cb 100644 --- a/crates/packager/src/package/nsis/installer.nsi +++ b/crates/packager/src/package/nsis/installer.nsi @@ -39,6 +39,7 @@ ${StrLoc} !define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}" !define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}" !define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}" +!define ESTIMATEDSIZE "{{estimated_size}}" Name "${PRODUCTNAME}" BrandingText "${COPYRIGHT}" @@ -468,17 +469,13 @@ SectionEnd app_check_done: !macroend -Var AppSize Section Install SetOutPath $INSTDIR - StrCpy $AppSize 0 !insertmacro CheckIfAppIsRunning ; Copy main executable File "${MAINBINARYSRCPATH}" - ${GetSize} "$INSTDIR" "/M=${MAINBINARYNAME}.exe /S=0B" $0 $1 $2 - IntOp $AppSize $AppSize + $0 ; Create resources directory structure {{#each resources_dirs}} @@ -488,15 +485,11 @@ Section Install ; Copy resources {{#each resources}} File /a "/oname={{this.[1]}}" "{{this.[0]}}" - ${GetSize} "$INSTDIR" "/M={{this.[1]}} /S=0B" $0 $1 $2 - IntOp $AppSize $AppSize + $0 {{/each}} ; Copy external binaries {{#each binaries}} File /a "/oname={{this}}" "{{@key}}" - ${GetSize} "$INSTDIR" "/M={{this}} /S=0B" $0 $1 $2 - IntOp $AppSize $AppSize + $0 {{/each}} ; Create file associations @@ -527,9 +520,7 @@ Section Install WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1" WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1" - IntOp $AppSize $AppSize / 1000 - IntFmt $AppSize "0x%08X" $AppSize - WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$AppSize" + WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "${ESTIMATEDSIZE}" ; Create start menu shortcut (GUI) !insertmacro MUI_STARTMENU_WRITE_BEGIN Application diff --git a/crates/packager/src/package/nsis/mod.rs b/crates/packager/src/package/nsis/mod.rs index 10f5005f..3ff4a7d0 100644 --- a/crates/packager/src/package/nsis/mod.rs +++ b/crates/packager/src/package/nsis/mod.rs @@ -53,12 +53,12 @@ const NSIS_REQUIRED_FILES: &[&str] = &[ ]; type DirectoriesSet = BTreeSet; -type ResourcesMap = Vec<(PathBuf, PathBuf)>; +type ResourcesMap = BTreeMap; #[tracing::instrument(level = "trace")] fn generate_resource_data(config: &Config) -> crate::Result<(DirectoriesSet, ResourcesMap)> { let mut directories = BTreeSet::new(); - let mut resources_map = Vec::new(); + let mut resources_map = BTreeMap::new(); for r in config.resources()? { directories.insert( r.target @@ -66,7 +66,7 @@ fn generate_resource_data(config: &Config) -> crate::Result<(DirectoriesSet, Res .unwrap_or_else(|| Path::new("")) .to_path_buf(), ); - resources_map.push((r.src, r.target)) + resources_map.insert(r.src, r.target); } Ok((directories, resources_map)) } @@ -234,6 +234,23 @@ fn add_build_number_if_needed(version_str: &str) -> crate::Result { )) } +fn generate_estimated_size(main: P, other_files: I) -> crate::Result +where + I: IntoIterator, + P: AsRef, + P2: AsRef, +{ + let mut size = std::fs::metadata(main)?.len(); + + for k in other_files { + size += std::fs::metadata(k)?.len(); + } + + size /= 1000; + + Ok(format!("{size:#08x}")) +} + #[tracing::instrument(level = "trace")] fn get_and_extract_nsis( #[allow(unused)] ctx: &Context, @@ -421,7 +438,7 @@ fn build_nsis_app_installer(ctx: &Context, nsis_path: &Path) -> crate::Result crate::Result