Skip to content

Commit

Permalink
Merge branch 'main' into feat/dmg-config
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Nov 30, 2023
2 parents 1f74c12 + 43ab529 commit cf1d16b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ base64 = "0.21"
tracing = "0.1"
time = "0.3"
tar = "0.4"
napi = { version = "2.12.2", default-features = false }
napi-derive = "2.12"
napi = { version = "2.14", default-features = false }
napi-derive = "2.14"
napi-build = "2.1.0"

[profile.release-size-optimized]
Expand Down
4 changes: 2 additions & 2 deletions crates/packager/src/package/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn create_info_plist(
"CFBundleTypeExtensions".into(),
plist::Value::Array(
association
.ext
.extensions
.iter()
.map(|ext| ext.to_string().into())
.collect(),
Expand All @@ -199,7 +199,7 @@ fn create_info_plist(
association
.name
.as_ref()
.unwrap_or(&association.ext[0])
.unwrap_or(&association.extensions[0])
.to_string()
.into(),
);
Expand Down
13 changes: 2 additions & 11 deletions crates/packager/src/package/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 27 additions & 6 deletions crates/packager/src/package/nsis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ const NSIS_REQUIRED_FILES: &[&str] = &[
];

type DirectoriesSet = BTreeSet<PathBuf>;
type ResourcesMap = Vec<(PathBuf, PathBuf)>;
type ResourcesMap = BTreeMap<PathBuf, PathBuf>;

#[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
.parent()
.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))
}
Expand Down Expand Up @@ -234,6 +234,23 @@ fn add_build_number_if_needed(version_str: &str) -> crate::Result<String> {
))
}

fn generate_estimated_size<I, P, P2>(main: P, other_files: I) -> crate::Result<String>
where
I: IntoIterator<Item = P2>,
P: AsRef<Path>,
P2: AsRef<Path>,
{
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,
Expand Down Expand Up @@ -422,7 +439,7 @@ fn build_nsis_app_installer(ctx: &Context, nsis_path: &Path) -> crate::Result<Ve
);

data.insert("main_binary_name", to_json(&main_binary_name));
data.insert("main_binary_path", to_json(main_binary_path));
data.insert("main_binary_path", to_json(&main_binary_path));

if let Some(file_associations) = &config.file_associations {
data.insert("file_associations", to_json(file_associations));
Expand All @@ -433,10 +450,14 @@ fn build_nsis_app_installer(ctx: &Context, nsis_path: &Path) -> crate::Result<Ve

let (resources_dirs, resources) = generate_resource_data(config)?;
data.insert("resources_dirs", to_json(resources_dirs));
data.insert("resources", to_json(resources));
data.insert("resources", to_json(&resources));

let binaries = generate_binaries_data(config)?;
data.insert("binaries", to_json(binaries));
data.insert("binaries", to_json(&binaries));

let estimated_size =
generate_estimated_size(main_binary_path, resources.keys().chain(binaries.keys()))?;
data.insert("estimated_size", to_json(estimated_size));

let mut handlebars = Handlebars::new();
handlebars.register_helper("or", Box::new(handlebars_or));
Expand Down

0 comments on commit cf1d16b

Please sign in to comment.