feat: add nsis-string plugin (#43)

This commit is contained in:
Amr Bashir
2025-05-25 10:01:13 +03:00
committed by GitHub
parent acb9ff9d1a
commit c04ba07154
8 changed files with 79 additions and 5 deletions

View File

@@ -63,6 +63,16 @@
"name": "${ pkg.pkg }.dll"
}
]
},
"nsis_string": {
"path": "./crates/nsis-string",
"manager": "rust",
"assets": [
{
"path": "target/i686-pc-windows-msvc/release/${ pkg.pkg }.dll",
"name": "${ pkg.pkg }.dll"
}
]
}
}
}

5
.changes/nsis-string.md Normal file
View File

@@ -0,0 +1,5 @@
---
"nsis_string": "minor"
---
Initial Release

View File

@@ -6,6 +6,7 @@ A collection of NSIS plugins written in rust.
| -------------------------------------------------- | ------------------------------------------------------------------------ |
| [nsis-process](./crates/nsis-process/) | Find and Kill processes, and run program as unelevated user |
| [nsis-semvercompare](./crates/nsis-semvercompare/) | Compare two semantic versions |
| [nsis-string](./crates/nsis-string/) | String manipulation |
| [nsis-tauri-utils](./crates/nsis-tauri-utils/) | A collection of all the above plugins into a single DLL for smaller size |
## License

View File

@@ -93,7 +93,7 @@ fn KillProcess() -> Result<(), Error> {
let processes = get_processes(&name);
if !processes.is_empty() && processes.into_iter().map(kill).all(|b| b) {
if !processes.is_empty() && processes.into_iter().all(kill) {
push(ZERO)
} else {
push(ONE)
@@ -119,10 +119,9 @@ fn KillProcessCurrentUser() -> Result<(), Error> {
processes
.into_iter()
.filter(|pid| belongs_to_user(user_sid, *pid))
.map(kill)
.all(|b| b)
.all(kill)
} else {
processes.into_iter().map(kill).all(|b| b)
processes.into_iter().all(kill)
};
if success {
@@ -388,7 +387,7 @@ mod tests {
let processes = get_processes("something_that_doesnt_exist.exe");
// TODO: maybe find some way to spawn a dummy process we can kill here?
// This will return true on empty iterators so it's basically no-op right now
assert!(processes.into_iter().map(kill).all(|b| b));
assert!(processes.into_iter().all(kill));
}
#[test]

View File

@@ -0,0 +1,14 @@
# Changelog
## \[0.3.0]
- [`5423579`](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/5423579860016c4f3074831eda03096ee4854e73)([#26](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/26)) Reduce the DLL size by using `no_std` and without static msvcrt.
## \[0.2.0]
- [`33ea4bc`](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/33ea4bcf2a573461ebc5181ef2921d8746005049)([#17](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/17)) Statically link CRT.
## \[0.1.0]
- Initial Release.
- [000d632](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/000d6326333f862741f1514de34542316445951e) ci: setup CI/CD and covector ([#2](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/2)) on 2023-01-21

View File

@@ -0,0 +1,16 @@
[package]
name = "nsis-string"
version = "0.0.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
[lib]
crate-type = ["cdylib"]
[features]
test = []
[dependencies]
nsis-plugin-api = { workspace = true }
windows-sys = { workspace = true }

View File

@@ -0,0 +1,5 @@
fn main() {
if std::env::var("CARGO_FEATURE_TEST").as_deref() != Ok("1") {
println!("cargo::rustc-link-arg=/ENTRY:DllMain")
}
}

View File

@@ -0,0 +1,24 @@
#![no_std]
use nsis_plugin_api::*;
nsis_plugin!();
/// Replaces all occurrences of a substring in a string with another substring.
///
/// Returns the modified string.
///
/// # Safety
///
/// This function always expects 3 strings on the stack ($string, $search, $replace) and will panic otherwise.
#[nsis_fn]
fn Replace() -> Result<(), Error> {
let string = popstr()?;
let search = popstr()?;
let replace = popstr()?;
let result = string.replace(&search, &replace);
pushstr(&result)?;
Ok(())
}