Skip to content

Commit

Permalink
Add build number function separated
Browse files Browse the repository at this point in the history
  • Loading branch information
akorovacki committed Jan 5, 2025
1 parent 815fbb7 commit 77ea045
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ OutFile "${OUTFILE}"
!define PLACEHOLDER_INSTALL_DIR "placeholder\${PRODUCTNAME}"
InstallDir "${PLACEHOLDER_INSTALL_DIR}"

VIProductVersion "${VERSIONWITHBUILD}"
VIProductVersion "${VERSION}"
VIAddVersionKey "ProductName" "${PRODUCTNAME}"
VIAddVersionKey "FileDescription" "${PRODUCTNAME}"
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
VIAddVersionKey "FileVersion" "${VERSION}"
VIAddVersionKey "ProductVersion" "${VERSION}"
VIAddVersionKey "ProductVersion" "${VERSIONWITHBUILD}"

; Plugins path, currently exists for linux only
!if "${PLUGINSPATH}" != ""
Expand Down
27 changes: 21 additions & 6 deletions crates/tauri-bundler/src/bundle/windows/nsis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,25 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
Ok(())
}

fn add_build_number_if_needed(version_str: &str) -> anyhow::Result<String> {
fn try_add_numeric_build_number(version_str: &str) -> anyhow::Result<String> {
let version = semver::Version::parse(version_str).context("invalid app version")?;
if !version.build.is_empty() {
let build = version.build.parse::<u64>();
if build.is_ok() {
return Ok(format!(
"{}.{}.{}.{}",
version.major, version.minor, version.patch, version.build
));
}
}

Ok(format!(
"{}.{}.{}.0",
version.major, version.minor, version.patch,
))
}

fn add_build_number(version_str: &str) -> anyhow::Result<String> {
let version = semver::Version::parse(version_str).context("invalid app version")?;
if !version.build.is_empty() {
return Ok(format!(
Expand Down Expand Up @@ -207,11 +225,8 @@ fn build_nsis_app_installer(
}

let version = settings.version_string();
data.insert("version", to_json(version));
data.insert(
"version_with_build",
to_json(add_build_number_if_needed(version)?),
);
data.insert("version", to_json(try_add_numeric_build_number(version)?));
data.insert("version_with_build", to_json(add_build_number(version)?));

data.insert(
"allow_downgrades",
Expand Down

0 comments on commit 77ea045

Please sign in to comment.